Jump to content
  • Advertisement
Sign in to follow this  
Yu Liu

How to retrieve a sampler state in SM5/D3D12

This topic is 870 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I need to use the tex2Dgrad() and I just used it in D3D9 + SM3 when we can easily write the following code in effect file:

 

sampler HeightSampler =
sampler_state
{
    Texture =(HeightTexture) ;
    MipFilter = LINEAR;
    MinFilter = LINEAR;
    MagFilter = LINEAR;
};

 

then we can call tex2Dgrad in this way:

 

tex2Dgrad(HeightSampler, MovedTex, dx, dy);

 

 

 

How can we get such a sampler state object in SM5 then?

Share this post


Link to post
Share on other sites
Advertisement

To be clearer about what you're doing in D3D9, the Effects framework is just a software wrapper.  Effects will pre-process this, take out the sampler states, replace them with a bunch of device->SetSamplerState calls, and optionally save and restore the previous state via stateblocks.  Effects in D3D11 will do similar but will create and set sampler state objects.  But the important thing to understand is that in each case Effects is nothing more than a software wrapper around the underlying API, and - in the absence of Effects - you can achieve the very same end result by just calling the underlying API directly yourself.

Share this post


Link to post
Share on other sites

Since you mention D3D12...

 

If you're getting into the habit of declaring your root signatures in HLSL then you can declare Static Samplers inline with the Root Signature. This is becoming quite common since actually a great many of the samplers that you want to use are known at shader-writing time and don't need to be configurable from code (it can also be a small perf win). Of course if you want some level of "Option Screen" configurability for things like Anisotropy Level then this won't help.

 

Static Samplers

Share this post


Link to post
Share on other sites

 Of course if you want some level of "Option Screen" configurability for things like Anisotropy Level then this won't help.

 

Just have a different rootsig file per option permutation  :D

Share this post


Link to post
Share on other sites

Thanks you guys so much for the help.

 

I finally found a alternative function in SM4 or later: SampleGrad(), so that I can call it with a existing texture and sampler in HLSL source:

 

g_txDiffuse.SampleGrad( g_samLinear, Input.Tex, ddx, ddy);

 

However I still wonder if we can use the old tex2Dgrad() in this case, as it requires a sampler argument that already bound to an texture, is there any way to initialize that kind of "sampler" in D3D12, I guess we should do that totally in CPU/C++ code side?

Share this post


Link to post
Share on other sites
D3D9/SM3 had samplers/textures as a single object.
D3D10/SM4 split them into two objects now, which must be configured in C++.

Share this post


Link to post
Share on other sites

D3D9/SM3 had samplers/textures as a single object.
D3D10/SM4 split them into two objects now, which must be configured in C++.

 

...and what this means is that in D3D10+ you can create a single sampler state and reuse it for multiple textures (because all the sampler state does is define how the texture is sampled, it has nothing to do with the actual texture itself).

 

So:

 

g_txDiffuse.SampleGrad( g_samLinear, Input.Tex, ddx, ddy);

g_txNormal.SampleGrad( g_samLinear, Input.Tex, ddx, ddy);

g_txSpecular.SampleGrad( g_samLinear, Input.Tex, ddx, ddy);

g_txLightmap.SampleGrad( g_samLinear, Input.Tex, ddx, ddy);

g_txWibble.SampleGrad( g_samLinear, Input.Tex, ddx, ddy);

 

Will sample 5 different textures using the same sampler state.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!