[require]
shader model >= 6.0
wave-ops
format r32-uint uav-load

[uav 0]
format r32-uint
size (buffer, 4)

8 15 8 10

[uav 1]
format r32-uint
size (buffer, 8)

0 0 0 0 0 0 0 0

[compute shader]
RWBuffer<uint> u1 : register(u1);

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    u1[id] = WaveIsFirstLane();
}

[test]
dispatch 4 1 1
probe uav 1 (0) u32(1)
probe uav 1 (1) u32(0)
probe uav 1 (2) u32(0)
probe uav 1 (3) u32(0)


[compute shader]
RWBuffer<uint> u1 : register(u1);

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    if (!id)
    {
        u1[0] = 0;
        return;
    }
    u1[id] = WaveIsFirstLane();
}

[test]
dispatch 4 1 1
probe uav 1 (0) u32(0)
probe uav 1 (1) u32(1)
probe uav 1 (2) u32(0)
probe uav 1 (3) u32(0)


[compute shader]
RWBuffer<uint> u1 : register(u1);

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    u1[id] = WaveGetLaneIndex();
}

[test]
dispatch 4 1 1
probe uav 1 (0) u32(0)
probe uav 1 (1) u32(1)
probe uav 1 (2) u32(2)
probe uav 1 (3) u32(3)


[compute shader]
RWBuffer<uint> u1 : register(u1);

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    // Between 4 and 128, and includes inactive and/or helper lanes.
    uint count = WaveGetLaneCount();
    u1[id] = count >= 4 && count <= 128;
}

[test]
dispatch 4 1 1
probe uav 1 (0) u32(1)
probe uav 1 (1) u32(1)
probe uav 1 (2) u32(1)
probe uav 1 (3) u32(1)


[compute shader]
RWBuffer<uint> u0;
RWBuffer<uint> u1;

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    uint i = (id & 1) ? -u0[id] : u0[id];
    u1[id] = WaveActiveMin(i);
}

[test]
dispatch 4 1 1
probe uav 1 (0) u32(8)
probe uav 1 (1) u32(8)
probe uav 1 (2) u32(8)
probe uav 1 (3) u32(8)


[compute shader]
RWBuffer<uint> u0;
RWBuffer<uint> u1;

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    bool b = u0[id] == 8;
    u1[id] = WaveActiveBallot(b).x;
}

[test]
dispatch 4 1 1
probe uav 1 (0) u32(5)
probe uav 1 (1) u32(5)
probe uav 1 (2) u32(5)
probe uav 1 (3) u32(5)


[compute shader]
RWBuffer<uint> u0;
RWBuffer<uint> u1;

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    uint i = u0[id] + u0[id ^ 1];
    u1[id] = WaveReadLaneFirst(i);
}

[test]
dispatch 4 1 1
probe uav 1 (0) u32(23)
probe uav 1 (1) u32(23)
probe uav 1 (2) u32(23)
probe uav 1 (3) u32(23)


[compute shader]
RWBuffer<uint> u0;
RWBuffer<uint> u1;

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    uint i = u0[id] + u0[id ^ 1];
    u1[id] = WaveReadLaneAt(i, 3);
}

[test]
dispatch 4 1 1
probe uav 1 (0) u32(18)
probe uav 1 (1) u32(18)
probe uav 1 (2) u32(18)
probe uav 1 (3) u32(18)


[compute shader]
RWBuffer<uint> u0;
RWBuffer<uint> u1;

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    uint i = u0[id] + u0[id ^ 1];
    // Non-uniform lane index
    u1[id] = WaveReadLaneAt(i, (id + 2) & 3);
}

[test]
dispatch 4 1 1
probe uav 1 (0) u32(18)
probe uav 1 (1) u32(18)
probe uav 1 (2) u32(23)
probe uav 1 (3) u32(23)


[compute shader]
RWBuffer<uint> u0;
RWBuffer<uint> u1;

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    bool b = u0[id] == 8;
    u1[id] = WaveActiveCountBits(b);
}

[test]
dispatch 4 1 1
probe uav 1 (0) u32(2)
probe uav 1 (1) u32(2)
probe uav 1 (2) u32(2)
probe uav 1 (3) u32(2)


[compute shader]
RWBuffer<uint> u0;
RWBuffer<uint> u1;

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    bool b = u0[id] == 8;
    u1[id] = WavePrefixCountBits(b);
}

[test]
dispatch 4 1 1
probe uav 1 (0) u32(0)
probe uav 1 (1) u32(1)
probe uav 1 (2) u32(1)
probe uav 1 (3) u32(2)


[compute shader]
RWBuffer<uint> u0;
RWBuffer<uint> u1;

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    u1[id] = WaveActiveSum(u0[id]);
}

[test]
dispatch 4 1 1
probe uav 1 (0) u32(41)
probe uav 1 (1) u32(41)
probe uav 1 (2) u32(41)
probe uav 1 (3) u32(41)


[compute shader]
RWBuffer<uint> u0;
RWBuffer<uint> u1;

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    u1[id] = WaveActiveBitAnd(u0[id]);
}

[test]
dispatch 4 1 1
probe uav 1 (0) u32(8)
probe uav 1 (1) u32(8)
probe uav 1 (2) u32(8)
probe uav 1 (3) u32(8)


[compute shader]
RWBuffer<uint> u0;
RWBuffer<uint> u1;

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    u1[id] = WaveActiveBitOr(u0[id]);
}

[test]
dispatch 4 1 1
probe uav 1 (0) u32(15)
probe uav 1 (1) u32(15)
probe uav 1 (2) u32(15)
probe uav 1 (3) u32(15)


[compute shader]
RWBuffer<uint> u0;
RWBuffer<uint> u1;

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    u1[id] = WaveActiveBitXor(u0[id]);
}

[test]
dispatch 4 1 1
probe uav 1 (0) u32(5)
probe uav 1 (1) u32(5)
probe uav 1 (2) u32(5)
probe uav 1 (3) u32(5)


[compute shader]
uniform uint2 u;

RWBuffer<uint> u0;
RWBuffer<uint> u1;

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    uint table[] = {u.x, u.y};
    uint i;

    // Value depends on control flow.
    if (id & 1)
        i = table[id / 2u];
    else
        i = u0[id / 2u];

    u1[id] = WaveActiveSum(i);
}

[test]
uniform 0 uint4 1 5 0 0
dispatch 4 1 1
probe uav 1 (0) u32(29)
probe uav 1 (1) u32(29)
probe uav 1 (2) u32(29)
probe uav 1 (3) u32(29)


[require]
shader model >= 6.0
wave-ops
int64
format r32g32b32a32-uint uav-load

[uav 0]
format r32g32b32a32-uint
size (buffer, 4)

1  8   16 0
1 11    5 0
2 15    4 0
4  8    6 0

[uav 1]
format r32g32b32a32-uint
size (buffer, 16)

0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0

[compute shader]
RWBuffer<uint64_t2> u0;
RWBuffer<uint64_t2> u1;

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    uint64_t2 u = u0[id] + u0[id ^ 1];
    u1[id] = WaveReadLaneFirst(u);
    u1[4 + id] = WaveReadLaneAt(u, 3);
}

[test]
bug(mvk) dispatch 4 1 1
probe uav 1 (0) u64(0x1300000002, 21)
probe uav 1 (1) u64(0x1300000002, 21)
probe uav 1 (2) u64(0x1300000002, 21)
probe uav 1 (3) u64(0x1300000002, 21)
probe uav 1 (4) u64(0x1700000006, 10)
probe uav 1 (5) u64(0x1700000006, 10)
probe uav 1 (6) u64(0x1700000006, 10)
probe uav 1 (7) u64(0x1700000006, 10)


[compute shader]
RWBuffer<uint64_t2> u0;
RWBuffer<uint64_t2> u1;

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    u1[id] = WaveActiveSum(u0[id]);
}

[test]
bug(mvk) dispatch 4 1 1
probe uav 1 (0) u64(0x2a00000008, 31)
probe uav 1 (1) u64(0x2a00000008, 31)
probe uav 1 (2) u64(0x2a00000008, 31)
probe uav 1 (3) u64(0x2a00000008, 31)


[compute shader]
RWBuffer<uint64_t2> u0;
RWBuffer<uint64_t2> u1;

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    u1[id] = WaveActiveProduct(u0[id]);
}

[test]
bug(mvk) dispatch 4 1 1
probe uav 1 (0) u64(0xe400000008, 0x780)
probe uav 1 (1) u64(0xe400000008, 0x780)
probe uav 1 (2) u64(0xe400000008, 0x780)
probe uav 1 (3) u64(0xe400000008, 0x780)


[compute shader]
RWBuffer<uint64_t2> u0;
RWBuffer<uint64_t2> u1;

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    u1[id] = WaveActiveMin(u0[id]);
}

[test]
bug(mvk) dispatch 4 1 1
probe uav 1 (0) u64(0x800000001, 4)
probe uav 1 (1) u64(0x800000001, 4)
probe uav 1 (2) u64(0x800000001, 4)
probe uav 1 (3) u64(0x800000001, 4)


[compute shader]
RWBuffer<uint64_t2> u0;
RWBuffer<uint64_t2> u1;

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    u1[id] = WaveActiveMax(u0[id]);
}

[test]
bug(mvk) dispatch 4 1 1
probe uav 1 (0) u64(0xf00000002, 16)
probe uav 1 (1) u64(0xf00000002, 16)
probe uav 1 (2) u64(0xf00000002, 16)
probe uav 1 (3) u64(0xf00000002, 16)


[compute shader]
RWBuffer<uint64_t2> u0;
RWBuffer<uint64_t2> u1;

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    u1[id] = WavePrefixSum(u0[id]);
}

[test]
bug(mvk) dispatch 4 1 1
probe uav 1 (0) u64(0, 0)
probe uav 1 (1) u64( 0x800000001, 16)
probe uav 1 (2) u64(0x1300000002, 21)
probe uav 1 (3) u64(0x2200000004, 25)


[compute shader]
RWBuffer<uint64_t2> u0;
RWBuffer<uint64_t2> u1;

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    u1[id] = WavePrefixProduct(u0[id]);
}

[test]
bug(mvk) dispatch 4 1 1
probe uav 1 (0) u64(1, 1)
probe uav 1 (1) u64( 0x800000001,  16)
probe uav 1 (2) u64(0x1300000001,  80)
probe uav 1 (3) u64(0x3500000002, 320)


[compute shader]
RWBuffer<uint64_t2> u0;
RWBuffer<uint64_t2> u1;

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    u1[id] = WaveActiveBitAnd(u0[id]);
}

[test]
bug(mvk) dispatch 4 1 1
probe uav 1 (0) u64(0x800000000, 0)
probe uav 1 (1) u64(0x800000000, 0)
probe uav 1 (2) u64(0x800000000, 0)
probe uav 1 (3) u64(0x800000000, 0)


[compute shader]
RWBuffer<uint64_t2> u0;
RWBuffer<uint64_t2> u1;

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    u1[id] = WaveActiveBitOr(u0[id]);
}

[test]
bug(mvk) dispatch 4 1 1
probe uav 1 (0) u64(0xf00000007, 0x17)
probe uav 1 (1) u64(0xf00000007, 0x17)
probe uav 1 (2) u64(0xf00000007, 0x17)
probe uav 1 (3) u64(0xf00000007, 0x17)


[compute shader]
RWBuffer<uint64_t2> u0;
RWBuffer<uint64_t2> u1;

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    u1[id] = WaveActiveBitXor(u0[id]);
}

[test]
bug(mvk) dispatch 4 1 1
probe uav 1 (0) u64(0x400000006, 0x17)
probe uav 1 (1) u64(0x400000006, 0x17)
probe uav 1 (2) u64(0x400000006, 0x17)
probe uav 1 (3) u64(0x400000006, 0x17)


[uav 0]
format r32g32b32a32-uint
size (buffer, 4)

 1  2    3  4
 5  6    7  8
 9 10   11 12
13 14   15 16

[compute shader]
RWBuffer<uint64_t2> u0;
RWBuffer<uint64_t2> u1;

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    uint i = WaveGetLaneIndex() % 4;
    uint64_t2 u = u0[i];
    u1[i] = QuadReadAcrossX(u);
}

[test]
bug(mvk) dispatch 4 1 1
probe uav 1 (0) u64(0x600000005,  0x800000007)
probe uav 1 (1) u64(0x200000001,  0x400000003)
probe uav 1 (2) u64(0xe0000000d, 0x100000000f)
probe uav 1 (3) u64(0xa00000009,  0xc0000000b)


[compute shader]
RWBuffer<uint64_t2> u0;
RWBuffer<uint64_t2> u1;

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    uint i = WaveGetLaneIndex() % 4;
    uint64_t2 u = u0[i];
    u1[i] = QuadReadAcrossY(u);
}

[test]
bug(mvk) dispatch 4 1 1
probe uav 1 (0) u64(0xa00000009,  0xc0000000b)
probe uav 1 (1) u64(0xe0000000d, 0x100000000f)
probe uav 1 (2) u64(0x200000001,  0x400000003)
probe uav 1 (3) u64(0x600000005,  0x800000007)


[compute shader]
RWBuffer<uint64_t2> u0;
RWBuffer<uint64_t2> u1;

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    uint i = WaveGetLaneIndex() % 4;
    uint64_t2 u = u0[i];
    u1[i] = QuadReadAcrossDiagonal(u);
}

[test]
bug(mvk) dispatch 4 1 1
probe uav 1 (0) u64(0xe0000000d, 0x100000000f)
probe uav 1 (1) u64(0xa00000009,  0xc0000000b)
probe uav 1 (2) u64(0x600000005,  0x800000007)
probe uav 1 (3) u64(0x200000001,  0x400000003)


[compute shader]
RWBuffer<uint64_t2> u0;
RWBuffer<uint64_t2> u1;

    [numthreads(4, 1, 1)]
void main(uint id : SV_GroupIndex)
{
    uint i = WaveGetLaneIndex() % 4;
    uint64_t2 u = u0[i];
    u1[i] = QuadReadLaneAt(u, 2);
}

[test]
bug(mvk) dispatch 4 1 1
probe uav 1 (0) u64(0xa00000009,  0xc0000000b)
probe uav 1 (1) u64(0xa00000009,  0xc0000000b)
probe uav 1 (2) u64(0xa00000009,  0xc0000000b)
probe uav 1 (3) u64(0xa00000009,  0xc0000000b)
