From ac4526744af59f4ae4cf301cb7d815f951bdbec6 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 26 Feb 2026 11:08:12 +0100 Subject: [PATCH] Add GPU profile events to WebGPU and use the by default in non-Release builds --- .../WebGPU/GPUContextWebGPU.cpp | 21 +++++++++++++++++++ .../GraphicsDevice/WebGPU/GPUContextWebGPU.h | 6 +++++- Source/Engine/Platform/Web/WebDefines.h | 3 ++- Source/Engine/Profiler/ProfilerGPU.cpp | 4 ++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Source/Engine/GraphicsDevice/WebGPU/GPUContextWebGPU.cpp b/Source/Engine/GraphicsDevice/WebGPU/GPUContextWebGPU.cpp index 9e24286aa..2111d9629 100644 --- a/Source/Engine/GraphicsDevice/WebGPU/GPUContextWebGPU.cpp +++ b/Source/Engine/GraphicsDevice/WebGPU/GPUContextWebGPU.cpp @@ -115,6 +115,27 @@ void GPUContextWebGPU::FrameEnd() Flush(); } +#if GPU_ALLOW_PROFILE_EVENTS + +#include "Engine/Utilities/StringConverter.h" + +void GPUContextWebGPU::EventBegin(const Char* name) +{ + StringAsANSI<> nameAnsi(name); + wgpuCommandEncoderPushDebugGroup(Encoder, { nameAnsi.Get(), (size_t)nameAnsi.Length() }); +} + +void GPUContextWebGPU::EventEnd() +{ + // Cannot insert commands in encoder during render pass + if (_renderPass) + EndRenderPass(); + + wgpuCommandEncoderPopDebugGroup(Encoder); +} + +#endif + void* GPUContextWebGPU::GetNativePtr() const { return Encoder; diff --git a/Source/Engine/GraphicsDevice/WebGPU/GPUContextWebGPU.h b/Source/Engine/GraphicsDevice/WebGPU/GPUContextWebGPU.h index c13c8e8c6..0b8852e51 100644 --- a/Source/Engine/GraphicsDevice/WebGPU/GPUContextWebGPU.h +++ b/Source/Engine/GraphicsDevice/WebGPU/GPUContextWebGPU.h @@ -57,7 +57,7 @@ private: int32 _indexBuffer32Bit : 1; int32 _blendFactorDirty : 1; int32 _blendFactorSet : 1; - int32 _renderTargetCount : 3; + int32 _renderTargetCount : 4; int32 _vertexBufferCount : 3; uint32 _stencilRef; Float4 _blendFactor; @@ -97,6 +97,10 @@ public: // [GPUContext] void FrameBegin() override; void FrameEnd() override; +#if GPU_ALLOW_PROFILE_EVENTS + void EventBegin(const Char* name) override; + void EventEnd() override; +#endif void* GetNativePtr() const override; bool IsDepthBufferBinded() override; void Clear(GPUTextureView* rt, const Color& color) override; diff --git a/Source/Engine/Platform/Web/WebDefines.h b/Source/Engine/Platform/Web/WebDefines.h index d5511d1f7..f52cf0e94 100644 --- a/Source/Engine/Platform/Web/WebDefines.h +++ b/Source/Engine/Platform/Web/WebDefines.h @@ -18,7 +18,8 @@ // Configure graphics #define GPU_ALLOW_TESSELLATION_SHADERS 0 #define GPU_ALLOW_GEOMETRY_SHADERS 0 -#define GPU_ALLOW_PROFILE_EVENTS 0 +//#define GPU_ALLOW_PROFILE_EVENTS 0 +#define GPU_AUTO_PROFILE_EVENTS (!BUILD_RELEASE) #define GPU_ENABLE_PRELOADING_RESOURCES 0 // Don't preload things unless needed // Threading is optional diff --git a/Source/Engine/Profiler/ProfilerGPU.cpp b/Source/Engine/Profiler/ProfilerGPU.cpp index 1ac51c83e..1ede560f7 100644 --- a/Source/Engine/Profiler/ProfilerGPU.cpp +++ b/Source/Engine/Profiler/ProfilerGPU.cpp @@ -16,7 +16,11 @@ RenderStatsData RenderStatsData::Counter; int32 ProfilerGPU::_depth = 0; bool ProfilerGPU::Enabled = false; +#if GPU_AUTO_PROFILE_EVENTS +bool ProfilerGPU::EventsEnabled = true; +#else bool ProfilerGPU::EventsEnabled = false; +#endif int32 ProfilerGPU::CurrentBuffer = 0; ProfilerGPU::EventBuffer ProfilerGPU::Buffers[PROFILER_GPU_EVENTS_FRAMES];