DirectXShaderCompiler
DirectXShaderCompiler copied to clipboard
SamplerDescriptorHeap[sampIdx] cannot be used inside of texture.Sample(...)
The following is a sample from this document: https://microsoft.github.io/DirectX-Specs/d3d/HLSL_SM_6_6_DynamicResources.html
Texture2D<float4> myTexture = ResourceDescriptorHeap[texIdx];
float4 result = myTexture.Sample(SamplerDescriptorHeap[sampIdx], coord);
But in practice (with the December 2021 release), doing this results in compilation errors:
MyShader.hlsl: error: no matching member function for call to 'Sample'
float4 result = myTexture.Sample(SamplerDescriptorHeap[sampIdx], coord);
~~~~~~~~~~~~~^~~~~~
note: candidate function template not viable: requires 3 arguments, but 2 were provided
note: candidate function template not viable: requires 4 arguments, but 2 were provided
note: candidate function template not viable: requires 5 arguments, but 2 were provided
Creating a separate SamplerState variable to store it and then using that works, casting within the Sample function like this also works:
myTexture.Sample(((SamplerState)SamplerDescriptorHeap[sampIdx]), coord);
Presumably some confusion between SamplerState and SamplerComparisonState, but since these use Sample() and SampleCmp() respectively, we might still expect it to just work.
Thank you for your time!
https://godbolt.org/z/6h1Kxo9sG