From 04b3e8746fa363b05ece9b314c8e3a067f971bbe Mon Sep 17 00:00:00 2001 From: Maciej Jesionowski Date: Mon, 26 Sep 2016 16:49:09 +0200 Subject: [PATCH] SPV: PrimitiveId in frag shader will emit Geometry capability Using PrimitiveId in a fragment shader requires declaring an OpCapability with either Geometry or Tessellation. --- SPIRV/GlslangToSpv.cpp | 8 +++++++- Test/baseResults/spv.400.frag.out | 14 ++++++++++++-- Test/spv.400.frag | 2 ++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index c79b6c21..34cdc5c2 100755 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -499,11 +499,17 @@ spv::BuiltIn TGlslangToSpvTraverser::TranslateBuiltInDecoration(glslang::TBuiltI case glslang::EbvInstanceIndex: return spv::BuiltInInstanceIndex; case glslang::EbvBaseVertex: case glslang::EbvBaseInstance: + case glslang::EbvDrawId: // TODO: Add SPIR-V builtin ID. logger->missingFunctionality("shader draw parameters"); return spv::BuiltInMax; - case glslang::EbvPrimitiveId: return spv::BuiltInPrimitiveId; + + case glslang::EbvPrimitiveId: + if (glslangIntermediate->getStage() == EShLangFragment) + builder.addCapability(spv::CapabilityGeometry); + return spv::BuiltInPrimitiveId; + case glslang::EbvInvocationId: return spv::BuiltInInvocationId; case glslang::EbvTessLevelInner: return spv::BuiltInTessLevelInner; case glslang::EbvTessLevelOuter: return spv::BuiltInTessLevelOuter; diff --git a/Test/baseResults/spv.400.frag.out b/Test/baseResults/spv.400.frag.out index f06b0fcd..7858845e 100644 --- a/Test/baseResults/spv.400.frag.out +++ b/Test/baseResults/spv.400.frag.out @@ -7,16 +7,17 @@ Linked fragment stage: // Module Version 10000 // Generated by (magic number): 80001 -// Id's are bound by 1114 +// Id's are bound by 1118 Capability Shader + Capability Geometry Capability Float64 Capability ImageGatherExtended Capability ClipDistance Capability SampledRect 1: ExtInstImport "GLSL.std.450" MemoryModel Logical GLSL450 - EntryPoint Fragment 4 "main" 13 1027 1033 1038 1050 1076 1097 1099 1105 1107 + EntryPoint Fragment 4 "main" 13 1027 1033 1038 1050 1076 1097 1099 1105 1107 1116 ExecutionMode 4 OriginUpperLeft Source GLSL 400 SourceExtension "GL_ARB_separate_shader_objects" @@ -55,6 +56,8 @@ Linked fragment stage: Name 1099 "vl2" Name 1105 "uo" Name 1107 "u" + Name 1115 "id" + Name 1116 "gl_PrimitiveID" Decorate 17(u2drs) DescriptorSet 0 Decorate 1025(arrayedSampler) DescriptorSet 0 Decorate 1027(i) Flat @@ -64,6 +67,8 @@ Linked fragment stage: Decorate 1097(gl_FragCoord) BuiltIn FragCoord Decorate 1099(vl2) Location 6 Decorate 1107(u) Flat + Decorate 1116(gl_PrimitiveID) Flat + Decorate 1116(gl_PrimitiveID) BuiltIn PrimitiveId 2: TypeVoid 3: TypeFunction 2 10: TypeFloat 32 @@ -185,9 +190,12 @@ Linked fragment stage: 1105(uo): 1104(ptr) Variable Output 1106: TypePointer Input 32(int) 1107(u): 1106(ptr) Variable Input + 1114: TypePointer Function 23(int) +1116(gl_PrimitiveID): 1026(ptr) Variable Input 4(main): 2 Function None 3 5: Label 1019(v): 1018(ptr) Variable Function + 1115(id): 1114(ptr) Variable Function 1028: 23(int) Load 1027(i) 1030: 1029(ptr) AccessChain 1025(arrayedSampler) 1028 1031: 1021 Load 1030 @@ -242,6 +250,8 @@ Linked fragment stage: Store 1105(uo) 1111 1112: 2 FunctionCall 6(foo23() 1113: 2 FunctionCall 8(doubles() + 1117: 23(int) Load 1116(gl_PrimitiveID) + Store 1115(id) 1117 Return FunctionEnd 6(foo23(): 2 Function None 3 diff --git a/Test/spv.400.frag b/Test/spv.400.frag index 05b4370b..d64c4700 100644 --- a/Test/spv.400.frag +++ b/Test/spv.400.frag @@ -259,5 +259,7 @@ void main() uo = u % i; foo23(); doubles(); + + int id = gl_PrimitiveID; }