From 16ef9da3725e06ea99eb622c6b51e0f73c237da3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Pi=C3=B1eiro?= Date: Thu, 25 Oct 2018 12:49:33 +0200 Subject: [PATCH] GlslangToSpv: prevent add XfbStride twice Without this commit, if the XfbStride was explicitly set, the decoration was added twice on the shader. v2 (changes after Jonh Kessenich first review) * Simplified by just removing the firs assignment * Removed assert --- SPIRV/GlslangToSpv.cpp | 2 - .../spv.xfbStrideJustOnce.vert.out | 74 +++++++++++++++++++ Test/spv.xfbStrideJustOnce.vert | 14 ++++ gtests/Spv.FromFile.cpp | 1 + 4 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 Test/baseResults/spv.xfbStrideJustOnce.vert.out create mode 100644 Test/spv.xfbStrideJustOnce.vert diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index 5c00024c6..495a976b6 100755 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -7163,8 +7163,6 @@ spv::Id TGlslangToSpvTraverser::getSymbolId(const glslang::TIntermSymbol* symbol builder.addDecoration(id, spv::DecorationInputAttachmentIndex, symbol->getQualifier().layoutAttachment); if (glslangIntermediate->getXfbMode()) { builder.addCapability(spv::CapabilityTransformFeedback); - if (symbol->getQualifier().hasXfbStride()) - builder.addDecoration(id, spv::DecorationXfbStride, symbol->getQualifier().layoutXfbStride); if (symbol->getQualifier().hasXfbBuffer()) { builder.addDecoration(id, spv::DecorationXfbBuffer, symbol->getQualifier().layoutXfbBuffer); unsigned stride = glslangIntermediate->getXfbStride(symbol->getQualifier().layoutXfbBuffer); diff --git a/Test/baseResults/spv.xfbStrideJustOnce.vert.out b/Test/baseResults/spv.xfbStrideJustOnce.vert.out new file mode 100644 index 000000000..9b459b503 --- /dev/null +++ b/Test/baseResults/spv.xfbStrideJustOnce.vert.out @@ -0,0 +1,74 @@ +spv.xfbStrideJustOnce.vert +// Module Version 10000 +// Generated by (magic number): 80007 +// Id's are bound by 33 + + Capability Shader + Capability TransformFeedback + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint Vertex 4 "main" 10 27 31 32 + ExecutionMode 4 Xfb + Source GLSL 450 + Name 4 "main" + Name 8 "block" + MemberName 8(block) 0 "y1_out" + MemberName 8(block) 1 "y2_out" + Name 10 "" + Name 25 "gl_PerVertex" + MemberName 25(gl_PerVertex) 0 "gl_Position" + MemberName 25(gl_PerVertex) 1 "gl_PointSize" + MemberName 25(gl_PerVertex) 2 "gl_ClipDistance" + MemberName 25(gl_PerVertex) 3 "gl_CullDistance" + Name 27 "" + Name 31 "gl_VertexID" + Name 32 "gl_InstanceID" + Decorate 8(block) Block + Decorate 10 Location 5 + Decorate 10 XfbBuffer 2 + Decorate 10 XfbStride 20 + MemberDecorate 25(gl_PerVertex) 0 BuiltIn Position + MemberDecorate 25(gl_PerVertex) 1 BuiltIn PointSize + MemberDecorate 25(gl_PerVertex) 2 BuiltIn ClipDistance + MemberDecorate 25(gl_PerVertex) 3 BuiltIn CullDistance + Decorate 25(gl_PerVertex) Block + Decorate 27 XfbBuffer 0 + Decorate 27 XfbStride 0 + Decorate 31(gl_VertexID) BuiltIn VertexId + Decorate 32(gl_InstanceID) BuiltIn InstanceId + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeFloat 32 + 7: TypeVector 6(float) 4 + 8(block): TypeStruct 6(float) 7(fvec4) + 9: TypePointer Output 8(block) + 10: 9(ptr) Variable Output + 11: TypeInt 32 1 + 12: 11(int) Constant 0 + 13: 6(float) Constant 1088421888 + 14: TypePointer Output 6(float) + 16: 11(int) Constant 1 + 17: 6(float) Constant 1065353216 + 18: 6(float) Constant 0 + 19: 7(fvec4) ConstantComposite 17 18 18 17 + 20: TypePointer Output 7(fvec4) + 22: TypeInt 32 0 + 23: 22(int) Constant 1 + 24: TypeArray 6(float) 23 +25(gl_PerVertex): TypeStruct 7(fvec4) 6(float) 24 24 + 26: TypePointer Output 25(gl_PerVertex) + 27: 26(ptr) Variable Output + 28: 7(fvec4) ConstantComposite 18 18 18 18 + 30: TypePointer Input 11(int) + 31(gl_VertexID): 30(ptr) Variable Input +32(gl_InstanceID): 30(ptr) Variable Input + 4(main): 2 Function None 3 + 5: Label + 15: 14(ptr) AccessChain 10 12 + Store 15 13 + 21: 20(ptr) AccessChain 10 16 + Store 21 19 + 29: 20(ptr) AccessChain 27 12 + Store 29 28 + Return + FunctionEnd diff --git a/Test/spv.xfbStrideJustOnce.vert b/Test/spv.xfbStrideJustOnce.vert new file mode 100644 index 000000000..2798c6a8e --- /dev/null +++ b/Test/spv.xfbStrideJustOnce.vert @@ -0,0 +1,14 @@ +#version 450 + +layout(xfb_buffer=2) out; + +layout(location=5, xfb_stride=20) out block { + float y1_out; + vec4 y2_out; +}; + +void main() { + y1_out = 7.0; + y2_out = vec4(1.0, 0.0, 0.0, 1.0); + gl_Position = vec4(0.0); +} diff --git a/gtests/Spv.FromFile.cpp b/gtests/Spv.FromFile.cpp index 66780f70f..1e17736fc 100755 --- a/gtests/Spv.FromFile.cpp +++ b/gtests/Spv.FromFile.cpp @@ -450,6 +450,7 @@ INSTANTIATE_TEST_CASE_P( "spv.xfbOffsetOnBlockMembersAssignment.vert", "spv.xfbOffsetOnStructMembersAssignment.vert", "spv.xfbOverlapOffsetCheckWithBlockAndMember.vert", + "spv.xfbStrideJustOnce.vert", })), FileNameAsCustomTestSuffix );