Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mgc::ShmBuffer: Fix texture setup synchronisation #3800

Merged
merged 3 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/test/mir/test/doubles/mock_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class MockGL
MOCK_METHOD(void, glEnable, (GLenum));
MOCK_METHOD(void, glEnableVertexAttribArray, (GLuint));
MOCK_METHOD(void, glFinish, ());
MOCK_METHOD(void, glFlush, ());
MOCK_METHOD(void, glFramebufferRenderbuffer,
(GLenum, GLenum, GLenum, GLuint));
MOCK_METHOD(void, glFramebufferTexture2D,
Expand Down
12 changes: 11 additions & 1 deletion src/platforms/common/server/shm_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ auto get_tex_id_on_context(mgc::EGLContextExecutor& egl_executor) -> std::shared

// Paranoia: Save the current value for the GL state that we're modifying...
GLint previous_texture;
glGetIntegerv(GL_TEXTURE_2D, &previous_texture);
glGetIntegerv(GL_TEXTURE_BINDING_2D, &previous_texture);

glBindTexture(GL_TEXTURE_2D, tex);
// The ShmBuffer *should* be immutable, so we can just set up the properties once
Expand All @@ -122,6 +122,16 @@ auto get_tex_id_on_context(mgc::EGLContextExecutor& egl_executor) -> std::shared

// ...and then restore the previous GL state.
glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(previous_texture));

/* We need these commands to be in the driver command stream before
* anything which uses them can be executed (which will likely be
* on another thread, in another EGLContext).
*
* glFlush() before the promise synchronisation point will ensure
* those commands are visible to the driver before we try and use
* their results.
*/
glFlush();
tex_promise->set_value(tex);
});
return tex_promise->get_future();
Expand Down
6 changes: 6 additions & 0 deletions tests/mir_test_doubles/mock_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,12 @@ void glFinish()
global_mock_gl->glFinish();
}

void glFlush()
{
CHECK_GLOBAL_VOID_MOCK();
global_mock_gl->glFlush();
}

void glGenerateMipmap(GLenum target)
{
CHECK_GLOBAL_VOID_MOCK();
Expand Down
Loading