我什么时候可以发布源 PBO?
我正在使用 PBO 在 CPU 和 GPU 之间异步移动数据。
当从 GPU 移动时,我知道在 PBO 上调用 glMapBuffer 后可以删除源纹理。
然而,反过来又如何呢?我什么时候知道从 PBO 到纹理 (glTexSubImage2D(..., NULL)) 的传输已完成并且我可以安全地释放或重新使用 PBO?是我绑定纹理后立即还是其他什么?
I'm using PBOs to asynchronously move data between my cpu and gpu.
When moving from the GPU i know I can delete the source texture after I have called glMapBuffer on the PBO.
However, what about the other way around? When do I know that the transfer from the PBO to the texture (glTexSubImage2D(..., NULL)) is done and I can safely release or re-use the PBO? Is it as soon as I bind the texture or something else?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为在调用
glTexImage
之后,您可以安全地删除或重用缓冲区,而不会出现错误,因为驱动程序会为您处理一切,包括延迟销毁(这是缓冲区对象的优势)。但这意味着,对glMapBuffer
的调用可能会阻塞,直到前面的glTexImage
复制完成。如果您想重用缓冲区并覆盖其全部内容,通常的做法是在调用glMapBuffer
之前使用glBufferData
重新分配它。这样驱动程序就知道您不再关心以前的内容,并且可以分配一个可以立即使用的新缓冲区(当确实不再使用包含以前内容的内存时,驱动程序会释放它)。请记住,您的缓冲区对象只是内存的句柄,驱动程序可以根据需要管理和复制。编辑:这意味着以另一种方式(GPU-CPU),您可以在
glGetTexImage
返回后删除源纹理,因为驱动程序管理幕后的所有内容。是否使用缓冲区对象的决定不应该对调用 GL 函数的顺序和时间产生任何影响。请记住,调用glDelete...
不会立即删除对象,它只是将此命令排入 GL 命令流中,即使这样,也取决于驱动程序何时真正释放任何内存。I think after calling
glTexImage
you are safe in deleting or reusing the buffer without errors, as the driver handles everything for you, including deferred destruction (that's the advantage of buffer objects). But this means, that calls toglMapBuffer
may block until the precedingglTexImage
copy has completed. If you want to reuse the buffer and just overwrite its whole content, it is common practice to realocate it withglBufferData
before callingglMapBuffer
. This way the driver knows you don't care about the previous content anymore and can allocate a new buffer that you can use immediately (the memory containing the previous content is then freed by the driver when it is really not used anymore). Just keep in mind that your buffer object is just a handle to memory, that the driver can manage and copy as it likes.EDIT: This means in the other way (GPU-CPU) you can delete the source texture after
glGetTexImage
has returned, as the driver manages everything behind the scenes. The decision of using buffer objects or not should not have any implications on the order and time in which you call GL functions. Keep in mind that callingglDelete...
does not immediately delete an object, it just enqueues this command into the GL command stream and even then, its up to the driver when it really frees any memory.