Is there any particular reason not to not use a single sampler state for multiple textures?

Is there any particular reason not to not use a single sampler state for multiple textures, or even a texture 2d array aside from readability and ease of creating the shader? does it come with some performance cost, or some loss of feature or something. i am trying to plan my material for my terrain and want to know what i’m getting into before deciding.

Connect as you want to. Pretty common. Some people like their shaders to sample separately, just so they can be tiled at different scales or a single texture can scroll while the rest doesn’t.

This is incorrect. Neither of those cases are reliant on having separate sampler states. Those only require different UVs.

On some hardware, unique sampler states per texture is better for performance. On others it’s worse for performance. And on others it makes no difference either way.

In the past each sampler state was tied directly to the physical TMU (Texture Mapping Unit) hardware on the GPU during the execution of the shader, and multiple textures could be sampled in parallel only if they used separate sampler states, and thus a separate TMU. This hasn’t been the case in decades though. On modern hardware the sampler state is just another bit of data sent to the TMU (or equivalent hardware) when sampling the texture. However there might be some cost to changing state, or still some limitations that a single sampler state can’t be reused in parallel for a single pixel. It’s hard to know exactly why as the low level of how this stuff actually works on modern GPUs is usually a trade secret, and unique to each GPU.

Similarly texture arrays can have serious performance impacts for some GPUs, even when compared to using an atlas or reusing a sampler state for all texture samples. But that’s mostly only an issue for some mobile GPUs.

However the TLDR version is, do what’s best for your shader, then see how it runs on your target hardware. That’s really the only way to know.

2 Likes