r.FastVRam.GBufferVelocity

r.FastVRam.GBufferVelocity

#Overview

name: r.FastVRam.GBufferVelocity

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

It is referenced in 10 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.FastVRam.GBufferVelocity is to control the allocation of fast VRAM for the G-Buffer velocity texture in Unreal Engine’s rendering system. This setting is part of the engine’s performance optimization features, specifically for managing memory allocation for rendering.

The r.FastVRam.GBufferVelocity variable is primarily used in the Renderer module of Unreal Engine. It affects how the engine allocates memory for the velocity component of the G-Buffer, which is crucial for various rendering effects, particularly those involving motion.

The value of this variable is set using the FASTVRAM_CVAR macro, which likely creates a console variable that can be adjusted at runtime. It’s initialized with a default value of 0, suggesting that by default, the engine does not allocate fast VRAM for the G-Buffer velocity texture.

This variable interacts closely with the GBufferVelocity variable, which represents the actual texture binding for the velocity component of the G-Buffer. The r.FastVRam.GBufferVelocity setting influences the creation flags for this texture.

Developers should be aware that changing this setting can affect rendering performance and memory usage. Enabling fast VRAM for the G-Buffer velocity texture might improve performance in scenes with a lot of motion, but it also increases the demand for fast VRAM, which is a limited resource.

Best practices when using this variable include:

  1. Only enable it if you’re experiencing performance issues related to velocity calculations or motion blur.
  2. Monitor performance and memory usage when adjusting this setting.
  3. Consider the target hardware capabilities, as not all systems have abundant fast VRAM.

Regarding the associated GBufferVelocity variable:

The purpose of GBufferVelocity is to represent the velocity component of the G-Buffer in Unreal Engine’s rendering system. It’s used to store per-pixel velocity information, which is crucial for effects like motion blur and temporal anti-aliasing.

This variable is used across multiple subsystems within the rendering pipeline, including the scene rendering, shader compilation, and texture management systems.

The value of GBufferVelocity is typically set during the initialization of the scene textures configuration. It’s assigned a binding based on the “Velocity” G-Buffer component.

GBufferVelocity interacts with several other rendering-related variables and is often used in conjunction with other G-Buffer components like GBufferD and GBufferE.

Developers should be aware that the GBufferVelocity texture might have special handling in some cases. For example, it’s excluded from the DisableDCC flag to optimize for scenarios where it doesn’t have many written pixels.

Best practices when working with GBufferVelocity include:

  1. Ensure proper initialization and binding in custom rendering paths.
  2. Consider its impact on memory usage and rendering performance when designing effects that rely on velocity information.
  3. Be cautious when modifying its format or creation flags, as it can affect various rendering features.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:

FASTVRAM_CVAR(GBufferE, 0);
FASTVRAM_CVAR(GBufferF, 0);
FASTVRAM_CVAR(GBufferVelocity, 0);
FASTVRAM_CVAR(HZB, 1);
FASTVRAM_CVAR(SceneDepth, 1);
FASTVRAM_CVAR(SceneColor, 1);
FASTVRAM_CVAR(Bloom, 1);
FASTVRAM_CVAR(BokehDOF, 1);
FASTVRAM_CVAR(CircleDOF, 1);

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/SceneTexturesConfig.cpp:301

Scope (from outer to inner):

file
function     void FSceneTexturesConfig::Init

Source code excerpt:

				BindingCache.Bindings[Layout].GBufferD = FindGBufferBindingByName(GBufferInfo, TEXT("GBufferD"), ShaderPlatform);
				BindingCache.Bindings[Layout].GBufferE = FindGBufferBindingByName(GBufferInfo, TEXT("GBufferE"), ShaderPlatform);
				BindingCache.Bindings[Layout].GBufferVelocity = FindGBufferBindingByName(GBufferInfo, TEXT("Velocity"), ShaderPlatform);

				// Remove DisableDCC flag for velocity. Only Nanite fast tile clear sets this flag currently
				// but we want to exclude velocity because it usually doesn't have many written pixels
				EnumRemoveFlags(BindingCache.Bindings[Layout].GBufferVelocity.Flags, TexCreate_DisableDCC);
			}

			BindingCache.GBufferParams = DefaultParams;
			BindingCache.bInitialized = true;

			if (ShadingPath == EShadingPath::Mobile)

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/SceneTexturesConfig.cpp:366

Scope (from outer to inner):

file
function     uint32 FSceneTexturesConfig::GetGBufferRenderTargetsInfo

Source code excerpt:

		IncludeBindingIfValid(Bindings.GBufferD);
		IncludeBindingIfValid(Bindings.GBufferE);
		IncludeBindingIfValid(Bindings.GBufferVelocity);
	}
	// Forward shading path. Simple forward shading does not use velocity.
	else if (IsUsingBasePassVelocity(ShaderPlatform))
	{
		const FGBufferBinding& GBufferVelocity = GBufferBindings[GBL_Default].GBufferVelocity;
		RenderTargetsInfo.RenderTargetFormats[RenderTargetCount] = GBufferVelocity.Format;
		RenderTargetsInfo.RenderTargetFlags[RenderTargetCount++] = GBufferVelocity.Flags;
	}

	// Store final number of render targets
	RenderTargetsInfo.RenderTargetsEnabled = RenderTargetCount;

	// Precache TODO: other flags

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/ShaderCompiler/ShaderGenerationUtil.cpp:1486

Scope (from outer to inner):

file
function     static FString CreateGBufferDecodeFunctionVariation

Source code excerpt:

				if (DecodeType == CoordUV || DecodeType == CoordUInt)
				{
					TargetName = TEXT("GBufferVelocity");
				}
				else if (DecodeType == SceneTextures || DecodeType == SceneTexturesLoad)
				{
					TargetName = TEXT("GBufferVelocity");
				}
			}

			FString CurrLine;
			if (DecodeType == CoordUV)
			{

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Public/GBufferInfo.h:276

Scope: file

Source code excerpt:

	FGBufferBinding GBufferD;
	FGBufferBinding GBufferE;
	FGBufferBinding GBufferVelocity;
};

struct FGBufferInfo
{
	static const int MaxTargets = 8;

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

Scope: file

Source code excerpt:

FASTVRAM_CVAR(GBufferE, 0);
FASTVRAM_CVAR(GBufferF, 0);
FASTVRAM_CVAR(GBufferVelocity, 0);
FASTVRAM_CVAR(HZB, 1);
FASTVRAM_CVAR(SceneDepth, 1);
FASTVRAM_CVAR(SceneColor, 1);
FASTVRAM_CVAR(Bloom, 1);
FASTVRAM_CVAR(BokehDOF, 1);
FASTVRAM_CVAR(CircleDOF, 1);

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

Scope (from outer to inner):

file
function     void FFastVramConfig::Update

Source code excerpt:

	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_GBufferE, GBufferE);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_GBufferF, GBufferF);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_GBufferVelocity, GBufferVelocity);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_HZB, HZB);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_SceneDepth, SceneDepth);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_SceneColor, SceneColor);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_Bloom, Bloom);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_BokehDOF, BokehDOF);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_CircleDOF, CircleDOF);

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

Scope: file

Source code excerpt:

	ETextureCreateFlags GBufferE;
	ETextureCreateFlags GBufferF;
	ETextureCreateFlags GBufferVelocity;
	ETextureCreateFlags HZB;
	ETextureCreateFlags SceneDepth;
	ETextureCreateFlags SceneColor;
	ETextureCreateFlags Bloom;
	ETextureCreateFlags BokehDOF;
	ETextureCreateFlags CircleDOF;

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneTextures.cpp:672

Scope (from outer to inner):

file
function     uint32 FSceneTextures::GetGBufferRenderTargets

Source code excerpt:

			{ TEXT("GBufferD"), GBufferD, Bindings.GBufferD.Index },
			{ TEXT("GBufferE"), GBufferE, Bindings.GBufferE.Index },
			{ TEXT("Velocity"), Velocity, Bindings.GBufferVelocity.Index }
		};

		for (const FGBufferEntry& Entry : GBufferEntries)
		{
			checkf(Entry.Index <= 0 || Entry.Texture != nullptr, TEXT("Texture '%s' was requested by FGBufferInfo, but it is null."), Entry.Name);
			if (Entry.Index > 0)

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VelocityRendering.cpp:391

Scope (from outer to inner):

file
function     ETextureCreateFlags FVelocityRendering::GetCreateFlags

Source code excerpt:

ETextureCreateFlags FVelocityRendering::GetCreateFlags(EShaderPlatform ShaderPlatform)
{
	const ETextureCreateFlags FastVRamFlag = BasePassCanOutputVelocity(ShaderPlatform) ? GFastVRamConfig.GBufferVelocity : TexCreate_None;
	return TexCreate_RenderTargetable | TexCreate_UAV | TexCreate_ShaderResource | FastVRamFlag;
}

FRDGTextureDesc FVelocityRendering::GetRenderTargetDesc(EShaderPlatform ShaderPlatform, FIntPoint Extent)
{
	return FRDGTextureDesc::Create2D(Extent, GetFormat(ShaderPlatform), FClearValueBinding::Transparent, GetCreateFlags(ShaderPlatform));