Error with custom shaders
ran-j opened this issue · 4 comments
Hey there, I`m facing a strange error while trying to set a second shader reource here is my code:
m_imageBatch->Begin(DirectX::DX11::SpriteSortMode::SpriteSortMode_Deferred,
m_alphaBlendState.Get(), nullptr, nullptr, cullMode, [=]
{
GetDeviceContext()->PSSetShader(material->GetPixelShader()->GetShader(), nullptr, 0);
if (auto cb = material->GetConstantBuffer())
{
auto buff = cb->GetBuffer();
GetDeviceContext()->PSSetConstantBuffers(0, 1, &buff);
}
if (sampler)
{
auto samplerRs = sampler->GetShaderResourceView();
GetDeviceContext()->PSSetShaderResources(1, 1, &samplerRs);
GetDeviceContext()->PSSetSamplers(1, 1, &sampler->m_sampler_state);
}
});
RECT rc = {size.left, size.top, size.left + size.width, size.top + size.height};
m_imageBatch->Draw(texture->GetShaderResourceView(), rc);
m_imageBatch->End();
D3D11 WARNING: ID3D11DeviceContext::DrawIndexed: The Pixel Shader unit expects a Sampler to be set at Slot 1, but none is bound. This is perfectly valid, as a NULL Sampler maps to default Sampler state. However, the developer may not want to rely on the defaults. [ EXECUTION WARNING #352: DEVICE_DRAW_SAMPLER_NOT_SET]
D3D11: **BREAK** enabled for the previous message, which was: [ WARNING EXECUTION #352: DEVICE_DRAW_SAMPLER_NOT_SET ]
Note I`m using the lastest verison (feb2024) with directx11.
Also I made obvius check like my pointers are not null etc.
This is a warning that I marked with a error.
If I just disable this warning works fine:
pInfoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_WARNING, true);
But the case is how can I solve this warning.
You didn't include your custom shader source, but are you sure the if (sampler)
clause of your lambda is being executed?
I'm 100% sure that if (sampler)
works.
2024-04-30.10-27-29.mp4
As I said if I disable directx warnings it works super fine.
As the warning indicates, it will 'work' but the warning is recommending you fix it since it is often very confusing.