A basic questions about shader resources (textures)

Started by
2 comments, last by kubera 12 years ago
Hi!

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:

ShaderA:
PSSetShaderResources( { X, Y } )
ShaderB:
PSSetShaderResources( { Z, NULL } )


or

ShaderA:
PSSetShaderResources( { X, Y } )
ShaderB:
PSSetShaderResources( { Z } )


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

Thank you very much.
Advertisement
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.
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.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

Thank you very much for the answers.

This topic is closed to new replies.

Advertisement