From ede96fa4868bc646c6230d948d11cf1a7b1f1179 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Sat, 30 May 2020 16:50:27 +1000 Subject: [PATCH] [client] egl: don't map the texture until it's needed The texture buffer may still be in use if we try to re-map it immediately, instead only map when we need it mapped, and unmap immediately after advancing the offset allowing the render thread to continue while the unmap operation occurs --- VERSION | 2 +- client/renderers/EGL/texture.c | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/VERSION b/VERSION index deaf99cd..c8672650 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -B2-rc2-8-gfcbdf7ba4f+1 \ No newline at end of file +B2-rc2-9-g67dec216d2+1 \ No newline at end of file diff --git a/client/renderers/EGL/texture.c b/client/renderers/EGL/texture.c index 7c1bce76..9353559f 100644 --- a/client/renderers/EGL/texture.c +++ b/client/renderers/EGL/texture.c @@ -300,9 +300,6 @@ bool egl_texture_setup(EGL_Texture * texture, enum EGL_PixelFormat pixFmt, size_ NULL, GL_MAP_WRITE_BIT ); - - if (!egl_texture_map(texture, i)) - return false; } return true; @@ -335,12 +332,15 @@ bool egl_texture_update(EGL_Texture * texture, const uint8_t * buffer) return true; } + if (!egl_texture_map(texture, s.w)) + return EGL_TEX_STATUS_ERROR; + memcpy(texture->tex[s.w].map, buffer, texture->pboBufferSize); atomic_store_explicit(&texture->state.w, next, memory_order_release); + egl_texture_unmap(texture, s.w); } else { - /* Non streaming, this is NOT thread safe */ for(int p = 0; p < texture->planeCount; ++p) { glBindTexture(GL_TEXTURE_2D, texture->tex[0].t[p]); @@ -368,6 +368,9 @@ bool egl_texture_update_from_frame(EGL_Texture * texture, const FrameBuffer * fr return true; } + if (!egl_texture_map(texture, s.w)) + return EGL_TEX_STATUS_ERROR; + framebuffer_read( frame, texture->tex[s.w].map, @@ -379,6 +382,8 @@ bool egl_texture_update_from_frame(EGL_Texture * texture, const FrameBuffer * fr ); atomic_store_explicit(&texture->state.w, next, memory_order_release); + egl_texture_unmap(texture, s.w); + return true; } @@ -395,7 +400,6 @@ enum EGL_TexStatus egl_texture_process(EGL_Texture * texture) return texture->ready ? EGL_TEX_STATUS_OK : EGL_TEX_STATUS_NOTREADY; /* update the texture */ - egl_texture_unmap(texture, s.u); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, texture->tex[s.u].pbo); for(int p = 0; p < texture->planeCount; ++p) { @@ -417,9 +421,6 @@ enum EGL_TexStatus egl_texture_process(EGL_Texture * texture) texture->ready = true; atomic_store_explicit(&texture->state.u, nextu, memory_order_release); - if (!egl_texture_map(texture, s.u)) - return EGL_TEX_STATUS_ERROR; - return EGL_TEX_STATUS_OK; }