From abfc5cc9e179807212682ee8508f517d114d337c Mon Sep 17 00:00:00 2001 From: Sergii Liebodkin Date: Fri, 13 Jun 2025 10:57:39 +0300 Subject: [PATCH] wg_engine: avoid forced texture flushes After introducing staged buffer removed the need for forced flush of each texture data into gpu General approach used for all data types Can increase performance on discrete GPUs --- src/renderer/wg_engine/tvgWgCommon.cpp | 8 ++++++-- src/renderer/wg_engine/tvgWgCommon.h | 1 + src/renderer/wg_engine/tvgWgCompositor.cpp | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/renderer/wg_engine/tvgWgCommon.cpp b/src/renderer/wg_engine/tvgWgCommon.cpp index 2bb493a6..a56a56a0 100644 --- a/src/renderer/wg_engine/tvgWgCommon.cpp +++ b/src/renderer/wg_engine/tvgWgCommon.cpp @@ -85,7 +85,6 @@ bool WgContext::allocateTexture(WGPUTexture& texture, uint32_t width, uint32_t h const WGPUTextureDataLayout textureDataLayout{ .bytesPerRow = 4 * width, .rowsPerImage = height }; const WGPUExtent3D writeSize{ .width = width, .height = height, .depthOrArrayLayers = 1 }; wgpuQueueWriteTexture(queue, &imageCopyTexture, data, 4 * width * height, &textureDataLayout, &writeSize); - wgpuQueueSubmit(queue, 0, nullptr); } else { releaseTexture(texture); texture = createTexture(width, height, format); @@ -94,7 +93,6 @@ bool WgContext::allocateTexture(WGPUTexture& texture, uint32_t width, uint32_t h const WGPUTextureDataLayout textureDataLayout{ .bytesPerRow = 4 * width, .rowsPerImage = height }; const WGPUExtent3D writeSize{ .width = width, .height = height, .depthOrArrayLayers = 1 }; wgpuQueueWriteTexture(queue, &imageCopyTexture, data, 4 * width * height, &textureDataLayout, &writeSize); - wgpuQueueSubmit(queue, 0, nullptr); return true; } return false; @@ -287,6 +285,12 @@ void WgContext::releaseCommandEncoder(WGPUCommandEncoder& commandEncoder) } +void WgContext::submit() +{ + wgpuQueueSubmit(queue, 0, nullptr); +} + + bool WgContext::invalid() { return !instance || !device; diff --git a/src/renderer/wg_engine/tvgWgCommon.h b/src/renderer/wg_engine/tvgWgCommon.h index b0831170..16825ca6 100644 --- a/src/renderer/wg_engine/tvgWgCommon.h +++ b/src/renderer/wg_engine/tvgWgCommon.h @@ -73,6 +73,7 @@ struct WgContext { void submitCommandEncoder(WGPUCommandEncoder encoder); void releaseCommandEncoder(WGPUCommandEncoder& encoder); + void submit(); bool invalid(); }; diff --git a/src/renderer/wg_engine/tvgWgCompositor.cpp b/src/renderer/wg_engine/tvgWgCompositor.cpp index f07be669..e3cf7e06 100644 --- a/src/renderer/wg_engine/tvgWgCompositor.cpp +++ b/src/renderer/wg_engine/tvgWgCompositor.cpp @@ -201,6 +201,7 @@ void WgCompositor::flush(WgContext& context) stageBufferGeometry.append(&meshDataBlit); stageBufferGeometry.flush(context); stageBufferPaint.flush(context); + context.submit(); }