Jump to content

  • Log In with Google      Sign In   
  • Create Account

Store G-buffer in render target or structured buffer?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 NotTakenSN   Members   -  Reputation: 149

Like
0Likes
Like

Posted 25 February 2013 - 02:58 PM

What's the best way for creating a g-buffer? Most of the documentation I've read suggest rendering the scene geometry normally and then writing to multiple render targets. A drawback to this method is that render targets have to be in the four 32-bit value format. This could waste memory space and bandwidth if you're not writing a multiple of four 32-bit values. Also, it restricts the geometric data alignment to single rows (where each row starts at xmin and increases to xmax with the same y value), when small tiles might be better for coalesced memory access later on in a compute shader.

 

Is it a better idea instead to write to a structured buffer? How would you go about doing the depth testing to ensure that the final value written into the structured buffer is actually on top? I would think one method would be to explicitly read the depth buffer, compare the values, then write to both the depth buffer and g-buffer if the test passes. The other option would be to define the earlydepthstencil attribute so that only fragments that pass the depth test can invoke the pixel shader (which writes the value to the g-buffer). Does this actually work? Are there major setbacks to this method?



Sponsor:

#2 MJP   Moderators   -  Reputation: 11380

Like
1Likes
Like

Posted 25 February 2013 - 03:58 PM

. A drawback to this method is that render targets have to be in the four 32-bit value format.

 

What makes you think that this is the case? You can choose whatever formats you want for your G-Buffer render targets, including those that have less than 4 components or that don't use full 32-bit precision for each component.

At any rate, I've never tried using a structured buffer as a G-Buffer and I don't know of anyone else that has. I think it should work okay, though. You definitely want to use the [earlydepthstencil] attribute, since this will not only ensure correct data in your G-Buffer but it will also enable the same optimizations used when rendering to a render target. The one major drawback that I can think of is that you would not be able to use MSAA with this setup. I would also suspect that it will not perform as well, due to specific optimizations in the hardware and driver used for writing to render target textures. But that's something you'd have to profile on different hardware to know for sure.



#3 Jason Z   Crossbones+   -  Reputation: 5062

Like
1Likes
Like

Posted 25 February 2013 - 05:01 PM

What's the best way for creating a g-buffer?

I completely understand where you are coming from with this question, but there is almost always no good answer to a 'what is the best way...' question when it comes to real time rendering - especially on a PC where the hardware varies from machine to machine.  To extend MJPs comments, if your particular situation calls for a very small G-buffer format, then you could probably use a smaller pixel format and save lots of memory.  Or, if your data is very large and you don't need coherent access to it, then a structured buffer might make more sense...  there is no good answer that is valid for all situations.

 

The best advice is to design your system accordingly so that trying out different methods for doing the same thing is easy.  In this case it wouldn't be such a big change, mostly some HLSL changes about how you write and access the data.  Try building the two methods in parallel, and then set up a specific test case that should exercise the usage that you expect to behave differently between the two.  You will learn more about the behavior of the algorithms this way, and then you will have data to back up your decisions.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS