yum-mirror/slang

Making it easier to work with shaders

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

Julius IkkalaImplement throw & catch statements (#6916)57c3f9382

master
1017 B47 linesraw
1//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj
2//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk -shaderobj
3//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -cpu -shaderobj
4
5// CHECK: 5
6// CHECK-NEXT: 1
7// CHECK-NEXT: 0
8
9//TEST_INPUT:ubuffer(data=[0 0 0], stride=4):out,name=outputBuffer
10RWStructuredBuffer<int> outputBuffer;
11
12enum MyError
13{
14    Fail = 1
15};
16
17T func<T: __BuiltinFloatingPointType>(T val) throws MyError
18{
19    do
20    {
21        if (val >= T(3))
22            throw MyError.Fail;
23        return val * T(2);
24    }
25    catch(err: MyError)
26    {
27        // Just rethrow to test catching inside a generic as well.
28        throw err;
29    }
30}
31
32[numthreads(1, 1, 1)]
33void computeMain(int3 dispatchThreadID: SV_DispatchThreadID)
34{
35    int i = 0;
36    do
37    {
38        outputBuffer[i] = int(try func(2.5f));
39        i+=1;
40        outputBuffer[i] = int(try func(3.5f));
41        i+=1;
42    }
43    catch(err: MyError)
44    {
45        outputBuffer[i] = reinterpret<int>(err);
46    }
47}