r.D3D12.Depth24Bit
r.D3D12.Depth24Bit
#Overview
name: r.D3D12.Depth24Bit
The value of this variable can be defined or overridden in .ini config files. 1
.ini config file referencing this setting variable.
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
0: Use 32-bit float depth buffer\n1: Use 24-bit fixed point depth buffer(default)\n
It is referenced in 4
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.D3D12.Depth24Bit is to control the depth buffer format in the D3D12 rendering system of Unreal Engine 5. It allows developers to choose between using a 32-bit float depth buffer or a 24-bit fixed point depth buffer.
This setting variable is primarily used by the D3D12 RHI (Rendering Hardware Interface) subsystem of Unreal Engine. It directly affects how depth information is stored and processed in the rendering pipeline.
The value of this variable is set through the console variable system in Unreal Engine. It’s defined as a TAutoConsoleVariable with a default value of 0, meaning it defaults to using a 32-bit float depth buffer.
The associated variable CVarD3D12UseD24 interacts directly with r.D3D12.Depth24Bit. They share the same value and are used interchangeably in the code.
Developers must be aware that changing this variable can affect rendering precision and potentially impact performance. The 24-bit fixed point depth buffer may offer better performance on some hardware but at the cost of reduced precision compared to the 32-bit float depth buffer.
Best practices when using this variable include:
- Testing thoroughly on target hardware to ensure the chosen depth buffer format doesn’t introduce visual artifacts.
- Considering the requirements of your game’s rendering needs, especially for scenes with large depth ranges.
- Profiling performance with both options to determine the best choice for your specific project.
Regarding the associated variable CVarD3D12UseD24:
- Its purpose is identical to r.D3D12.Depth24Bit, serving as an internal representation of the same setting.
- It’s used directly in the D3D12 RHI implementation to configure the depth buffer format.
- The value is read using the GetValueOnAnyThread() method, indicating it can be accessed from multiple threads.
- When CVarD3D12UseD24 is true (non-zero), it sets the depth-stencil format to DXGI_FORMAT_R24G8_TYPELESS and configures related pixel format properties.
- Developers should treat CVarD3D12UseD24 and r.D3D12.Depth24Bit as the same setting, using whichever is more appropriate for their context (console commands vs. code).
#Setting Variables
#References In INI files
Location: <Workspace>/Engine/Config/BaseDeviceProfiles.ini:1224, section: [HoloLens DeviceProfile]
- INI Section:
HoloLens DeviceProfile
- Raw value:
1
- Is Array:
False
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/D3D12RHI/Private/D3D12RHI.cpp:26
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarD3D12UseD24(
TEXT("r.D3D12.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 CVarD3D12UseD24
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/D3D12RHI/Private/D3D12RHI.cpp:25
Scope: file
Source code excerpt:
TEXT("Whether to enable binding of debug names to D3D12 resources."));
static TAutoConsoleVariable<int32> CVarD3D12UseD24(
TEXT("r.D3D12.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/D3D12RHI/Private/D3D12RHI.cpp:103
Scope (from outer to inner):
file
function FD3D12DynamicRHI::FD3D12DynamicRHI
Source code excerpt:
GPixelFormats[PF_BC4 ].PlatformFormat = DXGI_FORMAT_BC4_UNORM;
GPixelFormats[PF_UYVY ].PlatformFormat = DXGI_FORMAT_UNKNOWN; // TODO: Not supported in D3D11
if (CVarD3D12UseD24.GetValueOnAnyThread())
{
GPixelFormats[PF_DepthStencil].PlatformFormat = DXGI_FORMAT_R24G8_TYPELESS;
GPixelFormats[PF_DepthStencil].BlockBytes = 4;
GPixelFormats[PF_DepthStencil].Supported = true;
GPixelFormats[PF_DepthStencil].bIs24BitUnormDepthStencil = true;
GPixelFormats[PF_X24_G8].PlatformFormat = DXGI_FORMAT_X24_TYPELESS_G8_UINT;
#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?