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 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
//
// Copyright 2020 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.
//
// EXT_shader_framebuffer_fetch_test.cpp:
// Test for EXT_shader_framebuffer_fetch and EXT_shader_framebuffer_fetch_non_coherent
//
#include "tests/test_utils/ShaderExtensionTest.h"
namespace
{
const char EXTPragma[] = "#extension GL_EXT_shader_framebuffer_fetch_non_coherent : require\n";
// Redeclare gl_LastFragData with noncoherent qualifier
const char ESSL100_LastFragDataRedeclared1[] =
R"(
uniform highp vec4 u_color;
layout(noncoherent) highp vec4 gl_LastFragData[gl_MaxDrawBuffers];
void main (void)
{
gl_FragColor = u_color + gl_LastFragData[0] + gl_LastFragData[2];
})";
// Use inout variable with noncoherent qualifier
const char ESSL300_InOut[] =
R"(
layout(noncoherent, location = 0) inout highp vec4 o_color;
uniform highp vec4 u_color;
void main (void)
{
o_color = clamp(o_color + u_color, vec4(0.0f), vec4(1.0f));
})";
// Use inout variable with noncoherent qualifier and 3-components vector
const char ESSL300_InOut2[] =
R"(
layout(noncoherent, location = 0) inout highp vec3 o_color;
uniform highp vec3 u_color;
void main (void)
{
o_color = clamp(o_color + u_color, vec3(0.0f), vec3(1.0f));
})";
// Use inout variable with noncoherent qualifier and integer type qualifier
const char ESSL300_InOut3[] =
R"(
layout(noncoherent, location = 0) inout highp ivec4 o_color;
uniform highp ivec4 u_color;
void main (void)
{
o_color = clamp(o_color + u_color, ivec4(0), ivec4(1));
})";
// Use inout variable with noncoherent qualifier and unsigned integer type qualifier
const char ESSL300_InOut4[] =
R"(
layout(noncoherent, location = 0) inout highp uvec4 o_color;
uniform highp uvec4 u_color;
void main (void)
{
o_color = clamp(o_color + u_color, uvec4(0), uvec4(1));
})";
// Use inout variable with noncoherent qualifier and inout function parameter
const char ESSL300_InOut5[] =
R"(
layout(noncoherent, location = 0) inout highp vec4 o_color;
uniform highp vec4 u_color;
void getClampValue(inout highp mat4 io_color, highp vec4 i_color)
{
io_color[0] = clamp(io_color[0] + i_color, vec4(0.0f), vec4(1.0f));
}
void main (void)
{
highp mat4 o_color_mat = mat4(0);
o_color_mat[0] = o_color;
getClampValue(o_color_mat, u_color);
o_color = o_color_mat[0];
})";
// Use multiple inout variables with noncoherent qualifier
const char ESSL300_InOut6[] =
R"(
layout(noncoherent, location = 0) inout highp vec4 o_color0;
layout(noncoherent, location = 1) inout highp vec4 o_color1;
layout(noncoherent, location = 2) inout highp vec4 o_color2;
layout(noncoherent, location = 3) inout highp vec4 o_color3;
uniform highp vec4 u_color;
void main (void)
{
o_color0 = clamp(o_color0 + u_color, vec4(0.0f), vec4(1.0f));
o_color1 = clamp(o_color1 + u_color, vec4(0.0f), vec4(1.0f));
o_color2 = clamp(o_color2 + u_color, vec4(0.0f), vec4(1.0f));
o_color3 = clamp(o_color3 + u_color, vec4(0.0f), vec4(1.0f));
})";
class EXTShaderFramebufferFetchNoncoherentTest : 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.";
}
testing::AssertionResult TestShaderCompile(ShShaderOutput shaderOutputType, const char *pragma)
{
const char *shaderStrings[] = {testing::get<1>(GetParam()), pragma,
testing::get<2>(GetParam())};
bool success =
sh::Compile(mCompilerList[shaderOutputType], shaderStrings, 3, mCompileOptions);
if (success)
{
return ::testing::AssertionSuccess()
<< "Compilation success(" << mShaderOutputList[shaderOutputType] << ")";
}
return ::testing::AssertionFailure() << sh::GetInfoLog(mCompilerList[shaderOutputType]);
}
void TestShaderCompile(bool expectation, const char *pragma)
{
for (auto shaderOutputType : mShaderOutputList)
{
if (expectation)
{
EXPECT_TRUE(TestShaderCompile(shaderOutputType.first, pragma));
}
else
{
EXPECT_FALSE(TestShaderCompile(shaderOutputType.first, pragma));
}
}
}
void SetExtensionEnable(bool enable)
{
for (auto shaderOutputType : mShaderOutputList)
{
mResourceList[shaderOutputType.first].MaxDrawBuffers = 8;
mResourceList[shaderOutputType.first].EXT_shader_framebuffer_fetch_non_coherent =
enable;
}
}
private:
std::map<ShShaderOutput, std::string> mShaderOutputList;
std::map<ShShaderOutput, ShHandle> mCompilerList;
std::map<ShShaderOutput, ShBuiltInResources> mResourceList;
};
class EXTShaderFramebufferFetchNoncoherentES100Test
: public EXTShaderFramebufferFetchNoncoherentTest
{};
// Extension flag is required to compile properly. Expect failure when it is
// not present.
TEST_P(EXTShaderFramebufferFetchNoncoherentES100Test, CompileFailsWithoutExtension)
{
SetExtensionEnable(false);
InitializeCompiler();
TestShaderCompile(false, EXTPragma);
}
// Extension directive is required to compile properly. Expect failure when
// it is not present.
TEST_P(EXTShaderFramebufferFetchNoncoherentES100Test, CompileFailsWithExtensionWithoutPragma)
{
SetExtensionEnable(true);
InitializeCompiler();
TestShaderCompile(false, "");
}
class EXTShaderFramebufferFetchNoncoherentES300Test
: public EXTShaderFramebufferFetchNoncoherentTest
{};
// Extension flag is required to compile properly. Expect failure when it is
// not present.
TEST_P(EXTShaderFramebufferFetchNoncoherentES300Test, CompileFailsWithoutExtension)
{
SetExtensionEnable(false);
InitializeCompiler();
TestShaderCompile(false, EXTPragma);
}
// Extension directive is required to compile properly. Expect failure when
// it is not present.
TEST_P(EXTShaderFramebufferFetchNoncoherentES300Test, CompileFailsWithExtensionWithoutPragma)
{
SetExtensionEnable(true);
InitializeCompiler();
TestShaderCompile(false, "");
}
INSTANTIATE_TEST_SUITE_P(CorrectESSL100Shaders,
EXTShaderFramebufferFetchNoncoherentES100Test,
Combine(Values(SH_GLES2_SPEC),
Values(sh::ESSLVersion100),
Values(ESSL100_LastFragDataRedeclared1)));
INSTANTIATE_TEST_SUITE_P(CorrectESSL300Shaders,
EXTShaderFramebufferFetchNoncoherentES300Test,
Combine(Values(SH_GLES3_SPEC),
Values(sh::ESSLVersion300),
Values(ESSL300_InOut,
ESSL300_InOut2,
ESSL300_InOut3,
ESSL300_InOut4,
ESSL300_InOut5,
ESSL300_InOut6)));
#if defined(ANGLE_ENABLE_VULKAN)
// Use gl_LastFragData without redeclaration of gl_LastFragData with noncoherent qualifier
const char ESSL100_LastFragDataWithoutRedeclaration[] =
R"(
uniform highp vec4 u_color;
void main (void)
{
gl_FragColor = u_color + gl_LastFragData[0];
})";
// Redeclare gl_LastFragData without noncoherent qualifier
const char ESSL100_LastFragDataRedeclaredWithoutNoncoherent[] =
R"(
uniform highp vec4 u_color;
highp vec4 gl_LastFragData[gl_MaxDrawBuffers];
void main (void)
{
gl_FragColor = u_color + gl_LastFragData[0];
})";
// Use inout variable without noncoherent qualifier
const char ESSL300_InOutWithoutNoncoherent[] =
R"(
layout(location = 0) inout highp vec4 o_color;
uniform highp vec4 u_color;
void main (void)
{
o_color = clamp(o_color + u_color, vec4(0.0f), vec4(1.0f));
})";
class EXTShaderFramebufferFetchNoncoherentSuccessTest
: public EXTShaderFramebufferFetchNoncoherentTest
{
public:
void SetUp() override
{
std::map<ShShaderOutput, std::string> shaderOutputList = {
{SH_SPIRV_VULKAN_OUTPUT, "SH_SPIRV_VULKAN_OUTPUT"}};
Initialize(shaderOutputList);
}
};
class EXTShaderFramebufferFetchNoncoherentFailureTest
: public EXTShaderFramebufferFetchNoncoherentSuccessTest
{};
class EXTShaderFramebufferFetchNoncoherentES100SuccessTest
: public EXTShaderFramebufferFetchNoncoherentSuccessTest
{};
class EXTShaderFramebufferFetchNoncoherentES100FailureTest
: public EXTShaderFramebufferFetchNoncoherentFailureTest
{};
// With extension flag and extension directive, compiling succeeds.
// Also test that the extension directive state is reset correctly.
TEST_P(EXTShaderFramebufferFetchNoncoherentES100SuccessTest, CompileSucceedsWithExtensionAndPragma)
{
SetExtensionEnable(true);
InitializeCompiler();
TestShaderCompile(true, EXTPragma);
// Test reset functionality.
TestShaderCompile(false, "");
TestShaderCompile(true, EXTPragma);
}
//
TEST_P(EXTShaderFramebufferFetchNoncoherentES100FailureTest, CompileFailsWithoutNoncoherent)
{
SetExtensionEnable(true);
InitializeCompiler();
TestShaderCompile(false, EXTPragma);
}
class EXTShaderFramebufferFetchNoncoherentES300SuccessTest
: public EXTShaderFramebufferFetchNoncoherentSuccessTest
{};
class EXTShaderFramebufferFetchNoncoherentES300FailureTest
: public EXTShaderFramebufferFetchNoncoherentFailureTest
{};
// With extension flag and extension directive, compiling succeeds.
// Also test that the extension directive state is reset correctly.
TEST_P(EXTShaderFramebufferFetchNoncoherentES300SuccessTest, CompileSucceedsWithExtensionAndPragma)
{
SetExtensionEnable(true);
InitializeCompiler();
TestShaderCompile(true, EXTPragma);
// Test reset functionality.
TestShaderCompile(false, "");
TestShaderCompile(true, EXTPragma);
}
//
TEST_P(EXTShaderFramebufferFetchNoncoherentES300FailureTest, CompileFailsWithoutNoncoherent)
{
SetExtensionEnable(true);
InitializeCompiler();
TestShaderCompile(false, EXTPragma);
}
// 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(CorrectESSL100Shaders,
EXTShaderFramebufferFetchNoncoherentES100SuccessTest,
Combine(Values(SH_GLES2_SPEC),
Values(sh::ESSLVersion100),
Values(ESSL100_LastFragDataRedeclared1)));
INSTANTIATE_TEST_SUITE_P(IncorrectESSL100Shaders,
EXTShaderFramebufferFetchNoncoherentES100FailureTest,
Combine(Values(SH_GLES2_SPEC),
Values(sh::ESSLVersion100),
Values(ESSL100_LastFragDataWithoutRedeclaration,
ESSL100_LastFragDataRedeclaredWithoutNoncoherent)));
INSTANTIATE_TEST_SUITE_P(CorrectESSL300Shaders,
EXTShaderFramebufferFetchNoncoherentES300SuccessTest,
Combine(Values(SH_GLES3_SPEC),
Values(sh::ESSLVersion300),
Values(ESSL300_InOut,
ESSL300_InOut2,
ESSL300_InOut3,
ESSL300_InOut4,
ESSL300_InOut5,
ESSL300_InOut6)));
INSTANTIATE_TEST_SUITE_P(IncorrectESSL300Shaders,
EXTShaderFramebufferFetchNoncoherentES300FailureTest,
Combine(Values(SH_GLES3_SPEC),
Values(sh::ESSLVersion300),
Values(ESSL300_InOutWithoutNoncoherent)));
#endif
} // anonymous namespace