Hi,
I’m trying to write a script (C++ or Blueprint) which needs access to the GPU bound time so I know exactly how long a frame took to process on the GPU.
I know you can use the delta on a frame tick - but this is similar to using Stat fps and it tells you the frame rate which locks to 90fps even if a frame only takes 5ms to render.
Does anyone know if there’s a way of finding out the render time of a frame in milliseconds?
Using the SteamVR>Settings>Performance>Display Frame timing shows the actual cpu/gpu bound time of each frame so it should be possible no?
/** How many cycles the renderthread used (excluding idle time). It's set once per frame in FViewport::Draw. */
extern RENDERCORE_API uint32 GRenderThreadTime;
/** How many cycles the gamethread used (excluding idle time). It's set once per frame in FViewport::Draw. */
extern RENDERCORE_API uint32 GGameThreadTime;
/** How many cycles it took to swap buffers to present the frame. */
extern RENDERCORE_API uint32 GSwapBufferTime;
const double CurrentTime = FApp::GetCurrentTime();
const double DeltaTime = CurrentTime - FApp::GetLastTime();
// Number of milliseconds in total last frame
const double RawFrameTime = DeltaTime * 1000.0;
// Number of milliseconds the gamethread was used last frame
const double RawGameThreadTime = FPlatformTime::ToMilliseconds(GGameThreadTime);
// Number of milliseconds the renderthread was used last frame
const double RawRenderThreadTime = FPlatformTime::ToMilliseconds(GRenderThreadTime);
// Number of milliseconds the GPU was busy last frame
const uint32 GPUCycles = RHIGetGPUFrameCycles();
const double RawGPUFrameTime = FPlatformTime::ToMilliseconds(GPUCycles);
The above code all works if I comment out the call to RHIGetGPUFrameCycles(); but adding that in does throw a linker error.
I have added the RenderCore module in the build.cs and have tried including DynamicRHI.h but it still throws the following if I try to compile with a call to RHIGetGPUFrameCycles();
The rest works though!
Any ideas what I’m missing that causes that lnk2001 ??
So that code kinda works but as far as i can tell it actually just pulls the ‘rounded up’ frame time.
For example:
SteamVR is showing 6ms per frame on GPU and 3ms per frame on CPU.
The RawRenderThreadTime and RawGPUFrameTime from that script are both returning ~11ms - obivously rounding off to the 1/frame-rate with the frame-rate maintaining 90fps.