2
$\begingroup$

I want to use PCF shadow map on my d3d11 app. My shadow map is an R16_FLOAT texture. When I use SampleCmpLevelZero it didn't give a correct result. After enabling debug layer, it shows:

The Shader Resource View in slot 1 of the Pixel Shader unit is using the Format (R16_FLOAT). This format does not support 'SampleCmp' or 'SampleCmpLevelZero', at least one of which is being used on the Resource by the shader. This mismatch is invalid if the shader actually uses the view (e.g. it is not skipped due to shader code branching).

But when I query whether the format support SampleCmp using the code below, it returns 0 which means success. Can someone explain why?

bool Renderer::InitRenderer(HWND hwnd)
{
    if (!InitD3D11App(hwnd)) return false;
    InitViewport();

    UINT formatSupport = D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON;
    printf("Support?\n");
    HRESULT hr = d3d11Device->CheckFormatSupport(DXGI_FORMAT_R16_FLOAT, &formatSupport);
    printf("result: %d\n", hr);
    if (!SUCCEEDED(hr))
    {
        printf("Nope!\n");
        return false;
    }

    return true;
}
$\endgroup$

1 Answer 1

1
$\begingroup$

Because I was using the CheckFormatSupport wrong. The second parameter is supposed to be an input.

Here is what it should be like.

bool Renderer::InitRenderer(HWND hwnd)
{
    if (!InitD3D11App(hwnd)) return false;
    InitViewport();

    UINT formatSupport;
    HRESULT hr = d3d11Device->CheckFormatSupport(DXGI_FORMAT_R16_FLOAT, &formatSupport);
    if (!SUCCEEDED(hr) || !(formatSupport & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON))
    {
        printf("Not supported!\n");
        return false;
    }

    return true;
}

https://www.gamedev.net/forums/topic/700419-r16_float-samplecmp-and-checkformatsupport/?tab=comments#comment-5397459

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.