r.DriverDetectionMethod

r.DriverDetectionMethod

#Overview

name: r.DriverDetectionMethod

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.DriverDetectionMethod is to define the implementation method used to detect the GPU driver in Unreal Engine 5. This setting is primarily used for checking old drivers, logging, and gathering statistics related to GPU drivers.

This setting variable is primarily used in the Core module of Unreal Engine, specifically within the Windows platform-specific implementation. It’s referenced in the WindowsPlatformMisc.cpp file, which is part of the core runtime functionality for Windows platforms.

The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 5, but can be changed at runtime through console commands or configuration files.

The associated variable CVarDriverDetectionMethod directly interacts with r.DriverDetectionMethod. They share the same value and purpose.

Developers must be aware that this variable affects how the engine detects and interacts with GPU drivers, which can impact performance and compatibility. The different methods (0 to 5) have varying levels of reliability and applicability depending on the system configuration, especially in multi-GPU setups.

Best practices when using this variable include:

  1. Understanding the implications of each detection method.
  2. Testing thoroughly when changing from the default value, especially on systems with multiple GPUs.
  3. Considering the target hardware configuration of the end-users when selecting a method.
  4. Monitoring performance and stability after changing this value.

Regarding the associated variable CVarDriverDetectionMethod:

The purpose of CVarDriverDetectionMethod is identical to r.DriverDetectionMethod. It’s the actual console variable implementation that controls the driver detection method.

This variable is used directly in the GetGPUDriverInfo function of the FWindowsPlatformMisc class. It determines which method is used to gather GPU driver information.

The value of this variable is set when the console variable is created, but can be changed at runtime using console commands.

As it’s the direct implementation of the console variable, it’s the primary way the engine code interacts with this setting.

Developers should be aware that changes to this variable will immediately affect how the engine detects GPU drivers, which could impact performance or cause issues if not set correctly.

Best practices include:

  1. Using the GetValueOnGameThread() method to access the current value safely.
  2. Considering thread safety when accessing or modifying this variable.
  3. Documenting any non-default values used in a project for easier debugging and maintenance.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Core/Private/Windows/WindowsPlatformMisc.cpp:85

Scope: file

Source code excerpt:

// this cvar can be removed once we have a single method that works well
static TAutoConsoleVariable<int32> CVarDriverDetectionMethod(
	TEXT("r.DriverDetectionMethod"),
	5,
	TEXT("Defines which implementation is used to detect the GPU driver (to check for old drivers, logs and statistics)\n"
	     "  0: Iterate available drivers in registry and choose the one with the same name, if in question use next method (happens)\n"
	     "  1: Get the driver of the primary adapter (might not be correct when dealing with multiple adapters)\n"
	     "  2: Use DirectX LUID (would be the best, not yet implemented)\n"
	     "  3: Use Windows functions, use the primary device (might be wrong when API is using another adapter)\n"

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Core/Private/Windows/WindowsPlatformMisc.cpp:84

Scope: file

Source code excerpt:


// this cvar can be removed once we have a single method that works well
static TAutoConsoleVariable<int32> CVarDriverDetectionMethod(
	TEXT("r.DriverDetectionMethod"),
	5,
	TEXT("Defines which implementation is used to detect the GPU driver (to check for old drivers, logs and statistics)\n"
	     "  0: Iterate available drivers in registry and choose the one with the same name, if in question use next method (happens)\n"
	     "  1: Get the driver of the primary adapter (might not be correct when dealing with multiple adapters)\n"
	     "  2: Use DirectX LUID (would be the best, not yet implemented)\n"

#Loc: <Workspace>/Engine/Source/Runtime/Core/Private/Windows/WindowsPlatformMisc.cpp:3597

Scope (from outer to inner):

file
function     FGPUDriverInfo FWindowsPlatformMisc::GetGPUDriverInfo

Source code excerpt:

	uint32 FoundDriverCount = 0;

	int32 Method = CVarDriverDetectionMethod.GetValueOnGameThread();

	if (Method == 5)
	{
		UE_CLOG(bVerbose, LogWindows, Log, TEXT("Gathering driver information using Windows Setup API"));
		FGPUDriverInfo Local;
		GetVideoDriverDetailsFromSetup(DeviceDescription, bVerbose, Local);