diff --git a/Test/baseResults/150.frag.out b/Test/baseResults/150.frag.out index 066b8bb4e..ba15b5cbf 100644 --- a/Test/baseResults/150.frag.out +++ b/Test/baseResults/150.frag.out @@ -2,7 +2,6 @@ ERROR: 0:4: 'redeclaration' : cannot redeclare with different qualification: gl_FragCoord ERROR: 0:5: 'redeclaration' : cannot redeclare with different qualification: gl_FragCoord ERROR: 0:6: 'layout qualifier' : can only apply origin_upper_left and pixel_center_origin to gl_FragCoord -ERROR: 0:14: 'gl_FragCoord' : cannot redeclare after use ERROR: 0:50: 'gl_PerFragment' : undeclared identifier ERROR: 0:53: 'double' : Reserved word. ERROR: 0:53: 'double' : not supported for this version or the enabled extensions @@ -19,7 +18,7 @@ ERROR: 0:154: 'assign' : cannot convert from ' const float' to ' temp 2-compone ERROR: 0:155: 'textureQueryLOD' : no matching overloaded function found ERROR: 0:155: 'assign' : cannot convert from ' const float' to ' temp 2-component vector of float' ERROR: 0:183: 'mix' : required extension not requested: GL_EXT_shader_integer_mix -ERROR: 18 compilation errors. No code generated. +ERROR: 17 compilation errors. No code generated. Shader version: 150 diff --git a/Test/baseResults/gl_FragCoord.frag.out b/Test/baseResults/gl_FragCoord.frag.out new file mode 100644 index 000000000..da9e8dccd --- /dev/null +++ b/Test/baseResults/gl_FragCoord.frag.out @@ -0,0 +1,269 @@ +gl_FragCoord.frag +Shader version: 150 +Requested GL_ARB_explicit_attrib_location +gl_FragCoord pixel center is integer +gl_FragCoord origin is upper left +0:? Sequence +0:9 Sequence +0:9 move second child to first child ( temp float) +0:9 'myGlobalVar' ( global float) +0:9 direct index ( temp float) +0:9 'gl_FragCoord' ( gl_FragCoord 4-component vector of float FragCoord) +0:9 Constant: +0:9 0 (const int) +0:16 Function Definition: main( ( global void) +0:16 Function Parameters: +0:17 Sequence +0:17 move second child to first child ( temp 4-component vector of float) +0:17 'myColor' (layout( location=0) out 4-component vector of float) +0:17 Constant: +0:17 0.200000 +0:17 0.200000 +0:17 0.200000 +0:17 0.200000 +0:18 Test condition and select ( temp void) +0:18 Condition +0:18 Compare Greater Than or Equal ( temp bool) +0:18 direct index ( temp float) +0:18 'gl_FragCoord' ( gl_FragCoord 4-component vector of float FragCoord) +0:18 Constant: +0:18 1 (const int) +0:18 Constant: +0:18 10.000000 +0:18 true case +0:19 Sequence +0:19 move second child to first child ( temp float) +0:19 direct index ( temp float) +0:19 'myColor' (layout( location=0) out 4-component vector of float) +0:19 Constant: +0:19 2 (const int) +0:19 Constant: +0:19 0.800000 +0:21 Test condition and select ( temp void) +0:21 Condition +0:21 Compare Equal ( temp bool) +0:21 direct index ( temp float) +0:21 'gl_FragCoord' ( gl_FragCoord 4-component vector of float FragCoord) +0:21 Constant: +0:21 1 (const int) +0:21 trunc ( global float) +0:21 direct index ( temp float) +0:21 'gl_FragCoord' ( gl_FragCoord 4-component vector of float FragCoord) +0:21 Constant: +0:21 1 (const int) +0:21 true case +0:22 Sequence +0:22 move second child to first child ( temp float) +0:22 direct index ( temp float) +0:22 'myColor' (layout( location=0) out 4-component vector of float) +0:22 Constant: +0:22 1 (const int) +0:22 Constant: +0:22 0.800000 +0:24 Test condition and select ( temp void) +0:24 Condition +0:24 Compare Equal ( temp bool) +0:24 direct index ( temp float) +0:24 'gl_FragCoord' ( gl_FragCoord 4-component vector of float FragCoord) +0:24 Constant: +0:24 0 (const int) +0:24 trunc ( global float) +0:24 direct index ( temp float) +0:24 'gl_FragCoord' ( gl_FragCoord 4-component vector of float FragCoord) +0:24 Constant: +0:24 0 (const int) +0:24 true case +0:25 Sequence +0:25 move second child to first child ( temp float) +0:25 direct index ( temp float) +0:25 'myColor' (layout( location=0) out 4-component vector of float) +0:25 Constant: +0:25 0 (const int) +0:25 Constant: +0:25 0.800000 +0:28 Sequence +0:28 move second child to first child ( temp 4-component vector of float) +0:28 'diff' ( temp 4-component vector of float) +0:28 subtract ( temp 4-component vector of float) +0:28 'gl_FragCoord' ( gl_FragCoord 4-component vector of float FragCoord) +0:28 'i' ( smooth in 4-component vector of float) +0:29 Test condition and select ( temp void) +0:29 Condition +0:29 Compare Greater Than ( temp bool) +0:29 Absolute value ( global float) +0:29 direct index ( temp float) +0:29 'diff' ( temp 4-component vector of float) +0:29 Constant: +0:29 2 (const int) +0:29 Constant: +0:29 0.001000 +0:29 true case +0:29 move second child to first child ( temp float) +0:29 direct index ( temp float) +0:29 'myColor' (layout( location=0) out 4-component vector of float) +0:29 Constant: +0:29 2 (const int) +0:29 Constant: +0:29 0.500000 +0:30 Test condition and select ( temp void) +0:30 Condition +0:30 Compare Greater Than ( temp bool) +0:30 Absolute value ( global float) +0:30 direct index ( temp float) +0:30 'diff' ( temp 4-component vector of float) +0:30 Constant: +0:30 3 (const int) +0:30 Constant: +0:30 0.001000 +0:30 true case +0:30 move second child to first child ( temp float) +0:30 direct index ( temp float) +0:30 'myColor' (layout( location=0) out 4-component vector of float) +0:30 Constant: +0:30 3 (const int) +0:30 Constant: +0:30 0.500000 +0:? Linker Objects +0:? 'gl_FragCoord' ( gl_FragCoord 4-component vector of float FragCoord) +0:? 'myGlobalVar' ( global float) +0:? 'i' ( smooth in 4-component vector of float) +0:? 'myColor' (layout( location=0) out 4-component vector of float) +0:? 'eps' ( const float) +0:? 0.001000 + + +Linked fragment stage: + + +Shader version: 150 +Requested GL_ARB_explicit_attrib_location +gl_FragCoord pixel center is integer +gl_FragCoord origin is upper left +0:? Sequence +0:9 Sequence +0:9 move second child to first child ( temp float) +0:9 'myGlobalVar' ( global float) +0:9 direct index ( temp float) +0:9 'gl_FragCoord' ( gl_FragCoord 4-component vector of float FragCoord) +0:9 Constant: +0:9 0 (const int) +0:16 Function Definition: main( ( global void) +0:16 Function Parameters: +0:17 Sequence +0:17 move second child to first child ( temp 4-component vector of float) +0:17 'myColor' (layout( location=0) out 4-component vector of float) +0:17 Constant: +0:17 0.200000 +0:17 0.200000 +0:17 0.200000 +0:17 0.200000 +0:18 Test condition and select ( temp void) +0:18 Condition +0:18 Compare Greater Than or Equal ( temp bool) +0:18 direct index ( temp float) +0:18 'gl_FragCoord' ( gl_FragCoord 4-component vector of float FragCoord) +0:18 Constant: +0:18 1 (const int) +0:18 Constant: +0:18 10.000000 +0:18 true case +0:19 Sequence +0:19 move second child to first child ( temp float) +0:19 direct index ( temp float) +0:19 'myColor' (layout( location=0) out 4-component vector of float) +0:19 Constant: +0:19 2 (const int) +0:19 Constant: +0:19 0.800000 +0:21 Test condition and select ( temp void) +0:21 Condition +0:21 Compare Equal ( temp bool) +0:21 direct index ( temp float) +0:21 'gl_FragCoord' ( gl_FragCoord 4-component vector of float FragCoord) +0:21 Constant: +0:21 1 (const int) +0:21 trunc ( global float) +0:21 direct index ( temp float) +0:21 'gl_FragCoord' ( gl_FragCoord 4-component vector of float FragCoord) +0:21 Constant: +0:21 1 (const int) +0:21 true case +0:22 Sequence +0:22 move second child to first child ( temp float) +0:22 direct index ( temp float) +0:22 'myColor' (layout( location=0) out 4-component vector of float) +0:22 Constant: +0:22 1 (const int) +0:22 Constant: +0:22 0.800000 +0:24 Test condition and select ( temp void) +0:24 Condition +0:24 Compare Equal ( temp bool) +0:24 direct index ( temp float) +0:24 'gl_FragCoord' ( gl_FragCoord 4-component vector of float FragCoord) +0:24 Constant: +0:24 0 (const int) +0:24 trunc ( global float) +0:24 direct index ( temp float) +0:24 'gl_FragCoord' ( gl_FragCoord 4-component vector of float FragCoord) +0:24 Constant: +0:24 0 (const int) +0:24 true case +0:25 Sequence +0:25 move second child to first child ( temp float) +0:25 direct index ( temp float) +0:25 'myColor' (layout( location=0) out 4-component vector of float) +0:25 Constant: +0:25 0 (const int) +0:25 Constant: +0:25 0.800000 +0:28 Sequence +0:28 move second child to first child ( temp 4-component vector of float) +0:28 'diff' ( temp 4-component vector of float) +0:28 subtract ( temp 4-component vector of float) +0:28 'gl_FragCoord' ( gl_FragCoord 4-component vector of float FragCoord) +0:28 'i' ( smooth in 4-component vector of float) +0:29 Test condition and select ( temp void) +0:29 Condition +0:29 Compare Greater Than ( temp bool) +0:29 Absolute value ( global float) +0:29 direct index ( temp float) +0:29 'diff' ( temp 4-component vector of float) +0:29 Constant: +0:29 2 (const int) +0:29 Constant: +0:29 0.001000 +0:29 true case +0:29 move second child to first child ( temp float) +0:29 direct index ( temp float) +0:29 'myColor' (layout( location=0) out 4-component vector of float) +0:29 Constant: +0:29 2 (const int) +0:29 Constant: +0:29 0.500000 +0:30 Test condition and select ( temp void) +0:30 Condition +0:30 Compare Greater Than ( temp bool) +0:30 Absolute value ( global float) +0:30 direct index ( temp float) +0:30 'diff' ( temp 4-component vector of float) +0:30 Constant: +0:30 3 (const int) +0:30 Constant: +0:30 0.001000 +0:30 true case +0:30 move second child to first child ( temp float) +0:30 direct index ( temp float) +0:30 'myColor' (layout( location=0) out 4-component vector of float) +0:30 Constant: +0:30 3 (const int) +0:30 Constant: +0:30 0.500000 +0:? Linker Objects +0:? 'gl_FragCoord' ( gl_FragCoord 4-component vector of float FragCoord) +0:? 'myGlobalVar' ( global float) +0:? 'i' ( smooth in 4-component vector of float) +0:? 'myColor' (layout( location=0) out 4-component vector of float) +0:? 'eps' ( const float) +0:? 0.001000 + diff --git a/Test/gl_FragCoord.frag b/Test/gl_FragCoord.frag new file mode 100644 index 000000000..7bb17920e --- /dev/null +++ b/Test/gl_FragCoord.frag @@ -0,0 +1,31 @@ +#version 150 core +#extension GL_ARB_explicit_attrib_location : enable + +#ifdef GL_ES +precision mediump float; +#endif + +layout (origin_upper_left,pixel_center_integer) in vec4 gl_FragCoord; +float myGlobalVar = gl_FragCoord.x; +layout (origin_upper_left,pixel_center_integer) in vec4 gl_FragCoord; + +in vec4 i; +layout (location = 0) out vec4 myColor; +const float eps=0.001; + +void main() { + myColor = vec4(0.2); + if (gl_FragCoord.y >= 10) { + myColor.b = 0.8; + } + if (gl_FragCoord.y == trunc(gl_FragCoord.y)) { + myColor.g = 0.8; + } + if (gl_FragCoord.x == trunc(gl_FragCoord.x)) { + myColor.r = 0.8; + } + + vec4 diff = gl_FragCoord - i; + if (abs(diff.z)>eps) myColor.b = 0.5; + if (abs(diff.w)>eps) myColor.a = 0.5; +} diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index 508b16b08..ae89889c4 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -4680,7 +4680,7 @@ TSymbol* TParseContext::redeclareBuiltinVariable(const TSourceLoc& loc, const TS symbolQualifier.storage != qualifier.storage) error(loc, "cannot change qualification of", "redeclaration", symbol->getName().c_str()); } else if (identifier == "gl_FragCoord") { - if (intermediate.inIoAccessed("gl_FragCoord")) + if (!intermediate.getTexCoordRedeclared() && intermediate.inIoAccessed("gl_FragCoord")) error(loc, "cannot redeclare after use", "gl_FragCoord", ""); if (qualifier.nopersp != symbolQualifier.nopersp || qualifier.flat != symbolQualifier.flat || qualifier.isMemory() || qualifier.isAuxiliary()) @@ -4690,6 +4690,9 @@ TSymbol* TParseContext::redeclareBuiltinVariable(const TSourceLoc& loc, const TS if (! builtIn && (publicType.pixelCenterInteger != intermediate.getPixelCenterInteger() || publicType.originUpperLeft != intermediate.getOriginUpperLeft())) error(loc, "cannot redeclare with different qualification:", "redeclaration", symbol->getName().c_str()); + + + intermediate.setTexCoordRedeclared(); if (publicType.pixelCenterInteger) intermediate.setPixelCenterInteger(); if (publicType.originUpperLeft) diff --git a/glslang/MachineIndependent/localintermediate.h b/glslang/MachineIndependent/localintermediate.h index c4d80159d..581e9aa2e 100644 --- a/glslang/MachineIndependent/localintermediate.h +++ b/glslang/MachineIndependent/localintermediate.h @@ -309,7 +309,7 @@ public: useVulkanMemoryModel(false), invocations(TQualifier::layoutNotSet), vertices(TQualifier::layoutNotSet), inputPrimitive(ElgNone), outputPrimitive(ElgNone), - pixelCenterInteger(false), originUpperLeft(false), + pixelCenterInteger(false), originUpperLeft(false),texCoordBuiltinRedeclared(false), vertexSpacing(EvsNone), vertexOrder(EvoNone), interlockOrdering(EioNone), pointMode(false), earlyFragmentTests(false), postDepthCoverage(false), depthLayout(EldNone), hlslFunctionality1(false), @@ -834,6 +834,8 @@ public: bool getOriginUpperLeft() const { return originUpperLeft; } void setPixelCenterInteger() { pixelCenterInteger = true; } bool getPixelCenterInteger() const { return pixelCenterInteger; } + void setTexCoordRedeclared() { texCoordBuiltinRedeclared = true; } + bool getTexCoordRedeclared() const { return texCoordBuiltinRedeclared; } void addBlendEquation(TBlendEquationShift b) { blendEquations |= (1 << b); } unsigned int getBlendEquations() const { return blendEquations; } bool setXfbBufferStride(int buffer, unsigned stride) @@ -1122,6 +1124,7 @@ protected: TLayoutGeometry outputPrimitive; bool pixelCenterInteger; bool originUpperLeft; + bool texCoordBuiltinRedeclared; TVertexSpacing vertexSpacing; TVertexOrder vertexOrder; TInterlockOrdering interlockOrdering; @@ -1182,6 +1185,7 @@ protected: // for callableData/callableDataIn // set of names of statically read/written I/O that might need extra checking std::set ioAccessed; + // source code of shader, useful as part of debug information std::string sourceFile; std::string sourceText; diff --git a/gtests/AST.FromFile.cpp b/gtests/AST.FromFile.cpp index 6270ca0df..1d975464f 100644 --- a/gtests/AST.FromFile.cpp +++ b/gtests/AST.FromFile.cpp @@ -295,6 +295,7 @@ INSTANTIATE_TEST_SUITE_P( "EndStreamPrimitive.geom", "floatBitsToInt.vert", "coord_conventions.frag", + "gl_FragCoord.frag" })), FileNameAsCustomTestSuffix );