4 // Keeps a pool of persistently mapped PBOs around that can be used as staging
5 // buffers for texture uploads. (Uploading from a PBO is asynchronous and done
6 // by the GPU, so assuming we don't need an extra copy into the PBO, this is a
7 // significant win over uploading from regular malloc-ed RAM.)
9 // Unlike Nageru's PBOFrameAllocator, these are not connected to
10 // a given frame, since we can have thousands of frames in the cache
11 // at any given time. Thus, we need to have separate fences for each PBO
12 // to know that the upload is done.
19 #include "shared/ref_counted_gl_sync.h"
23 uint8_t *ptr; // Mapped memory.
24 RefCountedGLsync upload_done;
29 PBOPool(size_t pbo_size = 8 << 20, // 8 MB, large enough for 1080p 4:2:2.
31 GLenum buffer = GL_PIXEL_UNPACK_BUFFER_ARB,
32 GLenum permissions = GL_MAP_WRITE_BIT,
33 GLenum map_bits = GL_MAP_FLUSH_EXPLICIT_BIT);
36 void release_pbo(PBO pbo); // Set a fence on upload_done if the PBO may still be in use.
41 std::mutex freelist_mutex;
42 std::queue<PBO> freelist;
45 GLenum buffer, permissions, map_bits;
48 extern PBOPool *global_pbo_pool;
49 void init_pbo_pool(); // Idempotent.
51 #endif // !defined(_PBO_POOL_H)