Hash :
02ae054c
Author :
Date :
2025-04-07T13:48:29
Translator: Fix init of inactive output variables Bug: chromium:398401939 Change-Id: I0df494b945b8d0e805a62cf7645d06bf233f36ca Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6438495 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Geoff Lang <geofflang@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 368 369
//
// Copyright 2021 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.
//
// KHR_blend_equation_advanced_test.cpp:
// Test for KHR_blend_equation_advanced and KHR_blend_equation_advanced_coherent
//
#include "tests/test_utils/ShaderExtensionTest.h"
#include "common/PackedEnums.h"
namespace
{
const char EXTPragma[] =
"#extension GL_KHR_blend_equation_advanced : require\n"
"#extension GL_EXT_shader_framebuffer_fetch_non_coherent : require\n";
// Use the multiply equation for blending
const char ESSL310_Simple[] =
R"(
precision highp float;
layout (blend_support_multiply) out;
layout (location = 0) out vec4 oCol;
uniform vec4 uSrcCol;
void main (void)
{
oCol = uSrcCol;
})";
const char ESSL310_DeclaredMultiplyScreenSeparately[] =
R"(
precision highp float;
layout (blend_support_multiply) out;
layout (blend_support_screen) out;
layout (location = 0) out vec4 oCol;
uniform vec4 uSrcCol;
void main (void)
{
oCol = uSrcCol;
})";
const char ESSL310_DeclaredMultiplyScreenSuccessively[] =
R"(
precision highp float;
layout (blend_support_multiply, blend_support_screen) out;
layout (location = 0) out vec4 oCol;
uniform vec4 uSrcCol;
void main (void)
{
oCol = uSrcCol;
})";
const char ESSL310_With_FramebufferFetch[] =
R"(
precision highp float;
layout (blend_support_multiply) out;
layout (location = 0, noncoherent) inout vec4 oCol;
uniform vec4 uSrcCol;
void main (void)
{
oCol = mix(oCol, uSrcCol, 0.5f);
})";
const char ESSL310_With_FramebufferFetchVec3[] =
R"(
precision highp float;
layout (blend_support_multiply) out;
layout (location = 0, noncoherent) inout vec3 oCol;
uniform vec3 uSrcCol;
void main (void)
{
oCol = mix(oCol, uSrcCol, 0.5f);
})";
class KHRBlendEquationAdvancedTest : public sh::ShaderExtensionTest
{
public:
void SetUp() override
{
std::map<ShShaderOutput, std::string> shaderOutputList = {
{SH_GLSL_450_CORE_OUTPUT, "SH_GLSL_450_CORE_OUTPUT"},
#if defined(ANGLE_ENABLE_VULKAN)
{SH_SPIRV_VULKAN_OUTPUT, "SH_SPIRV_VULKAN_OUTPUT"}
#endif
};
Initialize(shaderOutputList);
}
void TearDown() override
{
for (auto shaderOutputType : mShaderOutputList)
{
DestroyCompiler(shaderOutputType.first);
}
}
void Initialize(std::map<ShShaderOutput, std::string> &shaderOutputList)
{
mShaderOutputList = std::move(shaderOutputList);
for (auto shaderOutputType : mShaderOutputList)
{
sh::InitBuiltInResources(&mResourceList[shaderOutputType.first]);
mCompilerList[shaderOutputType.first] = nullptr;
}
}
void DestroyCompiler(ShShaderOutput shaderOutputType)
{
if (mCompilerList[shaderOutputType])
{
sh::Destruct(mCompilerList[shaderOutputType]);
mCompilerList[shaderOutputType] = nullptr;
}
}
void InitializeCompiler()
{
for (auto shaderOutputType : mShaderOutputList)
{
InitializeCompiler(shaderOutputType.first);
}
}
void InitializeCompiler(ShShaderOutput shaderOutputType)
{
DestroyCompiler(shaderOutputType);
if (shaderOutputType == SH_SPIRV_VULKAN_OUTPUT || shaderOutputType == SH_MSL_METAL_OUTPUT)
{
mCompileOptions.removeInactiveVariables = true;
}
mCompilerList[shaderOutputType] =
sh::ConstructCompiler(GL_FRAGMENT_SHADER, testing::get<0>(GetParam()), shaderOutputType,
&mResourceList[shaderOutputType]);
ASSERT_TRUE(mCompilerList[shaderOutputType] != nullptr)
<< "Compiler for " << mShaderOutputList[shaderOutputType]
<< " could not be constructed.";
}
enum class Emulation
{
Disabled,
Enabled
};
testing::AssertionResult TestShaderCompile(ShShaderOutput shaderOutputType,
const char *pragma,
Emulation emulate)
{
const char *shaderStrings[] = {testing::get<1>(GetParam()), pragma,
testing::get<2>(GetParam())};
ShCompileOptions compileFlags = mCompileOptions;
if (emulate == Emulation::Enabled)
{
compileFlags.addAdvancedBlendEquationsEmulation = true;
}
bool success = sh::Compile(mCompilerList[shaderOutputType], shaderStrings, 3, compileFlags);
if (success)
{
return ::testing::AssertionSuccess()
<< "Compilation success(" << mShaderOutputList[shaderOutputType] << ")";
}
return ::testing::AssertionFailure() << sh::GetInfoLog(mCompilerList[shaderOutputType]);
}
void TestShaderCompile(bool expectation, const char *pragma, Emulation emulate)
{
for (auto shaderOutputType : mShaderOutputList)
{
if (expectation)
{
EXPECT_TRUE(TestShaderCompile(shaderOutputType.first, pragma, emulate));
}
else
{
EXPECT_FALSE(TestShaderCompile(shaderOutputType.first, pragma, emulate));
}
}
}
void SetExtensionEnable(bool enable)
{
for (auto shaderOutputType : mShaderOutputList)
{
mResourceList[shaderOutputType.first].KHR_blend_equation_advanced = enable;
mResourceList[shaderOutputType.first].EXT_shader_framebuffer_fetch_non_coherent =
enable;
}
}
protected:
std::map<ShShaderOutput, std::string> mShaderOutputList;
std::map<ShShaderOutput, ShHandle> mCompilerList;
std::map<ShShaderOutput, ShBuiltInResources> mResourceList;
};
class KHRBlendEquationAdvancedES310Test : public KHRBlendEquationAdvancedTest
{};
// Extension flag is required to compile properly. Expect failure when it is not present.
TEST_P(KHRBlendEquationAdvancedES310Test, CompileFailsWithoutExtension)
{
SetExtensionEnable(false);
InitializeCompiler();
TestShaderCompile(false, EXTPragma, Emulation::Disabled);
}
// Extension directive is required to compile properly. Expect failure when it is not present.
TEST_P(KHRBlendEquationAdvancedES310Test, CompileFailsWithExtensionWithoutPragma)
{
SetExtensionEnable(true);
InitializeCompiler();
TestShaderCompile(false, "", Emulation::Disabled);
}
INSTANTIATE_TEST_SUITE_P(CorrectESSL310Shaders,
KHRBlendEquationAdvancedES310Test,
Combine(Values(SH_GLES3_1_SPEC),
Values(sh::ESSLVersion310),
Values(ESSL310_Simple,
ESSL310_With_FramebufferFetch,
ESSL310_With_FramebufferFetchVec3,
ESSL310_DeclaredMultiplyScreenSeparately,
ESSL310_DeclaredMultiplyScreenSuccessively)));
#if defined(ANGLE_ENABLE_VULKAN)
class KHRBlendEquationAdvancedSuccessTest : public KHRBlendEquationAdvancedTest
{
public:
void SetUp() override
{
std::map<ShShaderOutput, std::string> shaderOutputList = {
{SH_SPIRV_VULKAN_OUTPUT, "SH_SPIRV_VULKAN_OUTPUT"}};
Initialize(shaderOutputList);
}
};
class KHRBlendEquationAdvancedES310SuccessTest : public KHRBlendEquationAdvancedSuccessTest
{};
// With extension flag and extension directive, compiling succeeds. Also test that the extension
// directive state is reset correctly.
TEST_P(KHRBlendEquationAdvancedES310SuccessTest, CompileSucceedsWithExtensionAndPragma)
{
SetExtensionEnable(true);
InitializeCompiler();
TestShaderCompile(true, EXTPragma, Emulation::Disabled);
// Test reset functionality.
TestShaderCompile(false, "", Emulation::Disabled);
TestShaderCompile(true, EXTPragma, Emulation::Disabled);
}
// Same as CompileSucceedsWithExtensionAndPragma but with emulation.
TEST_P(KHRBlendEquationAdvancedES310SuccessTest, CompileSucceedsWithExtensionAndPragmaWithEmulation)
{
SetExtensionEnable(true);
InitializeCompiler();
TestShaderCompile(true, EXTPragma, Emulation::Enabled);
}
// The SL #version 100 shaders that are correct work similarly
// in both GL2 and GL3, with and without the version string.
INSTANTIATE_TEST_SUITE_P(CorrectESSL310Shaders,
KHRBlendEquationAdvancedES310SuccessTest,
Combine(Values(SH_GLES3_1_SPEC),
Values(sh::ESSLVersion310),
Values(ESSL310_Simple,
ESSL310_With_FramebufferFetch,
ESSL310_With_FramebufferFetchVec3,
ESSL310_DeclaredMultiplyScreenSeparately,
ESSL310_DeclaredMultiplyScreenSuccessively)));
class KHRBlendEquationAdvancedEnabledListCheckTest : public KHRBlendEquationAdvancedTest
{
public:
void SetUp() override
{
std::map<ShShaderOutput, std::string> shaderOutputList = {
{SH_SPIRV_VULKAN_OUTPUT, "SH_SPIRV_VULKAN_OUTPUT"}};
Initialize(shaderOutputList);
}
const ShHandle &GetCompilerHandle(const ShShaderOutput outputType) const
{
return mCompilerList.at(outputType);
}
};
class KHRBlendEquationAdvancedEnabledSeparatelyTest
: public KHRBlendEquationAdvancedEnabledListCheckTest
{};
// Test for declaring different blend equations in separate layout declarations
TEST_P(KHRBlendEquationAdvancedEnabledSeparatelyTest, DeclaredEquationSeparately)
{
SetExtensionEnable(true);
InitializeCompiler();
TestShaderCompile(true, EXTPragma, Emulation::Disabled);
const ShHandle compilerHandle = GetCompilerHandle(SH_SPIRV_VULKAN_OUTPUT);
gl::BlendEquationBitSet enabledBlendEquation(sh::GetAdvancedBlendEquations(compilerHandle));
EXPECT_TRUE(enabledBlendEquation.test(gl::BlendEquationType::Multiply));
EXPECT_TRUE(enabledBlendEquation.test(gl::BlendEquationType::Screen));
}
// Same as DeclaredEquationSeparately but with emulation.
TEST_P(KHRBlendEquationAdvancedEnabledSeparatelyTest, DeclaredEquationSeparatelyWithEmulation)
{
SetExtensionEnable(true);
InitializeCompiler();
TestShaderCompile(true, EXTPragma, Emulation::Enabled);
}
INSTANTIATE_TEST_SUITE_P(CorrectESSL310Shaders,
KHRBlendEquationAdvancedEnabledSeparatelyTest,
Combine(Values(SH_GLES3_1_SPEC),
Values(sh::ESSLVersion310),
Values(ESSL310_DeclaredMultiplyScreenSeparately)));
class KHRBlendEquationAdvancedEnabledSuccessivelyTest
: public KHRBlendEquationAdvancedEnabledListCheckTest
{};
// Test for declaring different blend equations in the same layout declaration
TEST_P(KHRBlendEquationAdvancedEnabledSuccessivelyTest, DeclaredEquationSuccessively)
{
SetExtensionEnable(true);
InitializeCompiler();
TestShaderCompile(true, EXTPragma, Emulation::Disabled);
const ShHandle compilerHandle = GetCompilerHandle(SH_SPIRV_VULKAN_OUTPUT);
gl::BlendEquationBitSet enabledBlendEquation(sh::GetAdvancedBlendEquations(compilerHandle));
EXPECT_TRUE(enabledBlendEquation.test(gl::BlendEquationType::Multiply));
EXPECT_TRUE(enabledBlendEquation.test(gl::BlendEquationType::Screen));
}
INSTANTIATE_TEST_SUITE_P(CorrectESSL310Shaders,
KHRBlendEquationAdvancedEnabledSuccessivelyTest,
Combine(Values(SH_GLES3_1_SPEC),
Values(sh::ESSLVersion310),
Values(ESSL310_DeclaredMultiplyScreenSuccessively)));
#endif
} // anonymous namespace