r.D3D11.Depth24Bit

r.D3D11.Depth24Bit

#Overview

name: r.D3D11.Depth24Bit

The value of this variable can be defined or overridden in .ini config files. 1 .ini config file referencing this setting variable.

It is referenced in 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.D3D11.Depth24Bit is to control the depth buffer format in DirectX 11 rendering. It allows developers to choose between a 32-bit float depth buffer and a 24-bit fixed point depth buffer.

This setting variable is primarily used by the DirectX 11 RHI (Rendering Hardware Interface) subsystem in Unreal Engine 5. It is specifically utilized in the D3D11RHI module, which handles DirectX 11 rendering implementation.

The value of this variable is set through a console variable (CVarD3D11UseD24) defined in the D3D11Device.cpp file. It is initialized with a default value of 0, which means it uses a 32-bit float depth buffer by default.

The associated variable CVarD3D11UseD24 interacts directly with r.D3D11.Depth24Bit. They share the same value and purpose, with CVarD3D11UseD24 being the actual console variable implementation in the engine’s code.

Developers must be aware that this variable is marked as ECVF_ReadOnly, meaning its value cannot be changed at runtime. It should be set before the engine initializes the rendering system.

Best practices when using this variable include:

  1. Consider the trade-offs between precision (32-bit float) and memory usage (24-bit fixed point) when choosing the depth buffer format.
  2. Ensure consistency across your project by setting this variable early in the initialization process.
  3. Be aware that changing this setting may affect the behavior of depth-dependent rendering features and post-processing effects.

Regarding the associated variable CVarD3D11UseD24:

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/BaseDeviceProfiles.ini:1223, section: [HoloLens DeviceProfile]

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Windows/D3D11RHI/Private/D3D11Device.cpp:25

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarD3D11UseD24(
	TEXT("r.D3D11.Depth24Bit"),
	0,
	TEXT("0: Use 32-bit float depth buffer\n1: Use 24-bit fixed point depth buffer(default)\n"),
	ECVF_ReadOnly
);

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/RHI/Public/RHISurfaceDataConversion.h:825

Scope (from outer to inner):

file
function     static bool ConvertRAWSurfaceDataToFLinearColor

Source code excerpt:

		)
	{
		//	see CVarD3D11UseD24/CVarD3D12UseD24
		ConvertRawR24G8DataToFLinearColor(Width, Height, In, SrcPitch, Out, InFlags);
		return true;
	}
	else if ( (Format == PF_X24_G8 || Format == PF_DepthStencil ) && GPixelFormats[Format].BlockBytes > 4 )
	{
		// @@ D3D 11/12 different?

#Loc: <Workspace>/Engine/Source/Runtime/Windows/D3D11RHI/Private/D3D11Device.cpp:24

Scope: file

Source code excerpt:

IMPLEMENT_MODULE(FD3D11DynamicRHIModule, D3D11RHI);

static TAutoConsoleVariable<int32> CVarD3D11UseD24(
	TEXT("r.D3D11.Depth24Bit"),
	0,
	TEXT("0: Use 32-bit float depth buffer\n1: Use 24-bit fixed point depth buffer(default)\n"),
	ECVF_ReadOnly
);

#Loc: <Workspace>/Engine/Source/Runtime/Windows/D3D11RHI/Private/D3D11Device.cpp:106

Scope (from outer to inner):

file
function     FD3D11DynamicRHI::FD3D11DynamicRHI

Source code excerpt:

	GPixelFormats[ PF_BC4			].PlatformFormat	= DXGI_FORMAT_BC4_UNORM;
	GPixelFormats[ PF_UYVY			].PlatformFormat	= DXGI_FORMAT_UNKNOWN;		// TODO: Not supported in D3D11
	if (CVarD3D11UseD24.GetValueOnAnyThread())
	{
		GPixelFormats[PF_DepthStencil].PlatformFormat = DXGI_FORMAT_R24G8_TYPELESS;
		GPixelFormats[PF_DepthStencil].BlockBytes = 4;
		GPixelFormats[PF_DepthStencil].bIs24BitUnormDepthStencil = true;
		GPixelFormats[PF_X24_G8].PlatformFormat = DXGI_FORMAT_X24_TYPELESS_G8_UINT;
		GPixelFormats[PF_X24_G8].BlockBytes = 4;