Sign in to follow this  
kubera

A basic questions about shader resources (textures)

Recommended Posts

[b]Hi![/b]

Could someone answer a simple qestion, please?
I have a few shaders.
They are using the different count of shader resources.
Have I to set unused slots to NULL before rendering?

Example (pseudocode):

ShaderA uses textures X and Y.
ShaderB uses only one, Z:

Which option is more correct:
[CODE]
ShaderA:
PSSetShaderResources( { X, Y } )
ShaderB:
PSSetShaderResources( { Z, NULL } )[/CODE]

or
[CODE]
ShaderA:
PSSetShaderResources( { X, Y } )
ShaderB:
PSSetShaderResources( { Z } )[/CODE]

They work similarly, but which is better?
(more efficient, more safe, etc.)

[i]Thank you very much.[/i]

Share this post


Link to post
Share on other sites
You don't have to set unused slots back to NULL. It can make things easier when you're debugging in PIX, and it can also make it easier to avoid read/write conflicts that occur when you have a resource bound as both an input and an output. But in general it's not necessary, and I don't think there's much performance difference.

Share this post


Link to post
Share on other sites
I'd use PSSetShaderResources ({X, Y, Z}), then read from slots 0 and 1 in Shader A and from slot 2 in Shader B. PSSetShaderResources will persist across shader changes (it belongs to the context, not the shader, so it makes sense that it does when you think about it) and you'll only need to set it once.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this