diff --git a/Test/baseResults/hlsl.shapeConv.frag.out b/Test/baseResults/hlsl.shapeConv.frag.out index 05bfa6ab..0fd379b5 100644 --- a/Test/baseResults/hlsl.shapeConv.frag.out +++ b/Test/baseResults/hlsl.shapeConv.frag.out @@ -102,8 +102,10 @@ gl_FragCoord origin is upper left 0:27 'v' ( temp 4-component vector of float) 0:27 Construct vec4 ( temp 4-component vector of float) 0:27 'f1' ( temp 1-component vector of float) -0:28 Construct float ( temp float) +0:28 direct index ( temp float) 0:28 'f1' ( temp 1-component vector of float) +0:28 Constant: +0:28 0 (const int) 0:29 Construct vec3 ( temp 3-component vector of float) 0:29 Construct float ( temp float) 0:29 'f1' ( temp 1-component vector of float) @@ -264,8 +266,10 @@ gl_FragCoord origin is upper left 0:27 'v' ( temp 4-component vector of float) 0:27 Construct vec4 ( temp 4-component vector of float) 0:27 'f1' ( temp 1-component vector of float) -0:28 Construct float ( temp float) +0:28 direct index ( temp float) 0:28 'f1' ( temp 1-component vector of float) +0:28 Constant: +0:28 0 (const int) 0:29 Construct vec3 ( temp 3-component vector of float) 0:29 Construct float ( temp float) 0:29 'f1' ( temp 1-component vector of float) @@ -320,7 +324,7 @@ gl_FragCoord origin is upper left // Module Version 10000 // Generated by (magic number): 8000b -// Id's are bound by 127 +// Id's are bound by 126 Capability Shader 1: ExtInstImport "GLSL.std.450" @@ -339,11 +343,11 @@ gl_FragCoord origin is upper left Name 34 "MyVal" Name 37 "foo" Name 70 "f1" - Name 83 "ui" - Name 88 "ui3" - Name 103 "mixed" - Name 115 "sf" - Name 118 "sf1" + Name 82 "ui" + Name 87 "ui3" + Name 102 "mixed" + Name 114 "sf" + Name 117 "sf1" 2: TypeVoid 3: TypeFunction 2 6: TypeFloat 32 @@ -375,11 +379,11 @@ gl_FragCoord origin is upper left 56: TypeInt 32 0 57: 56(int) Constant 0 62: TypeVector 41(bool) 4 - 82: TypePointer Function 56(int) - 85: TypeVector 56(int) 3 - 87: TypePointer Function 85(ivec3) - 122: 6(float) Constant 1077936128 - 123: 7(fvec4) ConstantComposite 122 122 122 122 + 81: TypePointer Function 56(int) + 84: TypeVector 56(int) 3 + 86: TypePointer Function 84(ivec3) + 121: 6(float) Constant 1077936128 + 122: 7(fvec4) ConstantComposite 121 121 121 121 4(main): 2 Function None 3 5: Label Return @@ -395,11 +399,11 @@ gl_FragCoord origin is upper left 34(MyVal): 23(ptr) Variable Function 37(foo): 23(ptr) Variable Function 70(f1): 9(ptr) Variable Function - 83(ui): 82(ptr) Variable Function - 88(ui3): 87(ptr) Variable Function - 103(mixed): 23(ptr) Variable Function - 115(sf): 9(ptr) Variable Function - 118(sf1): 9(ptr) Variable Function + 82(ui): 81(ptr) Variable Function + 87(ui3): 86(ptr) Variable Function + 102(mixed): 23(ptr) Variable Function + 114(sf): 9(ptr) Variable Function + 117(sf1): 9(ptr) Variable Function Store 15(v) 17 Store 15(v) 19 20: 6(float) Load 12(f) @@ -443,47 +447,46 @@ gl_FragCoord origin is upper left 77: 7(fvec4) CompositeConstruct 76 76 76 76 78: 62(bvec4) FOrdLessThan 75 77 79: 6(float) Load 70(f1) - 80: 6(float) Load 70(f1) - 81: 22(fvec3) CompositeConstruct 80 80 80 - 84: 56(int) Load 83(ui) - 86: 85(ivec3) CompositeConstruct 84 84 84 - 89: 85(ivec3) Load 88(ui3) - 90: 85(ivec3) ShiftRightLogical 86 89 - 91: 85(ivec3) Load 88(ui3) - 92: 56(int) Load 83(ui) - 93: 85(ivec3) CompositeConstruct 92 92 92 - 94: 85(ivec3) ShiftRightLogical 91 93 - 95: 6(float) Load 70(f1) - 96: 7(fvec4) Load 15(v) - 97: 7(fvec4) CompositeConstruct 95 95 95 95 - 98: 7(fvec4) FMul 96 97 - Store 15(v) 98 - 99: 7(fvec4) Load 15(v) - 100: 6(float) CompositeExtract 99 0 - 101: 6(float) Load 70(f1) - 102: 6(float) FMul 101 100 - Store 70(f1) 102 - 104: 22(fvec3) Load 24(u) - 105: 7(fvec4) Load 15(v) - 106: 6(float) CompositeExtract 105 0 - 107: 6(float) CompositeExtract 105 1 - 108: 6(float) CompositeExtract 105 2 - 109: 22(fvec3) CompositeConstruct 106 107 108 - 110: 22(fvec3) FMul 104 109 - Store 103(mixed) 110 - 111: 22(fvec3) Load 24(u) - 112: 6(float) CompositeExtract 111 0 - Store 12(f) 112 - 113: 22(fvec3) Load 24(u) - 114: 6(float) CompositeExtract 113 0 - Store 70(f1) 114 - 116: 7(fvec4) Load 15(v) - 117: 6(float) CompositeExtract 116 0 - Store 115(sf) 117 - 119: 7(fvec4) Load 15(v) - 120: 6(float) CompositeExtract 119 0 - Store 118(sf1) 120 - 121: 7(fvec4) Load 11(input) - 124: 7(fvec4) FMul 121 123 - ReturnValue 124 + 80: 22(fvec3) CompositeConstruct 79 79 79 + 83: 56(int) Load 82(ui) + 85: 84(ivec3) CompositeConstruct 83 83 83 + 88: 84(ivec3) Load 87(ui3) + 89: 84(ivec3) ShiftRightLogical 85 88 + 90: 84(ivec3) Load 87(ui3) + 91: 56(int) Load 82(ui) + 92: 84(ivec3) CompositeConstruct 91 91 91 + 93: 84(ivec3) ShiftRightLogical 90 92 + 94: 6(float) Load 70(f1) + 95: 7(fvec4) Load 15(v) + 96: 7(fvec4) CompositeConstruct 94 94 94 94 + 97: 7(fvec4) FMul 95 96 + Store 15(v) 97 + 98: 7(fvec4) Load 15(v) + 99: 6(float) CompositeExtract 98 0 + 100: 6(float) Load 70(f1) + 101: 6(float) FMul 100 99 + Store 70(f1) 101 + 103: 22(fvec3) Load 24(u) + 104: 7(fvec4) Load 15(v) + 105: 6(float) CompositeExtract 104 0 + 106: 6(float) CompositeExtract 104 1 + 107: 6(float) CompositeExtract 104 2 + 108: 22(fvec3) CompositeConstruct 105 106 107 + 109: 22(fvec3) FMul 103 108 + Store 102(mixed) 109 + 110: 22(fvec3) Load 24(u) + 111: 6(float) CompositeExtract 110 0 + Store 12(f) 111 + 112: 22(fvec3) Load 24(u) + 113: 6(float) CompositeExtract 112 0 + Store 70(f1) 113 + 115: 7(fvec4) Load 15(v) + 116: 6(float) CompositeExtract 115 0 + Store 114(sf) 116 + 118: 7(fvec4) Load 15(v) + 119: 6(float) CompositeExtract 118 0 + Store 117(sf1) 119 + 120: 7(fvec4) Load 11(input) + 123: 7(fvec4) FMul 120 122 + ReturnValue 123 FunctionEnd diff --git a/Test/baseResults/hlsl.swizzle.vec1.comp.out b/Test/baseResults/hlsl.swizzle.vec1.comp.out new file mode 100644 index 00000000..e1583b88 --- /dev/null +++ b/Test/baseResults/hlsl.swizzle.vec1.comp.out @@ -0,0 +1,72 @@ +hlsl.swizzle.vec1.comp +Shader version: 500 +local_size = (1, 1, 1) +0:? Sequence +0:2 Function Definition: @main( ( temp void) +0:2 Function Parameters: +0:? Sequence +0:4 move second child to first child ( temp float) +0:4 direct index ( temp float) +0:4 'f1' ( temp 1-component vector of float) +0:4 Constant: +0:4 0 (const int) +0:4 Constant: +0:4 0.500000 +0:2 Function Definition: main( ( temp void) +0:2 Function Parameters: +0:? Sequence +0:2 Function Call: @main( ( temp void) +0:? Linker Objects + + +Linked compute stage: + + +Shader version: 500 +local_size = (1, 1, 1) +0:? Sequence +0:2 Function Definition: @main( ( temp void) +0:2 Function Parameters: +0:? Sequence +0:4 move second child to first child ( temp float) +0:4 direct index ( temp float) +0:4 'f1' ( temp 1-component vector of float) +0:4 Constant: +0:4 0 (const int) +0:4 Constant: +0:4 0.500000 +0:2 Function Definition: main( ( temp void) +0:2 Function Parameters: +0:? Sequence +0:2 Function Call: @main( ( temp void) +0:? Linker Objects + +// Module Version 10000 +// Generated by (magic number): 8000b +// Id's are bound by 13 + + Capability Shader + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint GLCompute 4 "main" + ExecutionMode 4 LocalSize 1 1 1 + Source HLSL 500 + Name 4 "main" + Name 6 "@main(" + Name 10 "f1" + 2: TypeVoid + 3: TypeFunction 2 + 8: TypeFloat 32 + 9: TypePointer Function 8(float) + 11: 8(float) Constant 1056964608 + 4(main): 2 Function None 3 + 5: Label + 12: 2 FunctionCall 6(@main() + Return + FunctionEnd + 6(@main(): 2 Function None 3 + 7: Label + 10(f1): 9(ptr) Variable Function + Store 10(f1) 11 + Return + FunctionEnd diff --git a/Test/hlsl.swizzle.vec1.comp b/Test/hlsl.swizzle.vec1.comp new file mode 100644 index 00000000..1ee454cc --- /dev/null +++ b/Test/hlsl.swizzle.vec1.comp @@ -0,0 +1,8 @@ +void main() +{ + float1 f1; + f1.x = 0.5; + + // This is not implemented + // f1.xx = float2(0.6, 0.7); +} diff --git a/glslang/HLSL/hlslParseHelper.cpp b/glslang/HLSL/hlslParseHelper.cpp index a1ae55c8..0fd724d0 100644 --- a/glslang/HLSL/hlslParseHelper.cpp +++ b/glslang/HLSL/hlslParseHelper.cpp @@ -962,14 +962,11 @@ TIntermTyped* HlslParseContext::handleDotDereference(const TSourceLoc& loc, TInt return addConstructor(loc, base, type); } } - if (base->getVectorSize() == 1) { + // Use EOpIndexDirect (below) with vec1.x so that it remains l-value (Test/hlsl.swizzle.vec1.comp) + if (base->getVectorSize() == 1 && selectors.size() > 1) { TType scalarType(base->getBasicType(), EvqTemporary, 1); - if (selectors.size() == 1) - return addConstructor(loc, base, scalarType); - else { - TType vectorType(base->getBasicType(), EvqTemporary, selectors.size()); - return addConstructor(loc, addConstructor(loc, base, scalarType), vectorType); - } + TType vectorType(base->getBasicType(), EvqTemporary, selectors.size()); + return addConstructor(loc, addConstructor(loc, base, scalarType), vectorType); } if (base->getType().getQualifier().isFrontEndConstant()) diff --git a/gtests/Hlsl.FromFile.cpp b/gtests/Hlsl.FromFile.cpp index 75af7c8c..c94a3381 100644 --- a/gtests/Hlsl.FromFile.cpp +++ b/gtests/Hlsl.FromFile.cpp @@ -420,6 +420,7 @@ INSTANTIATE_TEST_SUITE_P( {"hlsl.structIoFourWay.frag", "main"}, {"hlsl.structStructName.frag", "main"}, {"hlsl.subpass.frag", "main"}, + {"hlsl.swizzle.vec1.comp", "main"}, {"hlsl.synthesizeInput.frag", "main"}, {"hlsl.texturebuffer.frag", "main"}, {"hlsl.texture.struct.frag", "main"},