diff --git a/Test/baseLegalResults/hlsl.flattenOpaqueInit.vert.out b/Test/baseLegalResults/hlsl.flattenOpaqueInit.vert.out index 21a960b5..874fd00a 100644 --- a/Test/baseLegalResults/hlsl.flattenOpaqueInit.vert.out +++ b/Test/baseLegalResults/hlsl.flattenOpaqueInit.vert.out @@ -2,12 +2,12 @@ hlsl.flattenOpaqueInit.vert WARNING: AST will form illegal SPIR-V; need to transform to legalize // Module Version 10000 // Generated by (magic number): 80001 -// Id's are bound by 117 +// Id's are bound by 125 Capability Shader 1: ExtInstImport "GLSL.std.450" MemoryModel Logical GLSL450 - EntryPoint Vertex 4 "main" 78 + EntryPoint Vertex 4 "main" 82 Source HLSL 500 Name 4 "main" Name 17 "FxaaTex" @@ -15,10 +15,10 @@ WARNING: AST will form illegal SPIR-V; need to transform to legalize MemberName 17(FxaaTex) 1 "tex" Name 38 "g_tInputTexture_sampler" Name 42 "g_tInputTexture" - Name 78 "@entryPointOutput" + Name 82 "@entryPointOutput" Decorate 38(g_tInputTexture_sampler) DescriptorSet 0 Decorate 42(g_tInputTexture) DescriptorSet 0 - Decorate 78(@entryPointOutput) Location 0 + Decorate 82(@entryPointOutput) Location 0 2: TypeVoid 3: TypeFunction 2 6: TypeSampler @@ -36,14 +36,14 @@ WARNING: AST will form illegal SPIR-V; need to transform to legalize 38(g_tInputTexture_sampler): 37(ptr) Variable UniformConstant 41: TypePointer UniformConstant 9 42(g_tInputTexture): 41(ptr) Variable UniformConstant - 77: TypePointer Output 11(fvec4) -78(@entryPointOutput): 77(ptr) Variable Output + 81: TypePointer Output 11(fvec4) +82(@entryPointOutput): 81(ptr) Variable Output 4(main): 2 Function None 3 5: Label - 90: 6 Load 38(g_tInputTexture_sampler) - 91: 9 Load 42(g_tInputTexture) - 115: 26 SampledImage 91 90 - 116: 11(fvec4) ImageSampleExplicitLod 115 31 Lod 32 - Store 78(@entryPointOutput) 116 + 96: 6 Load 38(g_tInputTexture_sampler) + 97: 9 Load 42(g_tInputTexture) + 123: 26 SampledImage 97 96 + 124: 11(fvec4) ImageSampleExplicitLod 123 31 Lod 32 + Store 82(@entryPointOutput) 124 Return FunctionEnd diff --git a/Test/baseResults/hlsl.flattenOpaqueInit.vert.out b/Test/baseResults/hlsl.flattenOpaqueInit.vert.out index dee2808d..368dde5a 100755 --- a/Test/baseResults/hlsl.flattenOpaqueInit.vert.out +++ b/Test/baseResults/hlsl.flattenOpaqueInit.vert.out @@ -65,10 +65,18 @@ Shader version: 500 0:20 'flattenTemp' ( temp structure{ temp sampler smpl, temp texture2D tex}) 0:20 Constant: 0:20 1 (const int) -0:21 Branch: Return with expression -0:21 Function Call: lookUp(struct-FxaaTex-p1-t211; ( temp 4-component vector of float) -0:? 'tex1.smpl' ( temp sampler) -0:? 'tex1.tex' ( temp texture2D) +0:21 Sequence +0:21 Sequence +0:21 move second child to first child ( temp sampler) +0:? 'tex3.smpl' ( temp sampler) +0:? 'tex1.smpl' ( temp sampler) +0:21 move second child to first child ( temp texture2D) +0:? 'tex3.tex' ( temp texture2D) +0:? 'tex1.tex' ( temp texture2D) +0:22 Branch: Return with expression +0:22 Function Call: lookUp(struct-FxaaTex-p1-t211; ( temp 4-component vector of float) +0:? 'tex3.smpl' ( temp sampler) +0:? 'tex3.tex' ( temp texture2D) 0:18 Function Definition: main( ( temp void) 0:18 Function Parameters: 0:? Sequence @@ -149,10 +157,18 @@ Shader version: 500 0:20 'flattenTemp' ( temp structure{ temp sampler smpl, temp texture2D tex}) 0:20 Constant: 0:20 1 (const int) -0:21 Branch: Return with expression -0:21 Function Call: lookUp(struct-FxaaTex-p1-t211; ( temp 4-component vector of float) -0:? 'tex1.smpl' ( temp sampler) -0:? 'tex1.tex' ( temp texture2D) +0:21 Sequence +0:21 Sequence +0:21 move second child to first child ( temp sampler) +0:? 'tex3.smpl' ( temp sampler) +0:? 'tex1.smpl' ( temp sampler) +0:21 move second child to first child ( temp texture2D) +0:? 'tex3.tex' ( temp texture2D) +0:? 'tex1.tex' ( temp texture2D) +0:22 Branch: Return with expression +0:22 Function Call: lookUp(struct-FxaaTex-p1-t211; ( temp 4-component vector of float) +0:? 'tex3.smpl' ( temp sampler) +0:? 'tex3.tex' ( temp texture2D) 0:18 Function Definition: main( ( temp void) 0:18 Function Parameters: 0:? Sequence @@ -166,12 +182,12 @@ Shader version: 500 // Module Version 10000 // Generated by (magic number): 80001 -// Id's are bound by 80 +// Id's are bound by 84 Capability Shader 1: ExtInstImport "GLSL.std.450" MemoryModel Logical GLSL450 - EntryPoint Vertex 4 "main" 78 + EntryPoint Vertex 4 "main" 82 Source HLSL 500 Name 4 "main" Name 15 "lookUp(struct-FxaaTex-p1-t211;" @@ -193,12 +209,14 @@ Shader version: 500 Name 62 "flattenTemp" Name 64 "tex2.smpl" Name 67 "tex2.tex" - Name 70 "param" - Name 72 "param" - Name 78 "@entryPointOutput" + Name 70 "tex3.smpl" + Name 72 "tex3.tex" + Name 74 "param" + Name 76 "param" + Name 82 "@entryPointOutput" Decorate 38(g_tInputTexture_sampler) DescriptorSet 0 Decorate 42(g_tInputTexture) DescriptorSet 0 - Decorate 78(@entryPointOutput) Location 0 + Decorate 82(@entryPointOutput) Location 0 2: TypeVoid 3: TypeFunction 2 6: TypeSampler @@ -225,12 +243,12 @@ Shader version: 500 54: TypeInt 32 1 55: 54(int) Constant 0 59: 54(int) Constant 1 - 77: TypePointer Output 11(fvec4) -78(@entryPointOutput): 77(ptr) Variable Output + 81: TypePointer Output 11(fvec4) +82(@entryPointOutput): 81(ptr) Variable Output 4(main): 2 Function None 3 5: Label - 79: 11(fvec4) FunctionCall 22(@main() - Store 78(@entryPointOutput) 79 + 83: 11(fvec4) FunctionCall 22(@main() + Store 82(@entryPointOutput) 83 Return FunctionEnd 15(lookUp(struct-FxaaTex-p1-t211;): 11(fvec4) Function None 12 @@ -263,8 +281,10 @@ Shader version: 500 62(flattenTemp): 44(ptr) Variable Function 64(tex2.smpl): 7(ptr) Variable Function 67(tex2.tex): 10(ptr) Variable Function - 70(param): 7(ptr) Variable Function - 72(param): 10(ptr) Variable Function + 70(tex3.smpl): 7(ptr) Variable Function + 72(tex3.tex): 10(ptr) Variable Function + 74(param): 7(ptr) Variable Function + 76(param): 10(ptr) Variable Function 50: 6 Load 38(g_tInputTexture_sampler) 51: 9 Load 42(g_tInputTexture) 52: 17(FxaaTex) CompositeConstruct 50 51 @@ -284,9 +304,13 @@ Shader version: 500 69: 9 Load 68 Store 67(tex2.tex) 69 71: 6 Load 53(tex1.smpl) - Store 70(param) 71 + Store 70(tex3.smpl) 71 73: 9 Load 58(tex1.tex) - Store 72(param) 73 - 74: 11(fvec4) FunctionCall 15(lookUp(struct-FxaaTex-p1-t211;) 70(param) 72(param) - ReturnValue 74 + Store 72(tex3.tex) 73 + 75: 6 Load 70(tex3.smpl) + Store 74(param) 75 + 77: 9 Load 72(tex3.tex) + Store 76(param) 77 + 78: 11(fvec4) FunctionCall 15(lookUp(struct-FxaaTex-p1-t211;) 74(param) 76(param) + ReturnValue 78 FunctionEnd diff --git a/Test/hlsl.flattenOpaqueInit.vert b/Test/hlsl.flattenOpaqueInit.vert index 75d28a9a..bcf39ceb 100644 --- a/Test/hlsl.flattenOpaqueInit.vert +++ b/Test/hlsl.flattenOpaqueInit.vert @@ -18,5 +18,6 @@ float4 main() : SV_TARGET0 { FxaaTex tex1 = { g_tInputTexture_sampler, g_tInputTexture }; FxaaTex tex2 = fillOpaque(); - return lookUp(tex1); -} \ No newline at end of file + FxaaTex tex3 = tex1; + return lookUp(tex3); +} diff --git a/hlsl/hlslParseHelper.cpp b/hlsl/hlslParseHelper.cpp index 91deb4f5..0ba5d27b 100755 --- a/hlsl/hlslParseHelper.cpp +++ b/hlsl/hlslParseHelper.cpp @@ -2595,7 +2595,8 @@ TIntermTyped* HlslParseContext::handleAssign(const TSourceLoc& loc, TOperator op } } - int memberIdx = 0; + int memberIdxLeft = 0; + int memberIdxRight = 0; // When dealing with split arrayed structures of built-ins, the arrayness is moved to the extracted built-in // variables, which is awkward when copying between split and unsplit structures. This variable tracks @@ -2635,8 +2636,10 @@ TIntermTyped* HlslParseContext::handleAssign(const TSourceLoc& loc, TOperator op subTree->setType(splitDerefType); } } else if (flattened && isFinalFlattening(derefType)) { - const TVector& flatVariables = isLeft ? *leftVariables : *rightVariables; - subTree = intermediate.addSymbol(*flatVariables[memberIdx++]); + if (isLeft) + subTree = intermediate.addSymbol(*(*leftVariables)[memberIdxLeft++]); + else + subTree = intermediate.addSymbol(*(*rightVariables)[memberIdxRight++]); } else { // Index operator if it's an aggregate, else EOpNull const TOperator accessOp = node->getType().isArray() ? EOpIndexDirect