From 6b3fd19d89922cd010ff2d727fc7ae82fce95100 Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Fri, 22 May 2015 01:53:15 +0000 Subject: [PATCH] glslang -> SPV: add decorations for built-ins that are inside blocks. git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@31266 e7fa87d3-cd2b-0410-9028-fcbf551c1848 --- SPIRV/GlslangToSpv.cpp | 15 ++++++++++----- SPIRV/disassemble.cpp | 3 ++- Test/baseResults/spv.150.geom.out | 6 ++++++ Test/baseResults/spv.150.vert.out | 4 ++++ Test/baseResults/spv.330.geom.out | 4 ++++ Test/baseResults/spv.400.tesc.out | 3 +++ Test/baseResults/spv.400.tese.out | 3 +++ Test/baseResults/spv.430.vert.out | 1 + 8 files changed, 33 insertions(+), 6 deletions(-) diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index 3ddc7b2e..4072d6a6 100644 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -303,9 +303,9 @@ spv::Decoration TranslateInvariantDecoration(const glslang::TType& type) } // Translate glslang built-in variable to SPIR-V built in decoration. -spv::BuiltIn TranslateBuiltInDecoration(const glslang::TIntermSymbol& node) +spv::BuiltIn TranslateBuiltInDecoration(glslang::TBuiltInVariable builtIn) { - switch (node.getQualifier().builtIn) { + switch (builtIn) { case glslang::EbvPosition: return spv::BuiltInPosition; case glslang::EbvPointSize: return spv::BuiltInPointSize; case glslang::EbvClipVertex: return spv::BuiltInClipVertex; @@ -1344,6 +1344,11 @@ spv::Id TGlslangToSpvTraverser::convertGlslangToSpvType(const glslang::TType& ty builder.addMemberDecoration(spvType, member, spv::DecorationComponent, glslangType.getQualifier().layoutComponent); if (glslangType.getQualifier().hasXfbOffset()) builder.addMemberDecoration(spvType, member, spv::DecorationOffset, glslangType.getQualifier().layoutXfbOffset); + + // built-in variable decorations + int builtIn = TranslateBuiltInDecoration(glslangType.getQualifier().builtIn); + if (builtIn != spv::BadValue) + builder.addMemberDecoration(spvType, member, spv::DecorationBuiltIn, builtIn); } } @@ -2412,9 +2417,9 @@ spv::Id TGlslangToSpvTraverser::getSymbolId(const glslang::TIntermSymbol* symbol } // built-in variable decorations - int num = TranslateBuiltInDecoration(*symbol); - if (num != spv::BadValue) - builder.addDecoration(id, spv::DecorationBuiltIn, num); + int builtIn = TranslateBuiltInDecoration(symbol->getQualifier().builtIn); + if (builtIn != spv::BadValue) + builder.addDecoration(id, spv::DecorationBuiltIn, builtIn); if (linkageOnly) builder.addDecoration(id, spv::DecorationNoStaticUse); diff --git a/SPIRV/disassemble.cpp b/SPIRV/disassemble.cpp index 7a9b10d9..8fcc5692 100644 --- a/SPIRV/disassemble.cpp +++ b/SPIRV/disassemble.cpp @@ -368,7 +368,8 @@ void SpirvStream::disassembleInstruction(Id resultId, Id /*typeId*/, Op opCode, disassembleIds(numOperands); return; case OperandVariableLiterals: - if (opCode == OpDecorate && stream[word - 1] == DecorationBuiltIn) { + if (opCode == OpDecorate && stream[word - 1] == DecorationBuiltIn || + opCode == OpMemberDecorate && stream[word - 1] == DecorationBuiltIn) { out << BuiltInString(stream[word++]); --numOperands; ++op; diff --git a/Test/baseResults/spv.150.geom.out b/Test/baseResults/spv.150.geom.out index d32c8da5..bde17299 100644 --- a/Test/baseResults/spv.150.geom.out +++ b/Test/baseResults/spv.150.geom.out @@ -45,9 +45,15 @@ Linked geometry stage: Decorate 9(fromVertex) Stream 3 Decorate 11 Stream 3 Decorate 14(fromVertex) Block + MemberDecorate 28(gl_PerVertex) 0 BuiltIn Position + MemberDecorate 28(gl_PerVertex) 1 BuiltIn PointSize + MemberDecorate 28(gl_PerVertex) 2 BuiltIn ClipDistance Decorate 28(gl_PerVertex) Block Decorate 28(gl_PerVertex) Stream 0 Decorate 30 Stream 0 + MemberDecorate 31(gl_PerVertex) 0 BuiltIn Position + MemberDecorate 31(gl_PerVertex) 1 BuiltIn PointSize + MemberDecorate 31(gl_PerVertex) 2 BuiltIn ClipDistance Decorate 31(gl_PerVertex) Block Decorate 48(gl_PrimitiveID) Stream 0 Decorate 48(gl_PrimitiveID) BuiltIn PrimitiveId diff --git a/Test/baseResults/spv.150.vert.out b/Test/baseResults/spv.150.vert.out index c2d8bdf5..a40a4544 100644 --- a/Test/baseResults/spv.150.vert.out +++ b/Test/baseResults/spv.150.vert.out @@ -42,6 +42,10 @@ Linked vertex stage: Name 51 "gl_VertexID" Name 52 "gl_InstanceID" MemberDecorate 14(gl_PerVertex) 0 Invariant + MemberDecorate 14(gl_PerVertex) 0 BuiltIn Position + MemberDecorate 14(gl_PerVertex) 1 BuiltIn PointSize + MemberDecorate 14(gl_PerVertex) 2 BuiltIn ClipDistance + MemberDecorate 14(gl_PerVertex) 3 BuiltIn ClipVertex Decorate 14(gl_PerVertex) Block Decorate 49(ui) NoStaticUse Decorate 51(gl_VertexID) BuiltIn VertexId diff --git a/Test/baseResults/spv.330.geom.out b/Test/baseResults/spv.330.geom.out index b9923e6f..ae4e043d 100644 --- a/Test/baseResults/spv.330.geom.out +++ b/Test/baseResults/spv.330.geom.out @@ -28,9 +28,13 @@ Linked geometry stage: MemberName 17(gl_PerVertex) 0 "gl_Position" MemberName 17(gl_PerVertex) 1 "gl_ClipDistance" Name 21 "gl_in" + MemberDecorate 12(gl_PerVertex) 0 BuiltIn Position + MemberDecorate 12(gl_PerVertex) 1 BuiltIn ClipDistance Decorate 12(gl_PerVertex) Block Decorate 12(gl_PerVertex) Stream 0 Decorate 14 Stream 0 + MemberDecorate 17(gl_PerVertex) 0 BuiltIn Position + MemberDecorate 17(gl_PerVertex) 1 BuiltIn ClipDistance Decorate 17(gl_PerVertex) Block 2: TypeVoid 3: TypeFunction 2 diff --git a/Test/baseResults/spv.400.tesc.out b/Test/baseResults/spv.400.tesc.out index edfae88c..ac08a2b9 100644 --- a/Test/baseResults/spv.400.tesc.out +++ b/Test/baseResults/spv.400.tesc.out @@ -52,6 +52,9 @@ Linked tessellation control stage: Decorate 39(gl_PatchVerticesIn) BuiltIn PatchVertices Decorate 42(gl_PrimitiveID) BuiltIn PrimitiveId Decorate 45(gl_InvocationID) BuiltIn InvocationId + MemberDecorate 47(gl_PerVertex) 0 BuiltIn Position + MemberDecorate 47(gl_PerVertex) 1 BuiltIn PointSize + MemberDecorate 47(gl_PerVertex) 2 BuiltIn ClipDistance Decorate 47(gl_PerVertex) Block Decorate 62(gl_TessLevelOuter) Patch Decorate 62(gl_TessLevelOuter) BuiltIn TessLevelOuter diff --git a/Test/baseResults/spv.400.tese.out b/Test/baseResults/spv.400.tese.out index 4d141ae2..d16eb8e2 100644 --- a/Test/baseResults/spv.400.tese.out +++ b/Test/baseResults/spv.400.tese.out @@ -62,6 +62,9 @@ Linked tessellation evaluation stage: Decorate 54(gl_TessLevelOuter) BuiltIn TessLevelOuter Decorate 62(gl_TessLevelInner) Patch Decorate 62(gl_TessLevelInner) BuiltIn TessLevelInner + MemberDecorate 67(gl_PerVertex) 0 BuiltIn Position + MemberDecorate 67(gl_PerVertex) 1 BuiltIn PointSize + MemberDecorate 67(gl_PerVertex) 2 BuiltIn ClipDistance Decorate 67(gl_PerVertex) Block Decorate 78(patchIn) Patch Decorate 78(patchIn) NoStaticUse diff --git a/Test/baseResults/spv.430.vert.out b/Test/baseResults/spv.430.vert.out index b1cf837f..d67e8faf 100644 --- a/Test/baseResults/spv.430.vert.out +++ b/Test/baseResults/spv.430.vert.out @@ -36,6 +36,7 @@ Linked vertex stage: Name 58 "sampb4" Name 60 "gl_VertexID" Name 61 "gl_InstanceID" + MemberDecorate 11(gl_PerVertex) 0 BuiltIn ClipDistance Decorate 11(gl_PerVertex) Block Decorate 35(badorder3) Flat Decorate 43(uv4) Location 4