2
\$\begingroup\$

I don't understand this error. The full output being :

The Pixel Shader unit expects a Sampler configured for default filtering to be set at Slot 0, but the sampler bound at this slot is configured for comparison filtering.

Here is how I create the sampler state.

// Skybox sampler description
D3D11_SAMPLER_DESC skyboxSamplerDesc;
ZeroMemory(&skyboxSamplerDesc, sizeof(D3D11_SAMPLER_DESC));
skyboxSamplerDesc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT;
skyboxSamplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
skyboxSamplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
skyboxSamplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
skyboxSamplerDesc.MipLODBias = 0.0f;
skyboxSamplerDesc.MaxAnisotropy = 16;
skyboxSamplerDesc.ComparisonFunc = D3D11_COMPARISON_EQUAL;
skyboxSamplerDesc.MinLOD = 0;
skyboxSamplerDesc.MaxLOD = D3D11_FLOAT32_MAX;

// Create the skybox texture sampler state
hr = g_d3dDevice->CreateSamplerState(&skyboxSamplerDesc, &g_SkyboxSamplerState);
if (FAILED(hr)) return false;

The bindings.

ID3D11SamplerState* samplerStates[2];
samplerStates[0] = g_SkyboxSamplerState;
samplerStates[1] = g_PixelDepthSamplerState;
g_d3dDeviceContext->PSSetSamplers(0, 2, samplerStates);

HLSL side.

SamplerState sbSamplerState : register (s0) {
    Filter = MIN_MAG_LINEAR_MIP_POINT;
    AddressU = CLAMP;
    AddressV = CLAMP;
    AddressW = CLAMP;
    ComparisonFunc = EQUAL;
};
\$\endgroup\$
4
+50
\$\begingroup\$

If your C++ code should specify the actual filtering state, your HLSL shader should not specify it, since everything written there will overwrite it (which is a feature of the effect-framework, not HLSL itself). This might be a bit weird, but works normally just fine. However, you are using a comparison filter on the C++ side (in your case D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT) and not on the HLSL side. Since everything should work without the effect-framework (the part that specifies the state within the shader), you are not allowed to set the comparision filter in the C++ code, since the HLSL code expects a default (non-comparision) sampler state type. So you need SamplerComparisonState instead:

SamplerComparisonState sbSamplerState : register (s0);

If you want, you can still keep the filtering state in the shader, but in any case the sampler state type (comparison or not) needs to be the same, both in the HLSL code and in the C++ code.

\$\endgroup\$
7
  • \$\begingroup\$ I still have the same error with SamplerState sbSamplerState : register (s0);. The real question being : why does the pixel shader expects default filtering (and what does it mean actually) ? I don't want default filtering I want linear filtering. I don't have this error showing up if I set filtering to D3D11_FILTER_MIN_MAG_MIP_POINT C++ side but I don't want that. Can you please elaborate ? \$\endgroup\$
    – PinkTurtle
    Sep 2 '15 at 12:35
  • \$\begingroup\$ I overlooked the type mismatches with the Comparison filter and did make some half-true statements about the nature of specifying the sampler state in the shader. I hope everything is correct and more clear now. Sorry for the confusion! \$\endgroup\$
    – Wumpf
    Sep 2 '15 at 13:20
  • \$\begingroup\$ Wow cool. Ima verify this ASAP. I am not using the effects framework thing at all - is it mandatory ? What is it ? Is it not deprecated ? The only thing I am trying to achieve by the way is linear filtering, so the boundaring pixels of a texture coordinate are interpolated, unlike nearest pixel value where only the closest pixel is returned based on texture coordinates. \$\endgroup\$
    – PinkTurtle
    Sep 2 '15 at 13:42
  • 1
    \$\begingroup\$ All right my bad. I was using D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT when what I was looking for is actually D3D11_FILTER_MIN_MAG_MIP_LINEAR - I don't know what comparison filtering is supposed to mean. \$\endgroup\$
    – PinkTurtle
    Sep 2 '15 at 13:51
  • \$\begingroup\$ Using the effect framework is not mandatory, but I thought that specifing the sampler state is a feature of it. How do you compile the shader? \$\endgroup\$
    – Wumpf
    Sep 2 '15 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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