Hash :
13829f20
Author :
Date :
2024-03-26T23:03:12
Vulkan: Optimize depth/stencil resolve with glBlitFramebuffer Like color resolve, depth/stencil resolve is now also possibly done by modifying the render pass and attaching a depth/stencil resolve attachment. Bug: angleproject:7551 Change-Id: I045e3875e24006d2473a55b6c3856dd768fe8b84 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5398004 Reviewed-by: Yuxin Hu <yuxinhu@google.com> Reviewed-by: Charlie Lao <cclao@google.com> 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 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 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
//
// 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 <optional>
#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 *> disabled;
std::vector<std::string> modifiedNameStorage;
std::vector<bool> shouldBe;
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 D3D
angle::GetFeatureName(angle::Feature::ZeroMaxLodWorkaround),
angle::GetFeatureName(angle::Feature::ExpandIntegerPowExpressions),
angle::GetFeatureName(angle::Feature::RewriteUnaryMinusOperator),
};
modifiedNameStorage.reserve(features.size());
shouldBe.reserve(features.size());
for (size_t i = 0; i < features.size(); i++)
{
modifiedNameStorage.push_back(modifyName(features[i]->name));
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};
mDisplay = eglGetPlatformDisplay(EGL_PLATFORM_ANGLE_ANGLE,
reinterpret_cast<void *>(EGL_DEFAULT_DISPLAY), dispattrs);
ASSERT_EGL_SUCCESS();
ASSERT_NE(mDisplay, EGL_NO_DISPLAY);
ASSERT_EQ(eglInitialize(mDisplay, nullptr, nullptr), EGLBoolean(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(mDisplay, 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)
{
for (int j = 0; j < 2; j++)
{
const bool testEnableOverride = (j != 0);
ANGLE_SKIP_TEST_IF(!initTest());
egl::Display *display = static_cast<egl::Display *>(mDisplay);
angle::FeatureList features = display->getFeatures();
// Note that we don't use the broader 'prefer_*' here because
// prefer_monolithic_pipelines_over_libraries may affect other feature
// flags.
std::vector<const char *> featuresToOverride = {"prefer_d*", nullptr};
std::vector<std::string> featureNameStorage;
std::vector<bool> shouldBe;
shouldBe.reserve(features.size());
featureNameStorage.reserve(features.size());
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 featureMatch = strncmp(featureName.c_str(), "preferd", 7) == 0;
std::optional<bool> overrideState;
if (featureMatch)
{
overrideState = testEnableOverride;
}
// Save what we expect the feature status will be when checking later.
shouldBe.push_back(overrideState.value_or(features[i]->enabled));
featureNameStorage.push_back(features[i]->name);
}
// Terminate the old display (we just used it to collect features)
eglTerminate(mDisplay);
mDisplay = nullptr;
// Create a new display with these overridden features.
EGLAttrib dispattrs[] = {EGL_PLATFORM_ANGLE_TYPE_ANGLE, GetParam().getRenderer(),
testEnableOverride ? EGL_FEATURE_OVERRIDES_ENABLED_ANGLE
: EGL_FEATURE_OVERRIDES_DISABLED_ANGLE,
reinterpret_cast<EGLAttrib>(featuresToOverride.data()), EGL_NONE};
mDisplay = eglGetPlatformDisplay(EGL_PLATFORM_ANGLE_ANGLE,
reinterpret_cast<void *>(EGL_DEFAULT_DISPLAY), dispattrs);
ASSERT_EGL_SUCCESS();
ASSERT_NE(mDisplay, EGL_NO_DISPLAY);
ASSERT_EQ(eglInitialize(mDisplay, nullptr, nullptr), EGLBoolean(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(mDisplay, EGL_FEATURE_STATUS_ANGLE, i))
<< featureNameStorage[i];
}
// Clean up display for next iteration.
eglTerminate(mDisplay);
mDisplay = nullptr;
}
}
// Ensure that dependent features are affected properly by overrides
TEST_P(EGLFeatureControlTest, OverrideFeaturesDependent)
{
ANGLE_SKIP_TEST_IF(!initTest());
egl::Display *display = static_cast<egl::Display *>(mDisplay);
angle::FeatureList features = display->getFeatures();
const std::vector<const char *> featuresDisabled = {
GetFeatureName(Feature::SupportsRenderpass2),
GetFeatureName(Feature::SupportsImage2dViewOf3d), nullptr};
const std::vector<const char *> featuresExpectDisabled = {
// Features we changed
GetFeatureName(Feature::SupportsRenderpass2),
GetFeatureName(Feature::SupportsImage2dViewOf3d),
// Features that must become disabled as a result of the above
GetFeatureName(Feature::SupportsDepthStencilResolve),
GetFeatureName(Feature::SupportsDepthStencilIndependentResolveNone),
GetFeatureName(Feature::SupportsSampler2dViewOf3d),
GetFeatureName(Feature::SupportsFragmentShadingRate),
};
std::vector<std::string> featureNameStorage;
std::vector<bool> shouldBe;
shouldBe.reserve(features.size());
featureNameStorage.reserve(features.size());
for (size_t i = 0; i < features.size(); i++)
{
bool featureMatch = false;
for (auto *ptr : featuresExpectDisabled)
{
if (strcmp(ptr, features[i]->name) == 0)
{
featureMatch = true;
break;
}
}
std::string featureName = std::string(features[i]->name);
std::transform(featureName.begin(), featureName.end(), featureName.begin(),
[](unsigned char c) { return std::tolower(c); });
// Save what we expect the feature status will be when checking later.
shouldBe.push_back(features[i]->enabled && !featureMatch);
// Store copy of the feature name string, in case we need to print for a test failure
featureNameStorage.push_back(features[i]->name);
}
// 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_DISABLED_ANGLE,
reinterpret_cast<EGLAttrib>(featuresDisabled.data()), EGL_NONE};
mDisplay = eglGetPlatformDisplay(EGL_PLATFORM_ANGLE_ANGLE,
reinterpret_cast<void *>(EGL_DEFAULT_DISPLAY), dispattrs);
ASSERT_EGL_SUCCESS();
ASSERT_NE(mDisplay, EGL_NO_DISPLAY);
ASSERT_EQ(eglInitialize(mDisplay, nullptr, nullptr), EGLBoolean(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(mDisplay, EGL_FEATURE_STATUS_ANGLE, i))
<< featureNameStorage[i];
}
}
ANGLE_INSTANTIATE_TEST(EGLFeatureControlTest,
WithNoFixture(ES2_D3D9()),
WithNoFixture(ES2_D3D11()),
WithNoFixture(ES2_OPENGL()),
WithNoFixture(ES2_VULKAN()),
WithNoFixture(ES3_D3D11()),
WithNoFixture(ES3_OPENGL()));