One of the major changes I have encountered between Direct3D 9 and Direct3D 11 is the new API for setting up texture sampling. In D3D9, it was sufficient to simply set a given value of a given property to a given sampler index and safely assume that state would remain (and be unaffected by other state changes) for as long as was needed by the application.

direct3Ddevice->SetSamplerState(samplerIndex, D3DSAMP_MAXANISOTROPY, value);

However, in D3D11, the process is a little more involved. First you create and populate an object of type D3D11_SAMPLER_DESC, then from that object create an ID3D11SamplerState, then apply that to a sampler index.

desc.MaxAnisotropy = value;
ID3D11SamplerState * state = 0;
direct3Dcontext->PSSetSamplers(samplerIndex, 1, &state);

I understand that this is designed to minimise the number of queued requests per frame by batching potentially a whole bunch of state changes into one object... However, if the developer wanted to, say, put a global anisotropic filtering setting in their game's options screen, they'd need to keep copies of the sampler descriptions of every sampler they use for every shader (to ensure that no other parameters would get lost), then iterate through all of those copies to apply the new filtering level, and recreate all those state objects.

Surely there must be a simpler way to apply a single sampler setting globally for an application?


No, there is not a simpler way. As you said, you must recreate all sampler objects that are affected by a change.

However, it doesn't have to be a lot of work. Typically, you can share a few samplers across many shaders. I typically have a single sampler with trilinear/aniso filtering and repeat addressing, reused for textures across all shaders. If the aniso setting is changed, only that one sampler needs to be recreated. I have another sampler with bilinear filtering and clamp addressing that's reused for all image resizing/postprocessing operations, and so on. You don't need to (and probably shouldn't) create a separate sampler object for every shader or texture.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.