gpu_driver_bug_list.cc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Copyright (c) 2013 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "gpu/config/gpu_driver_bug_list.h"
  5. #include "base/check_op.h"
  6. #include "gpu/config/gpu_driver_bug_list_autogen.h"
  7. #include "gpu/config/gpu_driver_bug_workaround_type.h"
  8. #include "gpu/config/gpu_switches.h"
  9. #include "gpu/config/gpu_util.h"
  10. namespace gpu {
  11. namespace {
  12. struct GpuDriverBugWorkaroundInfo {
  13. GpuDriverBugWorkaroundType type;
  14. const char* name;
  15. };
  16. const GpuDriverBugWorkaroundInfo kFeatureList[] = {
  17. #define GPU_OP(type, name) { type, #name },
  18. GPU_DRIVER_BUG_WORKAROUNDS(GPU_OP)
  19. #undef GPU_OP
  20. };
  21. } // namespace anonymous
  22. GpuDriverBugList::GpuDriverBugList(const GpuControlListData& data)
  23. : GpuControlList(data) {}
  24. GpuDriverBugList::~GpuDriverBugList() = default;
  25. // static
  26. std::unique_ptr<GpuDriverBugList> GpuDriverBugList::Create() {
  27. GpuControlListData data(kGpuDriverBugListEntryCount,
  28. kGpuDriverBugListEntries);
  29. return Create(data);
  30. }
  31. // static
  32. std::unique_ptr<GpuDriverBugList> GpuDriverBugList::Create(
  33. const GpuControlListData& data) {
  34. std::unique_ptr<GpuDriverBugList> list(new GpuDriverBugList(data));
  35. DCHECK_EQ(static_cast<int>(std::size(kFeatureList)),
  36. NUMBER_OF_GPU_DRIVER_BUG_WORKAROUND_TYPES);
  37. for (int i = 0; i < NUMBER_OF_GPU_DRIVER_BUG_WORKAROUND_TYPES; ++i) {
  38. list->AddSupportedFeature(kFeatureList[i].name,
  39. kFeatureList[i].type);
  40. }
  41. return list;
  42. }
  43. std::string GpuDriverBugWorkaroundTypeToString(
  44. GpuDriverBugWorkaroundType type) {
  45. if (type < NUMBER_OF_GPU_DRIVER_BUG_WORKAROUND_TYPES)
  46. return kFeatureList[type].name;
  47. else
  48. return "unknown";
  49. }
  50. // static
  51. void GpuDriverBugList::AppendWorkaroundsFromCommandLine(
  52. std::set<int>* workarounds,
  53. const base::CommandLine& command_line) {
  54. DCHECK(workarounds);
  55. for (int i = 0; i < NUMBER_OF_GPU_DRIVER_BUG_WORKAROUND_TYPES; i++) {
  56. if (command_line.HasSwitch(kFeatureList[i].name)) {
  57. // Check for disabling workaround flag.
  58. if (command_line.GetSwitchValueASCII(kFeatureList[i].name) == "0") {
  59. workarounds->erase(kFeatureList[i].type);
  60. continue;
  61. }
  62. // Removing conflicting workarounds.
  63. switch (kFeatureList[i].type) {
  64. case FORCE_HIGH_PERFORMANCE_GPU:
  65. workarounds->erase(FORCE_LOW_POWER_GPU);
  66. workarounds->insert(FORCE_HIGH_PERFORMANCE_GPU);
  67. break;
  68. case FORCE_LOW_POWER_GPU:
  69. workarounds->erase(FORCE_HIGH_PERFORMANCE_GPU);
  70. workarounds->insert(FORCE_LOW_POWER_GPU);
  71. break;
  72. default:
  73. workarounds->insert(kFeatureList[i].type);
  74. break;
  75. }
  76. }
  77. }
  78. }
  79. // static
  80. void GpuDriverBugList::AppendAllWorkarounds(
  81. std::vector<const char*>* workarounds) {
  82. static_assert(std::extent<decltype(kFeatureList)>::value ==
  83. NUMBER_OF_GPU_DRIVER_BUG_WORKAROUND_TYPES,
  84. "Expected kFeatureList to include all gpu workarounds");
  85. DCHECK(workarounds->empty());
  86. workarounds->resize(NUMBER_OF_GPU_DRIVER_BUG_WORKAROUND_TYPES);
  87. size_t i = 0;
  88. for (const GpuDriverBugWorkaroundInfo& feature : kFeatureList)
  89. (*workarounds)[i++] = feature.name;
  90. }
  91. // static
  92. bool GpuDriverBugList::AreEntryIndicesValid(
  93. const std::vector<uint32_t>& entry_indices) {
  94. return GpuControlList::AreEntryIndicesValid(entry_indices,
  95. kGpuDriverBugListEntryCount);
  96. }
  97. } // namespace gpu