From 174ccb8f1dce3cfcfeca31aa30a361c19bc677c9 Mon Sep 17 00:00:00 2001 From: LoopDawg Date: Sat, 20 May 2017 21:40:27 -0600 Subject: [PATCH] HLSL: Add imat, umat, and bmat constructors Fixes #894 --- SPIRV/GlslangToSpv.cpp | 27 + Test/baseResults/hlsl.constructimat.frag.out | 694 +++++++++++++++++++ Test/hlsl.constructimat.frag | 52 ++ glslang/Include/intermediate.h | 27 + glslang/MachineIndependent/Intermediate.cpp | 123 +++- glslang/MachineIndependent/intermOut.cpp | 27 + gtests/Hlsl.FromFile.cpp | 1 + hlsl/hlslParseHelper.cpp | 54 ++ 8 files changed, 987 insertions(+), 18 deletions(-) create mode 100644 Test/baseResults/hlsl.constructimat.frag.out create mode 100644 Test/hlsl.constructimat.frag diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index 3597c0a3f..f3b065309 100755 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -1528,6 +1528,33 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt case glslang::EOpConstructDMat4x2: case glslang::EOpConstructDMat4x3: case glslang::EOpConstructDMat4x4: + case glslang::EOpConstructIMat2x2: + case glslang::EOpConstructIMat2x3: + case glslang::EOpConstructIMat2x4: + case glslang::EOpConstructIMat3x2: + case glslang::EOpConstructIMat3x3: + case glslang::EOpConstructIMat3x4: + case glslang::EOpConstructIMat4x2: + case glslang::EOpConstructIMat4x3: + case glslang::EOpConstructIMat4x4: + case glslang::EOpConstructUMat2x2: + case glslang::EOpConstructUMat2x3: + case glslang::EOpConstructUMat2x4: + case glslang::EOpConstructUMat3x2: + case glslang::EOpConstructUMat3x3: + case glslang::EOpConstructUMat3x4: + case glslang::EOpConstructUMat4x2: + case glslang::EOpConstructUMat4x3: + case glslang::EOpConstructUMat4x4: + case glslang::EOpConstructBMat2x2: + case glslang::EOpConstructBMat2x3: + case glslang::EOpConstructBMat2x4: + case glslang::EOpConstructBMat3x2: + case glslang::EOpConstructBMat3x3: + case glslang::EOpConstructBMat3x4: + case glslang::EOpConstructBMat4x2: + case glslang::EOpConstructBMat4x3: + case glslang::EOpConstructBMat4x4: #ifdef AMD_EXTENSIONS case glslang::EOpConstructF16Mat2x2: case glslang::EOpConstructF16Mat2x3: diff --git a/Test/baseResults/hlsl.constructimat.frag.out b/Test/baseResults/hlsl.constructimat.frag.out new file mode 100644 index 000000000..adabb80c2 --- /dev/null +++ b/Test/baseResults/hlsl.constructimat.frag.out @@ -0,0 +1,694 @@ +hlsl.constructimat.frag +Shader version: 500 +gl_FragCoord origin is upper left +0:? Sequence +0:2 Function Definition: @main( ( temp int) +0:2 Function Parameters: +0:? Sequence +0:6 Sequence +0:6 move second child to first child ( temp 4X4 matrix of int) +0:6 'var443' ( temp 4X4 matrix of int) +0:6 Constant: +0:6 0 (const int) +0:6 1 (const int) +0:6 0 (const int) +0:6 0 (const int) +0:6 1 (const int) +0:6 1 (const int) +0:6 0 (const int) +0:6 0 (const int) +0:6 1 (const int) +0:6 0 (const int) +0:6 0 (const int) +0:6 0 (const int) +0:6 0 (const int) +0:6 0 (const int) +0:6 0 (const int) +0:6 0 (const int) +0:7 Sequence +0:7 move second child to first child ( temp 4X4 matrix of int) +0:7 'var444' ( temp 4X4 matrix of int) +0:? Constant: +0:? 0 (const int) +0:? 1 (const int) +0:? 0 (const int) +0:? 0 (const int) +0:? 1 (const int) +0:? 1 (const int) +0:? 0 (const int) +0:? 0 (const int) +0:? 1 (const int) +0:? 0 (const int) +0:? 0 (const int) +0:? 0 (const int) +0:? 0 (const int) +0:? 0 (const int) +0:? 0 (const int) +0:? 0 (const int) +0:11 Sequence +0:11 move second child to first child ( temp 4X2 matrix of int) +0:11 'var423' ( temp 4X2 matrix of int) +0:11 Constant: +0:11 0 (const int) +0:11 1 (const int) +0:11 1 (const int) +0:11 1 (const int) +0:11 1 (const int) +0:11 0 (const int) +0:11 0 (const int) +0:11 0 (const int) +0:12 Sequence +0:12 move second child to first child ( temp 4X2 matrix of int) +0:12 'var424' ( temp 4X2 matrix of int) +0:? Constant: +0:? 0 (const int) +0:? 1 (const int) +0:? 1 (const int) +0:? 1 (const int) +0:? 1 (const int) +0:? 0 (const int) +0:? 0 (const int) +0:? 0 (const int) +0:16 Sequence +0:16 move second child to first child ( temp 3X2 matrix of int) +0:16 'var323' ( temp 3X2 matrix of int) +0:16 Constant: +0:16 0 (const int) +0:16 1 (const int) +0:16 1 (const int) +0:16 1 (const int) +0:16 1 (const int) +0:16 0 (const int) +0:17 Sequence +0:17 move second child to first child ( temp 3X2 matrix of int) +0:17 'var234' ( temp 3X2 matrix of int) +0:? Constant: +0:? 0 (const int) +0:? 1 (const int) +0:? 1 (const int) +0:? 1 (const int) +0:? 1 (const int) +0:? 0 (const int) +0:22 Sequence +0:22 move second child to first child ( temp 4X4 matrix of uint) +0:22 'uvar443' ( temp 4X4 matrix of uint) +0:22 Constant: +0:22 0 (const uint) +0:22 1 (const uint) +0:22 0 (const uint) +0:22 0 (const uint) +0:22 1 (const uint) +0:22 1 (const uint) +0:22 0 (const uint) +0:22 0 (const uint) +0:22 1 (const uint) +0:22 0 (const uint) +0:22 0 (const uint) +0:22 0 (const uint) +0:22 0 (const uint) +0:22 0 (const uint) +0:22 0 (const uint) +0:22 0 (const uint) +0:23 Sequence +0:23 move second child to first child ( temp 4X4 matrix of uint) +0:23 'uvar444' ( temp 4X4 matrix of uint) +0:? Constant: +0:? 0 (const uint) +0:? 1 (const uint) +0:? 0 (const uint) +0:? 0 (const uint) +0:? 1 (const uint) +0:? 1 (const uint) +0:? 0 (const uint) +0:? 0 (const uint) +0:? 1 (const uint) +0:? 0 (const uint) +0:? 0 (const uint) +0:? 0 (const uint) +0:? 0 (const uint) +0:? 0 (const uint) +0:? 0 (const uint) +0:? 0 (const uint) +0:27 Sequence +0:27 move second child to first child ( temp 4X2 matrix of uint) +0:27 'uvar423' ( temp 4X2 matrix of uint) +0:27 Constant: +0:27 0 (const uint) +0:27 1 (const uint) +0:27 1 (const uint) +0:27 1 (const uint) +0:27 1 (const uint) +0:27 0 (const uint) +0:27 0 (const uint) +0:27 0 (const uint) +0:28 Sequence +0:28 move second child to first child ( temp 4X2 matrix of uint) +0:28 'uvar424' ( temp 4X2 matrix of uint) +0:? Constant: +0:? 0 (const uint) +0:? 1 (const uint) +0:? 1 (const uint) +0:? 1 (const uint) +0:? 1 (const uint) +0:? 0 (const uint) +0:? 0 (const uint) +0:? 0 (const uint) +0:32 Sequence +0:32 move second child to first child ( temp 3X2 matrix of uint) +0:32 'uvar323' ( temp 3X2 matrix of uint) +0:32 Constant: +0:32 0 (const uint) +0:32 1 (const uint) +0:32 1 (const uint) +0:32 1 (const uint) +0:32 1 (const uint) +0:32 0 (const uint) +0:33 Sequence +0:33 move second child to first child ( temp 3X2 matrix of uint) +0:33 'uvar234' ( temp 3X2 matrix of uint) +0:? Constant: +0:? 0 (const uint) +0:? 1 (const uint) +0:? 1 (const uint) +0:? 1 (const uint) +0:? 1 (const uint) +0:? 0 (const uint) +0:38 Sequence +0:38 move second child to first child ( temp 4X4 matrix of bool) +0:38 'bvar443' ( temp 4X4 matrix of bool) +0:38 Constant: +0:38 false (const bool) +0:38 true (const bool) +0:38 false (const bool) +0:38 false (const bool) +0:38 true (const bool) +0:38 true (const bool) +0:38 false (const bool) +0:38 false (const bool) +0:38 true (const bool) +0:38 false (const bool) +0:38 false (const bool) +0:38 false (const bool) +0:38 false (const bool) +0:38 false (const bool) +0:38 false (const bool) +0:38 false (const bool) +0:39 Sequence +0:39 move second child to first child ( temp 4X4 matrix of bool) +0:39 'bvar444' ( temp 4X4 matrix of bool) +0:? Constant: +0:? false (const bool) +0:? true (const bool) +0:? false (const bool) +0:? false (const bool) +0:? true (const bool) +0:? true (const bool) +0:? false (const bool) +0:? false (const bool) +0:? true (const bool) +0:? false (const bool) +0:? false (const bool) +0:? false (const bool) +0:? false (const bool) +0:? false (const bool) +0:? false (const bool) +0:? false (const bool) +0:43 Sequence +0:43 move second child to first child ( temp 4X2 matrix of bool) +0:43 'bvar423' ( temp 4X2 matrix of bool) +0:43 Constant: +0:43 false (const bool) +0:43 true (const bool) +0:43 true (const bool) +0:43 true (const bool) +0:43 true (const bool) +0:43 false (const bool) +0:43 false (const bool) +0:43 false (const bool) +0:44 Sequence +0:44 move second child to first child ( temp 4X2 matrix of bool) +0:44 'bvar424' ( temp 4X2 matrix of bool) +0:? Constant: +0:? false (const bool) +0:? true (const bool) +0:? true (const bool) +0:? true (const bool) +0:? true (const bool) +0:? false (const bool) +0:? false (const bool) +0:? false (const bool) +0:48 Sequence +0:48 move second child to first child ( temp 3X2 matrix of bool) +0:48 'bvar323' ( temp 3X2 matrix of bool) +0:48 Constant: +0:48 false (const bool) +0:48 true (const bool) +0:48 true (const bool) +0:48 true (const bool) +0:48 true (const bool) +0:48 false (const bool) +0:49 Sequence +0:49 move second child to first child ( temp 3X2 matrix of bool) +0:49 'bvar234' ( temp 3X2 matrix of bool) +0:? Constant: +0:? false (const bool) +0:? true (const bool) +0:? true (const bool) +0:? true (const bool) +0:? true (const bool) +0:? false (const bool) +0:51 Branch: Return with expression +0:51 Constant: +0:51 0 (const int) +0:2 Function Definition: main( ( temp void) +0:2 Function Parameters: +0:? Sequence +0:2 move second child to first child ( temp int) +0:? '@entryPointOutput' (layout( location=0) out int) +0:2 Function Call: @main( ( temp int) +0:? Linker Objects +0:? '@entryPointOutput' (layout( location=0) out int) + + +Linked fragment stage: + + +Shader version: 500 +gl_FragCoord origin is upper left +0:? Sequence +0:2 Function Definition: @main( ( temp int) +0:2 Function Parameters: +0:? Sequence +0:6 Sequence +0:6 move second child to first child ( temp 4X4 matrix of int) +0:6 'var443' ( temp 4X4 matrix of int) +0:6 Constant: +0:6 0 (const int) +0:6 1 (const int) +0:6 0 (const int) +0:6 0 (const int) +0:6 1 (const int) +0:6 1 (const int) +0:6 0 (const int) +0:6 0 (const int) +0:6 1 (const int) +0:6 0 (const int) +0:6 0 (const int) +0:6 0 (const int) +0:6 0 (const int) +0:6 0 (const int) +0:6 0 (const int) +0:6 0 (const int) +0:7 Sequence +0:7 move second child to first child ( temp 4X4 matrix of int) +0:7 'var444' ( temp 4X4 matrix of int) +0:? Constant: +0:? 0 (const int) +0:? 1 (const int) +0:? 0 (const int) +0:? 0 (const int) +0:? 1 (const int) +0:? 1 (const int) +0:? 0 (const int) +0:? 0 (const int) +0:? 1 (const int) +0:? 0 (const int) +0:? 0 (const int) +0:? 0 (const int) +0:? 0 (const int) +0:? 0 (const int) +0:? 0 (const int) +0:? 0 (const int) +0:11 Sequence +0:11 move second child to first child ( temp 4X2 matrix of int) +0:11 'var423' ( temp 4X2 matrix of int) +0:11 Constant: +0:11 0 (const int) +0:11 1 (const int) +0:11 1 (const int) +0:11 1 (const int) +0:11 1 (const int) +0:11 0 (const int) +0:11 0 (const int) +0:11 0 (const int) +0:12 Sequence +0:12 move second child to first child ( temp 4X2 matrix of int) +0:12 'var424' ( temp 4X2 matrix of int) +0:? Constant: +0:? 0 (const int) +0:? 1 (const int) +0:? 1 (const int) +0:? 1 (const int) +0:? 1 (const int) +0:? 0 (const int) +0:? 0 (const int) +0:? 0 (const int) +0:16 Sequence +0:16 move second child to first child ( temp 3X2 matrix of int) +0:16 'var323' ( temp 3X2 matrix of int) +0:16 Constant: +0:16 0 (const int) +0:16 1 (const int) +0:16 1 (const int) +0:16 1 (const int) +0:16 1 (const int) +0:16 0 (const int) +0:17 Sequence +0:17 move second child to first child ( temp 3X2 matrix of int) +0:17 'var234' ( temp 3X2 matrix of int) +0:? Constant: +0:? 0 (const int) +0:? 1 (const int) +0:? 1 (const int) +0:? 1 (const int) +0:? 1 (const int) +0:? 0 (const int) +0:22 Sequence +0:22 move second child to first child ( temp 4X4 matrix of uint) +0:22 'uvar443' ( temp 4X4 matrix of uint) +0:22 Constant: +0:22 0 (const uint) +0:22 1 (const uint) +0:22 0 (const uint) +0:22 0 (const uint) +0:22 1 (const uint) +0:22 1 (const uint) +0:22 0 (const uint) +0:22 0 (const uint) +0:22 1 (const uint) +0:22 0 (const uint) +0:22 0 (const uint) +0:22 0 (const uint) +0:22 0 (const uint) +0:22 0 (const uint) +0:22 0 (const uint) +0:22 0 (const uint) +0:23 Sequence +0:23 move second child to first child ( temp 4X4 matrix of uint) +0:23 'uvar444' ( temp 4X4 matrix of uint) +0:? Constant: +0:? 0 (const uint) +0:? 1 (const uint) +0:? 0 (const uint) +0:? 0 (const uint) +0:? 1 (const uint) +0:? 1 (const uint) +0:? 0 (const uint) +0:? 0 (const uint) +0:? 1 (const uint) +0:? 0 (const uint) +0:? 0 (const uint) +0:? 0 (const uint) +0:? 0 (const uint) +0:? 0 (const uint) +0:? 0 (const uint) +0:? 0 (const uint) +0:27 Sequence +0:27 move second child to first child ( temp 4X2 matrix of uint) +0:27 'uvar423' ( temp 4X2 matrix of uint) +0:27 Constant: +0:27 0 (const uint) +0:27 1 (const uint) +0:27 1 (const uint) +0:27 1 (const uint) +0:27 1 (const uint) +0:27 0 (const uint) +0:27 0 (const uint) +0:27 0 (const uint) +0:28 Sequence +0:28 move second child to first child ( temp 4X2 matrix of uint) +0:28 'uvar424' ( temp 4X2 matrix of uint) +0:? Constant: +0:? 0 (const uint) +0:? 1 (const uint) +0:? 1 (const uint) +0:? 1 (const uint) +0:? 1 (const uint) +0:? 0 (const uint) +0:? 0 (const uint) +0:? 0 (const uint) +0:32 Sequence +0:32 move second child to first child ( temp 3X2 matrix of uint) +0:32 'uvar323' ( temp 3X2 matrix of uint) +0:32 Constant: +0:32 0 (const uint) +0:32 1 (const uint) +0:32 1 (const uint) +0:32 1 (const uint) +0:32 1 (const uint) +0:32 0 (const uint) +0:33 Sequence +0:33 move second child to first child ( temp 3X2 matrix of uint) +0:33 'uvar234' ( temp 3X2 matrix of uint) +0:? Constant: +0:? 0 (const uint) +0:? 1 (const uint) +0:? 1 (const uint) +0:? 1 (const uint) +0:? 1 (const uint) +0:? 0 (const uint) +0:38 Sequence +0:38 move second child to first child ( temp 4X4 matrix of bool) +0:38 'bvar443' ( temp 4X4 matrix of bool) +0:38 Constant: +0:38 false (const bool) +0:38 true (const bool) +0:38 false (const bool) +0:38 false (const bool) +0:38 true (const bool) +0:38 true (const bool) +0:38 false (const bool) +0:38 false (const bool) +0:38 true (const bool) +0:38 false (const bool) +0:38 false (const bool) +0:38 false (const bool) +0:38 false (const bool) +0:38 false (const bool) +0:38 false (const bool) +0:38 false (const bool) +0:39 Sequence +0:39 move second child to first child ( temp 4X4 matrix of bool) +0:39 'bvar444' ( temp 4X4 matrix of bool) +0:? Constant: +0:? false (const bool) +0:? true (const bool) +0:? false (const bool) +0:? false (const bool) +0:? true (const bool) +0:? true (const bool) +0:? false (const bool) +0:? false (const bool) +0:? true (const bool) +0:? false (const bool) +0:? false (const bool) +0:? false (const bool) +0:? false (const bool) +0:? false (const bool) +0:? false (const bool) +0:? false (const bool) +0:43 Sequence +0:43 move second child to first child ( temp 4X2 matrix of bool) +0:43 'bvar423' ( temp 4X2 matrix of bool) +0:43 Constant: +0:43 false (const bool) +0:43 true (const bool) +0:43 true (const bool) +0:43 true (const bool) +0:43 true (const bool) +0:43 false (const bool) +0:43 false (const bool) +0:43 false (const bool) +0:44 Sequence +0:44 move second child to first child ( temp 4X2 matrix of bool) +0:44 'bvar424' ( temp 4X2 matrix of bool) +0:? Constant: +0:? false (const bool) +0:? true (const bool) +0:? true (const bool) +0:? true (const bool) +0:? true (const bool) +0:? false (const bool) +0:? false (const bool) +0:? false (const bool) +0:48 Sequence +0:48 move second child to first child ( temp 3X2 matrix of bool) +0:48 'bvar323' ( temp 3X2 matrix of bool) +0:48 Constant: +0:48 false (const bool) +0:48 true (const bool) +0:48 true (const bool) +0:48 true (const bool) +0:48 true (const bool) +0:48 false (const bool) +0:49 Sequence +0:49 move second child to first child ( temp 3X2 matrix of bool) +0:49 'bvar234' ( temp 3X2 matrix of bool) +0:? Constant: +0:? false (const bool) +0:? true (const bool) +0:? true (const bool) +0:? true (const bool) +0:? true (const bool) +0:? false (const bool) +0:51 Branch: Return with expression +0:51 Constant: +0:51 0 (const int) +0:2 Function Definition: main( ( temp void) +0:2 Function Parameters: +0:? Sequence +0:2 move second child to first child ( temp int) +0:? '@entryPointOutput' (layout( location=0) out int) +0:2 Function Call: @main( ( temp int) +0:? Linker Objects +0:? '@entryPointOutput' (layout( location=0) out int) + +// Module Version 10000 +// Generated by (magic number): 80001 +// Id's are bound by 98 + + Capability Shader + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint Fragment 4 "main" 96 + ExecutionMode 4 OriginUpperLeft + Source HLSL 500 + Name 4 "main" + Name 8 "@main(" + Name 13 "var443" + Name 21 "var444" + Name 25 "var423" + Name 31 "var424" + Name 34 "var323" + Name 36 "var234" + Name 41 "uvar443" + Name 49 "uvar444" + Name 53 "uvar423" + Name 59 "uvar424" + Name 62 "uvar323" + Name 64 "uvar234" + Name 69 "bvar443" + Name 77 "bvar444" + Name 81 "bvar423" + Name 87 "bvar424" + Name 90 "bvar323" + Name 92 "bvar234" + Name 96 "@entryPointOutput" + Decorate 96(@entryPointOutput) Location 0 + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeInt 32 1 + 7: TypeFunction 6(int) + 10: TypeVector 6(int) 4 + 11: TypeMatrix 10(ivec4) 4 + 12: TypePointer Function 11 + 14: 6(int) Constant 0 + 15: 6(int) Constant 1 + 16: 10(ivec4) ConstantComposite 14 15 14 14 + 17: 10(ivec4) ConstantComposite 15 15 14 14 + 18: 10(ivec4) ConstantComposite 15 14 14 14 + 19: 10(ivec4) ConstantComposite 14 14 14 14 + 20: 11 ConstantComposite 16 17 18 19 + 22: TypeVector 6(int) 2 + 23: TypeMatrix 22(ivec2) 4 + 24: TypePointer Function 23 + 26: 22(ivec2) ConstantComposite 14 15 + 27: 22(ivec2) ConstantComposite 15 15 + 28: 22(ivec2) ConstantComposite 15 14 + 29: 22(ivec2) ConstantComposite 14 14 + 30: 23 ConstantComposite 26 27 28 29 + 32: TypeMatrix 22(ivec2) 3 + 33: TypePointer Function 32 + 35: 32 ConstantComposite 26 27 28 + 37: TypeInt 32 0 + 38: TypeVector 37(int) 4 + 39: TypeMatrix 38(ivec4) 4 + 40: TypePointer Function 39 + 42: 37(int) Constant 0 + 43: 37(int) Constant 1 + 44: 38(ivec4) ConstantComposite 42 43 42 42 + 45: 38(ivec4) ConstantComposite 43 43 42 42 + 46: 38(ivec4) ConstantComposite 43 42 42 42 + 47: 38(ivec4) ConstantComposite 42 42 42 42 + 48: 39 ConstantComposite 44 45 46 47 + 50: TypeVector 37(int) 2 + 51: TypeMatrix 50(ivec2) 4 + 52: TypePointer Function 51 + 54: 50(ivec2) ConstantComposite 42 43 + 55: 50(ivec2) ConstantComposite 43 43 + 56: 50(ivec2) ConstantComposite 43 42 + 57: 50(ivec2) ConstantComposite 42 42 + 58: 51 ConstantComposite 54 55 56 57 + 60: TypeMatrix 50(ivec2) 3 + 61: TypePointer Function 60 + 63: 60 ConstantComposite 54 55 56 + 65: TypeBool + 66: TypeVector 65(bool) 4 + 67: TypeMatrix 66(bvec4) 4 + 68: TypePointer Function 67 + 70: 65(bool) ConstantFalse + 71: 65(bool) ConstantTrue + 72: 66(bvec4) ConstantComposite 70 71 70 70 + 73: 66(bvec4) ConstantComposite 71 71 70 70 + 74: 66(bvec4) ConstantComposite 71 70 70 70 + 75: 66(bvec4) ConstantComposite 70 70 70 70 + 76: 67 ConstantComposite 72 73 74 75 + 78: TypeVector 65(bool) 2 + 79: TypeMatrix 78(bvec2) 4 + 80: TypePointer Function 79 + 82: 78(bvec2) ConstantComposite 70 71 + 83: 78(bvec2) ConstantComposite 71 71 + 84: 78(bvec2) ConstantComposite 71 70 + 85: 78(bvec2) ConstantComposite 70 70 + 86: 79 ConstantComposite 82 83 84 85 + 88: TypeMatrix 78(bvec2) 3 + 89: TypePointer Function 88 + 91: 88 ConstantComposite 82 83 84 + 95: TypePointer Output 6(int) +96(@entryPointOutput): 95(ptr) Variable Output + 4(main): 2 Function None 3 + 5: Label + 97: 6(int) FunctionCall 8(@main() + Store 96(@entryPointOutput) 97 + Return + FunctionEnd + 8(@main(): 6(int) Function None 7 + 9: Label + 13(var443): 12(ptr) Variable Function + 21(var444): 12(ptr) Variable Function + 25(var423): 24(ptr) Variable Function + 31(var424): 24(ptr) Variable Function + 34(var323): 33(ptr) Variable Function + 36(var234): 33(ptr) Variable Function + 41(uvar443): 40(ptr) Variable Function + 49(uvar444): 40(ptr) Variable Function + 53(uvar423): 52(ptr) Variable Function + 59(uvar424): 52(ptr) Variable Function + 62(uvar323): 61(ptr) Variable Function + 64(uvar234): 61(ptr) Variable Function + 69(bvar443): 68(ptr) Variable Function + 77(bvar444): 68(ptr) Variable Function + 81(bvar423): 80(ptr) Variable Function + 87(bvar424): 80(ptr) Variable Function + 90(bvar323): 89(ptr) Variable Function + 92(bvar234): 89(ptr) Variable Function + Store 13(var443) 20 + Store 21(var444) 20 + Store 25(var423) 30 + Store 31(var424) 30 + Store 34(var323) 35 + Store 36(var234) 35 + Store 41(uvar443) 48 + Store 49(uvar444) 48 + Store 53(uvar423) 58 + Store 59(uvar424) 58 + Store 62(uvar323) 63 + Store 64(uvar234) 63 + Store 69(bvar443) 76 + Store 77(bvar444) 76 + Store 81(bvar423) 86 + Store 87(bvar424) 86 + Store 90(bvar323) 91 + Store 92(bvar234) 91 + ReturnValue 14 + FunctionEnd diff --git a/Test/hlsl.constructimat.frag b/Test/hlsl.constructimat.frag new file mode 100644 index 000000000..f320ba152 --- /dev/null +++ b/Test/hlsl.constructimat.frag @@ -0,0 +1,52 @@ +int main() : SV_TARGET +{ + // integer mat constructors + const int4x4 var441 = { 0,1,0,0, 1,1,0,0, 1,0,0,0, 0,0,0,0 }; + const int4x4 var442 = int4x4( 0,1,0,0, 1,1,0,0, 1,0,0,0, 0,0,0,0 ); + int4x4 var443 = { 0,1,0,0, 1,1,0,0, 1,0,0,0, 0,0,0,0 }; + int4x4 var444 = int4x4( 0,1,0,0, 1,1,0,0, 1,0,0,0, 0,0,0,0 ); + + const int4x2 var421 = { 0,1, 1,1, 1,0, 0,0 }; + const int4x2 var422 = int4x2( 0,1, 1,1, 1,0, 0,0 ); + int4x2 var423 = { 0,1, 1,1, 1,0, 0,0 }; + int4x2 var424 = int4x2( 0,1, 1,1, 1,0, 0,0 ); + + const int3x2 var321 = { 0,1, 1,1, 1,0 }; + const int3x2 var322 = int3x2( 0,1, 1,1, 1,0 ); + int3x2 var323 = { 0,1, 1,1, 1,0 }; + int3x2 var234 = int3x2( 0,1, 1,1, 1,0); + + // unsigned integer mat constructors + const uint4x4 uvar441 = { 0,1,0,0, 1,1,0,0, 1,0,0,0, 0,0,0,0 }; + const uint4x4 uvar442 = uint4x4( 0,1,0,0, 1,1,0,0, 1,0,0,0, 0,0,0,0 ); + uint4x4 uvar443 = { 0,1,0,0, 1,1,0,0, 1,0,0,0, 0,0,0,0 }; + uint4x4 uvar444 = uint4x4( 0,1,0,0, 1,1,0,0, 1,0,0,0, 0,0,0,0 ); + + const uint4x2 uvar421 = { 0,1, 1,1, 1,0, 0,0 }; + const uint4x2 uvar422 = uint4x2( 0,1, 1,1, 1,0, 0,0 ); + uint4x2 uvar423 = { 0,1, 1,1, 1,0, 0,0 }; + uint4x2 uvar424 = uint4x2( 0,1, 1,1, 1,0, 0,0 ); + + const uint3x2 uvar321 = { 0,1, 1,1, 1,0 }; + const uint3x2 uvar322 = uint3x2( 0,1, 1,1, 1,0 ); + uint3x2 uvar323 = { 0,1, 1,1, 1,0 }; + uint3x2 uvar234 = uint3x2( 0,1, 1,1, 1,0); + + // boolean mat constructors + const bool4x4 bvar441 = { 0,1,0,0, 1,1,0,0, 1,0,0,0, 0,0,0,0 }; + const bool4x4 bvar442 = bool4x4( 0,1,0,0, 1,1,0,0, 1,0,0,0, 0,0,0,0 ); + bool4x4 bvar443 = { 0,1,0,0, 1,1,0,0, 1,0,0,0, 0,0,0,0 }; + bool4x4 bvar444 = bool4x4( 0,1,0,0, 1,1,0,0, 1,0,0,0, 0,0,0,0 ); + + const bool4x2 bvar421 = { 0,1, 1,1, 1,0, 0,0 }; + const bool4x2 bvar422 = bool4x2( 0,1, 1,1, 1,0, 0,0 ); + bool4x2 bvar423 = { 0,1, 1,1, 1,0, 0,0 }; + bool4x2 bvar424 = bool4x2( 0,1, 1,1, 1,0, 0,0 ); + + const bool3x2 bvar321 = { 0,1, 1,1, 1,0 }; + const bool3x2 bvar322 = bool3x2( 0,1, 1,1, 1,0 ); + bool3x2 bvar323 = { 0,1, 1,1, 1,0 }; + bool3x2 bvar234 = bool3x2( 0,1, 1,1, 1,0); + + return 0; +} diff --git a/glslang/Include/intermediate.h b/glslang/Include/intermediate.h index d9b6d05a4..5115db9d5 100644 --- a/glslang/Include/intermediate.h +++ b/glslang/Include/intermediate.h @@ -436,6 +436,33 @@ enum TOperator { EOpConstructDMat4x2, EOpConstructDMat4x3, EOpConstructDMat4x4, + EOpConstructIMat2x2, + EOpConstructIMat2x3, + EOpConstructIMat2x4, + EOpConstructIMat3x2, + EOpConstructIMat3x3, + EOpConstructIMat3x4, + EOpConstructIMat4x2, + EOpConstructIMat4x3, + EOpConstructIMat4x4, + EOpConstructUMat2x2, + EOpConstructUMat2x3, + EOpConstructUMat2x4, + EOpConstructUMat3x2, + EOpConstructUMat3x3, + EOpConstructUMat3x4, + EOpConstructUMat4x2, + EOpConstructUMat4x3, + EOpConstructUMat4x4, + EOpConstructBMat2x2, + EOpConstructBMat2x3, + EOpConstructBMat2x4, + EOpConstructBMat3x2, + EOpConstructBMat3x3, + EOpConstructBMat3x4, + EOpConstructBMat4x2, + EOpConstructBMat4x3, + EOpConstructBMat4x4, #ifdef AMD_EXTENSIONS EOpConstructFloat16, EOpConstructF16Vec2, diff --git a/glslang/MachineIndependent/Intermediate.cpp b/glslang/MachineIndependent/Intermediate.cpp index 0251de895..663e30c66 100644 --- a/glslang/MachineIndependent/Intermediate.cpp +++ b/glslang/MachineIndependent/Intermediate.cpp @@ -1220,21 +1220,79 @@ TOperator TIntermediate::mapTypeToConstructorOp(const TType& type) const break; #endif case EbtInt: - switch(type.getVectorSize()) { - case 1: op = EOpConstructInt; break; - case 2: op = EOpConstructIVec2; break; - case 3: op = EOpConstructIVec3; break; - case 4: op = EOpConstructIVec4; break; - default: break; // some compilers want this + if (type.getMatrixCols()) { + switch (type.getMatrixCols()) { + case 2: + switch (type.getMatrixRows()) { + case 2: op = EOpConstructIMat2x2; break; + case 3: op = EOpConstructIMat2x3; break; + case 4: op = EOpConstructIMat2x4; break; + default: break; // some compilers want this + } + break; + case 3: + switch (type.getMatrixRows()) { + case 2: op = EOpConstructIMat3x2; break; + case 3: op = EOpConstructIMat3x3; break; + case 4: op = EOpConstructIMat3x4; break; + default: break; // some compilers want this + } + break; + case 4: + switch (type.getMatrixRows()) { + case 2: op = EOpConstructIMat4x2; break; + case 3: op = EOpConstructIMat4x3; break; + case 4: op = EOpConstructIMat4x4; break; + default: break; // some compilers want this + } + break; + } + } else { + switch(type.getVectorSize()) { + case 1: op = EOpConstructInt; break; + case 2: op = EOpConstructIVec2; break; + case 3: op = EOpConstructIVec3; break; + case 4: op = EOpConstructIVec4; break; + default: break; // some compilers want this + } } break; case EbtUint: - switch(type.getVectorSize()) { - case 1: op = EOpConstructUint; break; - case 2: op = EOpConstructUVec2; break; - case 3: op = EOpConstructUVec3; break; - case 4: op = EOpConstructUVec4; break; - default: break; // some compilers want this + if (type.getMatrixCols()) { + switch (type.getMatrixCols()) { + case 2: + switch (type.getMatrixRows()) { + case 2: op = EOpConstructUMat2x2; break; + case 3: op = EOpConstructUMat2x3; break; + case 4: op = EOpConstructUMat2x4; break; + default: break; // some compilers want this + } + break; + case 3: + switch (type.getMatrixRows()) { + case 2: op = EOpConstructUMat3x2; break; + case 3: op = EOpConstructUMat3x3; break; + case 4: op = EOpConstructUMat3x4; break; + default: break; // some compilers want this + } + break; + case 4: + switch (type.getMatrixRows()) { + case 2: op = EOpConstructUMat4x2; break; + case 3: op = EOpConstructUMat4x3; break; + case 4: op = EOpConstructUMat4x4; break; + default: break; // some compilers want this + } + break; + } + } else { + switch(type.getVectorSize()) { + case 1: op = EOpConstructUint; break; + case 2: op = EOpConstructUVec2; break; + case 3: op = EOpConstructUVec3; break; + case 4: op = EOpConstructUVec4; break; + default: break; // some compilers want this + } } break; case EbtInt64: @@ -1256,12 +1314,41 @@ TOperator TIntermediate::mapTypeToConstructorOp(const TType& type) const } break; case EbtBool: - switch(type.getVectorSize()) { - case 1: op = EOpConstructBool; break; - case 2: op = EOpConstructBVec2; break; - case 3: op = EOpConstructBVec3; break; - case 4: op = EOpConstructBVec4; break; - default: break; // some compilers want this + if (type.getMatrixCols()) { + switch (type.getMatrixCols()) { + case 2: + switch (type.getMatrixRows()) { + case 2: op = EOpConstructBMat2x2; break; + case 3: op = EOpConstructBMat2x3; break; + case 4: op = EOpConstructBMat2x4; break; + default: break; // some compilers want this + } + break; + case 3: + switch (type.getMatrixRows()) { + case 2: op = EOpConstructBMat3x2; break; + case 3: op = EOpConstructBMat3x3; break; + case 4: op = EOpConstructBMat3x4; break; + default: break; // some compilers want this + } + break; + case 4: + switch (type.getMatrixRows()) { + case 2: op = EOpConstructBMat4x2; break; + case 3: op = EOpConstructBMat4x3; break; + case 4: op = EOpConstructBMat4x4; break; + default: break; // some compilers want this + } + break; + } + } else { + switch(type.getVectorSize()) { + case 1: op = EOpConstructBool; break; + case 2: op = EOpConstructBVec2; break; + case 3: op = EOpConstructBVec3; break; + case 4: op = EOpConstructBVec4; break; + default: break; // some compilers want this + } } break; default: diff --git a/glslang/MachineIndependent/intermOut.cpp b/glslang/MachineIndependent/intermOut.cpp index e5b555bb0..31f599c47 100644 --- a/glslang/MachineIndependent/intermOut.cpp +++ b/glslang/MachineIndependent/intermOut.cpp @@ -505,6 +505,33 @@ bool TOutputTraverser::visitAggregate(TVisit /* visit */, TIntermAggregate* node case EOpConstructDMat4x2: out.debug << "Construct dmat4x2"; break; case EOpConstructDMat4x3: out.debug << "Construct dmat4x3"; break; case EOpConstructDMat4x4: out.debug << "Construct dmat4"; break; + case EOpConstructIMat2x2: out.debug << "Construct imat2"; break; + case EOpConstructIMat2x3: out.debug << "Construct imat2x3"; break; + case EOpConstructIMat2x4: out.debug << "Construct imat2x4"; break; + case EOpConstructIMat3x2: out.debug << "Construct imat3x2"; break; + case EOpConstructIMat3x3: out.debug << "Construct imat3"; break; + case EOpConstructIMat3x4: out.debug << "Construct imat3x4"; break; + case EOpConstructIMat4x2: out.debug << "Construct imat4x2"; break; + case EOpConstructIMat4x3: out.debug << "Construct imat4x3"; break; + case EOpConstructIMat4x4: out.debug << "Construct imat4"; break; + case EOpConstructUMat2x2: out.debug << "Construct umat2"; break; + case EOpConstructUMat2x3: out.debug << "Construct umat2x3"; break; + case EOpConstructUMat2x4: out.debug << "Construct umat2x4"; break; + case EOpConstructUMat3x2: out.debug << "Construct umat3x2"; break; + case EOpConstructUMat3x3: out.debug << "Construct umat3"; break; + case EOpConstructUMat3x4: out.debug << "Construct umat3x4"; break; + case EOpConstructUMat4x2: out.debug << "Construct umat4x2"; break; + case EOpConstructUMat4x3: out.debug << "Construct umat4x3"; break; + case EOpConstructUMat4x4: out.debug << "Construct umat4"; break; + case EOpConstructBMat2x2: out.debug << "Construct bmat2"; break; + case EOpConstructBMat2x3: out.debug << "Construct bmat2x3"; break; + case EOpConstructBMat2x4: out.debug << "Construct bmat2x4"; break; + case EOpConstructBMat3x2: out.debug << "Construct bmat3x2"; break; + case EOpConstructBMat3x3: out.debug << "Construct bmat3"; break; + case EOpConstructBMat3x4: out.debug << "Construct bmat3x4"; break; + case EOpConstructBMat4x2: out.debug << "Construct bmat4x2"; break; + case EOpConstructBMat4x3: out.debug << "Construct bmat4x3"; break; + case EOpConstructBMat4x4: out.debug << "Construct bmat4"; break; #ifdef AMD_EXTENSIONS case EOpConstructFloat16: out.debug << "Construct float16_t"; break; case EOpConstructF16Vec2: out.debug << "Construct f16vec2"; break; diff --git a/gtests/Hlsl.FromFile.cpp b/gtests/Hlsl.FromFile.cpp index 8f12c5549..f5c0add30 100644 --- a/gtests/Hlsl.FromFile.cpp +++ b/gtests/Hlsl.FromFile.cpp @@ -100,6 +100,7 @@ INSTANTIATE_TEST_CASE_P( {"hlsl.conditional.frag", "PixelShaderFunction"}, {"hlsl.constantbuffer.frag", "main"}, {"hlsl.constructexpr.frag", "main"}, + {"hlsl.constructimat.frag", "main"}, {"hlsl.depthGreater.frag", "PixelShaderFunction"}, {"hlsl.depthLess.frag", "PixelShaderFunction"}, {"hlsl.discard.frag", "PixelShaderFunction"}, diff --git a/hlsl/hlslParseHelper.cpp b/hlsl/hlslParseHelper.cpp index e875cb7b4..fe4dffbbc 100755 --- a/hlsl/hlslParseHelper.cpp +++ b/hlsl/hlslParseHelper.cpp @@ -5150,6 +5150,33 @@ bool HlslParseContext::constructorError(const TSourceLoc& loc, TIntermNode* node case EOpConstructDMat4x2: case EOpConstructDMat4x3: case EOpConstructDMat4x4: + case EOpConstructIMat2x2: + case EOpConstructIMat2x3: + case EOpConstructIMat2x4: + case EOpConstructIMat3x2: + case EOpConstructIMat3x3: + case EOpConstructIMat3x4: + case EOpConstructIMat4x2: + case EOpConstructIMat4x3: + case EOpConstructIMat4x4: + case EOpConstructUMat2x2: + case EOpConstructUMat2x3: + case EOpConstructUMat2x4: + case EOpConstructUMat3x2: + case EOpConstructUMat3x3: + case EOpConstructUMat3x4: + case EOpConstructUMat4x2: + case EOpConstructUMat4x3: + case EOpConstructUMat4x4: + case EOpConstructBMat2x2: + case EOpConstructBMat2x3: + case EOpConstructBMat2x4: + case EOpConstructBMat3x2: + case EOpConstructBMat3x3: + case EOpConstructBMat3x4: + case EOpConstructBMat4x2: + case EOpConstructBMat4x3: + case EOpConstructBMat4x4: constructingMatrix = true; break; default: @@ -7274,6 +7301,15 @@ TIntermTyped* HlslParseContext::constructBuiltIn(const TType& type, TOperator op case EOpConstructIVec2: case EOpConstructIVec3: case EOpConstructIVec4: + case EOpConstructIMat2x2: + case EOpConstructIMat2x3: + case EOpConstructIMat2x4: + case EOpConstructIMat3x2: + case EOpConstructIMat3x3: + case EOpConstructIMat3x4: + case EOpConstructIMat4x2: + case EOpConstructIMat4x3: + case EOpConstructIMat4x4: case EOpConstructInt: basicOp = EOpConstructInt; break; @@ -7281,6 +7317,15 @@ TIntermTyped* HlslParseContext::constructBuiltIn(const TType& type, TOperator op case EOpConstructUVec2: case EOpConstructUVec3: case EOpConstructUVec4: + case EOpConstructUMat2x2: + case EOpConstructUMat2x3: + case EOpConstructUMat2x4: + case EOpConstructUMat3x2: + case EOpConstructUMat3x3: + case EOpConstructUMat3x4: + case EOpConstructUMat4x2: + case EOpConstructUMat4x3: + case EOpConstructUMat4x4: case EOpConstructUint: basicOp = EOpConstructUint; break; @@ -7288,6 +7333,15 @@ TIntermTyped* HlslParseContext::constructBuiltIn(const TType& type, TOperator op case EOpConstructBVec2: case EOpConstructBVec3: case EOpConstructBVec4: + case EOpConstructBMat2x2: + case EOpConstructBMat2x3: + case EOpConstructBMat2x4: + case EOpConstructBMat3x2: + case EOpConstructBMat3x3: + case EOpConstructBMat3x4: + case EOpConstructBMat4x2: + case EOpConstructBMat4x3: + case EOpConstructBMat4x4: case EOpConstructBool: basicOp = EOpConstructBool; break;