diff options
author | Kimmo Kinnunen <kkinnunen@apple.com> | 2024-04-22 18:11:30 -0700 |
---|---|---|
committer | Angle LUCI CQ <angle-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2024-04-23 03:32:32 +0000 |
commit | 6fe8a399dd7fd5dd7fe2d8e4eae81a5b5f586aa9 (patch) | |
tree | c3608b125c738c6931e9c986193792139b41e56e | |
parent | 2905a6a6e299910aa9f472dc11c06f6b22561f09 (diff) | |
download | angle-6fe8a399dd7fd5dd7fe2d8e4eae81a5b5f586aa9.tar.gz |
Metal: Fix rewritten out variables with underscores
Fix compilation in case of output variables start with underscores.
Make name emission always emit MSL name ANGLE_{name}, so that GLSL `_e`
and `e` cannot clash. This regressed in angleproject:8558.
Bug: chromium:335744344
Change-Id: Ibae4dba4a24888acc1461582e69d48218ba11176
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5473412
Reviewed-by: Kenneth Russell <kbr@chromium.org>
Auto-Submit: Kimmo Kinnunen <kkinnunen@apple.com>
Commit-Queue: Kimmo Kinnunen <kkinnunen@apple.com>
Reviewed-by: Kimmo Kinnunen <kkinnunen@apple.com>
-rw-r--r-- | src/compiler/translator/msl/Name.cpp | 6 | ||||
-rw-r--r-- | src/compiler/translator/msl/TranslatorMSL.cpp | 2 | ||||
-rw-r--r-- | src/tests/gl_tests/GLSLTest.cpp | 60 |
3 files changed, 62 insertions, 6 deletions
diff --git a/src/compiler/translator/msl/Name.cpp b/src/compiler/translator/msl/Name.cpp index 9dc3b5481a..7faed0f5ba 100644 --- a/src/compiler/translator/msl/Name.cpp +++ b/src/compiler/translator/msl/Name.cpp @@ -96,13 +96,9 @@ void Name::emitImpl(T &out) const { out << mRawName; } - else if (mRawName[0] != '_') - { - out << kAngleInternalPrefix << '_' << mRawName; - } else { - out << kAngleInternalPrefix << mRawName; + out << kAngleInternalPrefix << '_' << mRawName; } break; diff --git a/src/compiler/translator/msl/TranslatorMSL.cpp b/src/compiler/translator/msl/TranslatorMSL.cpp index 73fb34d17f..06d309e1ad 100644 --- a/src/compiler/translator/msl/TranslatorMSL.cpp +++ b/src/compiler/translator/msl/TranslatorMSL.cpp @@ -520,7 +520,7 @@ void AddFragDepthEXTDeclaration(TCompiler &compiler, TIntermBlock &root, TSymbol // EXT_blend_func_extended usage, the exact variable may be unknown until the // program is linked. TVariable *alpha0 = - new TVariable(&symbolTable, sh::ImmutableString("_ALPHA0"), + new TVariable(&symbolTable, sh::ImmutableString("ALPHA0"), StaticType::Get<EbtFloat, EbpUndefined, EvqSpecConst, 1, 1>(), SymbolType::AngleInternal); diff --git a/src/tests/gl_tests/GLSLTest.cpp b/src/tests/gl_tests/GLSLTest.cpp index fde319d879..58feeaf77b 100644 --- a/src/tests/gl_tests/GLSLTest.cpp +++ b/src/tests/gl_tests/GLSLTest.cpp @@ -19231,6 +19231,66 @@ Foo foo(float bar) EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } +// Test that underscores in array names work with out arrays. +TEST_P(GLSLTest_ES3, UnderscoresWorkWithOutArrays) +{ + GLuint fbo; + glGenFramebuffers(1, &fbo); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); + + GLuint textures[4]; + glGenTextures(4, textures); + + for (size_t texIndex = 0; texIndex < ArraySize(textures); texIndex++) + { + glBindTexture(GL_TEXTURE_2D, textures[texIndex]); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA, + GL_UNSIGNED_BYTE, nullptr); + } + + GLint maxDrawBuffers; + glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers); + ASSERT_GE(maxDrawBuffers, 4); + + GLuint readFramebuffer; + glGenFramebuffers(1, &readFramebuffer); + glBindFramebuffer(GL_READ_FRAMEBUFFER, readFramebuffer); + + constexpr char kFS[] = R"(#version 300 es +precision highp float; +out vec4 _e[4]; +void main() +{ + _e[0] = vec4(1.0, 0.0, 0.0, 1.0); + _e[1] = vec4(0.0, 1.0, 0.0, 1.0); + _e[2] = vec4(0.0, 0.0, 1.0, 1.0); + _e[3] = vec4(1.0, 1.0, 1.0, 1.0); +} +)"; + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); + GLenum allBufs[4] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, + GL_COLOR_ATTACHMENT3}; + constexpr GLuint kMaxBuffers = 4; + // Enable all draw buffers. + for (GLuint texIndex = 0; texIndex < kMaxBuffers; texIndex++) + { + glBindTexture(GL_TEXTURE_2D, textures[texIndex]); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + texIndex, GL_TEXTURE_2D, + textures[texIndex], 0); + glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + texIndex, GL_TEXTURE_2D, + textures[texIndex], 0); + } + glDrawBuffers(kMaxBuffers, allBufs); + + // Draw with simple program. + drawQuad(program, essl3_shaders::PositionAttrib(), 0.5f, 1.0f, true); + ASSERT_GL_NO_ERROR(); + verifyAttachment2DColor(0, textures[0], GL_TEXTURE_2D, 0, GLColor::red); + verifyAttachment2DColor(1, textures[1], GL_TEXTURE_2D, 0, GLColor::green); + verifyAttachment2DColor(2, textures[2], GL_TEXTURE_2D, 0, GLColor::blue); + verifyAttachment2DColor(3, textures[3], GL_TEXTURE_2D, 0, GLColor::white); +} + } // anonymous namespace ANGLE_INSTANTIATE_TEST_ES2_AND_ES3_AND( |