r.D3D12.GPUTimeFromTimestamps

r.D3D12.GPUTimeFromTimestamps

#Overview

name: r.D3D12.GPUTimeFromTimestamps

This variable is created as a Console Variable (cvar).

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.D3D12.GPUTimeFromTimestamps is to control the method used for computing GPU frame time in the Direct3D 12 rendering hardware interface (RHI) of Unreal Engine 5. Specifically, it determines whether to prefer using timestamps or the GetHardwareGPUFrameTime function for this computation.

This setting variable is primarily used in the D3D12RHI module, which is responsible for interfacing with the Direct3D 12 API. Based on the callsites, it’s evident that this variable is utilized within the FD3D12DynamicRHI class, specifically in the ProcessTimestamps function.

The value of this variable is set using a TAutoConsoleVariable, which means it can be changed at runtime through the console or configuration files. The default value is set to D3D12_PREFER_QUERIES_FOR_GPU_TIME, which is likely a constant defined elsewhere in the codebase.

The associated variable CVarGPUTimeFromTimestamps interacts directly with r.D3D12.GPUTimeFromTimestamps. They share the same value and purpose, with CVarGPUTimeFromTimestamps being the actual console variable object used in the code.

Developers must be aware that changing this variable will affect how GPU frame time is calculated, which could impact performance metrics and potentially debugging information. The choice between timestamps and GetHardwareGPUFrameTime may have different implications depending on the specific hardware and driver implementations.

Best practices when using this variable include:

  1. Understanding the performance implications of each method on your target hardware.
  2. Consistent use across development and production environments to ensure comparable metrics.
  3. Monitoring the impact on overall engine performance when changing this setting.
  4. Considering the accuracy requirements of your project when choosing between the two methods.

Regarding the associated variable CVarGPUTimeFromTimestamps:

The purpose of CVarGPUTimeFromTimestamps is to provide a runtime-configurable way to control the GPU frame time calculation method. It’s the actual console variable object that encapsulates the r.D3D12.GPUTimeFromTimestamps setting.

This variable is used directly in the D3D12RHI module, specifically within the FD3D12DynamicRHI::ProcessTimestamps function. It determines whether to use the GetHardwareGPUFrameTime function or rely on timestamps for GPU time calculation.

The value of CVarGPUTimeFromTimestamps is set when it’s declared, but can be changed at runtime through the console or configuration files due to its nature as a TAutoConsoleVariable.

CVarGPUTimeFromTimestamps interacts directly with the engine’s GPU timing system, influencing how GPU performance is measured and reported.

Developers should be aware that this variable’s value is checked on any thread (GetValueOnAnyThread()), which means it should be treated as a global setting that can affect multiple parts of the rendering pipeline.

Best practices for using CVarGPUTimeFromTimestamps include:

  1. Documenting any changes to this variable in performance testing scenarios.
  2. Being consistent in its usage across different development stages and platforms.
  3. Understanding the potential impact on profiling and debugging tools that rely on accurate GPU timing information.
  4. Considering thread safety when accessing or modifying this variable, as it’s accessed from multiple threads.

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Runtime/D3D12RHI/Private/D3D12Submission.cpp:1251

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarGPUTimeFromTimestamps(
	TEXT("r.D3D12.GPUTimeFromTimestamps"),
	D3D12_PREFER_QUERIES_FOR_GPU_TIME,
	TEXT("Prefer timestamps instead of GetHardwareGPUFrameTime to compute GPU frame time"),
	ECVF_RenderThreadSafe);

void FD3D12DynamicRHI::ProcessTimestamps(TIndirectArray<FD3D12Timing>& Timing)
{

#Associated Variable and Callsites

This variable is associated with another variable named CVarGPUTimeFromTimestamps. They share the same value. See the following C++ source code.

#Loc: <Workspace>/Engine/Source/Runtime/D3D12RHI/Private/D3D12Submission.cpp:1250

Scope: file

Source code excerpt:

#endif

static TAutoConsoleVariable<int32> CVarGPUTimeFromTimestamps(
	TEXT("r.D3D12.GPUTimeFromTimestamps"),
	D3D12_PREFER_QUERIES_FOR_GPU_TIME,
	TEXT("Prefer timestamps instead of GetHardwareGPUFrameTime to compute GPU frame time"),
	ECVF_RenderThreadSafe);

void FD3D12DynamicRHI::ProcessTimestamps(TIndirectArray<FD3D12Timing>& Timing)

#Loc: <Workspace>/Engine/Source/Runtime/D3D12RHI/Private/D3D12Submission.cpp:1336

Scope (from outer to inner):

file
function     void FD3D12DynamicRHI::ProcessTimestamps

Source code excerpt:

	 
	double HardwareGPUTime = 0.0;
	if (GetHardwareGPUFrameTime(HardwareGPUTime) && CVarGPUTimeFromTimestamps.GetValueOnAnyThread() == 0)
	{
		SET_CYCLE_COUNTER(STAT_RHI_GPUTotalTimeHW, HardwareGPUTime);
		GGPUFrameTime = HardwareGPUTime;
	}
	else
	{