How to sample a texture in a compute shader ?

Hello,

I am trying to sample a texture in a compute shader. Following the compute shader documentation page. You need to create a sampler, then use texture.Sample().

I defined my texture and sampler as

Texture2D<float4> myTexture;
SamplerState linearClampSampler

and call it as float4 color = myTexture.Sample(linearClampSampler, uv);

However, this gives me an cannot map expression to cs_5_0 instruction set error

What is the correct way to sample a texture in a compute shader ?

1 Like

It turns out SampleLevel works

float4 color = myTexture.SampleLevel(linearClampSampler, uv, 0);

I wish this kind of simple example was added in the compute shader documentation.

8 Likes

@barbelot Coz Mipmapping sampling is not defined in compute shader pipeline, you need to specifiy the texture lod manully

3 Likes