From 78a4557621c77dbe29f4b6f98ce6582c68da88fe Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Fri, 8 Jul 2016 14:05:15 -0600 Subject: [PATCH] SPV: Fix issue #376; declare Geometry capability for fragment use of gl_Layer. --- SPIRV/GlslangToSpv.cpp | 35 +++++++++++--------- Test/baseResults/spv.430.frag.out | 54 +++++++++++++++++++++++++++++++ Test/spv.430.frag | 10 ++++++ gtests/Spv.FromFile.cpp | 1 + 4 files changed, 84 insertions(+), 16 deletions(-) create mode 100755 Test/baseResults/spv.430.frag.out create mode 100644 Test/spv.430.frag diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index 04c4017b2..725aac172 100755 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -416,19 +416,19 @@ spv::BuiltIn TGlslangToSpvTraverser::TranslateBuiltInDecoration(glslang::TBuiltI { switch (builtIn) { case glslang::EbvPointSize: - // Defer adding the capability until the built-in is actually used. - if (!memberDeclaration) { - switch (glslangIntermediate->getStage()) { - case EShLangGeometry: - builder.addCapability(spv::CapabilityGeometryPointSize); - break; - case EShLangTessControl: - case EShLangTessEvaluation: - builder.addCapability(spv::CapabilityTessellationPointSize); - break; - default: - break; - } + // Defer adding the capability until the built-in is actually used. + if (! memberDeclaration) { + switch (glslangIntermediate->getStage()) { + case EShLangGeometry: + builder.addCapability(spv::CapabilityGeometryPointSize); + break; + case EShLangTessControl: + case EShLangTessEvaluation: + builder.addCapability(spv::CapabilityTessellationPointSize); + break; + default: + break; + } } return spv::BuiltInPointSize; @@ -440,12 +440,12 @@ spv::BuiltIn TGlslangToSpvTraverser::TranslateBuiltInDecoration(glslang::TBuiltI // case glslang::EbvClipDistance: if (!memberDeclaration) - builder.addCapability(spv::CapabilityClipDistance); + builder.addCapability(spv::CapabilityClipDistance); return spv::BuiltInClipDistance; case glslang::EbvCullDistance: if (!memberDeclaration) - builder.addCapability(spv::CapabilityCullDistance); + builder.addCapability(spv::CapabilityCullDistance); return spv::BuiltInCullDistance; case glslang::EbvViewportIndex: @@ -464,6 +464,10 @@ spv::BuiltIn TGlslangToSpvTraverser::TranslateBuiltInDecoration(glslang::TBuiltI builder.addCapability(spv::CapabilitySampleRateShading); return spv::BuiltInSampleMask; + case glslang::EbvLayer: + builder.addCapability(spv::CapabilityGeometry); + return spv::BuiltInLayer; + case glslang::EbvPosition: return spv::BuiltInPosition; case glslang::EbvVertexId: return spv::BuiltInVertexId; case glslang::EbvInstanceId: return spv::BuiltInInstanceId; @@ -477,7 +481,6 @@ spv::BuiltIn TGlslangToSpvTraverser::TranslateBuiltInDecoration(glslang::TBuiltI return (spv::BuiltIn)spv::BadValue; case glslang::EbvPrimitiveId: return spv::BuiltInPrimitiveId; case glslang::EbvInvocationId: return spv::BuiltInInvocationId; - case glslang::EbvLayer: return spv::BuiltInLayer; case glslang::EbvTessLevelInner: return spv::BuiltInTessLevelInner; case glslang::EbvTessLevelOuter: return spv::BuiltInTessLevelOuter; case glslang::EbvTessCoord: return spv::BuiltInTessCoord; diff --git a/Test/baseResults/spv.430.frag.out b/Test/baseResults/spv.430.frag.out new file mode 100755 index 000000000..0058e9c81 --- /dev/null +++ b/Test/baseResults/spv.430.frag.out @@ -0,0 +1,54 @@ +spv.430.frag +Warning, version 430 is not yet complete; most version-specific features are present, but some are missing. + + +Linked fragment stage: + + +// Module Version 10000 +// Generated by (magic number): 80001 +// Id's are bound by 24 + + Capability Shader + Capability Geometry + Capability MultiViewport + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint Fragment 4 "main" 9 14 19 + ExecutionMode 4 OriginUpperLeft + Source GLSL 430 + Name 4 "main" + Name 9 "color" + Name 14 "gl_Layer" + Name 19 "gl_ViewportIndex" + Decorate 14(gl_Layer) Flat + Decorate 14(gl_Layer) BuiltIn Layer + Decorate 19(gl_ViewportIndex) Flat + Decorate 19(gl_ViewportIndex) BuiltIn ViewportIndex + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeFloat 32 + 7: TypeVector 6(float) 4 + 8: TypePointer Output 7(fvec4) + 9(color): 8(ptr) Variable Output + 10: 6(float) Constant 1065353216 + 11: 7(fvec4) ConstantComposite 10 10 10 10 + 12: TypeInt 32 1 + 13: TypePointer Input 12(int) + 14(gl_Layer): 13(ptr) Variable Input +19(gl_ViewportIndex): 13(ptr) Variable Input + 4(main): 2 Function None 3 + 5: Label + Store 9(color) 11 + 15: 12(int) Load 14(gl_Layer) + 16: 6(float) ConvertSToF 15 + 17: 7(fvec4) Load 9(color) + 18: 7(fvec4) VectorTimesScalar 17 16 + Store 9(color) 18 + 20: 12(int) Load 19(gl_ViewportIndex) + 21: 6(float) ConvertSToF 20 + 22: 7(fvec4) Load 9(color) + 23: 7(fvec4) VectorTimesScalar 22 21 + Store 9(color) 23 + Return + FunctionEnd diff --git a/Test/spv.430.frag b/Test/spv.430.frag new file mode 100644 index 000000000..e547f6109 --- /dev/null +++ b/Test/spv.430.frag @@ -0,0 +1,10 @@ +#version 430 core + +out vec4 color; + +void main() +{ + color = vec4(1.0); + color *= gl_Layer; + color *= gl_ViewportIndex; +} diff --git a/gtests/Spv.FromFile.cpp b/gtests/Spv.FromFile.cpp index 8296efdee..dbe0507df 100644 --- a/gtests/Spv.FromFile.cpp +++ b/gtests/Spv.FromFile.cpp @@ -126,6 +126,7 @@ INSTANTIATE_TEST_CASE_P( "spv.400.tesc", "spv.400.tese", "spv.420.geom", + "spv.430.frag", "spv.430.vert", "spv.450.tesc", "spv.accessChain.frag",