summaryrefslogtreecommitdiffstats
path: root/tests/bugs/vec-compare.slang
blob: b2f5802e42df6616bc791dd3c8250af075408450 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -shaderobj
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj

//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name outputBuffer
RWStructuredBuffer<int> outputBuffer;

[numthreads(4,4,1)]
void computeMain(int2 pixelIndex : SV_DispatchThreadID)
{
    
    // We will test floats, uints, and int vectors
    // We need all comparisons < > <= >= == !=
    
    int x = pixelIndex.x;
    int y = pixelIndex.y;
    
    int uintBits;
    {
        uint2 v = { uint(x), uint(y) };
        uint2 test = { 1, 3 };
        
        int bits = 0;
        bits |= any(v <  test)   ? 0x01 : 0;
        bits |= any(v <= test)   ? 0x02 : 0;
        bits |= any(v == test)   ? 0x04 : 0; 
        bits |= any(v >  test)   ? 0x08 : 0;
        bits |= any(v >= test)   ? 0x10 : 0;
        bits |= any(v != test)   ? 0x20 : 0;
        uintBits = bits;
    }
    
    int intBits;
    {
        int2 v = { x, y };
        int2 test = { 2, 0 };
        
        int bits = 0;
        bits |= any(v <  test)   ? 0x01 : 0;
        bits |= any(v <= test)   ? 0x02 : 0;
        bits |= any(v == test)   ? 0x04 : 0; 
        bits |= any(v >  test)   ? 0x08 : 0;
        bits |= any(v >= test)   ? 0x10 : 0;
        bits |= any(v != test)   ? 0x20 : 0;
        intBits = bits;
    }
    
    int floatBits;
    {
        float2 v = { float(x), float(y) };
        float2 test = { 1, 2 };
        
        int bits = 0;
        bits |= any(v <  test)   ? 0x01 : 0;
        bits |= any(v <= test)   ? 0x02 : 0;
        bits |= any(v == test)   ? 0x04 : 0; 
        bits |= any(v >  test)   ? 0x08 : 0;
        bits |= any(v >= test)   ? 0x10 : 0;
        bits |= any(v != test)   ? 0x20 : 0;
        floatBits = bits;
    }
       
    int coerceBits;
    {
        float2 v = { float(x), float(y) };
        int2 test = { 1, 2 };
        
        int bits = 0;
        bits |= any(v <  test)   ? 0x01 : 0;
        bits |= any(v <= test)   ? 0x02 : 0;
        bits |= any(v == test)   ? 0x04 : 0; 
        bits |= any(v >  test)   ? 0x08 : 0;
        bits |= any(v >= test)   ? 0x10 : 0;
        bits |= any(v != test)   ? 0x20 : 0;
        coerceBits = bits;
    }
    
    outputBuffer[pixelIndex.x + pixelIndex.y * 4] = (coerceBits << 24) | (floatBits << 16) | (intBits << 8) | (uintBits);
}