Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 3fe06eb

Browse files
vontureCommit Bot
authored andcommitted
D3D: Make sure Lod0 functions are never referenced in non-fragment shaders.
The lod0 functions would not be declared but could still be referenced by vertex shaders. BUG=angleproject:3471 Change-Id: I635a8465ce68dc22a6f7387b30bf7e93b14dd67d Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1622741 Commit-Queue: Geoff Lang <[email protected]> Reviewed-by: Jiajia Qin <[email protected]>
1 parent 6722009 commit 3fe06eb

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/compiler/translator/OutputHLSL.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2293,7 +2293,8 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
22932293
{
22942294
TIntermSequence *arguments = node->getSequence();
22952295

2296-
bool lod0 = mInsideDiscontinuousLoop || mOutputLod0Function;
2296+
bool lod0 = (mInsideDiscontinuousLoop || mOutputLod0Function) &&
2297+
mShaderType == GL_FRAGMENT_SHADER;
22972298
if (node->getOp() == EOpCallFunctionInAST)
22982299
{
22992300
if (node->isArray())

src/tests/gl_tests/GLSLTest.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,6 +1975,41 @@ TEST_P(GLSLTest, TextureLOD)
19751975
glDeleteShader(shader);
19761976
}
19771977

1978+
// HLSL generates extra lod0 variants of functions. There was a bug that incorrectly reworte
1979+
// function calls to use them in vertex shaders. http://anglebug.com/3471
1980+
TEST_P(GLSLTest, TextureLODRewriteInVertexShader)
1981+
{
1982+
constexpr char kVS[] = R"(
1983+
precision highp float;
1984+
uniform int uni;
1985+
uniform sampler2D texture;
1986+
1987+
vec4 A();
1988+
1989+
vec4 B() {
1990+
vec4 a;
1991+
for(int r=0; r<14; r++){
1992+
if (r < uni) return vec4(0.0);
1993+
a = A();
1994+
}
1995+
return a;
1996+
}
1997+
1998+
vec4 A() {
1999+
return texture2D(texture, vec2(0.0, 0.0));
2000+
}
2001+
2002+
void main() {
2003+
gl_Position = B();
2004+
})";
2005+
2006+
constexpr char kFS[] = R"(
2007+
void main() { gl_FragColor = vec4(gl_FragCoord.x / 640.0, gl_FragCoord.y / 480.0, 0, 1); }
2008+
)";
2009+
2010+
ANGLE_GL_PROGRAM(program, kVS, kFS);
2011+
}
2012+
19782013
// Test to verify the a shader can have a sampler unused in a vertex shader
19792014
// but used in the fragment shader.
19802015
TEST_P(GLSLTest, VerifySamplerInBothVertexAndFragmentShaders)

0 commit comments

Comments
 (0)