Fix missing GPU events when using shaders profiling/debugging or graphics dev tools are enabled

This commit is contained in:
Wojtek Figat
2024-07-03 18:29:42 +02:00
parent b3d77ab9eb
commit b8100e9417
5 changed files with 23 additions and 11 deletions

View File

@@ -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())

View File

@@ -15,6 +15,7 @@ int32 ProfilerGPU::_depth = 0;
Array<GPUTimerQuery*> ProfilerGPU::_timerQueriesPool;
Array<GPUTimerQuery*> 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()

View File

@@ -134,13 +134,18 @@ public:
/// </summary>
API_FIELD() static bool Enabled;
/// <summary>
/// True if GPU events are enabled (see GPUContext::EventBegin), otherwise false. Cannot be changed during rendering.
/// </summary>
API_FIELD() static bool EventsEnabled;
/// <summary>
/// The current frame buffer to collect events.
/// </summary>
static int32 CurrentBuffer;
/// <summary>
/// The events buffers (one per frame).
/// The event buffers (one per frame).
/// </summary>
static EventBuffer Buffers[PROFILER_GPU_EVENTS_FRAMES];

View File

@@ -224,6 +224,7 @@ void ProfilingTools::SetEnabled(bool enabled)
{
ProfilerCPU::Enabled = enabled;
ProfilerGPU::Enabled = enabled;
ProfilerGPU::EventsEnabled = enabled;
NetworkInternal::EnableProfiling = enabled;
}

View File

@@ -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