Hash :
f395f34b
Author :
Date :
2023-08-03T13:58:43
features: frontload feature overrides
This allows us to have features that depend on the state of other
features more reliably.
For example, let's say you have two features:
ANGLE_FEATURE_CONDITION(&mFeatures, allowX, (benefitsFromX || isSpecificHardware) && !isBadHardware);
ANGLE_FEATURE_CONDITION(&mFeatures, supportsX, hardware.featureXSupported && mFeatures.allowX.enabled);
Before this change, if you overrode allowX, the override would be
applied too late for the supportsX test.
This also helps with disabling dependent features via overrides. For
example, if you disable "supportsRenderpass2", it will also disable
features depending on it, such as "supportsDepthStencilResolve" and
"supportsFragmentShadingRate".
By frontloading the feature overrides, we can have cross-dependencies
between "feature supported on this platform" and "allow this feature by
policy".
Bug: angleproject:8291
Change-Id: Id6da2c89428fa896d677fe8d5a41369277a21b31
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4749524
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
Auto-Submit: Steven Noonan <steven@uplinklabs.net>
Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
//
// Copyright 2019 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Feature.h: Definition of structs to hold feature/workaround information.
//
#ifndef ANGLE_PLATFORM_FEATURE_H_
#define ANGLE_PLATFORM_FEATURE_H_
#include <map>
#include <string>
#include <vector>
#define ANGLE_FEATURE_CONDITION(set, feature, cond) \
do \
{ \
if (!(set)->feature.hasOverride) \
{ \
(set)->feature.enabled = cond; \
(set)->feature.condition = ANGLE_STRINGIFY(cond); \
} \
} while (0)
namespace angle
{
enum class FeatureCategory
{
FrontendFeatures,
FrontendWorkarounds,
OpenGLWorkarounds,
OpenGLFeatures,
D3DWorkarounds,
VulkanFeatures,
VulkanWorkarounds,
VulkanAppWorkarounds,
MetalFeatures,
MetalWorkarounds,
};
constexpr char kFeatureCategoryFrontendWorkarounds[] = "Frontend workarounds";
constexpr char kFeatureCategoryFrontendFeatures[] = "Frontend features";
constexpr char kFeatureCategoryOpenGLWorkarounds[] = "OpenGL workarounds";
constexpr char kFeatureCategoryOpenGLFeatures[] = "OpenGL features";
constexpr char kFeatureCategoryD3DWorkarounds[] = "D3D workarounds";
constexpr char kFeatureCategoryVulkanAppWorkarounds[] = "Vulkan app workarounds";
constexpr char kFeatureCategoryVulkanWorkarounds[] = "Vulkan workarounds";
constexpr char kFeatureCategoryVulkanFeatures[] = "Vulkan features";
constexpr char kFeatureCategoryMetalFeatures[] = "Metal features";
constexpr char kFeatureCategoryMetalWorkarounds[] = "Metal workarounds";
constexpr char kFeatureCategoryUnknown[] = "Unknown";
inline const char *FeatureCategoryToString(const FeatureCategory &fc)
{
switch (fc)
{
case FeatureCategory::FrontendFeatures:
return kFeatureCategoryFrontendFeatures;
break;
case FeatureCategory::FrontendWorkarounds:
return kFeatureCategoryFrontendWorkarounds;
break;
case FeatureCategory::OpenGLWorkarounds:
return kFeatureCategoryOpenGLWorkarounds;
break;
case FeatureCategory::OpenGLFeatures:
return kFeatureCategoryOpenGLFeatures;
break;
case FeatureCategory::D3DWorkarounds:
return kFeatureCategoryD3DWorkarounds;
break;
case FeatureCategory::VulkanFeatures:
return kFeatureCategoryVulkanFeatures;
break;
case FeatureCategory::VulkanWorkarounds:
return kFeatureCategoryVulkanWorkarounds;
break;
case FeatureCategory::VulkanAppWorkarounds:
return kFeatureCategoryVulkanAppWorkarounds;
break;
case FeatureCategory::MetalFeatures:
return kFeatureCategoryMetalFeatures;
break;
case FeatureCategory::MetalWorkarounds:
return kFeatureCategoryMetalWorkarounds;
break;
default:
return kFeatureCategoryUnknown;
break;
}
}
constexpr char kFeatureStatusEnabled[] = "enabled";
constexpr char kFeatureStatusDisabled[] = "disabled";
inline const char *FeatureStatusToString(const bool &status)
{
if (status)
{
return kFeatureStatusEnabled;
}
return kFeatureStatusDisabled;
}
struct FeatureInfo;
using FeatureMap = std::map<std::string, FeatureInfo *>;
using FeatureList = std::vector<const FeatureInfo *>;
struct FeatureInfo
{
FeatureInfo(const FeatureInfo &other);
FeatureInfo(const char *name,
const FeatureCategory &category,
const char *description,
FeatureMap *const mapPtr,
const char *bug);
~FeatureInfo();
void applyOverride(bool state);
// The name of the workaround, lowercase, camel_case
const char *const name;
// The category that the workaround belongs to. Eg. "Vulkan workarounds"
const FeatureCategory category;
// A short description to be read by the user.
const char *const description;
// A link to the bug, if any
const char *const bug;
// Whether the workaround is enabled or not. Determined by heuristics like vendor ID and
// version, but may be overriden to any value.
bool enabled = false;
// Whether this feature has an override applied to it, and the condition to
// enable it should not be checked.
bool hasOverride = false;
// A stringified version of the condition used to set 'enabled'. ie "IsNvidia() && IsApple()"
const char *condition;
};
inline FeatureInfo::FeatureInfo(const FeatureInfo &other) = default;
inline FeatureInfo::FeatureInfo(const char *name,
const FeatureCategory &category,
const char *description,
FeatureMap *const mapPtr,
const char *bug = "")
: name(name),
category(category),
description(description),
bug(bug),
enabled(false),
condition("")
{
if (mapPtr != nullptr)
{
(*mapPtr)[std::string(name)] = this;
}
}
inline FeatureInfo::~FeatureInfo() = default;
struct FeatureSetBase
{
public:
FeatureSetBase();
~FeatureSetBase();
private:
// Non-copyable
FeatureSetBase(const FeatureSetBase &other) = delete;
FeatureSetBase &operator=(const FeatureSetBase &other) = delete;
protected:
FeatureMap members = FeatureMap();
public:
void reset();
void overrideFeatures(const std::vector<std::string> &featureNames, bool enabled);
void populateFeatureList(FeatureList *features) const;
const FeatureMap &getFeatures() const { return members; }
};
inline FeatureSetBase::FeatureSetBase() = default;
inline FeatureSetBase::~FeatureSetBase() = default;
} // namespace angle
#endif // ANGLE_PLATFORM_WORKAROUND_H_