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

<p>Here is what it should be like.</p>

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

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

    return true;
}
</code></pre>

<p><a href="https://www.gamedev.net/forums/topic/700419-r16_float-samplecmp-and-checkformatsupport/?tab=comments#comment-5397459" rel="nofollow noreferrer">https://www.gamedev.net/forums/topic/700419-r16_float-samplecmp-and-checkformatsupport/?tab=comments#comment-5397459</a></p>

CC BY-SA 4.0
2018-12-23T18:00:50.500Z
2018-12-23T18:00:50.500Z
ACskyline
<p>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:</p>

<blockquote>
  <p>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).</p>
</blockquote>

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

<pre><code>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-&gt;CheckFormatSupport(DXGI_FORMAT_R16_FLOAT, &amp;formatSupport);
    printf("result: %d\n", hr);
    if (!SUCCEEDED(hr))
    {
        printf("Nope!\n");
        return false;
    }

    return true;
}
</code></pre>

<shadow><hlsl><directx11><shadow-mapping><direct3d>
R16_FLOAT, SampleCmp and CheckFormatSupport
ACskyline
# R16_FLOAT, SampleCmp and CheckFormatSupport

(Asked by: username_0 on 2018-12-23)

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;
}

```

**Tags:** shadow, hlsl, directx11, shadow-mapping, direct3d


---

## 1 answers

### Answer by username_0 on 2018-12-23. Score: 1 | Accepted answer

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>


---

