Commit 297ae211 by steve-lunarg

WIP: HLSL: Treat HLSL rows as GLSL columns.

WIP: HLSL: EOpGenMul arg reversal
parent a21187a7
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -17,9 +17,9 @@ gl_FragCoord origin is upper left ...@@ -17,9 +17,9 @@ gl_FragCoord origin is upper left
0:? Linker Objects 0:? Linker Objects
0:? 'f1' (global 1-component vector of float) 0:? 'f1' (global 1-component vector of float)
0:? 'fmat11' (global 1X1 matrix of float) 0:? 'fmat11' (global 1X1 matrix of float)
0:? 'fmat41' (global 1X4 matrix of float) 0:? 'fmat41' (global 4X1 matrix of float)
0:? 'fmat12' (global 2X1 matrix of float) 0:? 'fmat12' (global 1X2 matrix of float)
0:? 'dmat23' (global 3X2 matrix of double) 0:? 'dmat23' (global 2X3 matrix of double)
0:? 'int44' (global 4X4 matrix of int) 0:? 'int44' (global 4X4 matrix of int)
...@@ -44,9 +44,9 @@ gl_FragCoord origin is upper left ...@@ -44,9 +44,9 @@ gl_FragCoord origin is upper left
0:? Linker Objects 0:? Linker Objects
0:? 'f1' (global 1-component vector of float) 0:? 'f1' (global 1-component vector of float)
0:? 'fmat11' (global 1X1 matrix of float) 0:? 'fmat11' (global 1X1 matrix of float)
0:? 'fmat41' (global 1X4 matrix of float) 0:? 'fmat41' (global 4X1 matrix of float)
0:? 'fmat12' (global 2X1 matrix of float) 0:? 'fmat12' (global 1X2 matrix of float)
0:? 'dmat23' (global 3X2 matrix of double) 0:? 'dmat23' (global 2X3 matrix of double)
0:? 'int44' (global 4X4 matrix of int) 0:? 'int44' (global 4X4 matrix of int)
// Module Version 10000 // Module Version 10000
...@@ -65,7 +65,7 @@ gl_FragCoord origin is upper left ...@@ -65,7 +65,7 @@ gl_FragCoord origin is upper left
Name 10 "inScalar" Name 10 "inScalar"
Name 14 "f1" Name 14 "f1"
Name 22 "fmat11" Name 22 "fmat11"
Name 26 "fmat41" Name 25 "fmat41"
Name 29 "fmat12" Name 29 "fmat12"
Name 34 "dmat23" Name 34 "dmat23"
Name 39 "int44" Name 39 "int44"
...@@ -81,16 +81,16 @@ gl_FragCoord origin is upper left ...@@ -81,16 +81,16 @@ gl_FragCoord origin is upper left
20: TypeMatrix 19(fvec) 1 20: TypeMatrix 19(fvec) 1
21: TypePointer Private 20 21: TypePointer Private 20
22(fmat11): 21(ptr) Variable Private 22(fmat11): 21(ptr) Variable Private
23: TypeVector 6(float) 4 23: TypeMatrix 19(fvec) 4
24: TypeMatrix 23(fvec4) 1 24: TypePointer Private 23
25: TypePointer Private 24 25(fmat41): 24(ptr) Variable Private
26(fmat41): 25(ptr) Variable Private 26: TypeVector 6(float) 2
27: TypeMatrix 19(fvec) 2 27: TypeMatrix 26(fvec2) 1
28: TypePointer Private 27 28: TypePointer Private 27
29(fmat12): 28(ptr) Variable Private 29(fmat12): 28(ptr) Variable Private
30: TypeFloat 64 30: TypeFloat 64
31: TypeVector 30(float) 2 31: TypeVector 30(float) 3
32: TypeMatrix 31(fvec2) 3 32: TypeMatrix 31(fvec3) 2
33: TypePointer Private 32 33: TypePointer Private 32
34(dmat23): 33(ptr) Variable Private 34(dmat23): 33(ptr) Variable Private
35: TypeInt 32 1 35: TypeInt 32 1
......
...@@ -192,8 +192,8 @@ gl_FragCoord origin is upper left ...@@ -192,8 +192,8 @@ gl_FragCoord origin is upper left
0:? 14.000000 0:? 14.000000
0:? 15.000000 0:? 15.000000
0:35 Sequence 0:35 Sequence
0:35 move second child to first child (temp 3X2 matrix of float) 0:35 move second child to first child (temp 2X3 matrix of float)
0:35 'r61' (temp 3X2 matrix of float) 0:35 'r61' (temp 2X3 matrix of float)
0:? Constant: 0:? Constant:
0:? 1.000000 0:? 1.000000
0:? 2.000000 0:? 2.000000
...@@ -202,8 +202,8 @@ gl_FragCoord origin is upper left ...@@ -202,8 +202,8 @@ gl_FragCoord origin is upper left
0:? 5.000000 0:? 5.000000
0:? 6.000000 0:? 6.000000
0:36 Sequence 0:36 Sequence
0:36 move second child to first child (temp 2X3 matrix of float) 0:36 move second child to first child (temp 3X2 matrix of float)
0:36 'r62' (temp 2X3 matrix of float) 0:36 'r62' (temp 3X2 matrix of float)
0:? Constant: 0:? Constant:
0:? 1.000000 0:? 1.000000
0:? 2.000000 0:? 2.000000
...@@ -212,8 +212,8 @@ gl_FragCoord origin is upper left ...@@ -212,8 +212,8 @@ gl_FragCoord origin is upper left
0:? 5.000000 0:? 5.000000
0:? 6.000000 0:? 6.000000
0:39 Sequence 0:39 Sequence
0:39 move second child to first child (temp 2X4 matrix of float) 0:39 move second child to first child (temp 4X2 matrix of float)
0:39 'r65' (temp 2X4 matrix of float) 0:39 'r65' (temp 4X2 matrix of float)
0:? Constant: 0:? Constant:
0:? 1.000000 0:? 1.000000
0:? 2.000000 0:? 2.000000
...@@ -224,8 +224,8 @@ gl_FragCoord origin is upper left ...@@ -224,8 +224,8 @@ gl_FragCoord origin is upper left
0:? 7.000000 0:? 7.000000
0:? 8.000000 0:? 8.000000
0:40 Sequence 0:40 Sequence
0:40 move second child to first child (temp 3X4 matrix of float) 0:40 move second child to first child (temp 4X3 matrix of float)
0:40 'r66' (temp 3X4 matrix of float) 0:40 'r66' (temp 4X3 matrix of float)
0:? Constant: 0:? Constant:
0:? 1.000000 0:? 1.000000
0:? 2.000000 0:? 2.000000
...@@ -444,8 +444,8 @@ gl_FragCoord origin is upper left ...@@ -444,8 +444,8 @@ gl_FragCoord origin is upper left
0:? 14.000000 0:? 14.000000
0:? 15.000000 0:? 15.000000
0:35 Sequence 0:35 Sequence
0:35 move second child to first child (temp 3X2 matrix of float) 0:35 move second child to first child (temp 2X3 matrix of float)
0:35 'r61' (temp 3X2 matrix of float) 0:35 'r61' (temp 2X3 matrix of float)
0:? Constant: 0:? Constant:
0:? 1.000000 0:? 1.000000
0:? 2.000000 0:? 2.000000
...@@ -454,8 +454,8 @@ gl_FragCoord origin is upper left ...@@ -454,8 +454,8 @@ gl_FragCoord origin is upper left
0:? 5.000000 0:? 5.000000
0:? 6.000000 0:? 6.000000
0:36 Sequence 0:36 Sequence
0:36 move second child to first child (temp 2X3 matrix of float) 0:36 move second child to first child (temp 3X2 matrix of float)
0:36 'r62' (temp 2X3 matrix of float) 0:36 'r62' (temp 3X2 matrix of float)
0:? Constant: 0:? Constant:
0:? 1.000000 0:? 1.000000
0:? 2.000000 0:? 2.000000
...@@ -464,8 +464,8 @@ gl_FragCoord origin is upper left ...@@ -464,8 +464,8 @@ gl_FragCoord origin is upper left
0:? 5.000000 0:? 5.000000
0:? 6.000000 0:? 6.000000
0:39 Sequence 0:39 Sequence
0:39 move second child to first child (temp 2X4 matrix of float) 0:39 move second child to first child (temp 4X2 matrix of float)
0:39 'r65' (temp 2X4 matrix of float) 0:39 'r65' (temp 4X2 matrix of float)
0:? Constant: 0:? Constant:
0:? 1.000000 0:? 1.000000
0:? 2.000000 0:? 2.000000
...@@ -476,8 +476,8 @@ gl_FragCoord origin is upper left ...@@ -476,8 +476,8 @@ gl_FragCoord origin is upper left
0:? 7.000000 0:? 7.000000
0:? 8.000000 0:? 8.000000
0:40 Sequence 0:40 Sequence
0:40 move second child to first child (temp 3X4 matrix of float) 0:40 move second child to first child (temp 4X3 matrix of float)
0:40 'r66' (temp 3X4 matrix of float) 0:40 'r66' (temp 4X3 matrix of float)
0:? Constant: 0:? Constant:
0:? 1.000000 0:? 1.000000
0:? 2.000000 0:? 2.000000
...@@ -501,13 +501,13 @@ gl_FragCoord origin is upper left ...@@ -501,13 +501,13 @@ gl_FragCoord origin is upper left
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80001 // Generated by (magic number): 80001
// Id's are bound by 147 // Id's are bound by 148
Capability Shader Capability Shader
Capability Float64 Capability Float64
1: ExtInstImport "GLSL.std.450" 1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450 MemoryModel Logical GLSL450
EntryPoint Fragment 4 "PixelShaderFunction" 145 EntryPoint Fragment 4 "PixelShaderFunction" 146
ExecutionMode 4 OriginUpperLeft ExecutionMode 4 OriginUpperLeft
Name 4 "PixelShaderFunction" Name 4 "PixelShaderFunction"
Name 9 "r00" Name 9 "r00"
...@@ -535,11 +535,11 @@ gl_FragCoord origin is upper left ...@@ -535,11 +535,11 @@ gl_FragCoord origin is upper left
Name 105 "r50" Name 105 "r50"
Name 122 "r51" Name 122 "r51"
Name 125 "r61" Name 125 "r61"
Name 131 "r62" Name 130 "r62"
Name 136 "r65" Name 136 "r65"
Name 141 "r66" Name 141 "r66"
Name 145 "@entryPointOutput" Name 146 "@entryPointOutput"
Decorate 145(@entryPointOutput) Location 0 Decorate 146(@entryPointOutput) Location 0
2: TypeVoid 2: TypeVoid
3: TypeFunction 2 3: TypeFunction 2
6: TypeFloat 32 6: TypeFloat 32
...@@ -635,25 +635,26 @@ gl_FragCoord origin is upper left ...@@ -635,25 +635,26 @@ gl_FragCoord origin is upper left
119: 6(float) Constant 1097859072 119: 6(float) Constant 1097859072
120: 7(fvec4) ConstantComposite 116 117 118 119 120: 7(fvec4) ConstantComposite 116 117 118 119
121: 103 ConstantComposite 107 110 115 120 121: 103 ConstantComposite 107 110 115 120
123: TypeMatrix 46(fvec2) 3 123: TypeMatrix 69(fvec3) 2
124: TypePointer Function 123 124: TypePointer Function 123
126: 46(fvec2) ConstantComposite 12 13 126: 69(fvec3) ConstantComposite 13 16 108
127: 46(fvec2) ConstantComposite 16 108 127: 123 ConstantComposite 72 126
128: 123 ConstantComposite 49 126 127 128: TypeMatrix 46(fvec2) 3
129: TypeMatrix 69(fvec3) 2 129: TypePointer Function 128
130: TypePointer Function 129 131: 46(fvec2) ConstantComposite 12 13
132: 69(fvec3) ConstantComposite 13 16 108 132: 46(fvec2) ConstantComposite 16 108
133: 129 ConstantComposite 72 132 133: 128 ConstantComposite 49 131 132
134: TypeMatrix 7(fvec4) 2 134: TypeMatrix 46(fvec2) 4
135: TypePointer Function 134 135: TypePointer Function 134
137: 7(fvec4) ConstantComposite 16 108 109 111 137: 46(fvec2) ConstantComposite 109 111
138: 134 ConstantComposite 14 137 138: 134 ConstantComposite 49 131 132 137
139: TypeMatrix 7(fvec4) 3 139: TypeMatrix 69(fvec3) 4
140: TypePointer Function 139 140: TypePointer Function 139
142: 7(fvec4) ConstantComposite 112 113 114 116 142: 69(fvec3) ConstantComposite 109 111 112
143: 139 ConstantComposite 14 137 142 143: 69(fvec3) ConstantComposite 113 114 116
144: TypePointer Output 6(float) 144: 139 ConstantComposite 72 126 142 143
145(@entryPointOutput): 144(ptr) Variable Output 145: TypePointer Output 6(float)
146(@entryPointOutput): 145(ptr) Variable Output
4(PixelShaderFunction): 2 Function None 3 4(PixelShaderFunction): 2 Function None 3
5: Label 5: Label
9(r00): 8(ptr) Variable Function 9(r00): 8(ptr) Variable Function
...@@ -681,7 +682,7 @@ gl_FragCoord origin is upper left ...@@ -681,7 +682,7 @@ gl_FragCoord origin is upper left
105(r50): 104(ptr) Variable Function 105(r50): 104(ptr) Variable Function
122(r51): 104(ptr) Variable Function 122(r51): 104(ptr) Variable Function
125(r61): 124(ptr) Variable Function 125(r61): 124(ptr) Variable Function
131(r62): 130(ptr) Variable Function 130(r62): 129(ptr) Variable Function
136(r65): 135(ptr) Variable Function 136(r65): 135(ptr) Variable Function
141(r66): 140(ptr) Variable Function 141(r66): 140(ptr) Variable Function
Store 9(r00) 14 Store 9(r00) 14
...@@ -708,10 +709,10 @@ gl_FragCoord origin is upper left ...@@ -708,10 +709,10 @@ gl_FragCoord origin is upper left
Store 100(r44) 102 Store 100(r44) 102
Store 105(r50) 121 Store 105(r50) 121
Store 122(r51) 121 Store 122(r51) 121
Store 125(r61) 128 Store 125(r61) 127
Store 131(r62) 133 Store 130(r62) 133
Store 136(r65) 138 Store 136(r65) 138
Store 141(r66) 143 Store 141(r66) 144
Store 145(@entryPointOutput) 106 Store 146(@entryPointOutput) 106
Return Return
FunctionEnd FunctionEnd
...@@ -5,7 +5,7 @@ Linked fragment stage: ...@@ -5,7 +5,7 @@ Linked fragment stage:
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80001 // Generated by (magic number): 80001
// Id's are bound by 144 // Id's are bound by 145
Capability Shader Capability Shader
Capability Float64 Capability Float64
...@@ -39,7 +39,7 @@ Linked fragment stage: ...@@ -39,7 +39,7 @@ Linked fragment stage:
Name 105 "r50" Name 105 "r50"
Name 122 "r51" Name 122 "r51"
Name 125 "r61" Name 125 "r61"
Name 131 "r62" Name 130 "r62"
Name 136 "r65" Name 136 "r65"
Name 141 "r66" Name 141 "r66"
2: TypeVoid 2: TypeVoid
...@@ -137,23 +137,24 @@ Linked fragment stage: ...@@ -137,23 +137,24 @@ Linked fragment stage:
119: 6(float) Constant 1097859072 119: 6(float) Constant 1097859072
120: 7(fvec4) ConstantComposite 116 117 118 119 120: 7(fvec4) ConstantComposite 116 117 118 119
121: 103 ConstantComposite 107 110 115 120 121: 103 ConstantComposite 107 110 115 120
123: TypeMatrix 46(fvec2) 3 123: TypeMatrix 69(fvec3) 2
124: TypePointer Function 123 124: TypePointer Function 123
126: 46(fvec2) ConstantComposite 12 13 126: 69(fvec3) ConstantComposite 13 16 108
127: 46(fvec2) ConstantComposite 16 108 127: 123 ConstantComposite 72 126
128: 123 ConstantComposite 49 126 127 128: TypeMatrix 46(fvec2) 3
129: TypeMatrix 69(fvec3) 2 129: TypePointer Function 128
130: TypePointer Function 129 131: 46(fvec2) ConstantComposite 12 13
132: 69(fvec3) ConstantComposite 13 16 108 132: 46(fvec2) ConstantComposite 16 108
133: 129 ConstantComposite 72 132 133: 128 ConstantComposite 49 131 132
134: TypeMatrix 7(fvec4) 2 134: TypeMatrix 46(fvec2) 4
135: TypePointer Function 134 135: TypePointer Function 134
137: 7(fvec4) ConstantComposite 16 108 109 111 137: 46(fvec2) ConstantComposite 109 111
138: 134 ConstantComposite 14 137 138: 134 ConstantComposite 49 131 132 137
139: TypeMatrix 7(fvec4) 3 139: TypeMatrix 69(fvec3) 4
140: TypePointer Function 139 140: TypePointer Function 139
142: 7(fvec4) ConstantComposite 112 113 114 116 142: 69(fvec3) ConstantComposite 109 111 112
143: 139 ConstantComposite 14 137 142 143: 69(fvec3) ConstantComposite 113 114 116
144: 139 ConstantComposite 72 126 142 143
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
9(r00): 8(ptr) Variable Function 9(r00): 8(ptr) Variable Function
...@@ -181,7 +182,7 @@ Linked fragment stage: ...@@ -181,7 +182,7 @@ Linked fragment stage:
105(r50): 104(ptr) Variable Function 105(r50): 104(ptr) Variable Function
122(r51): 104(ptr) Variable Function 122(r51): 104(ptr) Variable Function
125(r61): 124(ptr) Variable Function 125(r61): 124(ptr) Variable Function
131(r62): 130(ptr) Variable Function 130(r62): 129(ptr) Variable Function
136(r65): 135(ptr) Variable Function 136(r65): 135(ptr) Variable Function
141(r66): 140(ptr) Variable Function 141(r66): 140(ptr) Variable Function
Store 9(r00) 14 Store 9(r00) 14
...@@ -208,9 +209,9 @@ Linked fragment stage: ...@@ -208,9 +209,9 @@ Linked fragment stage:
Store 100(r44) 102 Store 100(r44) 102
Store 105(r50) 121 Store 105(r50) 121
Store 122(r51) 121 Store 122(r51) 121
Store 125(r61) 128 Store 125(r61) 127
Store 131(r62) 133 Store 130(r62) 133
Store 136(r65) 138 Store 136(r65) 138
Store 141(r66) 143 Store 141(r66) 144
ReturnValue 106 ReturnValue 106
FunctionEnd FunctionEnd
...@@ -482,3 +482,12 @@ void TestGenMulNxM(float inF0, float inF1, ...@@ -482,3 +482,12 @@ void TestGenMulNxM(float inF0, float inF1,
float2x4 r15 = mul(inFM2x3, inFM3x4); float2x4 r15 = mul(inFM2x3, inFM3x4);
float3x4 r16 = mul(inFM3x2, inFM2x4); float3x4 r16 = mul(inFM3x2, inFM2x4);
} }
struct PS_OUTPUT { float4 color : SV_Target0; };
PS_OUTPUT main()
{
PS_OUTPUT ps_output;
ps_output.color = 1.0;
return ps_output;
};
uniform int idx;
uniform float3x2 um;
struct PS_OUTPUT
{
float4 Color : SV_Target0;
};
PS_OUTPUT main()
{
// matrices of 3 rows, 2 columns (regardless of row vs col major storage)
const float3x2 m1 = { { 10, 11 }, // row-wise initialization
{ 12, 13 },
{ 14, 15 } };
const float3x2 m2 = { 20, 21, 22, 23, 24, 25 }; // component-wise matrix initialization is allowed
const float3x2 m3 = { 30, 31, 33, 33, 34, 35 }; // component-wise matrix initialization is allowed
// These can be observed in the AST post-const folding to ensure we obtain the right value,
// as given in comments to the right of each line. Note that the first indirection into a
// matrix returns a row vector.
float e1_00 = m1[0][0]; // 10
float e1_01 = m1[0][1]; // 11
float e1_10 = m1[1][0]; // 12
float e1_11 = m1[1][1]; // 13
float e1_20 = m1[2][0]; // 14
float e1_21 = m1[2][1]; // 15
float e2_00 = m2[0][0]; // 20
float e2_01 = m2[0][1]; // 21
float e2_10 = m2[1][0]; // 22
float e2_11 = m2[1][1]; // 23
float e2_20 = m2[2][0]; // 24
float e2_21 = m2[2][1]; // 25
// float e3a_00 = m3._m00; // TODO... also as an lvalue for a non-const matrix
// float e3b_00 = m3._11; // TODO... also as an lvalue for a non-const matrix
float2 r0a = m1[0]; // row0: 10,11: types must match: constant index into constant
float2 r1a = m1[1]; // row1: 12,13: ...
float2 r2a = m1[2]; // row2: 14,15: ...
float2 r0b = m2[idx]; // types should match: variable index into constant
float2 r0c = um[idx]; // types should match: variable index into variable
PS_OUTPUT psout;
psout.Color = e2_11; // 23
return psout;
}
...@@ -110,7 +110,7 @@ INSTANTIATE_TEST_CASE_P( ...@@ -110,7 +110,7 @@ INSTANTIATE_TEST_CASE_P(
{"hlsl.intrinsics.evalfns.frag", "main"}, {"hlsl.intrinsics.evalfns.frag", "main"},
{"hlsl.intrinsics.double.frag", "PixelShaderFunction"}, {"hlsl.intrinsics.double.frag", "PixelShaderFunction"},
{"hlsl.intrinsics.f1632.frag", "PixelShaderFunction"}, {"hlsl.intrinsics.f1632.frag", "PixelShaderFunction"},
{"hlsl.intrinsics.frag", "PixelShaderFunction"}, {"hlsl.intrinsics.frag", "main"},
{"hlsl.intrinsics.lit.frag", "PixelShaderFunction"}, {"hlsl.intrinsics.lit.frag", "PixelShaderFunction"},
{"hlsl.intrinsics.negative.comp", "ComputeShaderFunction"}, {"hlsl.intrinsics.negative.comp", "ComputeShaderFunction"},
{"hlsl.intrinsics.negative.frag", "PixelShaderFunction"}, {"hlsl.intrinsics.negative.frag", "PixelShaderFunction"},
...@@ -124,6 +124,7 @@ INSTANTIATE_TEST_CASE_P( ...@@ -124,6 +124,7 @@ INSTANTIATE_TEST_CASE_P(
{"hlsl.load.offset.dx10.frag", "main"}, {"hlsl.load.offset.dx10.frag", "main"},
{"hlsl.load.offsetarray.dx10.frag", "main"}, {"hlsl.load.offsetarray.dx10.frag", "main"},
{"hlsl.multiEntry.vert", "RealEntrypoint"}, {"hlsl.multiEntry.vert", "RealEntrypoint"},
{"hlsl.matrixindex.frag", "main"},
{"hlsl.numericsuffixes.frag", "main"}, {"hlsl.numericsuffixes.frag", "main"},
{"hlsl.overload.frag", "PixelShaderFunction"}, {"hlsl.overload.frag", "PixelShaderFunction"},
{"hlsl.pp.line.frag", "main"}, {"hlsl.pp.line.frag", "main"},
......
...@@ -1597,8 +1597,10 @@ void HlslParseContext::decomposeIntrinsic(const TSourceLoc& loc, TIntermTyped*& ...@@ -1597,8 +1597,10 @@ void HlslParseContext::decomposeIntrinsic(const TSourceLoc& loc, TIntermTyped*&
case EOpGenMul: case EOpGenMul:
{ {
// mul(a,b) -> MatrixTimesMatrix, MatrixTimesVector, MatrixTimesScalar, VectorTimesScalar, Dot, Mul // mul(a,b) -> MatrixTimesMatrix, MatrixTimesVector, MatrixTimesScalar, VectorTimesScalar, Dot, Mul
TIntermTyped* arg0 = argAggregate->getSequence()[0]->getAsTyped(); // Since we are treating HLSL rows like GLSL columns (the first matrix indirection),
TIntermTyped* arg1 = argAggregate->getSequence()[1]->getAsTyped(); // we must reverse the operand order here. Hence, arg0 gets sequence[1], etc.
TIntermTyped* arg0 = argAggregate->getSequence()[1]->getAsTyped();
TIntermTyped* arg1 = argAggregate->getSequence()[0]->getAsTyped();
if (arg0->isVector() && arg1->isVector()) { // vec * vec if (arg0->isVector() && arg1->isVector()) { // vec * vec
node->getAsAggregate()->setOperator(EOpDot); node->getAsAggregate()->setOperator(EOpDot);
...@@ -4144,15 +4146,21 @@ TIntermTyped* HlslParseContext::convertInitializerList(const TSourceLoc& loc, co ...@@ -4144,15 +4146,21 @@ TIntermTyped* HlslParseContext::convertInitializerList(const TSourceLoc& loc, co
return nullptr; return nullptr;
} }
} else if (type.isMatrix()) { } else if (type.isMatrix()) {
if (type.getMatrixCols() != (int)initList->getSequence().size()) { if (type.computeNumComponents() == (int)initList->getSequence().size()) {
error(loc, "wrong number of matrix columns:", "initializer list", type.getCompleteString().c_str()); // This means the matrix is initialized component-wise, rather than as
return nullptr; // a series of rows and columns. We can just use the list directly as
} // a constructor; no further processing needed.
TType vectorType(type, 0); // dereferenced type } else {
for (int i = 0; i < type.getMatrixCols(); ++i) { if (type.getMatrixCols() != (int)initList->getSequence().size()) {
initList->getSequence()[i] = convertInitializerList(loc, vectorType, initList->getSequence()[i]->getAsTyped()); error(loc, "wrong number of matrix columns:", "initializer list", type.getCompleteString().c_str());
if (initList->getSequence()[i] == nullptr)
return nullptr; return nullptr;
}
TType vectorType(type, 0); // dereferenced type
for (int i = 0; i < type.getMatrixCols(); ++i) {
initList->getSequence()[i] = convertInitializerList(loc, vectorType, initList->getSequence()[i]->getAsTyped());
if (initList->getSequence()[i] == nullptr)
return nullptr;
}
} }
} else if (type.isVector()) { } else if (type.isVector()) {
if (type.getVectorSize() != (int)initList->getSequence().size()) { if (type.getVectorSize() != (int)initList->getSequence().size()) {
......
...@@ -218,7 +218,6 @@ int FixedVecSize(const char* arg) ...@@ -218,7 +218,6 @@ int FixedVecSize(const char* arg)
glslang::TString& AppendTypeName(glslang::TString& s, const char* argOrder, const char* argType, int dim0, int dim1) glslang::TString& AppendTypeName(glslang::TString& s, const char* argOrder, const char* argType, int dim0, int dim1)
{ {
const bool isTranspose = (argOrder[0] == '^'); const bool isTranspose = (argOrder[0] == '^');
const bool isMatMul = (argOrder[0] == '#');
const bool isTexture = IsTextureType(argOrder[0]); const bool isTexture = IsTextureType(argOrder[0]);
const bool isArrayed = IsTextureArrayed(argOrder[0]); const bool isArrayed = IsTextureArrayed(argOrder[0]);
const bool isSampler = IsSamplerType(argType[0]); const bool isSampler = IsSamplerType(argType[0]);
...@@ -229,8 +228,6 @@ glslang::TString& AppendTypeName(glslang::TString& s, const char* argOrder, cons ...@@ -229,8 +228,6 @@ glslang::TString& AppendTypeName(glslang::TString& s, const char* argOrder, cons
if (isTranspose) { // Take transpose of matrix dimensions if (isTranspose) { // Take transpose of matrix dimensions
std::swap(dim0, dim1); std::swap(dim0, dim1);
} else if (isMatMul) {
dim0 = dim1; // set vector dimension to mat col
} else if (isTexture) { } else if (isTexture) {
if (type == 'F') // map base type to texture of that type. if (type == 'F') // map base type to texture of that type.
type = 'T'; // e.g, int -> itexture, uint -> utexture, etc. type = 'T'; // e.g, int -> itexture, uint -> utexture, etc.
...@@ -240,7 +237,7 @@ glslang::TString& AppendTypeName(glslang::TString& s, const char* argOrder, cons ...@@ -240,7 +237,7 @@ glslang::TString& AppendTypeName(glslang::TString& s, const char* argOrder, cons
type = 'u'; type = 'u';
} }
if (isTranspose || isMatMul) if (isTranspose)
++argOrder; ++argOrder;
char order = *argOrder; char order = *argOrder;
...@@ -312,16 +309,14 @@ glslang::TString& AppendTypeName(glslang::TString& s, const char* argOrder, cons ...@@ -312,16 +309,14 @@ glslang::TString& AppendTypeName(glslang::TString& s, const char* argOrder, cons
switch (order) { switch (order) {
case '-': break; // no dimensions for voids case '-': break; // no dimensions for voids
case 'S': break; // no dimensions on scalars case 'S': break; // no dimensions on scalars
case 'V': s += ('0' + char(dim0)); break; case 'V':
s += ('0' + char(dim0));
break;
case 'M': case 'M':
{ s += ('0' + char(dim0));
if (!UseHlslTypes) // GLSL has column first for mat types s += 'x';
std::swap(dim0, dim1); s += ('0' + char(dim1));
s += ('0' + char(dim0)); break;
s += 'x';
s += ('0' + char(dim1));
break;
}
default: default:
break; break;
} }
...@@ -427,6 +422,7 @@ void TBuiltInParseablesHlsl::createMatTimesMat() ...@@ -427,6 +422,7 @@ void TBuiltInParseablesHlsl::createMatTimesMat()
const int retRows = xRows; const int retRows = xRows;
const int retCols = yCols; const int retCols = yCols;
// Create a mat * mat of the appropriate dimensions
AppendTypeName(s, "M", "F", retRows, retCols); // add return type AppendTypeName(s, "M", "F", retRows, retCols); // add return type
s.append(" "); // space between type and name s.append(" "); // space between type and name
s.append("mul"); // intrinsic name s.append("mul"); // intrinsic name
...@@ -438,6 +434,31 @@ void TBuiltInParseablesHlsl::createMatTimesMat() ...@@ -438,6 +434,31 @@ void TBuiltInParseablesHlsl::createMatTimesMat()
s.append(");\n"); // close paren s.append(");\n"); // close paren
} }
// Create M*V
AppendTypeName(s, "V", "F", xRows, 1); // add return type
s.append(" "); // space between type and name
s.append("mul"); // intrinsic name
s.append("("); // open paren
AppendTypeName(s, "M", "F", xRows, xCols); // add X input
s.append(", ");
AppendTypeName(s, "V", "F", xCols, 1); // add Y input
s.append(");\n"); // close paren
// Create V*M
AppendTypeName(s, "V", "F", xCols, 1); // add return type
s.append(" "); // space between type and name
s.append("mul"); // intrinsic name
s.append("("); // open paren
AppendTypeName(s, "V", "F", xRows, 1); // add Y input
s.append(", ");
AppendTypeName(s, "M", "F", xRows, xCols); // add X input
s.append(");\n"); // close paren
} }
} }
} }
...@@ -482,7 +503,6 @@ void TBuiltInParseablesHlsl::initialize(int /*version*/, EProfile /*profile*/, c ...@@ -482,7 +503,6 @@ void TBuiltInParseablesHlsl::initialize(int /*version*/, EProfile /*profile*/, c
// '>' as first letter of order creates an output parameter // '>' as first letter of order creates an output parameter
// '<' as first letter of order creates an input parameter // '<' as first letter of order creates an input parameter
// '^' as first letter of order takes transpose dimensions // '^' as first letter of order takes transpose dimensions
// '#' as first letter of order sets rows=cols for mats
// '%' as first letter of order creates texture of given F/I/U type (texture, itexture, etc) // '%' as first letter of order creates texture of given F/I/U type (texture, itexture, etc)
// '@' as first letter of order creates arrayed texture of given type // '@' as first letter of order creates arrayed texture of given type
// '$' / '&' as first letter of order creates 2DMS / 2DMSArray textures // '$' / '&' as first letter of order creates 2DMS / 2DMSArray textures
...@@ -592,9 +612,7 @@ void TBuiltInParseablesHlsl::initialize(int /*version*/, EProfile /*profile*/, c ...@@ -592,9 +612,7 @@ void TBuiltInParseablesHlsl::initialize(int /*version*/, EProfile /*profile*/, c
{ "mul", "M", nullptr, "S,M", "FI,", EShLangAll }, { "mul", "M", nullptr, "S,M", "FI,", EShLangAll },
{ "mul", "V", nullptr, "V,S", "FI,", EShLangAll }, { "mul", "V", nullptr, "V,S", "FI,", EShLangAll },
{ "mul", "S", nullptr, "V,V", "FI,", EShLangAll }, { "mul", "S", nullptr, "V,V", "FI,", EShLangAll },
{ "mul", "#V", nullptr, "V,M", "FI,", EShLangAll },
{ "mul", "M", nullptr, "M,S", "FI,", EShLangAll }, { "mul", "M", nullptr, "M,S", "FI,", EShLangAll },
{ "mul", "V", nullptr, "M,#V", "FI,", EShLangAll },
// mat*mat form of mul is handled in createMatTimesMat() // mat*mat form of mul is handled in createMatTimesMat()
{ "noise", "S", "F", "V", "F", EShLangPS }, { "noise", "S", "F", "V", "F", EShLangPS },
{ "normalize", nullptr, nullptr, "V", "F", EShLangAll }, { "normalize", nullptr, nullptr, "V", "F", EShLangAll },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment