yum-mirror/slang

Making it easier to work with shaders

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

James Helferty (NVIDIA)render-test: Change D3D12 default to sm_6_5 (#8320)f02b08490

master
2.5 KiB107 linesraw
1//TEST():SIMPLE(filecheck=CHECK):-entry computeMain -stage compute -line-directive-mode none -target hlsl -loop-inversion
2//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=OUT):-shaderobj -output-using-type
3//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=OUT):-dx12 -shaderobj -output-using-type
4//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=OUT):-cpu -shaderobj -output-using-type
5//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=OUT):-vk -shaderobj -output-using-type
6//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=OUT):-cpu -shaderobj -output-using-type
7
8// Check that all the backends cope with the slightly unusual IR the loop inversion generated
9
10// OUT: 180
11
12// For all the below functions, verify that the body (adding to j and
13// incrementing i) comes before any break. This verifies that the `break` has
14// been moved to the end of the loop.
15
16//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer
17RWStructuredBuffer<int> outputBuffer;
18
19// A standard loop
20// CHECK-LABEL: int a_{{.*}}()
21// CHECK-NOT: break;
22// CHECK: int {{.*}} = j_{{.*}} + [[i:i_[0-9]+]]
23// CHECK: [[i]] + int(1);
24// CHECK: if(
25// CHECK: break;
26// CHECK: return
27int a()
28{
29    int j = 0;
30    for(int i = 0; i < 10; ++i)
31        j += i;
32    return j;
33}
34
35// A vanilla while loop
36// CHECK-LABEL: int b_{{.*}}()
37// CHECK-NOT: break;
38// CHECK: int {{.*}} = j_{{.*}} + [[i:i_[0-9]+]]
39// CHECK: [[i]] + int(1);
40// CHECK: if(
41// CHECK: break;
42// CHECK: return
43int b()
44{
45    int j = 0;
46    int i = 0;
47    while(i < 10)
48    {
49        j += i;
50        i++;
51    }
52    return j;
53}
54
55// A while loop with a break on the false branch
56// CHECK-LABEL: int c_{{.*}}()
57// CHECK-NOT: break;
58// CHECK: int {{.*}} = j_{{.*}} + [[i:i_[0-9]+]]
59// CHECK: [[i]] + int(1);
60// CHECK: if(
61// CHECK: break;
62// CHECK: return
63int c()
64{
65    int j = 0;
66    int i = 0;
67    do
68    {
69        if(i < 10)
70            {}
71        else
72            break;
73        j += i;
74        i++;
75    } while(true);
76    return j;
77}
78
79// A while loop with a break on the true branch
80// CHECK-LABEL: int d_{{.*}}()
81// CHECK-NOT: break;
82// CHECK: int {{.*}} = j_{{.*}} + [[i:i_[0-9]+]]
83// CHECK: [[i]] + int(1);
84// CHECK: if(
85// CHECK: break;
86// CHECK: return
87int d()
88{
89    int j = 0;
90    int i = 0;
91    do
92    {
93        if(i >= 10)
94            break;
95        else
96            {}
97        j += i;
98        i++;
99    } while(true);
100    return j;
101}
102
103[numthreads(1, 1, 1)]
104void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
105{
106    outputBuffer[dispatchThreadID.x] = a() + b() + c() + d();
107}