Move shader source code length adjustment to the main compilation routine

This commit is contained in:
Wojtek Figat
2021-01-05 14:25:38 +01:00
parent 6adb489276
commit 336a3bd484
3 changed files with 6 additions and 4 deletions

View File

@@ -322,8 +322,6 @@ bool ProcessShaderBase(CookAssetsStep::AssetCookData& data, ShaderAssetBase* ass
auto sourceLength = sourceChunk->Size(); auto sourceLength = sourceChunk->Size();
Encryption::DecryptBytes((byte*)source, sourceLength); Encryption::DecryptBytes((byte*)source, sourceLength);
source[sourceLength - 1] = 0; source[sourceLength - 1] = 0;
while (sourceLength > 2 && source[sourceLength - 1] == 0)
sourceLength--;
// Init shader cache output stream // Init shader cache output stream
// TODO: reuse MemoryWriteStream per cooking process to reduce dynamic memory allocations // TODO: reuse MemoryWriteStream per cooking process to reduce dynamic memory allocations

View File

@@ -60,7 +60,7 @@ public:
ShadersCompilationService ShadersCompilationServiceInstance; ShadersCompilationService ShadersCompilationServiceInstance;
bool ShadersCompilation::Compile(const ShaderCompilationOptions& options) bool ShadersCompilation::Compile(ShaderCompilationOptions& options)
{ {
PROFILE_CPU_NAMED("Shader.Compile"); PROFILE_CPU_NAMED("Shader.Compile");
@@ -86,6 +86,10 @@ bool ShadersCompilation::Compile(const ShaderCompilationOptions& options)
return true; return true;
} }
// Adjust input source length if it ends with null
while (options.SourceLength > 2 && options.Source[options.SourceLength - 1] == 0)
options.SourceLength--;
const DateTime startTime = DateTime::NowUTC(); const DateTime startTime = DateTime::NowUTC();
const FeatureLevel featureLevel = RenderTools::GetFeatureLevel(options.Profile); const FeatureLevel featureLevel = RenderTools::GetFeatureLevel(options.Profile);

View File

@@ -20,7 +20,7 @@ public:
/// </summary> /// </summary>
/// <param name="options">Compilation options</param> /// <param name="options">Compilation options</param>
/// <returns>True if failed, otherwise false</returns> /// <returns>True if failed, otherwise false</returns>
static bool Compile(const ShaderCompilationOptions& options); static bool Compile(ShaderCompilationOptions& options);
/// <summary> /// <summary>
/// Registers shader asset for the automated reloads on source includes changes. /// Registers shader asset for the automated reloads on source includes changes.