yum-mirror/slang

Making it easier to work with shaders

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

jsmall-nvidiaGeneric experiments (#2119)160111a0e

master
935 B45 linesraw
1//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj
2
3/* A test to use generics to treat an enum as a set. 
4Here we simplify previous example, by not allowing the backing type be 
5a specialization parameter (and just use int).
6
7Moreover here E is constrained to __EnumType.
8
9Works
10*/
11
12//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer
13RWStructuredBuffer<float> outputBuffer;
14
15enum Enum
16{
17    A = 0x1,
18    B = 0x2, 
19    C = 0x4,
20};
21
22__generic<E : __EnumType>
23struct Flags
24{
25    [mutating] void set(E e) { value |= (int)e; }
26    bool isSet(E e) { return (((int)e) & value) != 0; }
27    int value = 0;
28};
29
30[numthreads(4, 1, 1)]
31void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
32{
33    int index = dispatchThreadID.x;
34    
35    Flags<Enum> flags;
36
37    if (index & 1)
38    {
39        flags.set(Enum::A);
40    }
41    bool isASet = flags.isSet(Enum::A);
42   
43	outputBuffer[index] = isASet ? 2 : 1;
44}
45