Files
UnrealEngineUWP/Engine/Source/Developer/ShaderFormatOpenGL/Public/ShaderFormatOpenGL.h
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

132 lines
7.8 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "Containers/Array.h"
#include "Containers/Map.h"
#include "Containers/UnrealString.h"
#include "CoreMinimal.h"
#include "HAL/Platform.h"
#include "RHIDefinitions.h"
#include "Templates/SharedPointer.h"
#include "hlslcc.h"
class FArchive;
#if PLATFORM_WINDOWS
#include "Windows/WindowsHWrapper.h"
#endif
class FShaderCompilerFlags;
struct FShaderCompilerInput;
struct FShaderCompilerOutput;
enum GLSLVersion
{
GLSL_150_REMOVED,
GLSL_430_REMOVED,
GLSL_ES2_REMOVED,
GLSL_ES2_WEBGL_REMOVED,
GLSL_150_ES2_DEPRECATED, // ES2 Emulation
GLSL_150_ES2_NOUB_DEPRECATED, // ES2 Emulation with NoUBs
GLSL_150_ES3_1, // ES3.1 Emulation
GLSL_ES2_IOS_REMOVED,
GLSL_310_ES_EXT_REMOVED,
GLSL_ES3_1_ANDROID,
GLSL_SWITCH,
GLSL_SWITCH_FORWARD,
GLSL_MAX
};
class SHADERFORMATOPENGL_API FOpenGLFrontend
{
public:
UE_DEPRECATED(5.4, "FOpenGLFrontend is deprecated and derived implementations no longer possible; OpenGL shader compilation should only be triggered from within the shader format code.")
virtual ~FOpenGLFrontend()
{
}
UE_DEPRECATED(5.4, "FOpenGLFrontend is deprecated and derived implementations no longer possible; OpenGL shader compilation should only be triggered from within the shader format code.")
void CompileShader(const struct FShaderCompilerInput& Input, struct FShaderCompilerOutput& Output, const class FString& WorkingDirectory, GLSLVersion Version);
protected:
// if true, the shader output map will contain true names (i.e. ColorModifier) instead of helper names for runtime binding (i.e. pb_5)
UE_DEPRECATED(5.4, "FOpenGLFrontend is deprecated and derived implementations no longer possible; OpenGL shader compilation should only be triggered from within the shader format code.")
virtual bool OutputTrueParameterNames()
{
return false;
}
UE_DEPRECATED(5.4, "FOpenGLFrontend is deprecated and derived implementations no longer possible; OpenGL shader compilation should only be triggered from within the shader format code.")
virtual bool IsSM5(GLSLVersion Version)
{
return false;
}
// what is the max number of samplers the shader platform can use?
UE_DEPRECATED(5.4, "FOpenGLFrontend is deprecated and derived implementations no longer possible; OpenGL shader compilation should only be triggered from within the shader format code.")
virtual uint32 GetMaxSamplers(GLSLVersion Version);
UE_DEPRECATED(5.4, "FOpenGLFrontend is deprecated and derived implementations no longer possible; OpenGL shader compilation should only be triggered from within the shader format code.")
virtual uint32 CalculateCrossCompilerFlags(GLSLVersion Version, const bool bFullPrecisionInPS, const FShaderCompilerFlags& CompilerFlags);
// set up compilation information like defines and HlslCompileTarget
PRAGMA_DISABLE_DEPRECATION_WARNINGS // FShaderCompilerDefinitions will be made internal in the future, marked deprecated until then
UE_DEPRECATED(5.4, "FOpenGLFrontend is deprecated and derived implementations no longer possible; OpenGL shader compilation should only be triggered from within the shader format code.")
virtual void SetupPerVersionCompilationEnvironment(GLSLVersion Version, class FShaderCompilerDefinitions& AdditionalDefines, EHlslCompileTarget& HlslCompilerTarget);
PRAGMA_ENABLE_DEPRECATION_WARNINGS
UE_DEPRECATED(5.4, "FOpenGLFrontend is deprecated and derived implementations no longer possible; OpenGL shader compilation should only be triggered from within the shader format code.")
virtual void ConvertOpenGLVersionFromGLSLVersion(GLSLVersion InVersion, int& OutMajorVersion, int& OutMinorVersion);
// create the compiling backend
UE_DEPRECATED(5.4, "FOpenGLFrontend is deprecated and derived implementations no longer possible; OpenGL shader compilation should only be triggered from within the shader format code.")
virtual struct FGlslCodeBackend* CreateBackend(GLSLVersion Version, uint32 CCFlags, EHlslCompileTarget HlslCompilerTarget);
// create the language spec
UE_DEPRECATED(5.4, "FOpenGLFrontend is deprecated and derived implementations no longer possible; OpenGL shader compilation should only be triggered from within the shader format code.")
virtual class FGlslLanguageSpec* CreateLanguageSpec(GLSLVersion Version, bool bDefaultPrecisionIsHalf);
// Allow a subclass to perform additional work on the cross compiled source code
UE_DEPRECATED(5.4, "FOpenGLFrontend is deprecated and derived implementations no longer possible; OpenGL shader compilation should only be triggered from within the shader format code.")
virtual bool PostProcessShaderSource(GLSLVersion Version, EShaderFrequency Frequency, const ANSICHAR* ShaderSource,
uint32 SourceLen, class FShaderParameterMap& ParameterMap, TMap<FString, FString>& BindingNameMap, TArray<struct FShaderCompilerError>& Errors,
const FShaderCompilerInput& ShaderInput)
{
return true;
}
// allow subclass to write out different output, returning true if it did write everything it needed
UE_DEPRECATED(5.4, "FOpenGLFrontend is deprecated and derived implementations no longer possible; OpenGL shader compilation should only be triggered from within the shader format code.")
virtual bool OptionalSerializeOutputAndReturnIfSerialized(FArchive& Ar)
{
return false;
}
UE_DEPRECATED(5.4, "FOpenGLFrontend is deprecated and derived implementations no longer possible; OpenGL shader compilation should only be triggered from within the shader format code.")
void BuildShaderOutput(FShaderCompilerOutput& ShaderOutput, const FShaderCompilerInput& ShaderInput, const ANSICHAR* InShaderSource, int32 SourceLen, GLSLVersion Version);
UE_DEPRECATED(5.4, "FOpenGLFrontend is deprecated and derived implementations no longer possible; OpenGL shader compilation should only be triggered from within the shader format code.")
void PrecompileShader(FShaderCompilerOutput& ShaderOutput, const FShaderCompilerInput& ShaderInput, const ANSICHAR* ShaderSource, GLSLVersion Version, EHlslShaderFrequency Frequency);
UE_DEPRECATED(5.4, "FOpenGLFrontend is deprecated and derived implementations no longer possible; OpenGL shader compilation should only be triggered from within the shader format code.")
bool PlatformSupportsOfflineCompilation(const GLSLVersion ShaderVersion) const;
// fills device capabilities in 'offline', mostly hardcoded values
UE_DEPRECATED(5.4, "FOpenGLFrontend is deprecated and derived implementations no longer possible; OpenGL shader compilation should only be triggered from within the shader format code.")
void FillDeviceCapsOfflineCompilation(struct FDeviceCapabilities &Caps, const GLSLVersion ShaderVersion) const;
// final source code processing, based on device capabilities, before actual (offline) compilation; it mostly mirrors the behaviour of OpenGLShaders.cpp/GLSLToDeviceCompatibleGLSL()
UE_DEPRECATED(5.4, "FOpenGLFrontend is deprecated and derived implementations no longer possible; OpenGL shader compilation should only be triggered from within the shader format code.")
TSharedPtr<ANSICHAR> PrepareCodeForOfflineCompilation(GLSLVersion ShaderVersion, EShaderFrequency Frequency, const ANSICHAR* InShaderSource) const;
UE_DEPRECATED(5.4, "FOpenGLFrontend is deprecated and derived implementations no longer possible; OpenGL shader compilation should only be triggered from within the shader format code.")
void CompileOffline(const FShaderCompilerInput& ShaderInput, FShaderCompilerOutput &Output, const GLSLVersion ShaderVersion, const ANSICHAR *InShaderSource);
// based on ShaderVersion decides what platform specific compiler to use
UE_DEPRECATED(5.4, "FOpenGLFrontend is deprecated and derived implementations no longer possible; OpenGL shader compilation should only be triggered from within the shader format code.")
void PlatformCompileOffline(const FShaderCompilerInput &Input, FShaderCompilerOutput& ShaderOutput, const ANSICHAR* ShaderSource, const GLSLVersion ShaderVersion);
};