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 we just fix the array size, so can test out other characteristics. 6 7indexOf can't compile because v == elements[i] cannot determine equality. 8 9It would seem like I should have an IEquality interface, that I could then make 10a T require. 11 12Doesn't work because 13 14.slang(29): error 30019: expected an expression of type 'Type', got 'T' 15 if (T::isEqual(v, elements[i])) 16 17 */ 18 19//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer 20RWStructuredBuffer<float> outputBuffer; 21 22interface IEquality 23{ 24 associatedtype Type; 25 static bool isEqual(Type a, Type b); 26}; 27 28extension int : IEquality 29{ 30 typedef int Type; 31 static bool isEqual(Type a, Type b) 32 { 33 return a == b; 34 } 35}; 36 37 38struct FixedArray<T : IEquality> 39{ 40 static const int SIZE = 4; 41 42 [mutating] void setAt(int i, T value) { elements[i] = value; } 43 T getAt(int i) { return elements[i]; } 44 int indexOf(T v) 45 { 46 for (int i = 0; i < SIZE; ++i) 47 { 48 if (T::isEqual(v, elements[i])) 49 { 50 return i; 51 } 52 return -1; 53 } 54 } 55 T elements[SIZE]; 56}; 57 58[numthreads(4, 1, 1)] 59void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 60{ 61 int index = dispatchThreadID.x; 62 63 FixedArray<int> arr; 64 arr.setAt(0, index); 65 66 outputBuffer[index] = 1 + arr.getAt(0); 67} 68 69