yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Jay KwakSupport arithmetics on generic arguments (#3968)2da28c50d

master
786 B35 linesraw
1// Test if generic arguments using arithmetics are folded properly.
2
3//TEST:SIMPLE(filecheck=HLSL): -stage compute -entry computeMain -target hlsl
4
5RWStructuredBuffer<float> outputBuffer;
6
7__generic<let ArraySize:int>
8struct MyStruct
9{
10  int elems[ArraySize];
11};
12
13__generic<let ArraySize:int>
14MyStruct<ArraySize / 2> Reduce(MyStruct<ArraySize> o)
15{
16  MyStruct<ArraySize / 2> result;
17  //HLSL:[[ReturnType:MyStruct_[0-9]*]] Reduce
18  //HLSL:[[ReturnType]] result
19
20  result.elems[0] = o.elems[0];
21
22  // Error happened here as the return type differs
23  // from the type of "result".
24  return result;
25}
26
27[numthreads(1, 1, 1)]
28void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
29{
30  MyStruct<4> a;
31  a.elems[0] = 2;
32
33  let result = Reduce(a);
34  outputBuffer[0] = result.elems[0];
35}