diff --git a/Source/Engine/Graphics/Graphics.cpp b/Source/Engine/Graphics/Graphics.cpp index 9535f3ecf..057cc0229 100644 --- a/Source/Engine/Graphics/Graphics.cpp +++ b/Source/Engine/Graphics/Graphics.cpp @@ -188,11 +188,13 @@ bool GraphicsService::Init() ); // Initialize - if (device->IsDebugToolAttached) + if (device->IsDebugToolAttached || + CommandLine::Options.ShaderProfile || + CommandLine::Options.ShaderDebug) { #if COMPILE_WITH_PROFILER - // Auto-enable GPU profiler - ProfilerGPU::Enabled = true; + // Auto-enable GPU events + ProfilerGPU::EventsEnabled = true; #endif } if (device->LoadContent()) diff --git a/Source/Engine/Profiler/ProfilerGPU.cpp b/Source/Engine/Profiler/ProfilerGPU.cpp index 1f5777fd2..6235ed669 100644 --- a/Source/Engine/Profiler/ProfilerGPU.cpp +++ b/Source/Engine/Profiler/ProfilerGPU.cpp @@ -15,6 +15,7 @@ int32 ProfilerGPU::_depth = 0; Array ProfilerGPU::_timerQueriesPool; Array ProfilerGPU::_timerQueriesFree; bool ProfilerGPU::Enabled = false; +bool ProfilerGPU::EventsEnabled = false; int32 ProfilerGPU::CurrentBuffer = 0; ProfilerGPU::EventBuffer ProfilerGPU::Buffers[PROFILER_GPU_EVENTS_FRAMES]; @@ -95,11 +96,12 @@ GPUTimerQuery* ProfilerGPU::GetTimerQuery() int32 ProfilerGPU::BeginEvent(const Char* name) { +#if GPU_ALLOW_PROFILE_EVENTS + if (EventsEnabled) + GPUDevice::Instance->GetMainContext()->EventBegin(name); +#endif if (!Enabled) return -1; -#if GPU_ALLOW_PROFILE_EVENTS - GPUDevice::Instance->GetMainContext()->EventBegin(name); -#endif Event e; e.Name = name; @@ -115,6 +117,10 @@ int32 ProfilerGPU::BeginEvent(const Char* name) void ProfilerGPU::EndEvent(int32 index) { +#if GPU_ALLOW_PROFILE_EVENTS + if (EventsEnabled) + GPUDevice::Instance->GetMainContext()->EventEnd(); +#endif if (index == -1) return; _depth--; @@ -123,10 +129,6 @@ void ProfilerGPU::EndEvent(int32 index) auto e = buffer.Get(index); e->Stats.Mix(RenderStatsData::Counter); e->Timer->End(); - -#if GPU_ALLOW_PROFILE_EVENTS - GPUDevice::Instance->GetMainContext()->EventEnd(); -#endif } void ProfilerGPU::BeginFrame() diff --git a/Source/Engine/Profiler/ProfilerGPU.h b/Source/Engine/Profiler/ProfilerGPU.h index 99fce3599..c316abb15 100644 --- a/Source/Engine/Profiler/ProfilerGPU.h +++ b/Source/Engine/Profiler/ProfilerGPU.h @@ -134,13 +134,18 @@ public: /// API_FIELD() static bool Enabled; + /// + /// True if GPU events are enabled (see GPUContext::EventBegin), otherwise false. Cannot be changed during rendering. + /// + API_FIELD() static bool EventsEnabled; + /// /// The current frame buffer to collect events. /// static int32 CurrentBuffer; /// - /// The events buffers (one per frame). + /// The event buffers (one per frame). /// static EventBuffer Buffers[PROFILER_GPU_EVENTS_FRAMES]; diff --git a/Source/Engine/Profiler/ProfilingTools.cpp b/Source/Engine/Profiler/ProfilingTools.cpp index 58f1c1ffc..8b39cba02 100644 --- a/Source/Engine/Profiler/ProfilingTools.cpp +++ b/Source/Engine/Profiler/ProfilingTools.cpp @@ -224,6 +224,7 @@ void ProfilingTools::SetEnabled(bool enabled) { ProfilerCPU::Enabled = enabled; ProfilerGPU::Enabled = enabled; + ProfilerGPU::EventsEnabled = enabled; NetworkInternal::EnableProfiling = enabled; } diff --git a/Source/Engine/ShadowsOfMordor/Builder.Jobs.cpp b/Source/Engine/ShadowsOfMordor/Builder.Jobs.cpp index c6b0cd056..4220c0be8 100644 --- a/Source/Engine/ShadowsOfMordor/Builder.Jobs.cpp +++ b/Source/Engine/ShadowsOfMordor/Builder.Jobs.cpp @@ -344,6 +344,7 @@ void ShadowsOfMordor::Builder::onJobRender(GPUContext* context) #if COMPILE_WITH_PROFILER auto gpuProfilerEnabled = ProfilerGPU::Enabled; ProfilerGPU::Enabled = false; + ProfilerGPU::EventsEnabled = false; #endif // Render hemispheres @@ -432,6 +433,7 @@ void ShadowsOfMordor::Builder::onJobRender(GPUContext* context) } #if COMPILE_WITH_PROFILER ProfilerGPU::Enabled = gpuProfilerEnabled; + ProfilerGPU::EventsEnabled = gpuProfilerEnabled; #endif // Report progress