yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f02b08490
master
1// NOTE we can't test on VK/gl at the moment because we don't support intrinsics over matrices on that target currently 2 3//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -shaderobj 4//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj 5//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -shaderobj 6//DISABLE_TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj 7//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj 8//DISABLE_TEST(compute):COMPARE_COMPUTE:-slang -shaderobj -mtl 9// Not supported in WGSL: Integer matrices 10//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-wgpu 11 12//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer 13RWStructuredBuffer<int> outputBuffer; 14 15int horizontalAdd(int3 v) { return v.x + v.y + v.z; } 16 17[numthreads(4, 1, 1)] 18void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 19{ 20 int idx = int(dispatchThreadID.x); 21 22 matrix<int, 3, 3> a = { { 0, 1, 2}, {2, 4, 6}, {16, 21, 32}}; 23 matrix<int, 3, 3> b = { { 4, 9, -1}, {-2, 4, 2}, {31, -3, 7}}; 24 25 matrix<int, 3, 3> t = {}; 26 27 t += max(a, b); 28 t += min(a, b); 29 t += abs(a); 30 t += b % 5; 31 32 { 33 int3 low = int3(3 + idx * 1); 34 int3 high = int3(5 + idx * 2); 35 36 t += clamp(a, matrix<int, 3, 3>(low, low, low), matrix<int, 3, 3>(high, high, high)); 37 } 38 39 // Access rows and elements, both read and write 40 41 a[0].x ++; 42 a[1][1] --; 43 a[0] = a[1]; 44 a[2].y += b[1].x; 45 46 t += a; 47 48 outputBuffer[idx] = horizontalAdd(t[0]) + horizontalAdd(t[1]) + horizontalAdd(t[2]); 49}