Commit 3fe06eb3 by Geoff Lang Committed by Commit Bot

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 <geofflang@chromium.org> Reviewed-by: 's avatarJiajia Qin <jiajia.qin@intel.com>
parent 6722009e
...@@ -2293,7 +2293,8 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -2293,7 +2293,8 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
{ {
TIntermSequence *arguments = node->getSequence(); TIntermSequence *arguments = node->getSequence();
bool lod0 = mInsideDiscontinuousLoop || mOutputLod0Function; bool lod0 = (mInsideDiscontinuousLoop || mOutputLod0Function) &&
mShaderType == GL_FRAGMENT_SHADER;
if (node->getOp() == EOpCallFunctionInAST) if (node->getOp() == EOpCallFunctionInAST)
{ {
if (node->isArray()) if (node->isArray())
......
...@@ -1975,6 +1975,41 @@ TEST_P(GLSLTest, TextureLOD) ...@@ -1975,6 +1975,41 @@ TEST_P(GLSLTest, TextureLOD)
glDeleteShader(shader); glDeleteShader(shader);
} }
// HLSL generates extra lod0 variants of functions. There was a bug that incorrectly reworte
// function calls to use them in vertex shaders. http://anglebug.com/3471
TEST_P(GLSLTest, TextureLODRewriteInVertexShader)
{
constexpr char kVS[] = R"(
precision highp float;
uniform int uni;
uniform sampler2D texture;
vec4 A();
vec4 B() {
vec4 a;
for(int r=0; r<14; r++){
if (r < uni) return vec4(0.0);
a = A();
}
return a;
}
vec4 A() {
return texture2D(texture, vec2(0.0, 0.0));
}
void main() {
gl_Position = B();
})";
constexpr char kFS[] = R"(
void main() { gl_FragColor = vec4(gl_FragCoord.x / 640.0, gl_FragCoord.y / 480.0, 0, 1); }
)";
ANGLE_GL_PROGRAM(program, kVS, kFS);
}
// Test to verify the a shader can have a sampler unused in a vertex shader // Test to verify the a shader can have a sampler unused in a vertex shader
// but used in the fragment shader. // but used in the fragment shader.
TEST_P(GLSLTest, VerifySamplerInBothVertexAndFragmentShaders) TEST_P(GLSLTest, VerifySamplerInBothVertexAndFragmentShaders)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment