What is the 4.19 equivalent for the removed SCOPED_GPU_STAT macro? [resolved]

Hey,

in UE Version 4.18 and earlier, I was able to profile GPU time in C++ code as follows:

First I declared a GPU stat at the beginning of my *.cpp:


DECLARE_FLOAT_COUNTER_STAT(TEXT("MyFunctionToProfile"), Stat_GPU_MyFunctionToProfile, STATGROUP_GPU);

Then I called this stat macro in the scope I wanted to profile:


FRHICommandListImmediate& RHICmdList = GRHICommandList.GetImmediateCommandList();
SCOPED_GPU_STAT(RHICmdList, Stat_GPU_MyFunctionToProfile);

Since version 4.19, the makro SCOPED_GPU_STAT seems to be missing (“identifier “SCOPED_GPU_STAT” is undefined”) and I get the following compiler error:

What can I use to profile GPU times again?

Best regards!

EDIT:
SCOPED_DRAW_EVENT works, but this stat doesn’t show up in “stat gpu” or in the session frontend when profiling with “stat startfile / stat stopfile”. It only shows in the GPU visualizer (CTRL+SHIFT+,), but since this only shows a single frame it’s not a viable replacement for the old SCOPED_GPU_STAT.

I figured the SCOPED_GPU_STAT did not actually get removed, Visual Studio 2015 just couldn’t find it.
I manually added my module path to the project as described in the bug report here, maybe that fixed the issue.

Since the SCOPED_GPU_STAT worked again, I could figure out what caused the compile errors. I was declaring my stats with the macro


DECLARE_FLOAT_COUNTER_STAT(TEXT("MyFunctionToProfile"), Stat_GPU_MyFunctionToProfile, STATGROUP_GPU);

but the correct macro to use is actually the following:


DECLARE_GPU_STAT_NAMED(Stat_GPU_MyFunctionToProfile, TEXT("MyFunctionToProfile"));

Now profiling works again - cheers :slight_smile:

EDIT:
Posted my solution into the C++ 4.19 Transition Guide .