From 33f85b6e5908c23d6836f776cb42b0a237b90289 Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Mon, 6 Mar 2017 08:51:35 -0700 Subject: [PATCH] SPV: Allow push constant buffers to not have an instance name. --- .../baseResults/spv.pushConstantAnon.vert.out | 66 +++++++++++++++++++ Test/baseResults/vulkan.frag.out | 3 +- Test/spv.pushConstantAnon.vert | 17 +++++ Test/vulkan.frag | 2 +- glslang/Include/revision.h | 4 +- glslang/MachineIndependent/ParseHelper.cpp | 5 +- gtests/Spv.FromFile.cpp | 1 + 7 files changed, 89 insertions(+), 9 deletions(-) create mode 100755 Test/baseResults/spv.pushConstantAnon.vert.out create mode 100644 Test/spv.pushConstantAnon.vert diff --git a/Test/baseResults/spv.pushConstantAnon.vert.out b/Test/baseResults/spv.pushConstantAnon.vert.out new file mode 100755 index 00000000..9559815b --- /dev/null +++ b/Test/baseResults/spv.pushConstantAnon.vert.out @@ -0,0 +1,66 @@ +spv.pushConstantAnon.vert +Warning, version 400 is not yet complete; most version-specific features are present, but some are missing. + +// Module Version 10000 +// Generated by (magic number): 80001 +// Id's are bound by 38 + + Capability Shader + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint Vertex 4 "main" 24 + Source GLSL 400 + Name 4 "main" + Name 11 "Material" + MemberName 11(Material) 0 "kind" + MemberName 11(Material) 1 "fa" + Name 13 "" + Name 24 "color" + Decorate 10 ArrayStride 4 + MemberDecorate 11(Material) 0 Offset 0 + MemberDecorate 11(Material) 1 Offset 4 + Decorate 11(Material) Block + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeInt 32 1 + 7: TypeFloat 32 + 8: TypeInt 32 0 + 9: 8(int) Constant 3 + 10: TypeArray 7(float) 9 + 11(Material): TypeStruct 6(int) 10 + 12: TypePointer PushConstant 11(Material) + 13: 12(ptr) Variable PushConstant + 14: 6(int) Constant 0 + 15: TypePointer PushConstant 6(int) + 22: TypeVector 7(float) 4 + 23: TypePointer Output 22(fvec4) + 24(color): 23(ptr) Variable Output + 25: 7(float) Constant 1045220557 + 26: 22(fvec4) ConstantComposite 25 25 25 25 + 28: 7(float) Constant 1056964608 + 29: 22(fvec4) ConstantComposite 28 28 28 28 + 31: 6(int) Constant 1 + 32: TypePointer PushConstant 7(float) + 4(main): 2 Function None 3 + 5: Label + 16: 15(ptr) AccessChain 13 14 + 17: 6(int) Load 16 + SelectionMerge 21 None + Switch 17 20 + case 1: 18 + case 2: 19 + 20: Label + 33: 32(ptr) AccessChain 13 31 31 + 34: 7(float) Load 33 + 35: 22(fvec4) CompositeConstruct 34 34 34 34 + Store 24(color) 35 + Branch 21 + 18: Label + Store 24(color) 26 + Branch 21 + 19: Label + Store 24(color) 29 + Branch 21 + 21: Label + Return + FunctionEnd diff --git a/Test/baseResults/vulkan.frag.out b/Test/baseResults/vulkan.frag.out index 0e3057eb..f4a81a0d 100644 --- a/Test/baseResults/vulkan.frag.out +++ b/Test/baseResults/vulkan.frag.out @@ -19,7 +19,6 @@ ERROR: 0:39: 'push_constant' : can only be used with a uniform ERROR: 0:43: 'non-opaque uniforms outside a block' : not allowed when using GLSL for Vulkan ERROR: 0:43: 'push_constant' : can only be used with a block ERROR: 0:45: 'push_constant' : cannot declare a default, can only be used on a block -ERROR: 0:47: 'push_constant' : requires an instance name ERROR: 0:52: 'input_attachment_index' : can only be used with a subpass ERROR: 0:53: 'input_attachment_index' : can only be used with a subpass ERROR: 0:54: 'subpass' : requires an input_attachment_index layout qualifier @@ -41,7 +40,7 @@ ERROR: 0:93: ',' : sampler constructor must appear at point of use ERROR: 0:94: ':' : wrong operand types: no operation ':' exists that takes a left-hand operand of type 'temp sampler2D' and a right operand of type 'temp sampler2D' (or there is no acceptable conversion) ERROR: 0:94: 'call argument' : sampler constructor must appear at point of use ERROR: 0:96: 'gl_NumSamples' : undeclared identifier -ERROR: 39 compilation errors. No code generated. +ERROR: 38 compilation errors. No code generated. ERROR: Linking fragment stage: Only one push_constant block is allowed per stage diff --git a/Test/spv.pushConstantAnon.vert b/Test/spv.pushConstantAnon.vert new file mode 100644 index 00000000..c4438b7c --- /dev/null +++ b/Test/spv.pushConstantAnon.vert @@ -0,0 +1,17 @@ +#version 400 + +layout(push_constant) uniform Material { + int kind; + float fa[3]; +}; + +out vec4 color; + +void main() +{ + switch (kind) { + case 1: color = vec4(0.2); break; + case 2: color = vec4(0.5); break; + default: color = vec4(fa[1]); break; + } +} diff --git a/Test/vulkan.frag b/Test/vulkan.frag index 16baf862..2b686eb2 100644 --- a/Test/vulkan.frag +++ b/Test/vulkan.frag @@ -46,7 +46,7 @@ layout(push_constant) uniform; // ERROR, needs an object layout(push_constant) uniform pcb2 { int a; -}; // ERROR, no instance name +}; // Okay now to have no instance name layout(input_attachment_index = 2) uniform subpassInput subD; layout(input_attachment_index = 3) uniform texture2D subDbad1; // ERROR, not a texture diff --git a/glslang/Include/revision.h b/glslang/Include/revision.h index 56445856..6f3da8fc 100644 --- a/glslang/Include/revision.h +++ b/glslang/Include/revision.h @@ -2,5 +2,5 @@ // For the version, it uses the latest git tag followed by the number of commits. // For the date, it uses the current date (when then script is run). -#define GLSLANG_REVISION "Overload400-PrecQual.1875" -#define GLSLANG_DATE "03-Mar-2017" +#define GLSLANG_REVISION "Overload400-PrecQual.1878" +#define GLSLANG_DATE "06-Mar-2017" diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index acb4d738..78f459a9 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -5797,11 +5797,8 @@ void TParseContext::blockQualifierCheck(const TSourceLoc& loc, const TQualifier& error(loc, "cannot use sample qualifier on an interface block", "sample", ""); if (qualifier.invariant) error(loc, "cannot use invariant qualifier on an interface block", "invariant", ""); - if (qualifier.layoutPushConstant) { + if (qualifier.layoutPushConstant) intermediate.addPushConstantCount(); - if (! instanceName) - error(loc, "requires an instance name", "push_constant", ""); - } } // diff --git a/gtests/Spv.FromFile.cpp b/gtests/Spv.FromFile.cpp index 10577bd4..1043ecbb 100644 --- a/gtests/Spv.FromFile.cpp +++ b/gtests/Spv.FromFile.cpp @@ -295,6 +295,7 @@ INSTANTIATE_TEST_CASE_P( "spv.separate.frag", "spv.shortCircuit.frag", "spv.pushConstant.vert", + "spv.pushConstantAnon.vert", "spv.subpass.frag", "spv.specConstant.vert", "spv.specConstant.comp",