diff options
| -rw-r--r-- | source/slang/slang-stdlib.cpp | 21 | ||||
| -rw-r--r-- | tests/bugs/gh-103.slang | 19 | ||||
| -rw-r--r-- | tests/bugs/gh-103.slang.expected | 49 |
3 files changed, 89 insertions, 0 deletions
diff --git a/source/slang/slang-stdlib.cpp b/source/slang/slang-stdlib.cpp index 3450e72d7..d266c0560 100644 --- a/source/slang/slang-stdlib.cpp +++ b/source/slang/slang-stdlib.cpp @@ -1833,6 +1833,27 @@ namespace Slang sb << "__intrinsic_op(" << int(op.opCode) << ") matrix<" << resultType << ",N,M> operator" << op.opName << "(" << leftQual << "matrix<" << leftType << ",N,M> left, matrix<" << rightType << ",N,M> right);\n"; break; } + + // We are going to go ahead and explicitly define combined + // operations for the scalar-op-vector, etc. cases, rather + // than rely on promotion rules. + + // scalar-vector and scalar-matrix + if (!(op.flags & ASSIGNMENT)) + { + sb << "__generic<let N : int> "; + sb << "__intrinsic_op(" << int(op.opCode) << ") vector<" << resultType << ",N> operator" << op.opName << "(" << leftQual << leftType << " left, vector<" << rightType << ",N> right);\n"; + + sb << "__generic<let N : int, let M : int> "; + sb << "__intrinsic_op(" << int(op.opCode) << ") matrix<" << resultType << ",N,M> operator" << op.opName << "(" << leftQual << leftType << " left, matrix<" << rightType << ",N,M> right);\n"; + } + + // vector-scalar and matrix-scalar + sb << "__generic<let N : int> "; + sb << "__intrinsic_op(" << int(op.opCode) << ") vector<" << resultType << ",N> operator" << op.opName << "(" << leftQual << "vector<" << leftType << ",N> left, " << rightType << " right);\n"; + + sb << "__generic<let N : int, let M : int> "; + sb << "__intrinsic_op(" << int(op.opCode) << ") matrix<" << resultType << ",N,M> operator" << op.opName << "(" << leftQual << "matrix<" << leftType << ",N,M> left, " << rightType << " right);\n"; } } diff --git a/tests/bugs/gh-103.slang b/tests/bugs/gh-103.slang new file mode 100644 index 000000000..2b10c2b3f --- /dev/null +++ b/tests/bugs/gh-103.slang @@ -0,0 +1,19 @@ +//TEST:COMPARE_HLSL: -profile ps_4_0 -entry main + +// Ensure that matrix-times-scalar works + +float4x4 doIt(float4x4 a, float b) +{ + return a * b; +} + +cbuffer C +{ + float4x4 a; + float b; +}; + +float4 main() : SV_Target +{ + return doIt(a, b)[0]; +} diff --git a/tests/bugs/gh-103.slang.expected b/tests/bugs/gh-103.slang.expected new file mode 100644 index 000000000..acf3026d9 --- /dev/null +++ b/tests/bugs/gh-103.slang.expected @@ -0,0 +1,49 @@ +result code = 0 +standard error = { +} +standard output = { +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// Buffer Definitions: +// +// cbuffer C +// { +// +// float4x4 a; // Offset: 0 Size: 64 +// float b; // Offset: 64 Size: 4 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// C cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// no Input +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_Target 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_constantbuffer cb0[5], immediateIndexed +dcl_output o0.xyzw +mul o0.x, cb0[0].x, cb0[4].x +mul o0.y, cb0[1].x, cb0[4].x +mul o0.z, cb0[2].x, cb0[4].x +mul o0.w, cb0[3].x, cb0[4].x +ret +// Approximately 5 instruction slots used +} |
