r.FastVRam.DistanceFieldCulledObjectBuffers

r.FastVRam.DistanceFieldCulledObjectBuffers

#Overview

name: r.FastVRam.DistanceFieldCulledObjectBuffers

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

It is referenced in 11 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.FastVRam.DistanceFieldCulledObjectBuffers is to control the memory allocation strategy for distance field culled object buffers in Unreal Engine 5’s rendering system. This setting variable is specifically related to the distance field rendering technique, which is used for various visual effects and optimizations.

The Unreal Engine subsystems that rely on this setting variable are primarily within the rendering module, specifically the distance field rendering and ambient occlusion systems. This can be seen from the file locations where the variable is referenced, such as DistanceFieldObjectCulling.cpp and DistanceFieldScreenGridLighting.cpp.

The value of this variable is set using the FASTVRAM_CVAR macro, which likely ties it to a console variable that can be adjusted at runtime. It is initialized with a value of 1 in the SceneRendering.cpp file.

This variable interacts closely with its associated variable DistanceFieldCulledObjectBuffers, which is used in various shader parameter structures and function calls related to distance field rendering.

Developers must be aware that this variable affects the performance and memory usage of the distance field rendering system. Setting it to 1 (as seen in the initialization) likely indicates that these buffers should be allocated in fast VRAM for improved performance.

Best practices when using this variable include:

  1. Ensuring that the system has enough fast VRAM to accommodate these buffers when enabled.
  2. Monitoring performance impacts when adjusting this setting.
  3. Considering the trade-offs between performance and memory usage, especially on systems with limited VRAM.

Regarding the associated variable DistanceFieldCulledObjectBuffers:

The purpose of DistanceFieldCulledObjectBuffers is to store and manage the culled object data for distance field rendering. It is used in various parts of the distance field rendering pipeline, including object culling, tile-based processing, and ambient occlusion calculations.

This variable is used across multiple rendering passes and shaders, as seen in the provided code excerpts. It is typically passed as a parameter to shader setup functions and included in shader parameter structures.

The value of this variable is likely set during the initialization of the distance field rendering system and updated as objects are culled and processed.

Developers should be aware that this variable represents an important data structure in the distance field rendering pipeline. Proper management and efficient use of this buffer can significantly impact rendering performance and quality.

Best practices for using DistanceFieldCulledObjectBuffers include:

  1. Ensuring that the buffer is properly initialized and updated throughout the rendering process.
  2. Optimizing the culling process to minimize the amount of data stored in this buffer.
  3. Considering the memory implications of this buffer, especially when working with large scenes or on memory-constrained platforms.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:

FASTVRAM_CVAR(ShadowCSM, 0);

FASTVRAM_CVAR(DistanceFieldCulledObjectBuffers, 1);
FASTVRAM_CVAR(DistanceFieldTileIntersectionResources, 1);
FASTVRAM_CVAR(DistanceFieldAOScreenGridResources, 1);
FASTVRAM_CVAR(ForwardLightingCullingResources, 1);
FASTVRAM_CVAR(GlobalDistanceFieldCullGridBuffers, 1);

TSharedPtr<FVirtualShadowMapClipmap> FVisibleLightInfo::FindShadowClipmapForView(const FViewInfo* View) const

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DistanceFieldObjectCulling.cpp:268

Scope (from outer to inner):

file
function     void ScatterTilesToObjects

Source code excerpt:

	PassParameters->VS.View = GetShaderBinding(View.ViewUniformBuffer);
	PassParameters->VS.DistanceFieldObjectBuffers = DistanceFieldObjectBuffers;
	PassParameters->VS.DistanceFieldCulledObjectBuffers = CulledObjectBufferParameters;
	PassParameters->VS.DistanceFieldAtlas = DistanceField::SetupAtlasParameters(GraphBuilder, DistanceFieldSceneData);
	PassParameters->VS.AOParameters = DistanceField::SetupAOShaderParameters(Parameters);

	{
		const int32 NumRings = StencilingGeometry::GLowPolyStencilSphereVertexBuffer.GetNumRings();
		const float RadiansPerRingSegment = PI / (float)NumRings;

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DistanceFieldObjectCulling.cpp:283

Scope (from outer to inner):

file
function     void ScatterTilesToObjects

Source code excerpt:

	PassParameters->PS.TileIntersectionParameters = TileIntersectionParameters;
	PassParameters->PS.DistanceFieldObjectBuffers = DistanceFieldObjectBuffers;
	PassParameters->PS.DistanceFieldCulledObjectBuffers = CulledObjectBufferParameters;
	PassParameters->PS.DistanceFieldAtlas = DistanceField::SetupAtlasParameters(GraphBuilder, DistanceFieldSceneData);
	PassParameters->PS.AOParameters = DistanceField::SetupAOShaderParameters(Parameters);
	PassParameters->PS.NumGroups = FVector2f(TileListGroupSize.X, TileListGroupSize.Y);

	PassParameters->SceneTextures = SceneTexturesUniformBuffer;
	PassParameters->ObjectIndirectArguments = ObjectIndirectArguments;

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DistanceFieldObjectCulling.cpp:390

Scope (from outer to inner):

file
function     void BuildTileObjectLists

Source code excerpt:

		PassParameters->View = View.ViewUniformBuffer;
		PassParameters->TileIntersectionParameters = TileIntersectionParameters;
		PassParameters->DistanceFieldCulledObjectBuffers = CulledObjectBufferParameters;
		PassParameters->DistanceFieldAtlas = DistanceField::SetupAtlasParameters(GraphBuilder, Scene.DistanceFieldSceneData);
		PassParameters->SceneTextures = SceneTexturesUniformBuffer;

		auto ComputeShader = View.ShaderMap->GetShader<FComputeCulledTilesStartOffsetCS>();
		const FIntVector GroupCount = FComputeShaderUtils::GetGroupCountWrapped(Scene.DistanceFieldSceneData.NumObjectsInBuffer, ComputeStartOffsetGroupSize);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DistanceFieldScreenGridLighting.cpp:144

Scope: file

Source code excerpt:

		SHADER_PARAMETER_STRUCT_REF(FViewUniformShaderParameters, View)
		SHADER_PARAMETER_STRUCT_INCLUDE(FDistanceFieldObjectBufferParameters, DistanceFieldObjectBuffers)
		SHADER_PARAMETER_STRUCT_INCLUDE(FDistanceFieldCulledObjectBufferParameters, DistanceFieldCulledObjectBuffers)
		SHADER_PARAMETER_STRUCT_INCLUDE(FDistanceFieldAtlasParameters, DistanceFieldAtlas)
		SHADER_PARAMETER_STRUCT_INCLUDE(FTileIntersectionParameters, TileIntersectionParameters)
		SHADER_PARAMETER_STRUCT_INCLUDE(FAOScreenGridParameters, AOScreenGridParameters)
		SHADER_PARAMETER_STRUCT_INCLUDE(FAOParameters, AOParameters)
		SHADER_PARAMETER_STRUCT_INCLUDE(FScreenGridParameters, ScreenGridParameters)
		SHADER_PARAMETER_STRUCT_INCLUDE(FGlobalDistanceFieldParameters2, GlobalDistanceFieldParameters)

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DistanceFieldScreenGridLighting.cpp:330

Scope (from outer to inner):

file
function     void FDeferredShadingSceneRenderer::RenderDistanceFieldAOScreenGrid

Source code excerpt:

		auto* PassParameters = GraphBuilder.AllocParameters<FConeTraceScreenGridGlobalOcclusionCS::FParameters>();
		PassParameters->View = View.ViewUniformBuffer;
		PassParameters->DistanceFieldCulledObjectBuffers = CulledObjectBufferParameters;
		PassParameters->DistanceFieldAtlas = DistanceField::SetupAtlasParameters(GraphBuilder, DistanceFieldSceneData);
		PassParameters->AOScreenGridParameters = AOScreenGridParameters;
		PassParameters->AOParameters = DistanceField::SetupAOShaderParameters(Parameters);
		PassParameters->ScreenGridParameters = SetupScreenGridParameters(View, DistanceFieldNormal);
		PassParameters->GlobalDistanceFieldParameters = SetupGlobalDistanceFieldParameters(View.GlobalDistanceFieldInfo.ParameterData);
		PassParameters->AOSampleParameters = SetupAOSampleParameters(View.Family->FrameNumber);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DistanceFieldScreenGridLighting.cpp:360

Scope (from outer to inner):

file
function     void FDeferredShadingSceneRenderer::RenderDistanceFieldAOScreenGrid

Source code excerpt:

		PassParameters->View = View.ViewUniformBuffer;
		PassParameters->DistanceFieldObjectBuffers = DistanceField::SetupObjectBufferParameters(GraphBuilder, DistanceFieldSceneData);
		PassParameters->DistanceFieldCulledObjectBuffers = CulledObjectBufferParameters;
		PassParameters->DistanceFieldAtlas = DistanceField::SetupAtlasParameters(GraphBuilder, DistanceFieldSceneData);
		PassParameters->TileIntersectionParameters = TileIntersectionParameters;
		PassParameters->AOScreenGridParameters = AOScreenGridParameters;
		PassParameters->AOParameters = DistanceField::SetupAOShaderParameters(Parameters);
		PassParameters->ScreenGridParameters = SetupScreenGridParameters(View, DistanceFieldNormal);
		if (bUseGlobalDistanceField)

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DistanceFieldVisualization.cpp:149

Scope (from outer to inner):

file
function     void FSceneRenderer::RenderMeshDistanceFieldVisualization

Source code excerpt:

		PassParameters->ReflectionStruct = CreateReflectionUniformBuffer(GraphBuilder, View);
		PassParameters->DistanceFieldObjectBuffers = DistanceField::SetupObjectBufferParameters(GraphBuilder, Scene->DistanceFieldSceneData);
		PassParameters->DistanceFieldCulledObjectBuffers = CulledObjectBufferParameters;
		PassParameters->DistanceFieldAtlas = DistanceField::SetupAtlasParameters(GraphBuilder, Scene->DistanceFieldSceneData);
		PassParameters->AOParameters = DistanceField::SetupAOShaderParameters(DFAOParameters);
		PassParameters->GlobalDistanceFieldParameters = SetupGlobalDistanceFieldParameters(View.GlobalDistanceFieldInfo.ParameterData);
		PassParameters->NumGroups = FVector2f(GroupSizeX, GroupSizeY);
		PassParameters->SceneTextures = SceneTextures.UniformBuffer;
		PassParameters->MobileSceneTextures = SceneTextures.MobileUniformBuffer;

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

Scope: file

Source code excerpt:

FASTVRAM_CVAR(ShadowCSM, 0);

FASTVRAM_CVAR(DistanceFieldCulledObjectBuffers, 1);
FASTVRAM_CVAR(DistanceFieldTileIntersectionResources, 1);
FASTVRAM_CVAR(DistanceFieldAOScreenGridResources, 1);
FASTVRAM_CVAR(ForwardLightingCullingResources, 1);
FASTVRAM_CVAR(GlobalDistanceFieldCullGridBuffers, 1);

TSharedPtr<FVirtualShadowMapClipmap> FVisibleLightInfo::FindShadowClipmapForView(const FViewInfo* View) const

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

Scope (from outer to inner):

file
function     void FFastVramConfig::Update

Source code excerpt:

	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_PostProcessMaterial, PostProcessMaterial);

	bDirty |= UpdateBufferFlagFromCVar(CVarFastVRam_DistanceFieldCulledObjectBuffers, DistanceFieldCulledObjectBuffers);
	bDirty |= UpdateBufferFlagFromCVar(CVarFastVRam_DistanceFieldTileIntersectionResources, DistanceFieldTileIntersectionResources);
	bDirty |= UpdateBufferFlagFromCVar(CVarFastVRam_DistanceFieldAOScreenGridResources, DistanceFieldAOScreenGridResources);
	bDirty |= UpdateBufferFlagFromCVar(CVarFastVRam_ForwardLightingCullingResources, ForwardLightingCullingResources);
	bDirty |= UpdateBufferFlagFromCVar(CVarFastVRam_GlobalDistanceFieldCullGridBuffers, GlobalDistanceFieldCullGridBuffers);

	// When Substrate is enable, remove Scene color from fast VRAM to leave space for material buffer which has more impact on performance

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

Scope: file

Source code excerpt:


	// Buffers
	EBufferUsageFlags DistanceFieldCulledObjectBuffers;
	EBufferUsageFlags DistanceFieldTileIntersectionResources;
	EBufferUsageFlags DistanceFieldAOScreenGridResources;
	EBufferUsageFlags ForwardLightingCullingResources;
	EBufferUsageFlags GlobalDistanceFieldCullGridBuffers;
	bool bDirty;