yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Sai Praveen BangaruAlways run AD cleanup pass. (#5157)7398e1e09

master
1.3 KiB45 linesraw
1//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type
2//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type
3//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -shaderobj
4
5//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer
6RWStructuredBuffer<float> outputBuffer;
7
8// This test just checks that we compile and run successfully.
9// "NDBuffer<float, 2>" & "no_diff NDBuffer<float, 2>" should resolve to the same code-gen type.
10// 
11
12struct NDBuffer<T, let N : int>
13{
14    RWStructuredBuffer<T> buffer;
15    int[N] strides;
16    int[N] transform;
17
18    T get(int[N] index) { return buffer[index[0]]; }
19}
20
21float _read_slice(int2 index, NDBuffer<float, 2> texture) 
22{ 
23    return texture.get({index.x, index.y}); 
24}
25
26[Differentiable]
27void _trampoline(no_diff in vector<int,2> index, in no_diff NDBuffer<float, 2> texture, no_diff out float _result)
28{
29    _result = _read_slice(index, texture);
30}
31
32
33[shader("compute")]
34[numthreads(1, 1, 1)]
35void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
36{
37    NDBuffer<float, 2> texture;
38    texture.buffer = outputBuffer;
39    texture.strides = {1, 1};
40
41    float result;
42    _trampoline({dispatchThreadID.x, dispatchThreadID.y}, texture, result);
43    outputBuffer[dispatchThreadID.x] = result;
44}
45