microsoft / DirectXTK

The DirectX Tool Kit (aka DirectXTK) is a collection of helper classes for writing DirectX 11.x code in C++
https://walbourn.github.io/directxtk/
MIT License
2.54k stars 505 forks source link

Error with custom shaders #446

Closed ran-j closed 3 months ago

ran-j commented 3 months ago

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();

but I got this strange error image

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.

ran-j commented 3 months ago

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.

walbourn commented 3 months ago

You didn't include your custom shader source, but are you sure the if (sampler) clause of your lambda is being executed?

ran-j commented 3 months ago

I'm 100% sure that if (sampler) works.

https://github.com/microsoft/DirectXTK/assets/17410205/b7999d05-ac12-4455-ae1c-553dcb892e1b

As I said if I disable directx warnings it works super fine.

walbourn commented 3 months ago

As the warning indicates, it will 'work' but the warning is recommending you fix it since it is often very confusing.