gpt4 book ai didi

opengl - 在覆盖整个帧缓冲区之前是否首选 glClear(GL_COLOR_BUFFER_BIT) ?

转载 作者:行者123 更新时间:2023-12-04 13:47:52 26 4
gpt4 key购买 nike

我看到了不同的意见。
目前,我只关心颜色数据。

Chapter 28. Graphics Pipeline Performance , 它说:

Avoid extraneous color-buffer clears. If every pixel is guaranteed to be overwritten in the frame buffer by your application, then avoid clearing color, because it costs precious bandwidth.



How does glClear() improve performance? ,它引用自 Apple's Technical Q&A on addressing flickering (QA1650) :

You must provide a color to every pixel on the screen. At the beginning of your drawing code, it is a good idea to use glClear() to initialize the color buffer. A full-screen clear of each of your color, depth, and stencil buffers (if you're using them) at the start of a frame can also generally improve your application's performance.



那篇文章中有一个答案:

By issuing a glClear command, you are telling the hardware that you do not need previous buffer content, thus it does not need to copy the color/depth/whatever from the framebuffer to the smaller tile memory.



对于那个答案,我的问题是:
如果没有混合,为什么我们需要从帧缓冲区中读取颜色数据。
(目前,我只关心颜色数据)

但无论如何,一般来说,我是否需要调用 glClear(GL_COLOR_BUFFER_BIT)

最佳答案

In Chapter 28. Graphics Pipeline Performance, it says:



有很多不同种类的硬件。在打印 GPU Gems #1 时流行的硬件上,这个建议是合理的。如今它不再是。

曾几何时,清除缓冲区实际上意味着硬件将访问每个像素并写入清除值。这个过程显然占用了大量的 GPU 时间,因此高性能应用程序开发人员尽最大努力 avoid incurring the wrath of the clear operation .

如今(我的意思是至少在过去 8 到 10 年内制造的几乎所有 GPU),图形芯片在清除方面更加智能。他们没有清除,而是使用帧缓冲区的缓存玩游戏。

在执行读取/修改/写入操作时,清除帧缓冲区图像的值很重要。这包括混合等,但也包括任何形式的深度或模板测试。为了执行 RMF 操作,您必须首先读取那里的值。

这就是聪明之处。当您“清除”帧缓冲区图像时,不会写入任何内容。相反,帧缓冲区图像地址空间无效。当读取操作发生在无效地址上时,它只返回清除值。这成本为零带宽。实际上,它节省了带宽,因为读取操作实际上不必读取内存。它只是获取一个明确的值。

根据缓存的工作方式,在进行纯写操作时,这甚至可能更快。但这取决于不同的硬件。

对于使用基于图块的渲染的移动硬件,这更重要。在 tile 开始处理之前,它必须读取帧缓冲区图像的当前值。如果图像被清除,则不需要读取任何内容;它只是将平铺内存设置为清晰的颜色。

即使您没有混合到帧缓冲区,这种情况也很重要。为什么?因为 GPU 和 API 都不知道您不会进行混合。它只知道您将对该图像执行一定数量的渲染操作。所以它必须假设最坏的情况并将图像读入瓷砖。当然,除非你事先清除了它。

简而言之,当将这些图像用于帧缓冲区时,首先清除图像通常不会比不清除图像慢。

以上都假设您清除了整个图像。如果您只清除图像的一个子区域,则不太可能发生此类优化。尽管它仍然是可能的,至少对于基于缓存行为的优化而言。

关于opengl - 在覆盖整个帧缓冲区之前是否首选 glClear(GL_COLOR_BUFFER_BIT) ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37335281/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com