18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-21 07:24:57 +01:00

fix(python): a screen uploaded by the worker goes into a texture of its own, put in place after a fence

With python.threadedupload (the default) the worker wrote the image into the texture the drawing thread
draws from, with glTexImage2D and glGenerateMipmap from its own context, and only a glFlush after. Nothing
ordered the two contexts: the drawing one could sample the texture while its storage was being made anew,
its level 0 half written or its mipmaps not made yet, and on a change of size the worker deleted the texture
and wrote a new name into `id` with no synchronisation.

The worker now uploads each image into a new texture, sets a fence after it and flushes. The drawing thread,
once per frame in python_taskqueue::update(), waits for that fence on the gpu (glWaitSync, the cpu goes on),
deletes the old texture and puts the new one in place. The worker no longer touches the texture drawn from,
nor `id`. An image the drawing thread didn't take yet is dropped by the next one. Without sync objects the
worker waits for the upload with glFinish.

The windows of python.displaywindows with python.sharectx bound the texture once; they now bind the name of
the last image put in place, which python_rt keeps for them.

Uploads on the drawing thread (python.threadedupload no, the Lua and WebAssembly screens, the editor) are
as they were.
This commit is contained in:
maj00r
2026-11-18 16:49:36 +01:00
parent 80fd5aad2b
commit 8811ee5a76
7 changed files with 169 additions and 4 deletions

View File

@@ -90,7 +90,8 @@ void python_screen_viewer::threadfunc()
glActiveTexture(GL_TEXTURE0);
if (Global.python_sharectx) {
glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(m_rt->shared_tex->get_id()));
window->shared_texture = m_rt->shared_tex->get_id();
glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(window->shared_texture));
}
else {
GLuint tex;
@@ -146,6 +147,8 @@ void python_screen_viewer::threadfunc()
}
glfwMakeContextCurrent(window->window);
if (Global.python_sharectx)
bind_shared_texture(*window);
gl::program::unbind();
gl::buffer::unbind();
@@ -188,6 +191,20 @@ void python_screen_viewer::threadfunc()
}
}
void python_screen_viewer::bind_shared_texture(window_state &Window) const
{
size_t texture;
{
std::scoped_lock guard(m_rt->mutex);
texture = m_rt->texture_id;
}
// each image uploaded by a worker comes in a texture of its own
if (texture == 0 || texture == Window.shared_texture)
return;
Window.shared_texture = texture;
glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(texture));
}
void python_screen_viewer::notify_window_fb_size(GLFWwindow const *window, int w, int h) const
{
for (auto const &conf : m_windows) {