yum-mirror/slang

Making it easier to work with shaders

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

Jay KwakFix potential test failures due to SPIRV validation failure (#6047)6437f2d37

master
2.1 KiB101 linesraw
1//TEST:SIMPLE(filecheck=CHK): -target spirv -entry computeMain
2
3// Using before assigning
4float regular_undefined_use(out float3 v)
5{
6    //CHK-DAG: ([[# @LINE + 1]]): warning 41015: use of uninitialized out parameter 'v'
7    float r = v.x + 1.0;
8    
9    //CHK-DAG: ([[# @LINE + 1]]): warning 41018: returning without initializing out parameter 'v'
10    return r;
11}
12
13// Returning before assigning
14float returning_undefined_use(out float x)
15{
16    //CHK-DAG: ([[# @LINE + 1]]): warning 41018: returning without initializing out parameter 'x'
17    return 0;
18}
19
20// Implicit, still returning before assigning
21void implicit_undefined_use(out float x) 
22{
23    //CHK-DAG: ([[# @LINE + 1]]): warning 41018: returning without initializing out parameter 'x'
24}
25
26// Warn on potential return paths
27void control_flow_undefined(bool b, out float y)
28{
29    if(b)
30    {
31        //CHK-DAG: ([[# @LINE + 1]]): warning 41018: returning without initializing out parameter 'y'
32        return;
33    }
34    y = 0;
35    return;
36}
37
38// No warnings if all paths are fine
39void control_flow_defined(bool b, out float y)
40{
41    if(b)
42    {
43        unused(y);
44        return;
45    }
46    y = 0;
47    return;
48}
49
50// Specialized handling for intrinsic asm
51void instrincs_defined(float x, out float exp)
52{
53    __intrinsic_asm "frexp";
54}
55
56// Specialized handling for target switches
57void target_switching_undefined(float x, out float exp)
58{
59    //CHK-DAG: ([[# @LINE + 2]]): warning 41018: returning without initializing out parameter 'exp'
60    __target_switch {}
61}
62
63void target_switching_defined(float x, out float exp)
64{
65    __target_switch
66    {
67    case glsl: __intrinsic_asm "frexp";
68    }
69}
70
71void target_switching_blocks(uint x, out half v)
72{
73    __target_switch
74    {
75    case hlsl:
76        if ((x & 2) == 0)
77            v = half(1);
78        else
79            v = half(1);
80        return;
81    case glsl:
82    case spirv:
83        {
84            if ((x & 2) == 0)
85                v = half(1);
86            else
87                v = half(1);
88            return;
89        }
90    }
91}
92
93//CHK-NOT: warning 41015
94//CHK-NOT: warning 41018
95
96[Shader("compute")]
97[NumThreads(4, 1, 1)]
98void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
99{
100}
101