yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
2a5d5b323
master
1//TEST(compute):COMPARE_COMPUTE:-dx11 -shaderobj 2//TEST(compute):COMPARE_COMPUTE:-vk -shaderobj 3//TEST(compute):COMPARE_COMPUTE:-cpu -xslang -disable-specialization -shaderobj 4//TEST(compute):COMPARE_COMPUTE:-cuda -xslang -disable-specialization -shaderobj 5 6// Test dynamic dispatch code gen for static member functions 7// of associated type. 8 9[anyValueSize(8)] 10interface IAssoc 11{ 12 int get(); 13 static int getBase(); 14} 15 16[anyValueSize(16)] 17interface IInterface 18{ 19 associatedtype Assoc : IAssoc; 20 int Compute(int inVal); 21}; 22 23int GenericCompute<T:IInterface>(T obj, int inVal) 24{ 25 return obj.Compute(inVal) + T.Assoc.getBase(); 26} 27 28struct Impl : IInterface 29{ 30 struct Assoc : IAssoc 31 { 32 int val; 33 int get() { return val; } 34 static int getBase() { return -1; } 35 }; 36 int base; 37 int Compute(int inVal) { return base + inVal * inVal; } 38}; 39 40int test(int inVal) 41{ 42 Impl obj; 43 obj.base = 1; 44 return GenericCompute<Impl>(obj, inVal); 45} 46 47//TEST_INPUT:ubuffer(data=[0 1 2 3], stride=4):out,name=outputBuffer 48RWStructuredBuffer<int> outputBuffer; 49 50[numthreads(4, 1, 1)] 51void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 52{ 53 uint tid = dispatchThreadID.x; 54 int inVal = outputBuffer[tid]; 55 int outVal = test(inVal); 56 outputBuffer[tid] = outVal; 57}