gl_PrimitiveID in GLSL fragment shader causes SPIR-V validation error #6007
Labels
goal:quality & productivity
Quality issues and issues that impact our productivity coding day to day inside slang
Milestone
gl_PrimitiveID
should be available in fragment shaders as well. Currently, if you try to use it, a SPIR-V validation issue occurs:This is because
OpCapability Geometry
should be required ifgl_PrimitiveID
is used in a fragment shader.Analysis:
This case would work correctly if
glsl.meta.slang
had justpublic in int gl_PrimitiveID : SV_PrimitiveID;
, because there's already logic inslang-emit-spirv.cpp
to handleSV_PrimitiveID
correctly. Unfortunately,gl_PrimitiveID
is also used in the ray tracing shaders, and to handle that use case,glsl.meta.slang
actually has this instead:This
PrimitiveIndex()
generatesPrimitiveId
usingspirv_asm
. When done this way, the SPIR-V emitter does not add the required capability in a fragment shader, but behaves correctly in the ray tracing shaders as they don't need additional capabilities for this builtin.It would probably not be too hard to just check through the
SPIRVAsmOperandBuiltinVar
s and require the Geometry capability ifPrimitiveId
is encountered, but that feels "hacky" to me and doesn't fix the GLSL emitter unnecessarily requiringGL_EXT_ray_tracing
because ofsetupExtForRayTracingBuiltIn()
. I'm not yet super familiar with the intricacies here; is there a way to have thisgl_PrimitiveID
property behave differently depending on what shader stage is accessing it?The text was updated successfully, but these errors were encountered: