yum-mirror/slang

Making it easier to work with shaders

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

kaizhangNVLower the priority of looking up the rank of scope (#5065)3240799c0

master
1.4 KiB63 linesraw
1// https://github.com/shader-slang/slang/issues/4476
2
3//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-cuda -compute -shaderobj
4//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-cpu -compute -shaderobj
5//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-slang -compute -shaderobj
6//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-slang -compute -dx12 -shaderobj
7//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-vk -compute -shaderobj
8
9//TEST_INPUT:ubuffer(data=[0 0 0], stride=4):out,name=outputBuffer
10RWStructuredBuffer<uint> outputBuffer;
11
12
13uint getData()
14{
15    return 1u;
16}
17
18struct DataObtainer
19{
20    uint data;
21    uint getData()
22    {
23        return data;
24    }
25
26    uint getValue()
27    {
28        return getData(); // will call DataObtainer::getData()
29    }
30
31    uint getValue2()
32    {
33        return ::getData(); // will call global getData()
34    }
35}
36
37uint myFunc(uint a)
38{
39    return a + 1u;
40}
41
42__generic<T: __BuiltinIntegerType>
43uint myFunc(T a)
44{
45    uint b = __intCast<uint, T>(a);
46    return b + 2u;
47}
48
49
50[numthreads(1, 1, 1)]
51[shader("compute")]
52void computeMain(uint3 threadID: SV_DispatchThreadID)
53{
54    DataObtainer obtainer = {2u};
55    outputBuffer[0] = obtainer.getValue();
56    outputBuffer[1] = obtainer.getValue2();
57
58    uint a = 1u;
59    outputBuffer[2] = myFunc(a); // will call myFunc(uint) which more specialized
60    // BUF: 2
61    // BUF-NEXT: 1
62    // BUF-NEXT: 2
63}