DirectXShaderCompiler icon indicating copy to clipboard operation
DirectXShaderCompiler copied to clipboard

SamplerDescriptorHeap[sampIdx] cannot be used inside of texture.Sample(...)

Open alextardif-zmi opened this issue 2 years ago • 1 comments

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!

alextardif-zmi avatar Jun 17 '22 22:06 alextardif-zmi

https://godbolt.org/z/6h1Kxo9sG

pow2clk avatar Apr 15 '24 21:04 pow2clk