Advertisement

Good practices for sharing parameters between multiple shaders and cleaning pipeline state

Started by June 01, 2018 08:37 PM
1 comment, last by vinterberg 6 years, 8 months ago

Hey,

There are a few things which confuse me regarding DirectX 11 and HLSL shaders in general. I would be very grateful for your advice!

1. Let's take for example a scene which invokes 2 totally separate pipeline render passes interchangeably. I understand I need to bind correct shaders for each of the render pass and potentially blend/depth or rasterizer state but what about resources such as Constant Buffers, Shader Resource Views and Unordered Access Views? Assuming that the second render pass uses none of the resources used by the first pass, do I still need to unbind the resources and clean pipeline state after first pass? Or is it ok to leave pipeline with unbound garbage since anything I'd need to bind for second pass would overwrite contents in the appropriate register slots anyway?

2. Is it a good practice to assign register slots manually to all resources in HLSL?

3. I thought about assigning manually register slots for every distinct render pass up to the maximum slot limit if neccessary. For example in 1 render pass I invoke 3 CS's, 2 VS's and 2 PS's and for all resources used by those shaders I try to fill as many register slots as neccessary and potentially reuse many times the same slot in shaders sharing the same resource. I was wondering if there is any performance penalty or gain when I bind all of my needed resources at the start of render pass and never gonna have to do it again until next render pass? - this means potentially binding a lot of registers and having excessive number of bound resources for every shader that is run.

4. Is it a good practice to create a separate include file for every resource that occurs in >= 2 shader files or is it better to duplicate the declarations? In first case, the code is imo easier to maintain and edit but might be harder to read if there's too many includes. I've come up with a compromise between these 2 like this: create a separate include file for every CB that occurs in >= 2 shader files and a separate include file for every sampler I ever need to use. All other resources like srvs and uavs I prefer to duplicate in multiple shaders because they take much less space than CB for example... I'm not sure however if that's a good practice

1) It's okay to leave stuff bound, like cbuffers etc.. If it's not accessed by the new-bound shader, no need to unbind :) But of course if you need to render to a texture used as input, you need to unbind it first - and vice versa..

2) I always do it, makes it easier to see which resource is bound to which slot!

3) IMHO It's generally best practice to only bind big resources once (not every render pass), like texture atlas and such - every time you bind a resource, it's uploaded to VRAM (that's how I understand it anyways).

 

.:vinterberg:.

This topic is closed to new replies.

Advertisement