What's a good way to organize samplers for HLSL?
- by Rei Miyasaka
According to MSDN, I can have 4096 samplers per context. That's a lot, considering there's only a handful of common sampler states.
That tempts me to initialize an array containing a whole bunch of common sampler states, assign them to every device context I use, and then in the pixel shaders refer to them by index using : register(s[n]) where n is the index in the array.
If I want more samplers for whatever reason, I can just add them on after the last slot.
Does this work? If not, when should I set the samplers? Should it be done when by the mesh renderer? The texture renderer? Or alongside PSSetShader?
Edit: That trick I wrote above doesn't work (at least not yet), as the compiler gives me this error message when I try to use the same register twice:
error X4500: overlapping register semantics not yet implemented 's0'
So how do people usually organize samplers, then?