yum-mirror/slang

Making it easier to work with shaders

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

jsmall-nvidiaLanguage experiments (#2068)447b7e0e2

master
784 B45 linesraw
1//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj
2
3/* Find max algorithm. 
4
5Works.
6 */
7
8//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer
9RWStructuredBuffer<float> outputBuffer;
10
11interface IComparable
12{
13    bool isLess(This other);
14};
15
16extension int : IComparable
17{
18	bool isLess(int other) { return this < other; }
19};
20
21T findMax<T : IComparable, let SIZE : int>(T arr[SIZE])
22{
23    T m = arr[0];
24    for (int i = 1; i < 8; ++i)
25    {
26        if (m.isLess(arr[i]))
27        {
28            m = arr[i];
29        }
30    }
31    return m;
32}
33
34
35[numthreads(4, 1, 1)]
36void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
37{
38    int index = dispatchThreadID.x;
39
40    int values[] = { 1, 3, - 1};
41    
42	outputBuffer[index] = findMax<int, 3>(values);
43}
44
45