r.ReadBuffer.AlignSize

r.ReadBuffer.AlignSize

#Overview

name: r.ReadBuffer.AlignSize

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

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.ReadBuffer.AlignSize is to control the alignment size for allocating blocks in rendering read buffers. It’s primarily used in the rendering system, specifically for managing dynamic read buffer allocation.

This setting variable is relied upon by the RenderCore module of Unreal Engine, as evidenced by its usage in the DynamicBufferAllocator.cpp file.

The value of this variable is set through the console variable system, using FAutoConsoleVariableRef. It’s initialized with a default value of 64 * 1024, which represents 256KB for a float buffer.

The variable interacts closely with GAlignReadBufferRenderingBufferSize, which is the associated C++ variable that directly holds the value set by r.ReadBuffer.AlignSize.

Developers should be aware that this variable affects memory allocation for rendering read buffers. Changing its value will impact the granularity of memory allocation, which can affect both memory usage and performance.

Best practices when using this variable include:

  1. Keeping it as a power of 2 for optimal memory alignment.
  2. Balancing between larger values (which may waste memory but reduce allocation frequency) and smaller values (which may be more memory-efficient but increase allocation overhead).
  3. Considering the typical size of data being stored in these buffers when adjusting this value.

Regarding the associated variable GAlignReadBufferRenderingBufferSize:

The purpose of GAlignReadBufferRenderingBufferSize is to store the actual value set by r.ReadBuffer.AlignSize. It’s used directly in the code to calculate buffer sizes and alignments.

This variable is used in the RenderCore module, specifically in the dynamic buffer allocation system.

Its value is set by the console variable system when r.ReadBuffer.AlignSize is modified.

It interacts directly with r.ReadBuffer.AlignSize and is used in calculations for buffer allocation sizes.

Developers should be aware that modifying r.ReadBuffer.AlignSize will directly affect this variable, and vice versa.

Best practices include:

  1. Not modifying this variable directly, but instead using r.ReadBuffer.AlignSize to change its value.
  2. Being mindful of its impact on memory allocation and performance when adjusting related settings.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/DynamicBufferAllocator.cpp:28

Scope: file

Source code excerpt:

int32 GAlignReadBufferRenderingBufferSize = 64 * 1024;
FAutoConsoleVariableRef CVarAlignReadBufferSize(
	TEXT("r.ReadBuffer.AlignSize"),
	GAlignReadBufferRenderingBufferSize,
	TEXT("The alignment size (in instances) to allocate in blocks for rendering read buffers. i.e. 64*1024 = 256k for a float buffer"));

struct FDynamicReadBufferPool
{
	/** List of vertex buffers. */

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/DynamicBufferAllocator.cpp:26

Scope: file

Source code excerpt:

	TEXT("The minimum size (in instances) to allocate in blocks for rendering read buffers. i.e. 256*1024 = 1mb for a float buffer"));

int32 GAlignReadBufferRenderingBufferSize = 64 * 1024;
FAutoConsoleVariableRef CVarAlignReadBufferSize(
	TEXT("r.ReadBuffer.AlignSize"),
	GAlignReadBufferRenderingBufferSize,
	TEXT("The alignment size (in instances) to allocate in blocks for rendering read buffers. i.e. 64*1024 = 256k for a float buffer"));

struct FDynamicReadBufferPool
{
	/** List of vertex buffers. */
	TIndirectArray<FDynamicAllocReadBuffer> Buffers;

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/DynamicBufferAllocator.cpp:143

Scope (from outer to inner):

file
function     FGlobalDynamicReadBuffer::FAllocation FGlobalDynamicReadBuffer::AllocateInternal

Source code excerpt:

		if (Buffer == nullptr)
		{
			const uint32 AlignedNum = FMath::DivideAndRoundUp(Num, (uint32)GAlignReadBufferRenderingBufferSize) * GAlignReadBufferRenderingBufferSize;
			const uint32 NewBufferSize = FMath::Max(AlignedNum, (uint32)GMinReadBufferRenderingBufferSize);
			Buffer = new FDynamicAllocReadBuffer();
			BufferPool->Buffers.Add(Buffer);
			Buffer->Initialize(*RHICmdList, TEXT("FGlobalDynamicReadBuffer_AllocateInternal"), sizeof(Type), NewBufferSize, Format, BUF_Dynamic);
		}