https://github.com/shader-slang/slang
Raw File
Tip revision: 073bcc10c7a3977ab1b32f9b3ae0d2a39e1d8e42 authored by Andrew Adams on 09 July 2021, 22:19:46 UTC
Fix typo in comment. (#1907)
Tip revision: 073bcc1
generics-syntax-2.slang
//TEST(compute):COMPARE_COMPUTE: -shaderobj
//TEST(compute):COMPARE_COMPUTE:-cpu -shaderobj

// Confirm that generics syntax can be used in user
// code and generates valid output.

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

struct GenStruct<T>
{
    T x;
};

GenStruct<T> test<T>(T val)
{
    GenStruct<T> rs;
    rs.x = val;
    return rs;
}


[numthreads(4, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
    uint tid = dispatchThreadID.x;
    float inVal = float(tid);
    GenStruct<float> outVal = test(inVal);
    outputBuffer[tid] = outVal.x;
}
back to top