yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
447b7e0e2
master
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/* Doesn't work because doesn't know can convert E into an int type. 5 6If E could be specified as any enum type then perhaps this could work. 7*/ 8 9//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer 10RWStructuredBuffer<float> outputBuffer; 11 12enum Enum 13{ 14 A = 0x1, 15 B = 0x2, 16 C = 0x4, 17}; 18 19__generic<E> 20struct Flags 21{ 22 [mutating] void set(E e) { value |= (int)e; } 23 void isSet(E e) { return (((int)e) & value) != 0; } 24 int value = 0; 25}; 26 27[numthreads(4, 1, 1)] 28void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 29{ 30 int index = dispatchThreadID.x; 31 32 Flags<Enum> flags; 33 34 if (index & 1) 35 { 36 flags.set(Enum::A); 37 } 38 bool isASet = flags.isSet(Enum::A); 39 40 outputBuffer[index] = isASet ? 2 : 1; 41} 42