Files
UnrealEngineUWP/Engine/Source/Developer/VulkanShaderFormat/Private/VulkanShaderFormat.cpp
dan elksnitis cc7c2c54f4 [shaders] shader format preprocessing cleanup & refactoring
- move uniform buffer cleanup and dead stripping into ShaderPreprocessor module's PreprocessShader function
- add "required symbols" to compiler input struct to specify additional symbols to keep during minification aside from those specified by the entrypoint; modify API such that both an entry point string and additional symbols can be specified (to avoid each backend needing to manually parse the compound RT entry point string)
- make use of ModifyShaderCompilerInput in all backends to set additional defines and required symbols on input struct up front; only use the AdditionalDefines map in cases where it's actually necessary
- remove the various per-platform defines for enabling minifier, no longer required now that this has been rolled out for all backends
- fix SCW directcompile mode; this had rotted due to pieces of the FShaderCompilerEnvironment having been added that weren't explicitly serialized to either cmdline or in the shader source. this now serializes as a base64 string written inside the USF containing all portions of the environment required for compilation (using the same serialization function as is used to write/read the SCW input file)
- use a debug flag for indicating we're in "direct compile" mode and should load the debug USF off disk, rather than the poorly named "bSkipPreprocessedCache" (this name is both inaccurate and also confusing due to the addition of the preprocessed job cache)
- modify platform "force wave32" mechanism to use a pragma directive to set a compiler define, instead of doing string replacement in the preprocessed source
- add a view version of the RT entrypoint parsing to use in preprocessing, note that other paths still need to construct fstrings due to further manipulation so keeping the FString path around too
- clean up backends manually checking the "directcompile" cmdline arg

#rb christopher.waters, Yuriy.ODonnell
#rb Chris.Waters
#rb Laura.Hermanns

[CL 30023082 by dan elksnitis in ue5-main branch]
2023-11-30 15:56:34 -05:00

149 lines
4.2 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "VulkanShaderFormat.h"
#include "VulkanCommon.h"
#include "Modules/ModuleInterface.h"
#include "Modules/ModuleManager.h"
#include "Interfaces/IShaderFormat.h"
#include "Interfaces/IShaderFormatModule.h"
#include "hlslcc.h"
#include "ShaderCore.h"
#include "ShaderCompilerCommon.h"
#include "ShaderCompilerCore.h"
#include "ShaderParameterParser.h"
#include "ShaderPreprocessor.h"
#include "ShaderPreprocessTypes.h"
#include "DXCWrapper.h"
#include "ShaderConductorContext.h"
#include "RHIShaderFormatDefinitions.inl"
extern void ModifyVulkanCompilerInput(FShaderCompilerInput& Input);
extern void CompileVulkanShader(
const FShaderCompilerInput& Input,
const FString& InPreprocessedSource,
FShaderCompilerOutput& Output,
const FString& WorkingDirectory);
extern void OutputVulkanDebugData(
const FShaderCompilerInput& Input,
const FShaderPreprocessOutput& PreprocessOutput,
const FShaderCompilerOutput& Output);
static const FGuid UE_SHADER_VULKAN_ES3_1_VER = FGuid("B84F72C8-3ECD-411E-993C-D7C7CEE26F28");
static const FGuid UE_SHADER_VULKAN_SM5_VER = FGuid("0715D8EE-9907-4A25-93AD-A3902C8E069A");
static const FGuid UE_SHADER_VULKAN_SM6_VER = FGuid("C5161730-83C6-40AF-A990-78CD4C1581DB");
class FShaderFormatVulkan : public IShaderFormat
{
FGuid InternalGetVersion(FName Format) const
{
if (Format == NAME_VULKAN_SM6)
{
return UE_SHADER_VULKAN_SM6_VER;
}
if (Format == NAME_VULKAN_SM5 || Format == NAME_VULKAN_SM5_ANDROID)
{
return UE_SHADER_VULKAN_SM5_VER;
}
if (Format == NAME_VULKAN_ES3_1_ANDROID || Format == NAME_VULKAN_ES3_1)
{
return UE_SHADER_VULKAN_ES3_1_VER;
}
FString FormatStr = Format.ToString();
checkf(0, TEXT("Invalid shader format passed to Vulkan shader compiler: %s"), *FormatStr);
return FGuid();
}
uint32 ShaderConductorVersionHash;
public:
FShaderFormatVulkan(uint32 InShaderConductorVersionHash)
: ShaderConductorVersionHash(InShaderConductorVersionHash)
{
}
virtual uint32 GetVersion(FName Format) const override
{
uint32 Version = HashCombine(GetTypeHash(HLSLCC_VersionMajor), GetTypeHash(HLSLCC_VersionMinor));
Version = HashCombine(Version, GetTypeHash(InternalGetVersion(Format)));
Version = HashCombine(Version, GetTypeHash(ShaderConductorVersionHash));
#if VULKAN_ENABLE_BINDING_DEBUG_NAMES
Version = HashCombine(Version, 0xFC0848E2);
#endif
return Version;
}
virtual void GetSupportedFormats(TArray<FName>& OutFormats) const
{
OutFormats.Add(NAME_VULKAN_SM5);
OutFormats.Add(NAME_VULKAN_ES3_1_ANDROID);
OutFormats.Add(NAME_VULKAN_ES3_1);
OutFormats.Add(NAME_VULKAN_SM5_ANDROID);
OutFormats.Add(NAME_VULKAN_SM6);
}
virtual void ModifyShaderCompilerInput(FShaderCompilerInput& Input) const override
{
ModifyVulkanCompilerInput(Input);
}
virtual bool PreprocessShader(const FShaderCompilerInput& Input, const FShaderCompilerEnvironment& Environment, FShaderPreprocessOutput& PreprocessOutput) const
{
return ::PreprocessShader(PreprocessOutput, Input, Environment);
}
virtual void CompilePreprocessedShader(const FShaderCompilerInput& Input, const FShaderPreprocessOutput& PreprocessOutput, FShaderCompilerOutput& Output,const FString& WorkingDirectory) const override
{
CompileVulkanShader(Input, PreprocessOutput.GetSource(), Output, WorkingDirectory);
}
virtual void OutputDebugData(const FShaderCompilerInput& Input, const FShaderPreprocessOutput& PreprocessOutput, const FShaderCompilerOutput& Output) const override
{
OutputVulkanDebugData(Input, PreprocessOutput, Output);
}
virtual const TCHAR* GetPlatformIncludeDirectory() const
{
return TEXT("Vulkan");
}
};
/**
* Module for Vulkan shaders
*/
static IShaderFormat* Singleton = nullptr;
class FVulkanShaderFormatModule : public IShaderFormatModule, public FShaderConductorModuleWrapper
{
public:
virtual ~FVulkanShaderFormatModule()
{
delete Singleton;
Singleton = nullptr;
}
virtual IShaderFormat* GetShaderFormat()
{
if (!Singleton)
{
Singleton = new FShaderFormatVulkan(FShaderConductorModuleWrapper::GetModuleVersionHash());
}
return Singleton;
}
virtual void ShutdownModule() override
{
CrossCompiler::FShaderConductorContext::Shutdown();
}
};
IMPLEMENT_MODULE( FVulkanShaderFormatModule, VulkanShaderFormat);