diff --git a/source/blender/draw/DRW_engine.hh b/source/blender/draw/DRW_engine.hh index 31893c24d17..3f4853eb0ad 100644 --- a/source/blender/draw/DRW_engine.hh +++ b/source/blender/draw/DRW_engine.hh @@ -119,6 +119,9 @@ void DRW_render_context_disable(Render *render); void DRW_submission_start(); void DRW_submission_end(); +void DRW_submission_mutex_init(); +void DRW_submission_mutex_exit(); + void DRW_gpu_context_create(); void DRW_gpu_context_destroy(); /** diff --git a/source/blender/draw/intern/draw_gpu_context.cc b/source/blender/draw/intern/draw_gpu_context.cc index 43903225792..10f01c5c6b6 100644 --- a/source/blender/draw/intern/draw_gpu_context.cc +++ b/source/blender/draw/intern/draw_gpu_context.cc @@ -30,6 +30,16 @@ static TicketMutex *submission_mutex = nullptr; +void DRW_submission_mutex_init() +{ + submission_mutex = BLI_ticket_mutex_alloc(); +} + +void DRW_submission_mutex_exit() +{ + BLI_ticket_mutex_free(submission_mutex); +} + void DRW_submission_start() { bool locked = BLI_ticket_mutex_lock_check_recursive(submission_mutex); @@ -69,7 +79,8 @@ void DRW_gpu_context_create() BLI_assert(system_gpu_context == nullptr); /* Ensure it's called once */ system_gpu_context_mutex = BLI_ticket_mutex_alloc(); - submission_mutex = BLI_ticket_mutex_alloc(); + DRW_submission_mutex_init(); + /* This changes the active context. */ system_gpu_context = WM_system_gpu_context_create(); WM_system_gpu_context_activate(system_gpu_context); @@ -95,7 +106,7 @@ void DRW_gpu_context_destroy() GPU_context_active_set(blender_gpu_context); GPU_context_discard(blender_gpu_context); WM_system_gpu_context_dispose(system_gpu_context); - BLI_ticket_mutex_free(submission_mutex); + DRW_submission_mutex_exit(); BLI_ticket_mutex_free(system_gpu_context_mutex); } } diff --git a/source/blender/draw/tests/draw_testing.cc b/source/blender/draw/tests/draw_testing.cc index 6fa23781bea..86f541f4191 100644 --- a/source/blender/draw/tests/draw_testing.cc +++ b/source/blender/draw/tests/draw_testing.cc @@ -4,6 +4,7 @@ #include "draw_testing.hh" +#include "DRW_engine.hh" #include "GPU_shader.hh" namespace blender::draw { @@ -13,6 +14,13 @@ namespace blender::draw { void DrawOpenGLTest::SetUp() { GPUOpenGLTest::SetUp(); + DRW_submission_mutex_init(); +} + +void DrawOpenGLTest::TearDown() +{ + DRW_submission_mutex_exit(); + GPUOpenGLTest::TearDown(); } #endif @@ -20,6 +28,13 @@ void DrawOpenGLTest::SetUp() void DrawMetalTest::SetUp() { GPUMetalTest::SetUp(); + DRW_submission_mutex_init(); +} + +void DrawMetalTest::TearDown() +{ + DRW_submission_mutex_exit(); + GPUMetalTest::TearDown(); } #endif @@ -27,6 +42,13 @@ void DrawMetalTest::SetUp() void DrawVulkanTest::SetUp() { GPUVulkanTest::SetUp(); + DRW_submission_mutex_init(); +} + +void DrawVulkanTest::TearDown() +{ + DRW_submission_mutex_exit(); + GPUVulkanTest::TearDown(); } #endif diff --git a/source/blender/draw/tests/draw_testing.hh b/source/blender/draw/tests/draw_testing.hh index bb7a941aba6..9bc439619c6 100644 --- a/source/blender/draw/tests/draw_testing.hh +++ b/source/blender/draw/tests/draw_testing.hh @@ -11,6 +11,7 @@ namespace blender::draw { class DrawOpenGLTest : public blender::gpu::GPUOpenGLTest { public: void SetUp() override; + void TearDown() override; }; # define DRAW_OPENGL_TEST(test_name) \ @@ -26,6 +27,7 @@ class DrawOpenGLTest : public blender::gpu::GPUOpenGLTest { class DrawMetalTest : public blender::gpu::GPUMetalTest { public: void SetUp() override; + void TearDown() override; }; # define DRAW_METAL_TEST(test_name) \ @@ -41,6 +43,7 @@ class DrawMetalTest : public blender::gpu::GPUMetalTest { class DrawVulkanTest : public blender::gpu::GPUVulkanTest { public: void SetUp() override; + void TearDown() override; }; # define DRAW_VULKAN_TEST(test_name) \