我有一个应用程序,它使用 Opengl 和像素缓冲区对象执行大量 GPGPU 来传输和处理数据。
目前我使用了这些资源的池,基本上我有一个池用于我的应用程序使用的每个缓冲区尺寸和用法。当资源的使用结束时,它返回到各自的池中以供重新使用。但是,我开始犹豫是否有任何问题,因为我需要在重新使用之前“孤立”PBO,以免干扰正在进行的传输。
我的问题是,池化资源(例如 PBO 和纹理)是否有任何好处,或者在需要时直接从 OpenGL 直接分配是否好?
这是我正在做的一个例子。反之亦然。
std::shared_ptr<pbo> create_pbo(int size, bool write)
{
auto pool = pbo_pools[write][size];
std::shared_ptr<pbo> buffer;
if(!pool->try_pop(buffer))
buffer = ogl_thread_.invoke([=]{return new pbo(size, write);});
return spl::shared_ptr<pbo>(buffer.get(), [=](pbo*) mutable
{
ogl_thread_.begin_invoke([=]() mutable
{
if(write)
buffer->map();
else // read
buffer->unmap();
pool->push(buffer);
});
});
}
最佳答案
I'm starting to have seconds thoughts whether there is any is in this since I need "orphan" the PBOs before re-use to not interfere with ongoing transfers.
不,你不必这样做。这就是 PBO 的好处:您可以向它们提交新数据,而对 glTex(Sub)Image 的调用可能仍在从它们读取数据,而不会破坏读取操作。
关于c++ - 汇集 PBO 和纹理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9166680/