yum-mirror/slang

Making it easier to work with shaders

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

Yong HeFix function side-effectness prop logic. (#2875)38ed03a72

master
1.7 KiB61 linesraw
1// func-resource-param-array.slang
2
3//TEST:CROSS_COMPILE:-target spirv-assembly -entry main -stage compute
4
5// Test that we gernerate expected code for scenarios involving
6// resource-type function parameters, even when working with
7// arrays of resources.
8
9int f(RWStructuredBuffer<int> fx,   uint fi)         { return fx[fi]    ; }
10
11// TODO: Note that we are declaring the function
12// parameter here with an explicitly-sized array
13// because Slang currently doesn't support converison
14// from a sized to an unsized array type.
15//
16int g(RWStructuredBuffer<int> gx[3], uint gi, uint gj) { return gx[gi][gj]; }
17
18RWStructuredBuffer<int> a;
19RWStructuredBuffer<int> b[3];
20
21// Note: Slang currently genreates an array-of-arrays in the output
22// for this declaration, which glslang complains leads to invalid
23// SPIR-V. This means that there is yet another legalization step
24// that Slang should perform on this declaration.
25//
26// For now we are fine with generating invalid SPIR-V, because
27// we are not going to execute the output of this test case.
28//
29RWStructuredBuffer<int> c[4][3];
30
31void main(uint3 tid : SV_DispatchThreadID)
32{
33    uint ii = tid.x;
34    uint jj = tid.y;
35
36    // Can we specialize `f`?
37    //
38    int tmp = f(a, ii);
39
40    // If we ask for the same specialization again, do
41    // we avoid code duplication?
42    //
43    tmp += f(a, jj);
44
45    // If we pass in a reference to an array element,
46    // can we still specialize?
47    //
48    tmp += f(b[ii], jj);
49
50    // If we have a function that takes an *array* can
51    // we specialize?
52    //
53    tmp += g(b, ii, jj);
54
55    // What if the function takes an array, and we pass
56    // in an element of an array-of-arrays?
57    //
58    tmp += g(c[ii], jj, tid.z);
59
60    a[ii] = tmp;
61}