yum-mirror/slang

Making it easier to work with shaders

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

Yong HeWarning on lossy implicit casts. (#2367)adaea0e99

master
1.5 KiB77 linesraw
1// enum.slang
2//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj
3//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj
4
5// Confirm operations that produce bools - such as comparisons, or && ||, ! work correctly
6
7//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name outputBuffer
8RWStructuredBuffer<int> outputBuffer;
9
10[numthreads(16, 1, 1)]
11void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
12{
13    uint tid = dispatchThreadID.x;; 
14
15    uint uv = tid;
16    int iv = int(tid);
17    
18    bool2 bv2 = { (tid & 1) != 0, tid > 10 };      
19    
20    float2 f2 = { float(tid), float(tid + 1) };
21    
22    bool bv = tid > 6;
23    let not_bv2 = !bv2;
24    
25    int r = 0;
26    if (bv)
27    {
28        r |= 0x0001;
29    }
30    if (!bv)
31    {
32        r |= 0x0002;
33    }
34    
35    if (iv != 0)
36    {
37        r|= 0x0004;
38    }
39    if (!bool(iv))
40    {
41        r|= 0x0008;
42    }
43
44    if (uv != 0)
45    {
46        r |= 0x0010;
47    }
48    if (!bool(uv))
49    {
50        r |= 0x0020;
51    }
52    
53    if (all(bv2))
54    {
55        r |= 0x0040;
56    }
57    if (all(not_bv2))
58    {
59        r |= 0x0080;
60    }
61    
62    if (any(!bool2(f2)))
63    {
64        r |= 0x0100;
65    }
66    
67    // TODO(JS): Support on GLSL targets
68    // This doesn't currently work on GLSL targets, and because there 
69    // do not appear to be any vector bitwise operations. Could be achieved
70    // by deconstructing, and reconstructing the vec result
71    /* if (all(f2 || bv2))
72    {
73        r |= 0x0200;
74    } */
75    
76    outputBuffer[tid] = r;
77}