In my Direct3D 11 application, I am using several sampler states to retrieve texture data. Some of them are used in all pixel shaders, some of them are only used in very specific ones.

The question may seem simple, but I was not able to find any decent information on the topic-

Are there any penalties (performance or otherwise) involved in creating a number of sampler states for the pixel shader stage of D3D11, setting them all at once and just never touching them again? My shaders would reference these samplers in HLSL if they need them (for instance some shaders would reference SamplerState linear_sampler : register(s0); while some others would reference SamplerState point_sampler : register(s1);, possibly without referencing s0 at all.

Also, is it correct, that if I never want to reference these samplers in my c++ code after creation and setting, I could just release my own external references after they are set and they will not get destroyed, as D3D is keeping internal references as long as they are "bound"(?) ? And even if had to somehow get a reference, I could simply use ID3D11DeviceContext::PSGetSamplers (of course accepting the involved performance penalty of the lookup), correct?


1 Answer 1


I don't have exact numbers as I have not done any benchmarks. That said, in my engine for compatibility with DirectX 9 I have one sampler per texture, so there are quite a few, and they are not always referenced in the shader. So far I have not noted any performance degradation compared to before we added DX9 support. As long as you create your sampler state at the beginning of the program and not (or rarely) during you should be fine (from the DirectX SDK documentation).

Concerning the references in the C++ side, I would want to hang onto them anyway; what happens when you change a sampler state ? You lose the previous one ? I'd store them somewhere "static" like says a static array of 16 samplers for example.

  • \$\begingroup\$ Thanks for your input! Concerning keeping references to SamplerStates in C++ code: Of course it depends on whether or not I can leave them bound. If I can leave all of them bound the whole time without any penalties, I don't see what I'd want to change about them since there are enough slots for every variant I might need. I'd rather set them up once and don't bother until it's absolutely necessary. And even if it is, I could still use PSGetSamplers as pointed out above, if I understood correctly \$\endgroup\$
    – Koarl
    Sep 14, 2011 at 15:35
  • \$\begingroup\$ Also, do you mean you have one sampler state per texture and set another sampler every time you set another texture? I don't know too much about DX9 (maybe sampler states work in different ways there) but that seems pretty redundant as most of your textures would surely utilize the same sampler states or did I completely misunderstand you there? \$\endgroup\$
    – Koarl
    Sep 14, 2011 at 15:43
  • \$\begingroup\$ That's because under DX9 each sampler was bound to exactly one texture. At least that's what I concluded after bashing my head for days wondering why my textures would display on the wrong sampler ! \$\endgroup\$ Sep 15, 2011 at 13:44
  • \$\begingroup\$ If you don't mind, could you please mark the question as solved if my answer satisfied you ? Thank you. \$\endgroup\$ Sep 16, 2011 at 13:04
  • \$\begingroup\$ To be frank, I was hoping to get some other sentiments on this as well. Also, from your answer it was not quite clear to me whether leaving samplers (or any kind of unused resources) bound to their respective pipeline stage involves any kind of penalty. \$\endgroup\$
    – Koarl
    Sep 21, 2011 at 7:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .