Hash :
163e56e4
Author :
Date :
2022-09-20T00:40:55
Allow feature overrides to end in * (wildcard) Makes it easier to apply overrides to features with long names. Also works around Android's limit of 92 characters for debug properties. Bug: b/238024366 Change-Id: I8f417287f92b2439de1a7b7d6abbaf9e61b405e8 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3906222 Reviewed-by: Amirali Abdolrashidi <abdolrashidi@google.com> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Yiwei Zhang <zzyiwei@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 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
//
// 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.
//
// Tests the eglQueryStringiANGLE and eglQueryDisplayAttribANGLE functions exposed by the
// extension EGL_ANGLE_feature_control.
#include <gtest/gtest.h>
#include "common/string_utils.h"
#include "libANGLE/Display.h"
#include "test_utils/ANGLETest.h"
using namespace angle;
class EGLFeatureControlTest : public ANGLETest<>
{
public:
void testSetUp() override { mDisplay = EGL_NO_DISPLAY; }
void testTearDown() override
{
if (mDisplay != EGL_NO_DISPLAY)
{
eglTerminate(mDisplay);
}
}
protected:
EGLDisplay mDisplay;
bool initTest()
{
// http://anglebug.com/3629 This test sporadically times out on Win10/Intel
if (IsWindows() && IsIntel())
return false;
EGLAttrib dispattrs[] = {EGL_PLATFORM_ANGLE_TYPE_ANGLE, GetParam().getRenderer(), EGL_NONE};
mDisplay = eglGetPlatformDisplay(EGL_PLATFORM_ANGLE_ANGLE,
reinterpret_cast<void *>(EGL_DEFAULT_DISPLAY), dispattrs);
EXPECT_NE(mDisplay, EGL_NO_DISPLAY);
EXPECT_EQ(eglInitialize(mDisplay, nullptr, nullptr), static_cast<EGLBoolean>(EGL_TRUE));
EXPECT_TRUE(IsEGLClientExtensionEnabled("EGL_ANGLE_feature_control"));
return true;
}
using FeatureNameModifier = std::function<std::string(const std::string &)>;
void testOverrideFeatures(FeatureNameModifier modifyName);
};
// Ensure eglQueryStringiANGLE generates EGL_BAD_DISPLAY if the display passed in is invalid.
TEST_P(EGLFeatureControlTest, InvalidDisplay)
{
ANGLE_SKIP_TEST_IF(!initTest());
EXPECT_EQ(nullptr, eglQueryStringiANGLE(EGL_NO_DISPLAY, EGL_FEATURE_NAME_ANGLE, 0));
EXPECT_EGL_ERROR(EGL_BAD_DISPLAY);
}
// Ensure eglQueryStringiANGLE generates EGL_BAD_PARAMETER if the index is negative.
TEST_P(EGLFeatureControlTest, NegativeIndex)
{
ANGLE_SKIP_TEST_IF(!initTest());
EXPECT_EQ(nullptr, eglQueryStringiANGLE(mDisplay, EGL_FEATURE_NAME_ANGLE, -1));
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
}
// Ensure eglQueryStringiANGLE generates EGL_BAD_PARAMETER if the index is out of bounds.
TEST_P(EGLFeatureControlTest, IndexOutOfBounds)
{
ANGLE_SKIP_TEST_IF(!initTest());
egl::Display *display = static_cast<egl::Display *>(mDisplay);
EXPECT_EQ(nullptr, eglQueryStringiANGLE(mDisplay, EGL_FEATURE_NAME_ANGLE,
display->getFeatures().size()));
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
}
// Ensure eglQueryStringiANGLE generates EGL_BAD_PARAMETER if the name is not one of the valid
// options specified in EGL_ANGLE_feature_control.
TEST_P(EGLFeatureControlTest, InvalidName)
{
ANGLE_SKIP_TEST_IF(!initTest());
EXPECT_EQ(nullptr, eglQueryStringiANGLE(mDisplay, 100, 0));
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
}
// For each valid name and index in the feature description arrays, query the values and ensure
// that no error is generated, and that the values match the correct values frim ANGLE's display's
// FeatureList.
TEST_P(EGLFeatureControlTest, QueryAll)
{
ANGLE_SKIP_TEST_IF(!initTest());
egl::Display *display = static_cast<egl::Display *>(mDisplay);
angle::FeatureList features = display->getFeatures();
for (size_t i = 0; i < features.size(); i++)
{
EXPECT_STREQ(features[i]->name, eglQueryStringiANGLE(mDisplay, EGL_FEATURE_NAME_ANGLE, i));
EXPECT_STREQ(FeatureCategoryToString(features[i]->category),
eglQueryStringiANGLE(mDisplay, EGL_FEATURE_CATEGORY_ANGLE, i));
EXPECT_STREQ(features[i]->description,
eglQueryStringiANGLE(mDisplay, EGL_FEATURE_DESCRIPTION_ANGLE, i));
EXPECT_STREQ(features[i]->bug, eglQueryStringiANGLE(mDisplay, EGL_FEATURE_BUG_ANGLE, i));
EXPECT_STREQ(FeatureStatusToString(features[i]->enabled),
eglQueryStringiANGLE(mDisplay, EGL_FEATURE_STATUS_ANGLE, i));
EXPECT_STREQ(features[i]->condition,
eglQueryStringiANGLE(mDisplay, EGL_FEATURE_CONDITION_ANGLE, i));
ASSERT_EGL_SUCCESS();
}
}
// Ensure eglQueryDisplayAttribANGLE returns the correct number of features when queried with
// attribute EGL_FEATURE_COUNT_ANGLE
TEST_P(EGLFeatureControlTest, FeatureCount)
{
ANGLE_SKIP_TEST_IF(!initTest());
egl::Display *display = static_cast<egl::Display *>(mDisplay);
EGLAttrib value = -1;
EXPECT_EQ(static_cast<EGLBoolean>(EGL_TRUE),
eglQueryDisplayAttribANGLE(mDisplay, EGL_FEATURE_COUNT_ANGLE, &value));
EXPECT_EQ(display->getFeatures().size(), static_cast<size_t>(value));
ASSERT_EGL_SUCCESS();
}
void EGLFeatureControlTest::testOverrideFeatures(FeatureNameModifier modifyName)
{
ANGLE_SKIP_TEST_IF(!initTest());
egl::Display *display = static_cast<egl::Display *>(mDisplay);
angle::FeatureList features = display->getFeatures();
// Build lists of features to enable/disabled. Toggle features we know are ok to toggle based
// from this list.
std::vector<const char *> enabled = std::vector<const char *>();
std::vector<const char *> disabled = std::vector<const char *>();
std::vector<std::string> modifiedNameStorage = std::vector<std::string>();
std::vector<bool> shouldBe = std::vector<bool>();
std::vector<std::string> testedFeatures = {
// Safe to toggle on GL
angle::GetFeatureName(angle::Feature::AddAndTrueToLoopCondition),
angle::GetFeatureName(angle::Feature::ClampFragDepth),
// Safe to toggle on GL and Vulkan
angle::GetFeatureName(angle::Feature::ClampPointSize),
// Safe to toggle on Vulkan
angle::GetFeatureName(angle::Feature::SupportsNegativeViewport),
// Safe to toggle on D3D
angle::GetFeatureName(angle::Feature::ZeroMaxLodWorkaround),
angle::GetFeatureName(angle::Feature::ExpandIntegerPowExpressions),
angle::GetFeatureName(angle::Feature::RewriteUnaryMinusOperator),
};
for (size_t i = 0; i < features.size(); i++)
{
modifiedNameStorage.push_back(modifyName(features[i]->name));
}
for (size_t i = 0; i < features.size(); i++)
{
bool toggle = std::find(testedFeatures.begin(), testedFeatures.end(),
std::string(features[i]->name)) != testedFeatures.end();
if (features[i]->enabled ^ toggle)
{
enabled.push_back(modifiedNameStorage[i].c_str());
}
else
{
disabled.push_back(modifiedNameStorage[i].c_str());
}
// Save what we expect the feature status will be when checking later.
shouldBe.push_back(features[i]->enabled ^ toggle);
}
disabled.push_back(0);
enabled.push_back(0);
// Terminate the old display (we just used it to collect features)
eglTerminate(mDisplay);
// Create a new display with these overridden features.
EGLAttrib dispattrs[] = {EGL_PLATFORM_ANGLE_TYPE_ANGLE,
GetParam().getRenderer(),
EGL_FEATURE_OVERRIDES_ENABLED_ANGLE,
reinterpret_cast<EGLAttrib>(enabled.data()),
EGL_FEATURE_OVERRIDES_DISABLED_ANGLE,
reinterpret_cast<EGLAttrib>(disabled.data()),
EGL_NONE};
EGLDisplay dpy_override = eglGetPlatformDisplay(
EGL_PLATFORM_ANGLE_ANGLE, reinterpret_cast<void *>(EGL_DEFAULT_DISPLAY), dispattrs);
ASSERT_EGL_SUCCESS();
ASSERT_TRUE(dpy_override != EGL_NO_DISPLAY);
ASSERT_TRUE(eglInitialize(dpy_override, nullptr, nullptr) == EGL_TRUE);
// Check that all features have the correct status (even the ones we toggled).
for (size_t i = 0; i < features.size(); i++)
{
EXPECT_STREQ(FeatureStatusToString(shouldBe[i]),
eglQueryStringiANGLE(dpy_override, EGL_FEATURE_STATUS_ANGLE, i))
<< modifiedNameStorage[i];
}
}
// Submit a list of features to override when creating the display with eglGetPlatformDisplay, and
// ensure that the features are correctly overridden.
TEST_P(EGLFeatureControlTest, OverrideFeatures)
{
testOverrideFeatures([](const std::string &featureName) { return featureName; });
}
// Similar to OverrideFeatures, but ensures that camelCase variants of the name match as well.
TEST_P(EGLFeatureControlTest, OverrideFeaturesCamelCase)
{
testOverrideFeatures(
[](const std::string &featureName) { return angle::ToCamelCase(featureName); });
}
// Similar to OverrideFeatures, but ensures wildcard matching works
TEST_P(EGLFeatureControlTest, OverrideFeaturesWildcard)
{
ANGLE_SKIP_TEST_IF(!initTest());
egl::Display *display = static_cast<egl::Display *>(mDisplay);
angle::FeatureList features = display->getFeatures();
// Build lists of features to enable/disabled. Toggle features we know are ok to toggle based
// from this list.
std::vector<const char *> enabled = {"prefer_*", nullptr};
std::vector<bool> shouldBe = std::vector<bool>();
for (size_t i = 0; i < features.size(); i++)
{
std::string featureName = std::string(features[i]->name);
std::transform(featureName.begin(), featureName.end(), featureName.begin(),
[](unsigned char c) { return std::tolower(c); });
const bool enable = strncmp(featureName.c_str(), "prefer", 6) == 0;
// Save what we expect the feature status will be when checking later.
shouldBe.push_back(features[i]->enabled || enable);
}
// Terminate the old display (we just used it to collect features)
eglTerminate(mDisplay);
// Create a new display with these overridden features.
EGLAttrib dispattrs[] = {EGL_PLATFORM_ANGLE_TYPE_ANGLE, GetParam().getRenderer(),
EGL_FEATURE_OVERRIDES_ENABLED_ANGLE,
reinterpret_cast<EGLAttrib>(enabled.data()), EGL_NONE};
EGLDisplay dpy_override = eglGetPlatformDisplay(
EGL_PLATFORM_ANGLE_ANGLE, reinterpret_cast<void *>(EGL_DEFAULT_DISPLAY), dispattrs);
ASSERT_EGL_SUCCESS();
ASSERT_TRUE(dpy_override != EGL_NO_DISPLAY);
ASSERT_TRUE(eglInitialize(dpy_override, nullptr, nullptr) == EGL_TRUE);
// Check that all features have the correct status (even the ones we toggled).
for (size_t i = 0; i < features.size(); i++)
{
EXPECT_STREQ(FeatureStatusToString(shouldBe[i]),
eglQueryStringiANGLE(dpy_override, EGL_FEATURE_STATUS_ANGLE, i))
<< features[i]->name;
}
}
ANGLE_INSTANTIATE_TEST(EGLFeatureControlTest,
WithNoFixture(ES2_D3D9()),
WithNoFixture(ES2_D3D11()),
WithNoFixture(ES2_OPENGL()),
WithNoFixture(ES2_VULKAN()),
WithNoFixture(ES3_D3D11()),
WithNoFixture(ES3_OPENGL()));