https://github.com/shader-slang/slang
Raw File
Tip revision: 6a360f74d41122d9b92a4050c2d51b57ddb2e197 authored by Tim Foley on 16 March 2021, 19:12:37 UTC
Enable building glslang from source (#1757)
Tip revision: 6a360f7
enum.slang
// enum.slang
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj
//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -shaderobj

// Confirm that basic `enum` declarations are supported.

enum Color
{
    Red,
    Green = (1 << 1),
    Blue,
}


int test(int val)
{
    Color c = Color.Red;

    if(val > 1)
    {
        c = Color.Green;
    }

    if(c == Color.Red)
    {
        if(val & 1)
        {
            c = Color.Blue;
        }
    }

    switch(c)
    {
    case Color.Red:
        val = 1;
        break;

    case Color.Green:
        val = 2;
        break;

    case Color.Blue:
        val = 3;
        break;

    default:
        val = -1;
        break;
    }

    return (val << 4) + int(c);
}

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

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

    int val = int(tid);
    val = test(val);

    outputBuffer[tid] = val;
}
back to top