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

fix(python): the image of the worker goes in place once its fence is signalled, the viewer binds it each frame

From the review of 8811ee5a:

- glWaitSync ordered only the context of the main window. The extra viewports and the windows of
  python.displaywindows draw in contexts of their own and could bind the new texture before the upload
  was done. commit_thread_upload() now asks the fence without waiting (glClientWaitSync, timeout 0) and
  puts the image in place only once it is signalled, so every context binding it afterwards has it whole.
  Until then the task stays in the upload queue and is asked again the next frame.
- The drawing thread chose between upload and commit by python.threadedupload, the worker by whether it
  got a context. With python.threadedupload on and no context made for the worker, the screens were no
  longer updated. The task now records that a worker uploaded it.
- The viewer of python.displaywindows told a new image by its texture name, but a deleted name comes back
  for a later texture. It binds the name of the last image each frame, read under the lock of the render
  target, and the name it starts with is read on the drawing thread when it is made.
This commit is contained in:
maj00r
2026-11-18 17:08:37 +01:00
parent 8811ee5a76
commit 61d195d9fc
7 changed files with 61 additions and 48 deletions

View File

@@ -788,27 +788,31 @@ void opengl_texture::upload_from_thread(size_t width, size_t height, const uint8
}
}
void opengl_texture::commit_thread_upload()
bool opengl_texture::commit_thread_upload()
{
std::optional<texture_thread_upload> upload;
texture_thread_upload upload;
{
std::scoped_lock lock{m_threaduploadmutex};
upload = std::exchange(m_threadupload, std::nullopt);
if (false == m_threadupload.has_value())
return true;
// asked without waiting. the image goes in place only once the upload is done, so every context binding it after
// has it whole: the extra viewports and the windows of python.displaywindows draw in contexts of their own
if (m_threadupload->fence != nullptr)
{
// a failed query (GL_WAIT_FAILED) isn't asked again: the image would never go in place
if (glClientWaitSync(m_threadupload->fence, 0, 0) == GL_TIMEOUT_EXPIRED)
return false;
glDeleteSync(m_threadupload->fence);
}
upload = *m_threadupload;
m_threadupload.reset();
}
if (false == upload.has_value())
return;
if (upload->fence != nullptr)
{
// the commands that follow wait on the gpu for the upload to be done, the cpu goes on
glWaitSync(upload->fence, 0, GL_TIMEOUT_IGNORED);
glDeleteSync(upload->fence);
}
if (id != invalid_id)
glDeleteTextures(1, &id);
id = upload->id;
data_width = static_cast<unsigned int>(upload->width);
data_height = static_cast<unsigned int>(upload->height);
id = upload.id;
data_width = static_cast<unsigned int>(upload.width);
data_height = static_cast<unsigned int>(upload.height);
data_format = GL_SRGB8_ALPHA8;
data_components = GL_RGBA;
if (type == "internalsrc:")
@@ -819,6 +823,7 @@ void opengl_texture::commit_thread_upload()
// the name deleted may come back for another texture, and a deleted texture isn't bound any more
for (auto &unit : units)
unit = -1;
return true;
}
void