Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly use glDiscardFramebufferEXT

This question relates to the OpenGL ES 2.0 Extension EXT_discard_framebuffer.

It is unclear to me which cases justify the use of this extension. If I call glDiscardFramebufferEXT() and it puts the specified attachable images in an undefined state this means that either:
- I don't care about the content anymore since it has been used with glReadPixels() already,
- I don't care about the content anymore since it has been used with glCopyTexSubImage() already,
- I shouldn't have made the render in the first place.

Clearly, only the 1st two cases make sense or are there other cases in which glDiscardFramebufferEXT() is useful? If yes, which are these cases?

like image 812
rsp1984 Avatar asked Jan 16 '23 22:01

rsp1984


2 Answers

glDiscardFramebufferEXT is a performance hint to the driver. Mobile GPUs use tile based deferred rendering. In that context setting any of your framebuffer to be discarded saves the gpu work and memory bandwith as it does not need to write it back to uniform memory.

Typically you will discard:

  • the depth buffer as it is not presented on screen. It is just used during rendering on the gpu.
  • the msaa buffer as it is resolved to a smaller buffer for presenting to screen.

Additionally any buffer that is just used for rendering on the GPU should be discarded so it is not written back to uniform memory.

like image 178
wulfgeng Avatar answered Jan 18 '23 22:01

wulfgeng


The main situation where I've seen DiscardFramebuffer used is when you have a multi-sampled renderbuffer that you just resolved to a texture using BlitFramebuffer or ResolveMultisampleFramebufferAPPLE (on iOS) in which case you no longer care about the contents of the original buffer.

like image 44
eodabash Avatar answered Jan 19 '23 00:01

eodabash