summaryrefslogtreecommitdiffstats
path: root/tests/experiments/generic/explicit-specialization-2.slang
blob: ea5c74813acb4dadcb9851d5f0086f977a9547ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//DISABLE_TEST:SIMPLE:-target hlsl -entry computeMain -profile cs_6_2

/* 
The following works, but *requires* the rotateLeft free function to work around the swizzle issue (seen in explicit-specialization.slang).
*/

RWStructuredBuffer<int> outputBuffer;

interface IRotatable 
{
    This rotateLeft();
};

extension int : IRotatable
{
    This rotateLeft() { const uint u = this; return This((u << 1) | (u >> 31)); }
};

extension uint : IRotatable
{
    This rotateLeft() { let u = this; return This((u << 1) | (u >> 31)); }
};

T rotateLeft<T : IRotatable>(T a) { return a.rotateLeft(); }

[numthreads(4, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
    uint tid = dispatchThreadID.x;

    let v = rotateLeft(tid) + rotateLeft((int)tid);
   
    outputBuffer[tid] = v;
}