summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2020-02-10 13:09:37 -0800
committerGitHub <noreply@github.com>2020-02-10 13:09:37 -0800
commit56771d655d77395e4fe879cc19771d461aa01190 (patch)
tree1ea915ae2db4a1e164f2676014c17f8c3c796629 /source
parent60dfb62e638a06ebdcef27138b63033b828ec2ef (diff)
Fix output GLSL for primitive ID in a geometry shader (#1214)
We had been translating an `SV_PrimitiveID` input in a shader over to `gl_PrimitiveID` in GLSL. That translation seemed to work just fine for users, so we thought it was correct. It turns out that `gl_PrimitiveID` is the correct GLSL for a primitive ID input in every stage *except* a geometry shader. In a geometry shader, `gl_PrimitiveID` is a primitive ID *output*, and if you want the input case you have to write `gl_PrimitiveIDIn` (note the `In` suffix). This change sets aside my bewilderment at the above long enough to implement a workaround in the GLSL legalization step. I also modified our current geometry shader cross compilation test to make use of an input primitive ID.
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-ir-glsl-legalize.cpp31
1 files changed, 29 insertions, 2 deletions
diff --git a/source/slang/slang-ir-glsl-legalize.cpp b/source/slang/slang-ir-glsl-legalize.cpp
index 263e56f55..2c889f341 100644
--- a/source/slang/slang-ir-glsl-legalize.cpp
+++ b/source/slang/slang-ir-glsl-legalize.cpp
@@ -414,9 +414,36 @@ GLSLSystemValueInfo* getGLSLSystemValueInfo(
{
// uint in hlsl, int in glsl
// https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/gl_PrimitiveID.xhtml
- name = "gl_PrimitiveID";
-
requiredType = builder->getBasicType(BaseType::Int);
+
+ switch( context->getStage() )
+ {
+ default:
+ name = "gl_PrimitiveID";
+ break;
+
+ case Stage::Geometry:
+ // GLSL makes a confusing design choice here.
+ //
+ // All the non-GS stages use `gl_PrimitiveID` to access
+ // the *input* primitive ID, but a GS uses `gl_PrimitiveID`
+ // to acces an *output* primitive ID (that will be passed
+ // along to the fragment shader).
+ //
+ // For a GS to get an input primitive ID (the thing that
+ // other stages access with `gl_PrimitiveID`), the
+ // programmer must write `gl_PrimitiveIDIn`.
+ //
+ if( kind == LayoutResourceKind::VaryingInput )
+ {
+ name = "gl_PrimitiveIDIn";
+ }
+ else
+ {
+ name = "gl_PrimitiveID";
+ }
+ break;
+ }
}
else if (semanticName == "sv_rendertargetarrayindex")
{