mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-21 08:35:01 +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:
@@ -11,6 +11,8 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#include <istream>
|
||||
#include <limits>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include "winheaders.h"
|
||||
#include <string>
|
||||
#include "model/ResourceManager.h"
|
||||
@@ -19,6 +21,14 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
struct texture_request; // texture data read by a worker thread, with gfx.textures.streaming
|
||||
|
||||
// an image uploaded by another thread into a texture of its own, waiting for the drawing thread to put it in place
|
||||
struct texture_thread_upload {
|
||||
GLuint id { 0 };
|
||||
GLsync fence { nullptr }; // set after the upload in the uploading context; none where the driver has no sync objects
|
||||
size_t width { 0 };
|
||||
size_t height { 0 };
|
||||
};
|
||||
|
||||
struct opengl_texture : public ITexture {
|
||||
static DDSURFACEDESC2 deserialize_ddsd(std::istream&);
|
||||
static DDCOLORKEY deserialize_ddck(std::istream&);
|
||||
@@ -85,6 +95,10 @@ struct opengl_texture : public ITexture {
|
||||
|
||||
virtual void make_from_memory(size_t width, size_t height, const uint8_t *data) override;
|
||||
virtual void update_from_memory(size_t width, size_t height, const uint8_t *data) override;
|
||||
// the image goes into a texture of its own, and the drawing thread swaps it in after the gpu has it (commit_thread_upload).
|
||||
// the texture drawn from is never written by the uploading thread
|
||||
void upload_from_thread(size_t width, size_t height, const uint8_t *data) override;
|
||||
void commit_thread_upload() override;
|
||||
|
||||
// members
|
||||
static constexpr GLuint invalid_id { std::numeric_limits<GLuint>::max() }; // id value of texture without GL resource
|
||||
@@ -101,6 +115,9 @@ struct opengl_texture : public ITexture {
|
||||
static std::array<GLuint, gl::MAX_TEXTURES + gl::HELPER_TEXTURES> units;
|
||||
static GLint m_activeunit;
|
||||
|
||||
std::mutex m_threaduploadmutex;
|
||||
std::optional<texture_thread_upload> m_threadupload; // guarded by m_threaduploadmutex
|
||||
|
||||
public:
|
||||
// methods
|
||||
void make_request();
|
||||
|
||||
Reference in New Issue
Block a user