https://github.com/shader-slang/slang
Raw File
Tip revision: 9a2a35f9282570ed075ebc2313f4aa9ed7a643ce authored by Tim Foley on 28 August 2020, 18:21:40 UTC
Avoid nondeterministic ordering of output (#1522)
Tip revision: 9a2a35f
half-calc.slang
//DISABLE_TEST(compute):COMPARE_COMPUTE:-dx12 -compute -use-dxil -profile cs_6_2 -render-features half
//TEST(compute):COMPARE_COMPUTE:-vk -compute -profile cs_6_2 -render-features half
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out

// Test for doing a calculation using half

RWStructuredBuffer<float> outputBuffer;

[numthreads(4, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
    uint tid = dispatchThreadID.x;
    
    //half2 v0 = { 1, -2 };
    //half2 v1 = { -2, 4 };
    
    //half2 v2 = (v0 * 2.0f + v1);
    
    // This should work (it compiles on dxc, but slang doesn't seem to have overloads yet)
    //half offset = length(v2);
    
    //half offset = v2.x + v2.y;
    
    half offset = 0.0f;
    
    half v = tid;
    v *= half(3.0f);
    v += half(1.0f);
    v += offset;
    
    outputBuffer[tid] = v;
}
back to top