https://github.com/shader-slang/slang
Raw File
Tip revision: 926009a58315845b3a3a95e2724486a6c9e987ea authored by Tomáš Pazdiora on 10 May 2024, 01:17:38 UTC
fix typo (#4144)
Tip revision: 926009a
op-assignment-unify-mat.slang
// We can't test on VK, as currently we don't support integer matrix types
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -vk
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj 
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -cpu

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

void silly<T : __BuiltinIntegerType, let ROWS : int, let COLS : int>(matrix<T, ROWS, COLS> a, inout matrix<T, ROWS, COLS> b)
{
    b *= a;
}

void silly2<T : __BuiltinIntegerType, let ROWS : int, let COLS : int>(matrix<T, ROWS, COLS> a, out matrix<T, ROWS, COLS> b)
{
    b = a;
}


[numthreads(4, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
    matrix<int, 2, 2> v = { 1, 2, 3, 4};
    matrix<uint, 2, 2> u = { 5, 6, 7, 8};

    int idx = int(dispatchThreadID.x);
    
    matrix<uint, 2, 2> uidx = { idx, idx * idx, idx + idx, idx + 2 };

    v += uidx;
    u += idx;

    silly(u, v);
    silly(v, u);

    // Check that detects issues with undefined variables.

    matrix<int, 2, 2> undef1, undef2;          // undefined
    // Downstream compilers detect this
    //silly(u, undef1);
    silly2(u, undef2);
    
    matrix<uint, 2, 2> added = (u + v + undef2);
    uint2 added2 = added[0] + added[1];

    outputBuffer[idx] = added2.x + added2.y;
}
back to top