Search code examples
c++winapidirectxhlslcompute-shader

Why error "X3666 cs_4_0 does not support types UAVs", when using cs_5_0 in code and environment?


I'm trying to compile a Compute Shader by replicating the example from this video.

https://channel9.msdn.com/Blogs/gclassy/DirectCompute-Lecture-Series-120-Basics-of-DirectCompute-Application-Development

I'm getting the following error message while compiling:

Error X3666    cs_4_0 does not support typed UAVs

Where is this error coming from? The configuration is cs_5_0 (in code an in VS2019). Here is the compile section of the code.

HRESULT DirectCompute::CreateShaders()
{
    HRESULT hr = S_OK;

    ID3DBlob* CS, * csError;

    hr = D3DCompileFromFile(L"ComputeShader.hlsl", NULL, NULL, "main", "cs_5_0", NULL, NULL,
        &CS, &csError);

    if (csError) {
        MessageBox(NULL, L"Failed compiling computer shader", L"Error", MB_OK);
        csError->Release();
    }

    hr = device->CreateComputeShader(
        CS->GetBufferPointer(),
        CS->GetBufferSize(),
        NULL,
        pComputeShader.GetAddressOf());

    context->CSSetShader(pComputeShader.Get(), NULL, 0);
    context->CSSetConstantBuffers(0, 1, pConstantBuffer.GetAddressOf());

    ID3D11ShaderResourceView* aSRViews[2] = { pBufferA_SRV.Get(), pBufferB_SRV.Get() };
    context->CSSetShaderResources(0, 2, aSRViews);

    ID3D11UnorderedAccessView* aUAViews[1] = { pBufferOut_UAV.Get() };
    context->CSSetUnorderedAccessViews(0, 1, aUAViews, NULL);


    context->Dispatch(matB_width, matA_height, 1);

    ID3D11ShaderResourceView* aSRViewsNULL[1] = { NULL };
    context->CSSetShaderResources(0, 1, aSRViewsNULL);

    ID3D11UnorderedAccessView* aUAViewsNULL[1] = { NULL };
    context->CSSetUnorderedAccessViews(0, 1, aUAViewsNULL, NULL);

    return hr;
}

No error if the RWBuffer reference in the shader is removed.

cbuffer SampleCB: register(b0)
{
    uint WidthA;
    uint HeightA;
    uint WidthB;
    uint HeightB;
    uint WidthOut;
    uint HeightOut;
};

struct SimpleBufType
{
    float val;
};

StructuredBuffer<SimpleBufType> MatrixA : register(t0);
Buffer<float> MatrixB: register(t1);

RWBuffer<float> Output : register(u0); //compiles if this is removed (as well as the output below)


[numthreads(1, 1, 1)]
void main( uint3 DTid : SV_DispatchThreadID )
{
    if (DTid.x < WidthB && DTid.y < HeightA)
    {
        float sum = 0;

        for (uint i = 0; i != WidthA; i++)
        {
            uint addrA = DTid.y * WidthA + i;
            uint addrB = DTid.x + i * WidthB;

            sum += MatrixA[addrA].val * MatrixB[addrB];
        }
        Output[DTid.y * WidthOut + DTid.x] = sum;
    }
}

Visual Studio is configured correctly I believe, I can use shaders 5.0 in another program.

Visual Studio 2019 Settings

Any idea what is causing the error? How to ensure the ComputeShader is defined as a cs_5_0 shader?


Solution

  • Switched the RWBuffer forRWStructuredBuffer and it works

    Still looking for indication about the error message and what is causing the issue with RWBuffer.