yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
2c2294d33
master
1//TEST(smoke,compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -shaderobj -output-using-type 2//TEST(smoke,compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -shaderobj -emit-spirv-directly -output-using-type 3 4// CHECK: 23 5// CHECK-NEXT: 23 6// CHECK-NEXT: 23 7// CHECK-NEXT: 23 8 9// This test tests that the 1-vector legalization works correctly. 10 11//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer 12RWStructuredBuffer<float> outputBuffer; 13 14// This struct helps test that nested access through 1-vectors works 15struct V 16{ 17 // 1-vector of 1-vector 18 vector<vector<float, 1>, 1> oo; 19 20 // 1-vector of n-vector 21 vector<vector<float, 4>, 1> on; 22 23 // n-vector of 1-vector 24 vector<vector<float, 1>, 4> no; 25}; 26 27vector<int, 1> get1Vec(int x) 28{ 29 return x; 30} 31 32V getV() 33{ 34 V v; 35 36 // Test swizzle store 37 v.oo.x.x = 1; 38 39 // Test assigning into subscript 40 v.on[0].wzyx = float4(4,3,2,1); 41 42 // Test assigning from vector 43 v.no.x = vector<float, 1>(1); 44 45 // Test assigning from scalar 46 v.no.y.x = 2; 47 48 // Test assigning from vector of vector 49 v.no.wz = vector<vector<float, 1>, 2>(3,4); 50 51 return v; 52} 53 54float sumV(V v) 55{ 56 return v.oo[0][0] 57 + v.on.x.x 58 + v.on.x.y 59 + v.on.x.z 60 + v.on.x.w 61 // Test arithmetic 62 + (v.no.x + v.no.y + v.no.z + v.no.w).x; 63} 64 65float3 splat(vector<float, 1> v) 66{ 67 // Test swizzle 68 return v.xxx; 69} 70 71// This function helps test that this legalization happens with generic length 72// vectors specialized to 1 73float triangle<let N : int>() 74{ 75 vector<float, N> v; 76 for(int i = 0; i < N; ++i) 77 v[i] = i+1; 78 79 float ret = 0; 80 for(int i = 0; i < N; ++i) 81 ret += v[i]; 82 return ret; 83} 84 85[numthreads(4, 1, 1)] 86void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 87{ 88 const V v = getV(); 89 outputBuffer[dispatchThreadID.x] 90 = sumV(v) 91 + triangle<1>() 92 + splat(v.oo.x).z; 93}