yum-mirror/slang

Making it easier to work with shaders

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

Yong HeDefer immutable buffer loads when emitting spirv. (#7579)c701ec00c

master
733 B27 linesraw
1//TEST:SIMPLE(filecheck=CHECK):-target spirv
2struct Data {
3    StructuredBuffer<float> input[2];
4    RWStructuredBuffer<float> output;
5    uint input_tensor_count;
6    StructuredBuffer<uint> index_buffer;
7    uint index_count;
8    
9    [mutating]
10    float fetch(int buffer, int index)
11    {
12        return input[buffer][index];
13    }
14};
15
16[shader("compute")]
17[numthreads(8, 8, 1)]
18void compute_main(uint3 tid: SV_DispatchThreadID, ParameterBlock<Data> data)
19{
20    float result = 0.0;
21    for (int i = 0; i < data.index_count; ++i) {
22        uint buffer = data.index_buffer[i];
23        //CHECK: ([[# @LINE+1]]): error
24        result += data.fetch(buffer, tid.x * 1024 + tid.y);
25    }
26    data.output[tid.x * 1024 + tid.y] = result;
27}