r.FastVRam.DOFReduce

r.FastVRam.DOFReduce

#Overview

name: r.FastVRam.DOFReduce

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

It is referenced in 6 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.FastVRam.DOFReduce is to control the memory allocation strategy for textures used in the Depth of Field (DOF) reduction pass within Unreal Engine’s rendering system.

This setting variable is primarily used by the rendering subsystem, specifically the post-processing module that handles Depth of Field effects. It’s part of the FastVRAM configuration system, which allows for fine-tuning of texture memory allocation across various rendering processes.

The value of this variable is set through the console variable system (CVar) in Unreal Engine. It’s initialized in the SceneRendering.cpp file using the FASTVRAM_CVAR macro.

The r.FastVRam.DOFReduce variable interacts closely with its associated variable DOFReduce. They share the same value and are used together to determine the texture creation flags for the DOF reduction pass.

Developers should be aware that modifying this variable will affect the memory allocation strategy for DOF reduction textures. Setting it to 1 (the default value) enables the use of fast VRAM for these textures, which can potentially improve rendering performance at the cost of using more expensive memory.

Best practices when using this variable include:

  1. Only modify it if you’re experiencing performance issues related to DOF or memory allocation.
  2. Monitor performance and memory usage when changing this value.
  3. Consider the target hardware capabilities when deciding whether to use fast VRAM.

Regarding the associated variable DOFReduce:

The purpose of DOFReduce is to store the actual texture creation flags determined by the r.FastVRam.DOFReduce setting. It’s used directly in the rendering code to set up the textures for the DOF reduction pass.

This variable is part of the FFastVramConfig struct and is updated in the FFastVramConfig::Update function based on the value of r.FastVRam.DOFReduce.

DOFReduce is used in the DiaphragmDOF::AddPasses function to set the texture creation flags for the reduced gather input descriptors in the DOF rendering process.

Developers should be aware that this variable directly affects the texture creation process and should be careful when modifying it directly. It’s generally preferable to modify r.FastVRam.DOFReduce instead, which will automatically update DOFReduce through the established update mechanism.

Best practices for DOFReduce include:

  1. Avoid modifying it directly; instead, use r.FastVRam.DOFReduce to control its value.
  2. When debugging texture creation issues in the DOF system, check this variable’s value to ensure it’s set as expected.
  3. Be aware of its impact on memory usage and performance when optimizing the DOF rendering process.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:500

Scope: file

Source code excerpt:

FASTVRAM_CVAR(DBufferMask, 0);
FASTVRAM_CVAR(DOFSetup, 1);
FASTVRAM_CVAR(DOFReduce, 1);
FASTVRAM_CVAR(DOFPostfilter, 1);
FASTVRAM_CVAR(PostProcessMaterial, 1);

FASTVRAM_CVAR(CustomDepth, 0);
FASTVRAM_CVAR(ShadowPointLight, 0);
FASTVRAM_CVAR(ShadowPerObject, 0);

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/DiaphragmDOF.cpp:1339

Scope (from outer to inner):

file
class        class FDiaphragmDOFRecombineCS : public FDiaphragmDOFShader

Source code excerpt:

IMPLEMENT_GLOBAL_SHADER(FDiaphragmDOFCocDilateCS,        "/Engine/Private/DiaphragmDOF/DOFCocTileDilate.usf",             "CocDilateMainCS",        SF_Compute);
IMPLEMENT_GLOBAL_SHADER(FDiaphragmDOFDownsampleCS,       "/Engine/Private/DiaphragmDOF/DOFDownsample.usf",                "DownsampleCS",           SF_Compute);
IMPLEMENT_GLOBAL_SHADER(FDiaphragmDOFReduceCS,           "/Engine/Private/DiaphragmDOF/DOFReduce.usf",                    "ReduceCS",               SF_Compute);
IMPLEMENT_GLOBAL_SHADER(FDiaphragmDOFScatterGroupPackCS, "/Engine/Private/DiaphragmDOF/DOFHybridScatterCompilation.usf",  "ScatterGroupPackMainCS", SF_Compute);
IMPLEMENT_GLOBAL_SHADER(FDiaphragmDOFBuildBokehLUTCS,    "/Engine/Private/DiaphragmDOF/DOFBokehLUT.usf",                  "BuildBokehLUTMainCS",    SF_Compute);
IMPLEMENT_GLOBAL_SHADER(FDiaphragmDOFGatherCS,           "/Engine/Private/DiaphragmDOF/DOFGatherPass.usf",                "GatherMainCS",           SF_Compute);
IMPLEMENT_GLOBAL_SHADER(FDiaphragmDOFPostfilterCS,       "/Engine/Private/DiaphragmDOF/DOFPostfiltering.usf",             "PostfilterMainCS",       SF_Compute);
IMPLEMENT_GLOBAL_SHADER(FDiaphragmDOFHybridScatterVS,    "/Engine/Private/DiaphragmDOF/DOFHybridScatterVertexShader.usf", "ScatterMainVS",          SF_Vertex);
IMPLEMENT_GLOBAL_SHADER(FDiaphragmDOFHybridScatterPS,    "/Engine/Private/DiaphragmDOF/DOFHybridScatterPixelShader.usf",  "ScatterMainPS",          SF_Pixel);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/DiaphragmDOF.cpp:1912

Scope (from outer to inner):

file
function     bool DiaphragmDOF::AddPasses

Source code excerpt:

			FDOFGatherInputDescs ReducedGatherInputDescs = HalfResGatherInputDescs;
			ReducedGatherInputDescs.SceneColor.NumMips = MipLevelCount;
			ReducedGatherInputDescs.SceneColor.Flags = (ReducedGatherInputDescs.SceneColor.Flags & ~(TexCreate_FastVRAM)) | (ETextureCreateFlags)GFastVRamConfig.DOFReduce;
			
			// Make sure the mip 0 is a multiple of 2^NumMips so there is no per mip level UV conversion to do in the gathering shader.
			// Also make sure it is a multiple of group size because reduce shader unconditionally output Mip0.
			int32 Multiple = FMath::Max(1 << (MipLevelCount - 1), kDefaultGroupSize);
			ReducedGatherInputDescs.SceneColor.Extent.X = Multiple * FMath::DivideAndRoundUp(ReducedGatherInputDescs.SceneColor.Extent.X, Multiple);
			ReducedGatherInputDescs.SceneColor.Extent.Y = Multiple * FMath::DivideAndRoundUp(ReducedGatherInputDescs.SceneColor.Extent.Y, Multiple);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:500

Scope: file

Source code excerpt:

FASTVRAM_CVAR(DBufferMask, 0);
FASTVRAM_CVAR(DOFSetup, 1);
FASTVRAM_CVAR(DOFReduce, 1);
FASTVRAM_CVAR(DOFPostfilter, 1);
FASTVRAM_CVAR(PostProcessMaterial, 1);

FASTVRAM_CVAR(CustomDepth, 0);
FASTVRAM_CVAR(ShadowPointLight, 0);
FASTVRAM_CVAR(ShadowPerObject, 0);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:700

Scope (from outer to inner):

file
function     void FFastVramConfig::Update

Source code excerpt:

	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_DBufferMask, DBufferMask);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_DOFSetup, DOFSetup);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_DOFReduce, DOFReduce);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_DOFPostfilter, DOFPostfilter);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_CustomDepth, CustomDepth);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_ShadowPointLight, ShadowPointLight);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_ShadowPerObject, ShadowPerObject);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_ShadowCSM, ShadowCSM);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_PostProcessMaterial, PostProcessMaterial);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.h:2850

Scope: file

Source code excerpt:

	ETextureCreateFlags DBufferMask;
	ETextureCreateFlags DOFSetup;
	ETextureCreateFlags DOFReduce;
	ETextureCreateFlags DOFPostfilter;
	ETextureCreateFlags PostProcessMaterial;

	ETextureCreateFlags CustomDepth;
	ETextureCreateFlags ShadowPointLight;
	ETextureCreateFlags ShadowPerObject;