[client] egl: don't unmap/map all buffers for each frame

This commit is contained in:
Geoffrey McRae 2020-05-29 15:48:59 +10:00
parent d7921c5d5f
commit 28c93ef5ac
2 changed files with 41 additions and 32 deletions

View File

@ -1 +1 @@
B2-rc2-4-g6d296f2b44+1 B2-rc2-5-gd7921c5d5f+1

View File

@ -123,11 +123,8 @@ void egl_texture_free(EGL_Texture ** texture)
*texture = NULL; *texture = NULL;
} }
static bool egl_texture_map(EGL_Texture * texture) static bool egl_texture_map(EGL_Texture * texture, uint8_t i)
{ {
// release old PBOs and delete and re-create the buffers
for(int i = 0; i < TEXTURE_COUNT; ++i)
{
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, texture->tex[i].pbo); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, texture->tex[i].pbo);
texture->tex[i].map = glMapBufferRange( texture->tex[i].map = glMapBufferRange(
GL_PIXEL_UNPACK_BUFFER, GL_PIXEL_UNPACK_BUFFER,
@ -143,23 +140,35 @@ static bool egl_texture_map(EGL_Texture * texture)
EGL_ERROR("glMapBufferRange failed for %d of %lu bytes", i, texture->pboBufferSize); EGL_ERROR("glMapBufferRange failed for %d of %lu bytes", i, texture->pboBufferSize);
return false; return false;
} }
}
return true;
}
static bool egl_texture_map_all(EGL_Texture * texture)
{
// release old PBOs and delete and re-create the buffers
for(int i = 0; i < TEXTURE_COUNT; ++i)
if (!egl_texture_map(texture, i))
return false;
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
return true; return true;
} }
static void egl_texture_unmap(EGL_Texture * texture) static void egl_texture_unmap(EGL_Texture * texture, uint8_t i)
{ {
for(int i = 0; i < TEXTURE_COUNT; ++i)
{
if (!texture->tex[i].map) if (!texture->tex[i].map)
continue; return;
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, texture->tex[i].pbo); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, texture->tex[i].pbo);
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
texture->tex[i].map = NULL; texture->tex[i].map = NULL;
} }
static void egl_texture_unmap_all(EGL_Texture * texture)
{
for(int i = 0; i < TEXTURE_COUNT; ++i)
egl_texture_unmap(texture, i);
} }
bool egl_texture_setup(EGL_Texture * texture, enum EGL_PixelFormat pixFmt, size_t width, size_t height, size_t stride, bool streaming) bool egl_texture_setup(EGL_Texture * texture, enum EGL_PixelFormat pixFmt, size_t width, size_t height, size_t stride, bool streaming)
@ -275,7 +284,7 @@ bool egl_texture_setup(EGL_Texture * texture, enum EGL_PixelFormat pixFmt, size_
} }
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
egl_texture_unmap(texture); egl_texture_unmap_all(texture);
// release old PBOs and delete and re-create the buffers // release old PBOs and delete and re-create the buffers
for(int i = 0; i < TEXTURE_COUNT; ++i) for(int i = 0; i < TEXTURE_COUNT; ++i)
@ -295,7 +304,7 @@ bool egl_texture_setup(EGL_Texture * texture, enum EGL_PixelFormat pixFmt, size_
); );
} }
if (!egl_texture_map(texture)) if (!egl_texture_map_all(texture))
return false; return false;
return true; return true;
@ -389,7 +398,7 @@ enum EGL_TexStatus egl_texture_process(EGL_Texture * texture)
return texture->ready ? EGL_TEX_STATUS_OK : EGL_TEX_STATUS_NOTREADY; return texture->ready ? EGL_TEX_STATUS_OK : EGL_TEX_STATUS_NOTREADY;
/* update the texture */ /* update the texture */
egl_texture_unmap(texture); egl_texture_unmap(texture, s.u);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, texture->tex[s.u].pbo); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, texture->tex[s.u].pbo);
for(int p = 0; p < texture->planeCount; ++p) for(int p = 0; p < texture->planeCount; ++p)
{ {
@ -407,12 +416,12 @@ enum EGL_TexStatus egl_texture_process(EGL_Texture * texture)
/* we must flush to ensure the sync is in the command buffer */ /* we must flush to ensure the sync is in the command buffer */
glFlush(); glFlush();
texture->ready = true;
atomic_store_explicit(&texture->state.u, nextu, memory_order_release); atomic_store_explicit(&texture->state.u, nextu, memory_order_release);
/* remap the for the next update */ /* remap the for the next update */
egl_texture_map(texture); egl_texture_map(texture, s.u);
texture->ready = true;
return EGL_TEX_STATUS_OK; return EGL_TEX_STATUS_OK;
} }