Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
add comment

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.

share|improve this answer
    
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 –  Koarl Sep 14 '11 at 15:35
    
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? –  Koarl Sep 14 '11 at 15:43
    
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 ! –  LeSnip3R Sep 15 '11 at 13:44
    
I see. Thanks for your take on things. –  Koarl Sep 15 '11 at 17:22
    
If you don't mind, could you please mark the question as solved if my answer satisfied you ? Thank you. –  LeSnip3R Sep 16 '11 at 13:04
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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