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 around use of an array like container. 4 5Here the attempt is to make the equality test separate from the type. 6This isn't a great answer because it relies on the right types set 7for T and E to work together. 8 9This doesn't work because... 10.slang(25): error 30019: expected an expression of type 'Type', got 'T' 11 if (E::isEqual(v, elements[i])) 12 13 */ 14 15//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer 16RWStructuredBuffer<float> outputBuffer; 17 18interface IEquality 19{ 20 associatedtype Type; 21 static bool isEqual(Type a, Type b); 22}; 23 24struct IntEquality : IEquality 25{ 26 typedef int Type; 27 static bool isEqual(Type a, Type b) { return a == b; } 28}; 29 30struct FixedArray<T, E : IEquality> 31{ 32 static const int SIZE = 4; 33 34 [mutating] void setAt(int i, T value) { elements[i] = value; } 35 T getAt(int i) { return elements[i]; } 36 int indexOf(T v) 37 { 38 for (int i = 0; i < SIZE; ++i) 39 { 40 if (E::isEqual(v, elements[i])) 41 { 42 return i; 43 } 44 return -1; 45 } 46 } 47 T elements[SIZE]; 48}; 49 50 51[numthreads(4, 1, 1)] 52void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 53{ 54 int index = dispatchThreadID.x; 55 56 FixedArray<int, IntEquality> arr; 57 arr.setAt(0, index); 58 59 outputBuffer[index] = 1 + arr.getAt(0); 60} 61