yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f02b08490
master
1//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -shaderobj 2// TODO(JS): 3// On CI systems DX11 test failed, so disable for now 4//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -shaderobj 5//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -output-using-type -shaderobj -render-feature hardware-device 6//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type -shaderobj -render-feature double 7//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-cuda -compute -output-using-type -shaderobj 8 9//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name outputBuffer 10RWStructuredBuffer<double4> outputBuffer; 11 12typedef double Float; 13 14typedef vector<Float, 3> FloatVector; 15typedef vector<int, 3> IntVector; 16typedef vector<uint, 3> UIntVector; 17 18[numthreads(4, 1, 1)] 19void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 20{ 21 int idx = int(dispatchThreadID.x); 22 23 Float vf = idx * (1.0f / (4.0f)); 24 25 FloatVector f = FloatVector(0.1f, vf, vf + 0.2f); 26 27 // Operate over all values 28 FloatVector ft = {}; 29 30 // TODO(JS): 31 // fmod - disabled not available on D3D for double 32 //ft += FloatVector(IntVector(((f % 0.11f) * 100) + 0.5)); 33 34 { 35 // Vector specific 36 FloatVector nv = normalize(f); 37 ft += nv; 38 39 FloatVector perp = cross(nv, f.zxy); 40 ft += perp; 41 42 43 // TODO(JS): 44 // Disabled because dotwith a double vector fails on dxc, with validation error (!) 45 //ft += dot(perp, f.zyx); 46 47 ft += length(f); 48 49 // TODO(JS): 50 // Disabled because reflect with double fails on dxc 51 //ft += reflect(f, FloatVector(0, 1, 0)); 52 } 53 54 // Reduced set of intrinsics that should work on all targets 55 56#if 0 57 // TODO(JS): 58 // Disabled because not supported on VK (glsl) in vector form 59 ft += rcp(1.0l + f); 60#endif 61 62 ft += sign(f - 0.5l); 63 64 ft += saturate(f * 4 - 2.0l); 65 66 ft += abs(f * 4 - 2.0l); 67 68 ft += min(0.5l, f); 69 ft += max(f, 0.75l); 70 71 ft += clamp(f, 0.1l, 0.3l); 72 73 outputBuffer[idx] = vector<Float, 4>(ft, 0); 74}