yum-mirror/slang

Making it easier to work with shaders

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

jsmall-nvidiaLanguage experiments (#2068)447b7e0e2

master
1020 B46 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.
4
5.slang(15): error 30060: expected a type, got a '__BuiltinIntegerType'
6    B value = 0;
7    
8.slang(23): error 30019: expected an expression of type 'int', got 'typeof(uint8_t)'
9    Flags<Enum, uint8_t> flags;
10                ^~~~~~~    
11*/
12
13//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer
14RWStructuredBuffer<float> outputBuffer;
15
16enum Enum
17{
18    A = 0x1,
19    B = 0x2, 
20    C = 0x4,
21};
22
23__generic<E, let B : __BuiltinIntegerType>
24struct Flags
25{
26    [mutating] void set(E e) { value |= (B)e; }
27    void isSet(E e) { return (((B)e) & value) != 0; }
28    B value = 0;
29};
30
31[numthreads(4, 1, 1)]
32void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
33{
34    int index = dispatchThreadID.x;
35    
36    Flags<Enum, uint8_t> flags;
37
38    if (index & 1)
39    {
40        flags.set(Enum::A);
41    }
42    bool isASet = flags.isSet(Enum::A);
43   
44	outputBuffer[index] = isASet ? 2 : 1;
45}
46