yum-mirror/slang

Making it easier to work with shaders

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

jsmall-nvidiaExample for compiler crash with recursive function calling (#2196)34f8b5e72

master
820 B28 linesraw
1//DISABLE_TEST:SIMPLE: -target hlsl -entry computeMain -stage compute
2
3// This is a simplified version of the mul-crash.slang test, that shows the underlying issue is recursion.
4// This test crashes when enabled, with a stack overrun. The crash happens when lowering into IR.
5//
6// It appears recursion in GLSL/HLSL is not allowed (at least with earlier shader models), but the compiler 
7// shouldn't crash. Moreover the Slang language can support recursion today on non GPU targets.
8
9RWStructuredBuffer<int> outputBuffer;
10
11int doRecursive(int a)
12{
13    if (a > 0)
14    {
15        return doRecursive(a - 1) + 2;
16    }
17    return 10;
18}
19
20[numthreads(4, 1, 1)]
21void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
22{
23    uint tid = dispatchThreadID.x;
24
25    let val = doRecursive(tid);
26
27    outputBuffer[tid] = val;
28}