Ternary operator with SamplerStates

45 Views Asked by At

Is it possible to do something like this in HLSL:

SamplerState Sampler0 : register(s0, space1);
SamplerState Sampler1 : register(s1, space1);

int samplerIndex;
// ...

float4 color = texture.Sample(samplerIndex == 1 ? Sampler0 : Sampler1, uv);

I got an error that: local resource not guaranteed to map to unique global resource

1

There are 1 best solutions below

0
Chuck Walbourn On

For this scenario, you are better off either:

(a) Building the same shader twice with two different static samplers.

-or-

(b) Use heap-based samplers so you can switch it out.

For examples of various 'combinations' handling, see DirectX Tool Kit for DX12