r.ReadBuffer.MinSize
r.ReadBuffer.MinSize
#Overview
name: r.ReadBuffer.MinSize
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
The minimum size (in instances) to allocate in blocks for rendering read buffers. i.e. 256*1024 = 1mb for a float buffer
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.ReadBuffer.MinSize is to set the minimum size for allocating blocks in rendering read buffers. It’s primarily used in the rendering system of Unreal Engine 5 to manage memory allocation for dynamic buffers.
This setting variable is utilized in the RenderCore module, specifically within the dynamic buffer allocation system. Based on the callsites, it’s clear that this variable is crucial for the FGlobalDynamicReadBuffer class, which is part of the rendering pipeline.
The value of this variable is set through the console variable system (CVarMinReadBufferSize). It’s initialized with a default value of 256 * 1024, which represents 1MB for a float buffer.
The r.ReadBuffer.MinSize interacts closely with another variable, GMinReadBufferRenderingBufferSize. They share the same value, and GMinReadBufferRenderingBufferSize is used directly in the code to determine buffer allocation sizes.
Developers should be aware that this variable affects memory usage and potentially performance. Setting it too low might result in frequent allocations, while setting it too high could waste memory.
Best practices when using this variable include:
- Adjusting it based on the specific needs of your project.
- Monitoring memory usage and performance when modifying this value.
- Considering the trade-off between memory usage and allocation frequency.
Regarding the associated variable GMinReadBufferRenderingBufferSize:
The purpose of GMinReadBufferRenderingBufferSize is to store the actual value used in the code for minimum buffer size calculations. It’s directly used in the AllocateInternal function of FGlobalDynamicReadBuffer to determine the new buffer size.
This variable is set by the r.ReadBuffer.MinSize console command and is used within the RenderCore module.
It interacts with GAlignReadBufferRenderingBufferSize to calculate the aligned and minimum buffer sizes.
Developers should be aware that changing r.ReadBuffer.MinSize will directly affect this variable and, consequently, the buffer allocation behavior.
Best practices include:
- Using this variable for read-only purposes in custom rendering code.
- Understanding that modifying r.ReadBuffer.MinSize will change this variable’s value.
- Considering the impact on memory usage and allocation patterns when adjusting the associated console variable.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/DynamicBufferAllocator.cpp:22
Scope: file
Source code excerpt:
int32 GMinReadBufferRenderingBufferSize = 256 * 1024;
FAutoConsoleVariableRef CVarMinReadBufferSize(
TEXT("r.ReadBuffer.MinSize"),
GMinReadBufferRenderingBufferSize,
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"),
#Associated Variable and Callsites
This variable is associated with another variable named GMinReadBufferRenderingBufferSize
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/DynamicBufferAllocator.cpp:19
Scope: file
Source code excerpt:
// The allocator works by looking for the first free buffer that contains the required number of elements. There is currently no trim so buffers stay in memory.
// To avoid increasing allocation sizes over multiple frames causing severe memory bloat (i.e. 100 elements, 1001 elements) we first align the required
// number of elements to GMinReadBufferRenderingBufferSize, we then take the max(aligned num, GMinReadBufferRenderingBufferSize)
int32 GMinReadBufferRenderingBufferSize = 256 * 1024;
FAutoConsoleVariableRef CVarMinReadBufferSize(
TEXT("r.ReadBuffer.MinSize"),
GMinReadBufferRenderingBufferSize,
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,
#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/DynamicBufferAllocator.cpp:144
Scope (from outer to inner):
file
function FGlobalDynamicReadBuffer::FAllocation FGlobalDynamicReadBuffer::AllocateInternal
Source code excerpt:
{
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);
}
// Lock the buffer if needed.