From 2da28c50d9c3699692eccde4b86d0b8d2323e55c Mon Sep 17 00:00:00 2001 From: Jay Kwak <82421531+jkwak-work@users.noreply.github.com> Date: Fri, 19 Apr 2024 16:43:21 -0700 Subject: Support arithmetics on generic arguments (#3968) Resovles an issue #3935 Slang had to fold the generic arguments after specialization. --- tests/bugs/gh-3935.slang | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/bugs/gh-3935.slang (limited to 'tests') diff --git a/tests/bugs/gh-3935.slang b/tests/bugs/gh-3935.slang new file mode 100644 index 000000000..9c8e9f19c --- /dev/null +++ b/tests/bugs/gh-3935.slang @@ -0,0 +1,35 @@ +// Test if generic arguments using arithmetics are folded properly. + +//TEST:SIMPLE(filecheck=HLSL): -stage compute -entry computeMain -target hlsl + +RWStructuredBuffer outputBuffer; + +__generic +struct MyStruct +{ + int elems[ArraySize]; +}; + +__generic +MyStruct Reduce(MyStruct o) +{ + MyStruct result; + //HLSL:[[ReturnType:MyStruct_[0-9]*]] Reduce + //HLSL:[[ReturnType]] result + + result.elems[0] = o.elems[0]; + + // Error happened here as the return type differs + // from the type of "result". + return result; +} + +[numthreads(1, 1, 1)] +void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) +{ + MyStruct<4> a; + a.elems[0] = 2; + + let result = Reduce(a); + outputBuffer[0] = result.elems[0]; +} -- cgit v1.2.3