From 085b8334906aba9737e761ff012830495666a294 Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Thu, 5 Jan 2017 10:28:26 -0700 Subject: [PATCH] HLSL: Fix issue #658: Don't adopt initializer constness from declaration. This also makes it match how GLSL handles the same thing. --- Test/baseResults/hlsl.init2.frag.out | 450 +++++++++++++++++++++++---- Test/hlsl.init2.frag | 19 ++ glslang/Include/revision.h | 4 +- hlsl/hlslParseHelper.cpp | 13 +- 4 files changed, 417 insertions(+), 69 deletions(-) diff --git a/Test/baseResults/hlsl.init2.frag.out b/Test/baseResults/hlsl.init2.frag.out index 9b53e304..d8d2d371 100644 --- a/Test/baseResults/hlsl.init2.frag.out +++ b/Test/baseResults/hlsl.init2.frag.out @@ -29,29 +29,147 @@ gl_FragCoord origin is upper left 0:20 8.000000 0:20 9.000000 0:20 10.000000 -0:26 Function Definition: main( (temp structure{temp 4-component vector of float color}) -0:26 Function Parameters: +0:22 Constant: +0:22 10.000000 +0:25 Sequence +0:25 move second child to first child (temp float) +0:25 'n' (temp float) +0:25 Constant: +0:25 0.000000 +0:26 Sequence +0:26 move second child to first child (temp 8-element array of 3-component vector of float) +0:26 'a' (const (read only) 8-element array of 3-component vector of float) +0:26 Construct vec3 (temp 8-element array of 3-component vector of float) +0:27 vector-scale (temp 3-component vector of float) +0:? Constant: +0:? 0.577350 +0:? 0.577350 +0:? 0.577350 +0:27 add second child into first child (temp float) +0:27 'n' (temp float) +0:27 Constant: +0:27 1.000000 +0:28 vector-scale (temp 3-component vector of float) +0:? Constant: +0:? -0.577350 +0:? -0.577350 +0:? -0.577350 +0:28 add second child into first child (temp float) +0:28 'n' (temp float) +0:28 Constant: +0:28 1.000000 +0:29 vector-scale (temp 3-component vector of float) +0:? Constant: +0:? -0.577350 +0:? -0.577350 +0:? 0.577350 +0:29 add second child into first child (temp float) +0:29 'n' (temp float) +0:29 Constant: +0:29 1.000000 +0:30 vector-scale (temp 3-component vector of float) +0:? Constant: +0:? -0.577350 +0:? 0.577350 +0:? -0.577350 +0:30 add second child into first child (temp float) +0:30 'n' (temp float) +0:30 Constant: +0:30 1.000000 +0:31 vector-scale (temp 3-component vector of float) +0:? Constant: +0:? -0.577350 +0:? 0.577350 +0:? 0.577350 +0:31 add second child into first child (temp float) +0:31 'n' (temp float) +0:31 Constant: +0:31 1.000000 +0:32 vector-scale (temp 3-component vector of float) +0:? Constant: +0:? 0.577350 +0:? -0.577350 +0:? -0.577350 +0:32 add second child into first child (temp float) +0:32 'n' (temp float) +0:32 Constant: +0:32 1.000000 +0:33 vector-scale (temp 3-component vector of float) +0:? Constant: +0:? 0.577350 +0:? -0.577350 +0:? 0.577350 +0:33 add second child into first child (temp float) +0:33 'n' (temp float) +0:33 Constant: +0:33 1.000000 +0:34 vector-scale (temp 3-component vector of float) +0:? Constant: +0:? 0.577350 +0:? 0.577350 +0:? -0.577350 +0:34 add second child into first child (temp float) +0:34 'n' (temp float) +0:34 Constant: +0:34 1.000000 +0:36 Sequence +0:36 move second child to first child (temp structure{temp 3-component vector of float a}) +0:36 'oneNonConst' (const (read only) structure{temp 3-component vector of float a}) +0:36 Construct structure (temp structure{temp 3-component vector of float a}) +0:36 vector-scale (temp 3-component vector of float) +0:? Constant: +0:? -0.577350 +0:? 0.577350 +0:? 0.577350 +0:36 add second child into first child (temp float) +0:36 'n' (temp float) +0:36 Constant: +0:36 1.000000 +0:38 Sequence +0:38 move second child to first child (temp structure{temp 3-component vector of float a, temp 3-component vector of float b}) +0:38 'twoNonConst' (const (read only) structure{temp 3-component vector of float a, temp 3-component vector of float b}) +0:38 Construct structure (temp structure{temp 3-component vector of float a, temp 3-component vector of float b}) +0:38 vector-scale (temp 3-component vector of float) +0:? Constant: +0:? -0.577350 +0:? 0.577350 +0:? 0.577350 +0:38 add second child into first child (temp float) +0:38 'n' (temp float) +0:38 Constant: +0:38 1.000000 +0:39 vector-scale (temp 3-component vector of float) +0:? Constant: +0:? -0.577350 +0:? 0.577350 +0:? 0.577350 +0:39 add second child into first child (temp float) +0:39 'n' (temp float) +0:39 Constant: +0:39 1.000000 +0:45 Function Definition: main( (temp structure{temp 4-component vector of float color}) +0:45 Function Parameters: 0:? Sequence -0:27 Function Call: Test1( (temp void) -0:30 move second child to first child (temp 4-component vector of float) -0:30 color: direct index for structure (temp 4-component vector of float) -0:30 'ps_output' (temp structure{temp 4-component vector of float color}) -0:30 Constant: -0:30 0 (const int) -0:30 Constant: -0:30 1.000000 -0:30 1.000000 -0:30 1.000000 -0:30 1.000000 -0:31 Sequence -0:31 Sequence -0:31 move second child to first child (temp 4-component vector of float) +0:46 Function Call: Test1( (temp void) +0:49 move second child to first child (temp 4-component vector of float) +0:49 color: direct index for structure (temp 4-component vector of float) +0:49 'ps_output' (temp structure{temp 4-component vector of float color}) +0:49 Constant: +0:49 0 (const int) +0:49 Constant: +0:49 1.000000 +0:49 1.000000 +0:49 1.000000 +0:49 1.000000 +0:50 Sequence +0:50 Sequence +0:50 move second child to first child (temp 4-component vector of float) 0:? 'color' (layout(location=0 ) out 4-component vector of float) -0:31 color: direct index for structure (temp 4-component vector of float) -0:31 'ps_output' (temp structure{temp 4-component vector of float color}) -0:31 Constant: -0:31 0 (const int) -0:31 Branch: Return +0:50 color: direct index for structure (temp 4-component vector of float) +0:50 'ps_output' (temp structure{temp 4-component vector of float color}) +0:50 Constant: +0:50 0 (const int) +0:50 Branch: Return 0:? Linker Objects 0:? 'color' (layout(location=0 ) out 4-component vector of float) @@ -89,40 +207,158 @@ gl_FragCoord origin is upper left 0:20 8.000000 0:20 9.000000 0:20 10.000000 -0:26 Function Definition: main( (temp structure{temp 4-component vector of float color}) -0:26 Function Parameters: +0:22 Constant: +0:22 10.000000 +0:25 Sequence +0:25 move second child to first child (temp float) +0:25 'n' (temp float) +0:25 Constant: +0:25 0.000000 +0:26 Sequence +0:26 move second child to first child (temp 8-element array of 3-component vector of float) +0:26 'a' (const (read only) 8-element array of 3-component vector of float) +0:26 Construct vec3 (temp 8-element array of 3-component vector of float) +0:27 vector-scale (temp 3-component vector of float) +0:? Constant: +0:? 0.577350 +0:? 0.577350 +0:? 0.577350 +0:27 add second child into first child (temp float) +0:27 'n' (temp float) +0:27 Constant: +0:27 1.000000 +0:28 vector-scale (temp 3-component vector of float) +0:? Constant: +0:? -0.577350 +0:? -0.577350 +0:? -0.577350 +0:28 add second child into first child (temp float) +0:28 'n' (temp float) +0:28 Constant: +0:28 1.000000 +0:29 vector-scale (temp 3-component vector of float) +0:? Constant: +0:? -0.577350 +0:? -0.577350 +0:? 0.577350 +0:29 add second child into first child (temp float) +0:29 'n' (temp float) +0:29 Constant: +0:29 1.000000 +0:30 vector-scale (temp 3-component vector of float) +0:? Constant: +0:? -0.577350 +0:? 0.577350 +0:? -0.577350 +0:30 add second child into first child (temp float) +0:30 'n' (temp float) +0:30 Constant: +0:30 1.000000 +0:31 vector-scale (temp 3-component vector of float) +0:? Constant: +0:? -0.577350 +0:? 0.577350 +0:? 0.577350 +0:31 add second child into first child (temp float) +0:31 'n' (temp float) +0:31 Constant: +0:31 1.000000 +0:32 vector-scale (temp 3-component vector of float) +0:? Constant: +0:? 0.577350 +0:? -0.577350 +0:? -0.577350 +0:32 add second child into first child (temp float) +0:32 'n' (temp float) +0:32 Constant: +0:32 1.000000 +0:33 vector-scale (temp 3-component vector of float) +0:? Constant: +0:? 0.577350 +0:? -0.577350 +0:? 0.577350 +0:33 add second child into first child (temp float) +0:33 'n' (temp float) +0:33 Constant: +0:33 1.000000 +0:34 vector-scale (temp 3-component vector of float) +0:? Constant: +0:? 0.577350 +0:? 0.577350 +0:? -0.577350 +0:34 add second child into first child (temp float) +0:34 'n' (temp float) +0:34 Constant: +0:34 1.000000 +0:36 Sequence +0:36 move second child to first child (temp structure{temp 3-component vector of float a}) +0:36 'oneNonConst' (const (read only) structure{temp 3-component vector of float a}) +0:36 Construct structure (temp structure{temp 3-component vector of float a}) +0:36 vector-scale (temp 3-component vector of float) +0:? Constant: +0:? -0.577350 +0:? 0.577350 +0:? 0.577350 +0:36 add second child into first child (temp float) +0:36 'n' (temp float) +0:36 Constant: +0:36 1.000000 +0:38 Sequence +0:38 move second child to first child (temp structure{temp 3-component vector of float a, temp 3-component vector of float b}) +0:38 'twoNonConst' (const (read only) structure{temp 3-component vector of float a, temp 3-component vector of float b}) +0:38 Construct structure (temp structure{temp 3-component vector of float a, temp 3-component vector of float b}) +0:38 vector-scale (temp 3-component vector of float) +0:? Constant: +0:? -0.577350 +0:? 0.577350 +0:? 0.577350 +0:38 add second child into first child (temp float) +0:38 'n' (temp float) +0:38 Constant: +0:38 1.000000 +0:39 vector-scale (temp 3-component vector of float) +0:? Constant: +0:? -0.577350 +0:? 0.577350 +0:? 0.577350 +0:39 add second child into first child (temp float) +0:39 'n' (temp float) +0:39 Constant: +0:39 1.000000 +0:45 Function Definition: main( (temp structure{temp 4-component vector of float color}) +0:45 Function Parameters: 0:? Sequence -0:27 Function Call: Test1( (temp void) -0:30 move second child to first child (temp 4-component vector of float) -0:30 color: direct index for structure (temp 4-component vector of float) -0:30 'ps_output' (temp structure{temp 4-component vector of float color}) -0:30 Constant: -0:30 0 (const int) -0:30 Constant: -0:30 1.000000 -0:30 1.000000 -0:30 1.000000 -0:30 1.000000 -0:31 Sequence -0:31 Sequence -0:31 move second child to first child (temp 4-component vector of float) +0:46 Function Call: Test1( (temp void) +0:49 move second child to first child (temp 4-component vector of float) +0:49 color: direct index for structure (temp 4-component vector of float) +0:49 'ps_output' (temp structure{temp 4-component vector of float color}) +0:49 Constant: +0:49 0 (const int) +0:49 Constant: +0:49 1.000000 +0:49 1.000000 +0:49 1.000000 +0:49 1.000000 +0:50 Sequence +0:50 Sequence +0:50 move second child to first child (temp 4-component vector of float) 0:? 'color' (layout(location=0 ) out 4-component vector of float) -0:31 color: direct index for structure (temp 4-component vector of float) -0:31 'ps_output' (temp structure{temp 4-component vector of float color}) -0:31 Constant: -0:31 0 (const int) -0:31 Branch: Return +0:50 color: direct index for structure (temp 4-component vector of float) +0:50 'ps_output' (temp structure{temp 4-component vector of float color}) +0:50 Constant: +0:50 0 (const int) +0:50 Branch: Return 0:? Linker Objects 0:? 'color' (layout(location=0 ) out 4-component vector of float) // Module Version 10000 // Generated by (magic number): 80001 -// Id's are bound by 47 +// Id's are bound by 107 Capability Shader 1: ExtInstImport "GLSL.std.450" MemoryModel Logical GLSL450 - EntryPoint Fragment 4 "main" 43 + EntryPoint Fragment 4 "main" 103 ExecutionMode 4 OriginUpperLeft Name 4 "main" Name 6 "Test1(" @@ -136,11 +372,20 @@ gl_FragCoord origin is upper left MemberName 25(mystruct2) 1 "b" MemberName 25(mystruct2) 2 "c" Name 27 "test5" - Name 34 "PS_OUTPUT" - MemberName 34(PS_OUTPUT) 0 "color" - Name 36 "ps_output" - Name 43 "color" - Decorate 43(color) Location 0 + Name 32 "n" + Name 39 "a" + Name 75 "one" + MemberName 75(one) 0 "a" + Name 77 "oneNonConst" + Name 82 "two" + MemberName 82(two) 0 "a" + MemberName 82(two) 1 "b" + Name 84 "twoNonConst" + Name 94 "PS_OUTPUT" + MemberName 94(PS_OUTPUT) 0 "color" + Name 96 "ps_output" + Name 103 "color" + Decorate 103(color) Location 0 2: TypeVoid 3: TypeFunction 2 8: TypeFloat 32 @@ -163,24 +408,44 @@ gl_FragCoord origin is upper left 29: 8(float) Constant 1091567616 30: 8(float) Constant 1092616192 31:25(mystruct2) ConstantComposite 28 29 30 - 33: TypeVector 8(float) 4 - 34(PS_OUTPUT): TypeStruct 33(fvec4) - 35: TypePointer Function 34(PS_OUTPUT) - 37: TypeInt 32 1 - 38: 37(int) Constant 0 - 39: 33(fvec4) ConstantComposite 13 13 13 13 - 40: TypePointer Function 33(fvec4) - 42: TypePointer Output 33(fvec4) - 43(color): 42(ptr) Variable Output + 33: 8(float) Constant 0 + 34: TypeVector 8(float) 3 + 35: TypeInt 32 0 + 36: 35(int) Constant 8 + 37: TypeArray 34(fvec3) 36 + 38: TypePointer Function 37 + 40: 8(float) Constant 1058262330 + 41: 34(fvec3) ConstantComposite 40 40 40 + 45: 8(float) Constant 3205745978 + 46: 34(fvec3) ConstantComposite 45 45 45 + 50: 34(fvec3) ConstantComposite 45 45 40 + 54: 34(fvec3) ConstantComposite 45 40 45 + 58: 34(fvec3) ConstantComposite 45 40 40 + 62: 34(fvec3) ConstantComposite 40 45 45 + 66: 34(fvec3) ConstantComposite 40 45 40 + 70: 34(fvec3) ConstantComposite 40 40 45 + 75(one): TypeStruct 34(fvec3) + 76: TypePointer Function 75(one) + 82(two): TypeStruct 34(fvec3) 34(fvec3) + 83: TypePointer Function 82(two) + 93: TypeVector 8(float) 4 + 94(PS_OUTPUT): TypeStruct 93(fvec4) + 95: TypePointer Function 94(PS_OUTPUT) + 97: TypeInt 32 1 + 98: 97(int) Constant 0 + 99: 93(fvec4) ConstantComposite 13 13 13 13 + 100: TypePointer Function 93(fvec4) + 102: TypePointer Output 93(fvec4) + 103(color): 102(ptr) Variable Output 4(main): 2 Function None 3 5: Label - 36(ps_output): 35(ptr) Variable Function - 32: 2 FunctionCall 6(Test1() - 41: 40(ptr) AccessChain 36(ps_output) 38 - Store 41 39 - 44: 40(ptr) AccessChain 36(ps_output) 38 - 45: 33(fvec4) Load 44 - Store 43(color) 45 + 96(ps_output): 95(ptr) Variable Function + 92: 2 FunctionCall 6(Test1() + 101: 100(ptr) AccessChain 96(ps_output) 98 + Store 101 99 + 104: 100(ptr) AccessChain 96(ps_output) 98 + 105: 93(fvec4) Load 104 + Store 103(color) 105 Return FunctionEnd 6(Test1(): 2 Function None 3 @@ -189,9 +454,64 @@ gl_FragCoord origin is upper left 17(test2): 11(ptr) Variable Function 23(test4): 22(ptr) Variable Function 27(test5): 26(ptr) Variable Function + 32(n): 22(ptr) Variable Function + 39(a): 38(ptr) Variable Function + 77(oneNonConst): 76(ptr) Variable Function + 84(twoNonConst): 83(ptr) Variable Function Store 12(test1) 16 Store 17(test2) 21 Store 23(test4) 24 Store 27(test5) 31 + Store 32(n) 33 + 42: 8(float) Load 32(n) + 43: 8(float) FAdd 42 13 + Store 32(n) 43 + 44: 34(fvec3) VectorTimesScalar 41 43 + 47: 8(float) Load 32(n) + 48: 8(float) FAdd 47 13 + Store 32(n) 48 + 49: 34(fvec3) VectorTimesScalar 46 48 + 51: 8(float) Load 32(n) + 52: 8(float) FAdd 51 13 + Store 32(n) 52 + 53: 34(fvec3) VectorTimesScalar 50 52 + 55: 8(float) Load 32(n) + 56: 8(float) FAdd 55 13 + Store 32(n) 56 + 57: 34(fvec3) VectorTimesScalar 54 56 + 59: 8(float) Load 32(n) + 60: 8(float) FAdd 59 13 + Store 32(n) 60 + 61: 34(fvec3) VectorTimesScalar 58 60 + 63: 8(float) Load 32(n) + 64: 8(float) FAdd 63 13 + Store 32(n) 64 + 65: 34(fvec3) VectorTimesScalar 62 64 + 67: 8(float) Load 32(n) + 68: 8(float) FAdd 67 13 + Store 32(n) 68 + 69: 34(fvec3) VectorTimesScalar 66 68 + 71: 8(float) Load 32(n) + 72: 8(float) FAdd 71 13 + Store 32(n) 72 + 73: 34(fvec3) VectorTimesScalar 70 72 + 74: 37 CompositeConstruct 44 49 53 57 61 65 69 73 + Store 39(a) 74 + 78: 8(float) Load 32(n) + 79: 8(float) FAdd 78 13 + Store 32(n) 79 + 80: 34(fvec3) VectorTimesScalar 58 79 + 81: 75(one) CompositeConstruct 80 + Store 77(oneNonConst) 81 + 85: 8(float) Load 32(n) + 86: 8(float) FAdd 85 13 + Store 32(n) 86 + 87: 34(fvec3) VectorTimesScalar 58 86 + 88: 8(float) Load 32(n) + 89: 8(float) FAdd 88 13 + Store 32(n) 89 + 90: 34(fvec3) VectorTimesScalar 58 89 + 91: 82(two) CompositeConstruct 87 90 + Store 84(twoNonConst) 91 Return FunctionEnd diff --git a/Test/hlsl.init2.frag b/Test/hlsl.init2.frag index 789f1a06..2b9b7e68 100644 --- a/Test/hlsl.init2.frag +++ b/Test/hlsl.init2.frag @@ -18,6 +18,25 @@ void Test1() struct mystruct2 { float a; float b; float c; }; mystruct2 test5 = { {8,}, {9,}, {10}, }; + const mystruct2 constTest5 = { {8,}, {9,}, {10}, }; + constTest5.c; + + const float step = 1.f; + float n = 0; + const float3 a[8] = { + normalize(float3(1, 1, 1)) * (n += step), + normalize(float3(-1, -1, -1)) * (n += step), + normalize(float3(-1, -1, 1)) * (n += step), + normalize(float3(-1, 1, -1)) * (n += step), + normalize(float3(-1, 1, 1)) * (n += step), + normalize(float3(1, -1, -1)) * (n += step), + normalize(float3(1, -1, 1)) * (n += step), + normalize(float3(1, 1, -1)) * (n += step) }; + + const struct one { float3 a; } oneNonConst = { normalize(float3(-1, 1, 1)) * (n += step) }; + const struct two { float3 a; + float3 b; } twoNonConst = { normalize(float3(-1, 1, 1)) * (n += step), + normalize(float3(-1, 1, 1)) * (n += step) }; } struct PS_OUTPUT { float4 color : SV_Target0; }; diff --git a/glslang/Include/revision.h b/glslang/Include/revision.h index cee8a8b7..777826d4 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.1730" -#define GLSLANG_DATE "03-Jan-2017" +#define GLSLANG_REVISION "Overload400-PrecQual.1739" +#define GLSLANG_DATE "05-Jan-2017" diff --git a/hlsl/hlslParseHelper.cpp b/hlsl/hlslParseHelper.cpp index 613b18a5..9357b2fc 100755 --- a/hlsl/hlslParseHelper.cpp +++ b/hlsl/hlslParseHelper.cpp @@ -5256,8 +5256,16 @@ TIntermNode* HlslParseContext::executeInitializer(const TSourceLoc& loc, TInterm // constructor-style subtree, allowing the rest of the code to operate // identically for both kinds of initializers. // + // + // Type can't be deduced from the initializer list, so a skeletal type to + // follow has to be passed in. Constness and specialization-constness + // should be deduced bottom up, not dictated by the skeletal type. + // + TType skeletalType; + skeletalType.shallowCopy(variable->getType()); + skeletalType.getQualifier().makeTemporary(); if (initializer->getAsAggregate() && initializer->getAsAggregate()->getOp() == EOpNull) - initializer = convertInitializerList(loc, variable->getType(), initializer); + initializer = convertInitializerList(loc, skeletalType, initializer); if (! initializer) { // error recovery; don't leave const without constant values if (qualifier == EvqConst) @@ -5458,8 +5466,9 @@ TIntermTyped* HlslParseContext::convertInitializerList(const TSourceLoc& loc, co emulatedConstructorArguments = initList->getSequence()[0]; else emulatedConstructorArguments = initList; + TIntermTyped* constructor = addConstructor(loc, emulatedConstructorArguments, type); - return addConstructor(loc, emulatedConstructorArguments, type); + return constructor; } // Lengthen list to be long enough to cover any gap from the current list size