bShareMaterialShaderCode
bShareMaterialShaderCode
#Overview
name: bShareMaterialShaderCode
The value of this variable can be defined or overridden in .ini config files. 2
.ini config files referencing this setting variable.
It is referenced in 4
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of bShareMaterialShaderCode is to control whether material shader code is shared across multiple materials in the game packaging process. This setting is primarily used for optimizing shader compilation and storage in the game’s final build.
This setting variable is primarily relied upon by the Unreal Engine’s packaging and shader compilation systems. Specifically, it is used in the following subsystems and modules:
- Project Packaging Settings (UProjectPackagingSettings class)
- Cook on the Fly Server (UCookOnTheFlyServer class)
- Shader Code Library (FShaderCodeLibrary class)
The value of this variable is set in the Project Packaging Settings, which can be accessed and modified through the Unreal Editor’s Project Settings menu. It is stored in the game’s configuration files.
This variable interacts with other systems and variables, such as:
- IsUsingShaderCodeLibrary function in the Cook on the Fly Server
- The overall shader compilation and packaging process
Developers must be aware of the following when using this variable:
- Enabling this option can reduce the overall size of shader code in the final game package.
- It may affect loading times, as mentioned in the comments.
- This setting is only effective when cooking content for distribution, not during development or when using cook-on-the-fly.
Best practices when using this variable include:
- Enable it for final releases to reduce package size and potentially improve patching efficiency.
- Test the game thoroughly with this option enabled to ensure there are no unexpected performance impacts or visual artifacts.
- Consider disabling it during development to reduce iteration times if shader compilation becomes a bottleneck.
- Be aware that this setting may have different impacts on different platforms, so test on all target platforms before finalizing the setting.
#Setting Variables
#References In INI files
Location: <Workspace>/Engine/Config/BaseGame.ini:113, section: [/Script/UnrealEd.ProjectPackagingSettings]
- INI Section:
/Script/UnrealEd.ProjectPackagingSettings
- Raw value:
True
- Is Array:
False
Location: <Workspace>/Projects/Lyra/Config/DefaultGame.ini:119, section: [/Script/UnrealEd.ProjectPackagingSettings]
- INI Section:
/Script/UnrealEd.ProjectPackagingSettings
- Raw value:
True
- Is Array:
False
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Developer/DeveloperToolSettings/Classes/Settings/ProjectPackagingSettings.h:428
Scope (from outer to inner):
file
class class UProjectPackagingSettings : public UObject
Source code excerpt:
*/
UPROPERTY(config, EditAnywhere, Category=Packaging)
bool bShareMaterialShaderCode;
/**
* With this option off, the shader code will be stored in the library essentially in a random order,
* squarely the same in which the assets were loaded by the cooker. Enabling this will sort the shaders
* by their hash, which makes the shader library more similar between the builds which can help patching, but
* can adversely affect loading times.
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/CookOnTheFlyServer.cpp:1159
Scope (from outer to inner):
file
function bool UCookOnTheFlyServer::IsUsingShaderCodeLibrary
Source code excerpt:
{
const UProjectPackagingSettings* const PackagingSettings = GetDefault<UProjectPackagingSettings>();
return IsDirectorCookByTheBook() && AllowShaderCompiling() && PackagingSettings->bShareMaterialShaderCode;
}
bool UCookOnTheFlyServer::IsUsingZenStore() const
{
return bZenStore;
}
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/CookOnTheFlyServer.cpp:7700
Scope (from outer to inner):
file
function void GetAdditionalCurrentIniVersionStrings
Source code excerpt:
UProjectPackagingSettings* PackagingSettings = Cast<UProjectPackagingSettings>(UProjectPackagingSettings::StaticClass()->GetDefaultObject());
IniVersionMap.Add(TEXT("IsUsingShaderCodeLibrary"), FString::Printf(TEXT("%d"), PackagingSettings->bShareMaterialShaderCode && CookOnTheFlyServer->IsUsingShaderCodeLibrary()));
}
bool UCookOnTheFlyServer::GetCurrentIniVersionStrings( const ITargetPlatform* TargetPlatform, UE::Cook::FIniSettingContainer& IniVersionStrings ) const
{
{
FScopeLock Lock(&ConfigFileCS);
#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/ShaderCodeLibrary.cpp:3509
Scope (from outer to inner):
file
function void FShaderCodeLibrary::InitForRuntime
Source code excerpt:
// Cannot be enabled by the server, pointless if we can't ever render and not compatible with cook-on-the-fly
bool bArchive = false;
GConfig->GetBool(TEXT("/Script/UnrealEd.ProjectPackagingSettings"), TEXT("bShareMaterialShaderCode"), bArchive, GGameIni);
// We cannot enable native shader libraries when running with NullRHI, so for consistency all libraries (both native and non-native) are disabled if FApp::CanEverRender() == false
bool bEnable = !FPlatformProperties::IsServerOnly() && FApp::CanEverRender() && bArchive;
#if !UE_BUILD_SHIPPING
const bool bCookOnTheFly = IsRunningCookOnTheFly();
bEnable &= !bCookOnTheFly;