diff --git a/Test/baseResults/hlsl.layoutOverride.vert.out b/Test/baseResults/hlsl.layoutOverride.vert.out new file mode 100755 index 00000000..597365ec --- /dev/null +++ b/Test/baseResults/hlsl.layoutOverride.vert.out @@ -0,0 +1,104 @@ +hlsl.layoutOverride.vert +Shader version: 500 +0:? Sequence +0:5 Function Definition: @main( ( temp 4-component vector of float) +0:5 Function Parameters: +0:? Sequence +0:6 Branch: Return with expression +0:6 texture ( temp 4-component vector of float) +0:6 Construct combined texture-sampler ( temp sampler2D) +0:6 'tex' (layout( set=2 binding=0) uniform texture2D) +0:6 'samp' ( uniform sampler) +0:? Constant: +0:? 0.200000 +0:? 0.300000 +0:5 Function Definition: main( ( temp void) +0:5 Function Parameters: +0:? Sequence +0:5 move second child to first child ( temp 4-component vector of float) +0:? '@entryPointOutput' ( out 4-component vector of float Position) +0:5 Function Call: @main( ( temp 4-component vector of float) +0:? Linker Objects +0:? 'tex' (layout( set=2 binding=0) uniform texture2D) +0:? 'samp' ( uniform sampler) +0:? '@entryPointOutput' ( out 4-component vector of float Position) + + +Linked vertex stage: + + +Shader version: 500 +0:? Sequence +0:5 Function Definition: @main( ( temp 4-component vector of float) +0:5 Function Parameters: +0:? Sequence +0:6 Branch: Return with expression +0:6 texture ( temp 4-component vector of float) +0:6 Construct combined texture-sampler ( temp sampler2D) +0:6 'tex' (layout( set=2 binding=0) uniform texture2D) +0:6 'samp' ( uniform sampler) +0:? Constant: +0:? 0.200000 +0:? 0.300000 +0:5 Function Definition: main( ( temp void) +0:5 Function Parameters: +0:? Sequence +0:5 move second child to first child ( temp 4-component vector of float) +0:? '@entryPointOutput' ( out 4-component vector of float Position) +0:5 Function Call: @main( ( temp 4-component vector of float) +0:? Linker Objects +0:? 'tex' (layout( set=2 binding=0) uniform texture2D) +0:? 'samp' ( uniform sampler) +0:? '@entryPointOutput' ( out 4-component vector of float Position) + +// Module Version 10000 +// Generated by (magic number): 80002 +// Id's are bound by 32 + + Capability Shader + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint Vertex 4 "main" 30 + Source HLSL 500 + Name 4 "main" + Name 9 "@main(" + Name 13 "tex" + Name 17 "samp" + Name 30 "@entryPointOutput" + Decorate 13(tex) DescriptorSet 2 + Decorate 13(tex) Binding 0 + Decorate 17(samp) DescriptorSet 0 + Decorate 30(@entryPointOutput) BuiltIn Position + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeFloat 32 + 7: TypeVector 6(float) 4 + 8: TypeFunction 7(fvec4) + 11: TypeImage 6(float) 2D sampled format:Unknown + 12: TypePointer UniformConstant 11 + 13(tex): 12(ptr) Variable UniformConstant + 15: TypeSampler + 16: TypePointer UniformConstant 15 + 17(samp): 16(ptr) Variable UniformConstant + 19: TypeSampledImage 11 + 21: TypeVector 6(float) 2 + 22: 6(float) Constant 1045220557 + 23: 6(float) Constant 1050253722 + 24: 21(fvec2) ConstantComposite 22 23 + 25: 6(float) Constant 0 + 29: TypePointer Output 7(fvec4) +30(@entryPointOutput): 29(ptr) Variable Output + 4(main): 2 Function None 3 + 5: Label + 31: 7(fvec4) FunctionCall 9(@main() + Store 30(@entryPointOutput) 31 + Return + FunctionEnd + 9(@main(): 7(fvec4) Function None 8 + 10: Label + 14: 11 Load 13(tex) + 18: 15 Load 17(samp) + 20: 19 SampledImage 14 18 + 26: 7(fvec4) ImageSampleExplicitLod 20 24 Lod 25 + ReturnValue 26 + FunctionEnd diff --git a/Test/hlsl.layoutOverride.vert b/Test/hlsl.layoutOverride.vert new file mode 100644 index 00000000..4c006018 --- /dev/null +++ b/Test/hlsl.layoutOverride.vert @@ -0,0 +1,7 @@ +layout(set=2,binding=0) Texture2D tex : register(t16); +SamplerState samp; + +float4 main() : SV_Position +{ + return tex.Sample(samp, float2(0.2, 0.3)); +} \ No newline at end of file diff --git a/gtests/Hlsl.FromFile.cpp b/gtests/Hlsl.FromFile.cpp index 9688f79c..1e936dad 100644 --- a/gtests/Hlsl.FromFile.cpp +++ b/gtests/Hlsl.FromFile.cpp @@ -211,6 +211,7 @@ INSTANTIATE_TEST_CASE_P( {"hlsl.intrinsics.promote.down.frag", "main"}, {"hlsl.intrinsics.promote.outputs.frag", "main"}, {"hlsl.layout.frag", "main"}, + {"hlsl.layoutOverride.vert", "main"}, {"hlsl.load.2dms.dx10.frag", "main"}, {"hlsl.load.array.dx10.frag", "main"}, {"hlsl.load.basic.dx10.frag", "main"}, diff --git a/hlsl/hlslParseHelper.cpp b/hlsl/hlslParseHelper.cpp index 40229402..7192747c 100755 --- a/hlsl/hlslParseHelper.cpp +++ b/hlsl/hlslParseHelper.cpp @@ -5856,7 +5856,10 @@ void HlslParseContext::handleRegister(const TSourceLoc& loc, TQualifier& qualifi case 'c': case 's': case 'u': - qualifier.layoutBinding = regNumber + subComponent; + // if nothing else has set the binding, do so now + // (other mechanisms override this one) + if (!qualifier.hasBinding()) + qualifier.layoutBinding = regNumber + subComponent; // This handles per-register layout sets numbers. For the global mode which sets // every symbol to the same value, see setLinkageLayoutSets(). @@ -5890,7 +5893,9 @@ void HlslParseContext::handleRegister(const TSourceLoc& loc, TQualifier& qualifi return true; }; - if (spaceDesc) { + // if nothing else has set the set, do so now + // (other mechanisms override this one) + if (spaceDesc && !qualifier.hasSet()) { if (! crackSpace()) { error(loc, "expected spaceN", "register", ""); return;