2
// Copyright 2019 The ANGLE Project Authors. All rights reserved.
3
// Use of this source code is governed by a BSD-style license that can be
4
// found in the LICENSE file.
6
// Feature.h: Definition of structs to hold feature/workaround information.
9
#ifndef ANGLE_PLATFORM_FEATURE_H_
10
#define ANGLE_PLATFORM_FEATURE_H_
16
#define ANGLE_FEATURE_CONDITION(set, feature, cond) \
19
set->feature.enabled = cond; \
20
set->feature.condition = ANGLE_STRINGIFY(cond); \
26
enum class FeatureCategory
31
D3DCompilerWorkarounds,
37
constexpr char kFeatureCategoryFrontendWorkarounds[] = "Frontend workarounds";
38
constexpr char kFeatureCategoryOpenGLWorkarounds[] = "OpenGL workarounds";
39
constexpr char kFeatureCategoryD3DWorkarounds[] = "D3D workarounds";
40
constexpr char kFeatureCategoryD3DCompilerWorkarounds[] = "D3D compiler workarounds";
41
constexpr char kFeatureCategoryVulkanWorkarounds[] = "Vulkan workarounds";
42
constexpr char kFeatureCategoryVulkanFeatures[] = "Vulkan features";
43
constexpr char kFeatureCategoryMetalFeatures[] = "Metal features";
44
constexpr char kFeatureCategoryUnknown[] = "Unknown";
46
inline const char *FeatureCategoryToString(const FeatureCategory &fc)
50
case FeatureCategory::FrontendWorkarounds:
51
return kFeatureCategoryFrontendWorkarounds;
54
case FeatureCategory::OpenGLWorkarounds:
55
return kFeatureCategoryOpenGLWorkarounds;
58
case FeatureCategory::D3DWorkarounds:
59
return kFeatureCategoryD3DWorkarounds;
62
case FeatureCategory::D3DCompilerWorkarounds:
63
return kFeatureCategoryD3DCompilerWorkarounds;
66
case FeatureCategory::VulkanWorkarounds:
67
return kFeatureCategoryVulkanWorkarounds;
70
case FeatureCategory::VulkanFeatures:
71
return kFeatureCategoryVulkanFeatures;
74
case FeatureCategory::MetalFeatures:
75
return kFeatureCategoryMetalFeatures;
79
return kFeatureCategoryUnknown;
84
constexpr char kFeatureStatusEnabled[] = "enabled";
85
constexpr char kFeatureStatusDisabled[] = "disabled";
87
inline const char *FeatureStatusToString(const bool &status)
91
return kFeatureStatusEnabled;
93
return kFeatureStatusDisabled;
98
using FeatureMap = std::map<std::string, Feature *>;
99
using FeatureList = std::vector<const Feature *>;
103
Feature(const Feature &other);
104
Feature(const char *name,
105
const FeatureCategory &category,
106
const char *description,
107
FeatureMap *const mapPtr,
111
// The name of the workaround, lowercase, camel_case
112
const char *const name;
114
// The category that the workaround belongs to. Eg. "Vulkan workarounds"
115
const FeatureCategory category;
117
// A short description to be read by the user.
118
const char *const description;
120
// A link to the bug, if any
121
const char *const bug;
123
// Whether the workaround is enabled or not. Determined by heuristics like vendor ID and
124
// version, but may be overriden to any value.
125
bool enabled = false;
127
// A stingified version of the condition used to set 'enabled'. ie "IsNvidia() && IsApple()"
128
const char *condition;
131
inline Feature::Feature(const Feature &other) = default;
132
inline Feature::Feature(const char *name,
133
const FeatureCategory &category,
134
const char *description,
135
FeatureMap *const mapPtr,
136
const char *bug = "")
139
description(description),
144
if (mapPtr != nullptr)
146
(*mapPtr)[std::string(name)] = this;
150
inline Feature::~Feature() = default;
152
struct FeatureSetBase
160
FeatureSetBase(const FeatureSetBase &other) = delete;
161
FeatureSetBase &operator=(const FeatureSetBase &other) = delete;
164
FeatureMap members = FeatureMap();
167
void overrideFeatures(const std::vector<std::string> &feature_names, const bool enabled)
169
for (const std::string &name : feature_names)
171
if (members.find(name) != members.end())
173
members[name]->enabled = enabled;
178
void populateFeatureList(FeatureList *features) const
180
for (FeatureMap::const_iterator it = members.begin(); it != members.end(); it++)
182
features->push_back(it->second);
187
inline FeatureSetBase::FeatureSetBase() = default;
188
inline FeatureSetBase::~FeatureSetBase() = default;
192
#endif // ANGLE_PLATFORM_WORKAROUND_H_