From f881f52f6c34dbc2aa0a0701d6600467fae5a5ee Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Mon, 17 Jul 2017 09:26:53 -0700 Subject: Add explicit operator overloads for scalar/matrix cases Fixes #103 - Previously I was relying on scalar-to-vector promotion to pick the right type in these cases, but I hadn't implemented scalar-to-matrix promotion (I should...) - Rather than relying on promotion behavior, this change goes ahead and adds explicit overloads. I think this is probably a better decision in the long term, since one might want to support these cases for operators, while warning (or erroring) on the more general cases of implicit conversion. - This covers matrix/scalar, scalar/matrix, vector/scalar, and scalar/vector cases --- tests/bugs/gh-103.slang | 19 ++++++++++++++++ tests/bugs/gh-103.slang.expected | 49 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 tests/bugs/gh-103.slang create mode 100644 tests/bugs/gh-103.slang.expected (limited to 'tests/bugs') 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 +} -- cgit v1.2.3