r.ShaderSource.CompressionLevel

r.ShaderSource.CompressionLevel

#Overview

name: r.ShaderSource.CompressionLevel

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.ShaderSource.CompressionLevel is to control the compression level for shader source code stored in memory within Unreal Engine 5.

This setting variable is primarily used by the rendering system, specifically in the RenderCore module. It affects how shader source code is compressed and stored in memory, which can impact performance and memory usage.

The value of this variable is set through the console variable system in Unreal Engine. It’s initialized with a default value of 1, which corresponds to the “SuperFast” compression level in the FOodleDataCompression::ECompressionLevel enum.

The r.ShaderSource.CompressionLevel console variable is directly associated with the GShaderSourceCompressionLevel global variable. They share the same value, and changes to the console variable will affect the global variable.

Developers should be aware that:

  1. This variable affects the trade-off between memory usage and compression/decompression speed for shader source code.
  2. The compression level is used in the FShaderSource::Compress function, which is likely called when shaders are loaded or compiled.
  3. The supported values for this variable correspond to the FOodleDataCompression::ECompressionLevel enum, which developers should refer to for valid options.

Best practices when using this variable include:

  1. Consider the target hardware and performance requirements when adjusting this value.
  2. Monitor memory usage and shader loading times when experimenting with different compression levels.
  3. Use the console variable system to adjust this value dynamically for testing purposes.
  4. Document any non-default values used in production to ensure consistency across development and deployment environments.

Regarding the associated variable GShaderSourceCompressionLevel:

This is a static global integer variable that directly stores the compression level value. It’s initialized with a default value of 1 and is updated whenever the r.ShaderSource.CompressionLevel console variable changes.

The GShaderSourceCompressionLevel variable is used in the FShaderSource::Compress function to determine the compression level when compressing shader source code. It’s cast to the FOodleDataCompression::ECompressionLevel enum before being used.

Developers should be aware that modifying GShaderSourceCompressionLevel directly is not recommended, as it may lead to inconsistencies with the console variable system. Instead, they should always use the r.ShaderSource.CompressionLevel console variable to adjust the compression level.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/ShaderSource.cpp:15

Scope: file

Source code excerpt:

static int32 GShaderSourceCompressionLevel = 1;
FAutoConsoleVariableRef CVarShaderSourceCompressionLevel(
	TEXT("r.ShaderSource.CompressionLevel"),
	GShaderSourceCompressionLevel,
	TEXT("Compression level for shader source stored in memory. See FOodleDataCompression::ECompressionLevel enum for supported values; default is SuperFast."),
	ECVF_Default);

FShaderSource::FShaderSource(FShaderSource::FViewType InSrc, int32 AdditionalSlack)
{

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/ShaderSource.cpp:13

Scope: file

Source code excerpt:

	ECVF_Default);

static int32 GShaderSourceCompressionLevel = 1;
FAutoConsoleVariableRef CVarShaderSourceCompressionLevel(
	TEXT("r.ShaderSource.CompressionLevel"),
	GShaderSourceCompressionLevel,
	TEXT("Compression level for shader source stored in memory. See FOodleDataCompression::ECompressionLevel enum for supported values; default is SuperFast."),
	ECVF_Default);

FShaderSource::FShaderSource(FShaderSource::FViewType InSrc, int32 AdditionalSlack)
{
	Set(InSrc, AdditionalSlack);

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/ShaderSource.cpp:64

Scope (from outer to inner):

file
function     void FShaderSource::Compress

Source code excerpt:

	checkf(!IsCompressed(), TEXT("FShaderSource is already compressed"));

	FOodleDataCompression::ECompressionLevel CompressionLevel = static_cast<FOodleDataCompression::ECompressionLevel>(GShaderSourceCompressionLevel);
	
	DecompressedSize = Source.Num();
	int32 CompressionBufferSize = FOodleDataCompression::CompressedBufferSizeNeeded(DecompressedSize);
	SourceCompressed.SetNumUninitialized(CompressionBufferSize);

	int32 CompressedSize = FOodleDataCompression::Compress(