yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
c35b763f8
master
1// array-size-group-shared.slang 2//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type 3 4//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer 5RWStructuredBuffer<uint> outputBuffer; 6 7interface IA 8{ 9 static const int M; 10} 11struct B : IA 12{ 13 static const int M = 2; 14} 15struct GenType<T : __BuiltinIntegerType, A: IA, let N : int, let M : int> 16{ 17 static const int HalfN = N > 1? N / A.M : 1; 18 static const int P = M + N; 19 20 // TODO(tfoley): What this test is testing seems to be outside 21 // the scope of what we ever intend to support in user code. 22 // Returning an `Ref<T>` is supposed to be a core-module-only 23 // thing, and even then is something that we would like to do less 24 // of over time. 25 // 26 // The only purpose of this test *seems* to be ensuring that this 27 // particular function (and the `groupshared` declaration inside 28 // it) "works," but the function itself is not something that we 29 // intend to be supported in Slang. 30 // 31 [ForceInline] 32 Ref<uint> weights(int index) 33 { 34 static groupshared uint w[P]; 35 return w[index]; 36 } 37 T sum(T arr[HalfN]) 38 { 39 T rs = T(0); 40 for (int i = 0; i < P; i++) 41 weights(i) = i; 42 for (int i = 0; i < HalfN; i++) 43 rs += arr[i]; 44 return rs; 45 } 46} 47 48[numthreads(1, 1, 1)] 49void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) 50{ 51 int arr[2] = { 1, 2 }; 52 GenType<int, B, 4, 2> obj; 53 outputBuffer[0] = obj.sum(arr); 54}