r.FastVRam.GBufferF

r.FastVRam.GBufferF

#Overview

name: r.FastVRam.GBufferF

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

It is referenced in 22 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.FastVRam.GBufferF is to control the texture creation flags for the GBuffer F texture in Unreal Engine’s rendering system. This variable is part of the Fast VRAM configuration, which allows developers to specify which render targets should be allocated in faster memory for improved performance.

The Unreal Engine rendering subsystem relies on this setting variable, particularly in the deferred shading path. It is used in the scene rendering process and affects how the GBuffer F texture is created and allocated.

The value of this variable is set through a console variable (CVAR) system, as evident from the FASTVRAM_CVAR(GBufferF, 0); line in the SceneRendering.cpp file.

This variable interacts closely with other GBuffer-related variables (GBufferD, GBufferE) and is part of the broader Fast VRAM configuration system. It’s used in conjunction with the FFastVramConfig struct to determine the texture creation flags for GBuffer F.

Developers should be aware that changing this variable can affect rendering performance and memory usage. It’s important to profile and test any changes to ensure they provide the desired performance improvements without negatively impacting other aspects of rendering.

Best practices when using this variable include:

  1. Only enabling it if you’re certain that GBuffer F should be allocated in fast VRAM.
  2. Considering the impact on overall VRAM usage and balancing it with other render targets.
  3. Testing thoroughly on target hardware to ensure performance benefits.

Regarding the associated variable GBufferF:

The purpose of GBufferF is to serve as a render target in the deferred shading pipeline. It’s one of several GBuffer textures used to store intermediate rendering information.

GBufferF is used across multiple Unreal Engine subsystems, including the main rendering pipeline, the TextureShare plugin, and various post-processing effects like the buffer inspector.

The value of GBufferF is typically set during the scene rendering process. It’s created as part of the SceneTextures initialization.

GBufferF interacts with other GBuffer textures (A, B, C, D, E) and is often used in combination with them in shaders and rendering passes.

Developers should be aware that the format and usage of GBufferF can vary depending on the specific rendering configuration and platform. It’s important to understand the contents and format of this texture when writing custom shaders or post-processing effects that use it.

Best practices for using GBufferF include:

  1. Understanding its contents and format for your specific rendering configuration.
  2. Considering its performance impact, especially when accessed in pixel shaders.
  3. Being aware of its potential absence in some rendering paths or configurations.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:

FASTVRAM_CVAR(GBufferD, 0);
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);

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Plugins/VirtualProduction/TextureShare/Source/TextureShare/Private/Game/ViewExtension/TextureShareSceneViewExtension.cpp:153

Scope (from outer to inner):

file
function     void FTextureShareSceneViewExtension::ShareSceneViewColors_RenderThread

Source code excerpt:

	AddShareTexturePass(UE::TextureShareStrings::SceneTextures::GBufferD, SceneTextures.GBufferD);
	AddShareTexturePass(UE::TextureShareStrings::SceneTextures::GBufferE, SceneTextures.GBufferE);
	AddShareTexturePass(UE::TextureShareStrings::SceneTextures::GBufferF, SceneTextures.GBufferF);
}

//////////////////////////////////////////////////////////////////////////////////////////////
FTextureShareSceneViewExtension::FTextureShareSceneViewExtension(const FAutoRegister& AutoRegister, const TSharedRef<ITextureShareObjectProxy, ESPMode::ThreadSafe>& InObjectProxy, FViewport* InLinkedViewport)
	: FSceneViewExtensionBase(AutoRegister)
	, LinkedViewport(InLinkedViewport)

#Loc: <Workspace>/Engine/Plugins/VirtualProduction/TextureShare/Source/TextureShare/Private/Misc/TextureShareStrings.h:21

Scope (from outer to inner):

file
namespace    UE::TextureShareStrings::SceneTextures

Source code excerpt:

	static constexpr auto GBufferD = TEXT("GBufferD");
	static constexpr auto GBufferE = TEXT("GBufferE");
	static constexpr auto GBufferF = TEXT("GBufferF");

	// Read-write RTTs
	static constexpr auto FinalColor = TEXT("FinalColor");
	static constexpr auto Backbuffer = TEXT("Backbuffer");
};

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/GBufferInfo.cpp:222

Scope: file

Source code excerpt:

 *    2: GBufferB
 *    3: GBufferC
 *    4: GBufferF (NOTE!)
 *    5: GBufferD
 *    if (GBUFFER_HAS_PRECSHADOWFACTOR)
 *        6: GBufferE
 * else if (SrcGlobal.GBUFFER_HAS_VELOCITY == 1 && SrcGlobal.GBUFFER_HAS_TANGENT == 1)
 *    assert(0)
 *
*/

/*
 * LegacyFormatIndex: EGBufferFormat enum. Going forward, we will have better granularity on choosing precision, so thes
 *    are just being maintained for the transition.
 *
 * bUsesVelocityDepth: Normal velocity format is half16 for RG. But when enabled, it changes to half16 RGBA with
 *    alpha storing depth and blue unused.
 *
 */

FGBufferInfo RENDERCORE_API FetchLegacyGBufferInfo(const FGBufferParams& Params)
{
	FGBufferInfo Info = {};

	check(!Params.bHasVelocity || !Params.bHasTangent);

	bool bStaticLighting = Params.bHasPrecShadowFactor;

	int32 TargetLighting = 0;
	int32 TargetGBufferA = 1;
	int32 TargetGBufferB = 2;
	int32 TargetGBufferC = 3;
	int32 TargetGBufferD = -1;
	int32 TargetGBufferE = -1;
	int32 TargetGBufferF = -1;
	int32 TargetVelocity = -1;
	int32 TargetSeparatedMainDirLight = -1;

	// Substrate outputs material data through UAV. Only SceneColor, PrecalcShadow & Velocity data are still emitted through RenderTargets
	if (Substrate::IsSubstrateEnabled())
	{

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/GBufferInfo.cpp:397

Scope (from outer to inner):

file
function     FGBufferInfo FetchLegacyGBufferInfo

Source code excerpt:

		TargetGBufferF = 4;
		TargetGBufferD = 5;
		Info.Targets[4].Init(GBT_Unorm_8_8_8_8,  TEXT("GBufferF"), false,  true,  true,  true);
		Info.Targets[5].Init(GBT_Unorm_8_8_8_8, TEXT("GBufferD"), false, true, true, true);
		TargetSeparatedMainDirLight = 6;
		if (Params.bHasPrecShadowFactor)
		{
			TargetGBufferE = 6;
			Info.Targets[6].Init(GBT_Unorm_8_8_8_8, TEXT("GBufferE"), false, true, true, true);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Internal/SceneTextures.h:75

Scope: file

Source code excerpt:

	FRDGTextureRef GBufferD{};
	FRDGTextureRef GBufferE{};
	FRDGTextureRef GBufferF{};

	// Additional Buffer texture used by mobile
	FRDGTextureMSAA DepthAux{};

	// Texture containing dynamic motion vectors. Can be bound by the base pass or its own velocity pass.
	FRDGTextureRef Velocity{};

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/AnisotropyRendering.cpp:357

Scope: file

Source code excerpt:

			if (bDoParallelPass)
			{
				AddClearRenderTargetPass(GraphBuilder, SceneTextures.GBufferF);

				PassParameters->RenderTargets[0] = FRenderTargetBinding(SceneTextures.GBufferF, ERenderTargetLoadAction::ELoad);

				GraphBuilder.AddPass(
					RDG_EVENT_NAME("AnisotropyPassParallel"),
					PassParameters,
					ERDGPassFlags::Raster | ERDGPassFlags::SkipRenderPass,
					[this, &View, &ParallelMeshPass, PassParameters](const FRDGPass* InPass, FRHICommandListImmediate& RHICmdList)

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/AnisotropyRendering.cpp:374

Scope: file

Source code excerpt:

			else
			{
				PassParameters->RenderTargets[0] = FRenderTargetBinding(SceneTextures.GBufferF, ERenderTargetLoadAction::EClear);

				GraphBuilder.AddPass(
					RDG_EVENT_NAME("AnisotropyPass"),
					PassParameters,
					ERDGPassFlags::Raster,
					[this, &View, &ParallelMeshPass, PassParameters](FRHICommandList& RHICmdList)

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessBufferInspector.cpp:14

Scope: file

Source code excerpt:

	RDG_TEXTURE_ACCESS(GBufferD, ERHIAccess::CopySrc)
	RDG_TEXTURE_ACCESS(GBufferE, ERHIAccess::CopySrc)
	RDG_TEXTURE_ACCESS(GBufferF, ERHIAccess::CopySrc)
	RDG_TEXTURE_ACCESS(SceneColor, ERHIAccess::CopySrc)
	RDG_TEXTURE_ACCESS(SceneColorBeforeTonemap, ERHIAccess::CopySrc)
	RDG_TEXTURE_ACCESS(SceneDepth, ERHIAccess::CopySrc)
	RDG_TEXTURE_ACCESS(OriginalSceneColor, ERHIAccess::CopySrc)
END_SHADER_PARAMETER_STRUCT()

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessBufferInspector.cpp:243

Scope: file

Source code excerpt:

				}

				if (Parameters.GBufferF)
				{
					FRHITexture* SourceBufferF = Parameters.GBufferF->GetRHI();
					if (DestinationBufferBCDEF->GetFormat() == SourceBufferF->GetFormat())
					{
						FRHICopyTextureInfo CopyInfo;
						CopyInfo.SourcePosition = SourcePoint;
						CopyInfo.Size = FIntVector(1, 1, 1);
						RHICmdList.CopyTexture(SourceBufferF, DestinationBufferBCDEF, CopyInfo);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessBufferInspector.cpp:282

Scope: file

Source code excerpt:

		FSceneTextureParameters SceneTextures = GetSceneTextureParameters(GraphBuilder, View);

		// GBufferF is optional, so it may be a dummy texture. Revert it to null if so.
		if (SceneTextures.GBufferFTexture->Desc.Extent != Inputs.OriginalSceneColor.Texture->Desc.Extent)
		{
			SceneTextures.GBufferFTexture = nullptr;
		}

		FPixelInspectorParameters* PassParameters = GraphBuilder.AllocParameters<FPixelInspectorParameters>();

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessBufferInspector.cpp:294

Scope: file

Source code excerpt:

		PassParameters->GBufferD = SceneTextures.GBufferDTexture;
		PassParameters->GBufferE = SceneTextures.GBufferETexture;
		PassParameters->GBufferF = SceneTextures.GBufferFTexture;
		PassParameters->SceneColor = Inputs.SceneColor.Texture;
		PassParameters->SceneColorBeforeTonemap = Inputs.SceneColorBeforeTonemap.Texture;
		PassParameters->SceneDepth = SceneTextures.SceneDepthTexture;
		PassParameters->OriginalSceneColor = Inputs.OriginalSceneColor.Texture;

		const FIntRect SceneColorViewRect(Inputs.SceneColor.ViewRect);

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

Scope: file

Source code excerpt:

FASTVRAM_CVAR(GBufferD, 0);
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);

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

Scope (from outer to inner):

file
function     void FFastVramConfig::Update

Source code excerpt:

	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_GBufferD, GBufferD);
	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);

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

Scope: file

Source code excerpt:

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneTextureParameters.cpp:29

Scope (from outer to inner):

file
function     FSceneTextureParameters GetSceneTextureParameters

Source code excerpt:

	Parameters.GBufferDTexture = GetIfProduced(SceneTextures.GBufferD);
	Parameters.GBufferETexture = GetIfProduced(SceneTextures.GBufferE);
	Parameters.GBufferFTexture = GetIfProduced(SceneTextures.GBufferF, SystemTextures.MidGrey);

	return Parameters;
}

FSceneTextureParameters GetSceneTextureParameters(FRDGBuilder& GraphBuilder, TRDGUniformBufferRef<FSceneTextureUniformParameters> SceneTextureUniformBuffer)
{

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

Scope (from outer to inner):

file
function     EPixelFormat FSceneTextures::GetGBufferFFormatAndCreateFlags

Source code excerpt:

	}

	OutCreateFlags = TexCreate_RenderTargetable | TexCreate_ShaderResource | GFastVRamConfig.GBufferF;
	return NormalGBufferFormat;
}

inline EPixelFormat GetMobileSceneDepthAuxPixelFormat(EShaderPlatform ShaderPlatform, bool bPreciseFormat)
{
	if (IsMobileDeferredShadingEnabled(ShaderPlatform) || bPreciseFormat)

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

Scope (from outer to inner):

file
function     void FSceneTextures::InitializeViewFamily

Source code excerpt:

		}

		// GBufferF is not yet part of the data driven GBuffer info.
		if (Config.ShadingPath == EShadingPath::Deferred)
		{
			ETextureCreateFlags GBufferFCreateFlags;
			EPixelFormat GBufferFPixelFormat = GetGBufferFFormatAndCreateFlags(GBufferFCreateFlags);
			const FRDGTextureDesc Desc = FRDGTextureDesc::Create2D(Config.Extent, GBufferFPixelFormat, FClearValueBinding({ 0.5f, 0.5f, 0.5f, 0.5f }), GBufferFCreateFlags | FlagsToAdd);
			SceneTextures.GBufferF = GraphBuilder.CreateTexture(Desc, TEXT("GBufferF"));
		}
	}

	if (Config.bRequiresDepthAux)
	{
		const float FarDepth = (float)ERHIZBuffer::FarPlane;

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

Scope (from outer to inner):

file
function     FRDGTextureRef GetSceneTexture

Source code excerpt:

	case ESceneTexture::GBufferD:       return SceneTextures.GBufferD;
	case ESceneTexture::GBufferE:       return SceneTextures.GBufferE;
	case ESceneTexture::GBufferF:       return SceneTextures.GBufferF;
	case ESceneTexture::SSAO:           return SceneTextures.ScreenSpaceAO;
	case ESceneTexture::CustomDepth:	return SceneTextures.CustomDepth.Depth;
	default:
		checkNoEntry();
		return nullptr;
	}

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

Scope (from outer to inner):

file
function     void SetupSceneTextureUniformParameters

Source code excerpt:

			}

			if (EnumHasAnyFlags(SetupMode, ESceneTextureSetupMode::GBufferF) && HasBeenProduced(SceneTextures->GBufferF))
			{
				SceneTextureParameters.GBufferFTexture = SceneTextures->GBufferF;
			}
		}

		if (EnumHasAnyFlags(SetupMode, ESceneTextureSetupMode::SceneVelocity) && HasBeenProduced(SceneTextures->Velocity))
		{
			SceneTextureParameters.GBufferVelocityTexture = SceneTextures->Velocity;

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Public/SceneRenderTargetParameters.h:19

Scope: file

Source code excerpt:

	GBufferD,
	GBufferE,
	GBufferF,
	SSAO,
	CustomDepth,
};

RENDERER_API FRDGTextureRef GetSceneTexture(const FSceneTextures& SceneTextures, ESceneTexture InSceneTexture);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Public/SceneRenderTargetParameters.h:37

Scope: file

Source code excerpt:

	GBufferD		= 1 << 6,
	GBufferE		= 1 << 7,
	GBufferF		= 1 << 8,
	SSAO			= 1 << 9,
	CustomDepth		= 1 << 10,
	GBuffers		= GBufferA | GBufferB | GBufferC | GBufferD | GBufferE | GBufferF,
	All				= SceneColor | SceneDepth | SceneVelocity | GBuffers | SSAO | CustomDepth
};
ENUM_CLASS_FLAGS(ESceneTextureSetupMode);

/** Fills the shader parameter struct. */
extern RENDERER_API void SetupSceneTextureUniformParameters(