You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
- 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]
152 lines
4.2 KiB
C++
152 lines
4.2 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
//
|
|
|
|
#include "ShaderFormatOpenGL.h"
|
|
|
|
#include "ShaderCompilerCommon.h"
|
|
#include "ShaderPreprocessor.h"
|
|
#include "ShaderPreprocessTypes.h"
|
|
#include "HAL/FileManager.h"
|
|
#include "Modules/ModuleManager.h"
|
|
#include "Interfaces/IShaderFormat.h"
|
|
#include "Interfaces/IShaderFormatModule.h"
|
|
#include "ShaderCore.h"
|
|
#include "ShaderCompilerCore.h"
|
|
|
|
static FName NAME_GLSL_150_ES3_1(TEXT("GLSL_150_ES31"));
|
|
static FName NAME_GLSL_ES3_1_ANDROID(TEXT("GLSL_ES3_1_ANDROID"));
|
|
|
|
extern bool ShouldUseDXC(FShaderCompilerFlags Flags);
|
|
|
|
extern void CompileOpenGLShader(
|
|
const FShaderCompilerInput& Input,
|
|
const FString& InPreprocessedSource,
|
|
FShaderCompilerOutput& Output,
|
|
const FString& WorkingDirectory,
|
|
GLSLVersion Version);
|
|
|
|
/** Version for shader format, this becomes part of the DDC key. */
|
|
static const FGuid UE_SHADER_GLSL_VER = FGuid("15A0CD3A-20CC-4F15-95CC-04E631068DFE");
|
|
|
|
class FShaderFormatGLSL : public UE::ShaderCompilerCommon::FBaseShaderFormat
|
|
{
|
|
static void CheckFormat(FName Format)
|
|
{
|
|
check(Format == NAME_GLSL_150_ES3_1 || Format == NAME_GLSL_ES3_1_ANDROID);
|
|
}
|
|
|
|
public:
|
|
virtual uint32 GetVersion(FName Format) const override
|
|
{
|
|
CheckFormat(Format);
|
|
FGuid GLSLVersion{};
|
|
if (ensure(Format == NAME_GLSL_150_ES3_1 || Format == NAME_GLSL_ES3_1_ANDROID))
|
|
{
|
|
GLSLVersion = UE_SHADER_GLSL_VER;
|
|
}
|
|
|
|
const uint32 BaseHash = GetTypeHash(GLSLVersion);
|
|
|
|
uint32 Version = GetTypeHash(HLSLCC_VersionMinor);
|
|
Version = HashCombine(Version, BaseHash);
|
|
|
|
return Version;
|
|
}
|
|
virtual void GetSupportedFormats(TArray<FName>& OutFormats) const override
|
|
{
|
|
OutFormats.Add(NAME_GLSL_150_ES3_1);
|
|
OutFormats.Add(NAME_GLSL_ES3_1_ANDROID);
|
|
}
|
|
|
|
static GLSLVersion TranslateFormatNameToEnum(FName Format)
|
|
{
|
|
if (Format == NAME_GLSL_150_ES3_1)
|
|
{
|
|
return GLSL_150_ES3_1;
|
|
}
|
|
else if (Format == NAME_GLSL_ES3_1_ANDROID)
|
|
{
|
|
return GLSL_ES3_1_ANDROID;
|
|
}
|
|
else
|
|
{
|
|
check(0);
|
|
return GLSL_MAX;
|
|
}
|
|
}
|
|
|
|
virtual void ModifyShaderCompilerInput(FShaderCompilerInput& Input) const override
|
|
{
|
|
GLSLVersion Version = TranslateFormatNameToEnum(Input.ShaderFormat);
|
|
switch (Version)
|
|
{
|
|
case GLSL_ES3_1_ANDROID:
|
|
Input.Environment.SetDefine(TEXT("COMPILER_GLSL_ES3_1"), 1);
|
|
Input.Environment.SetDefine(TEXT("ES3_1_PROFILE"), 1);
|
|
break;
|
|
|
|
case GLSL_150_ES3_1:
|
|
Input.Environment.SetDefine(TEXT("COMPILER_GLSL"), 1);
|
|
Input.Environment.SetDefine(TEXT("ES3_1_PROFILE"), 1);
|
|
Input.Environment.SetDefine(TEXT("row_major"), TEXT(""));
|
|
break;
|
|
|
|
default:
|
|
check(0);
|
|
}
|
|
Input.Environment.SetDefine(TEXT("OPENGL_PROFILE"), 1);
|
|
|
|
const bool bUseDXC = ShouldUseDXC(Input.Environment.CompilerFlags);
|
|
Input.Environment.SetDefine(TEXT("COMPILER_HLSLCC"), bUseDXC ? 2 : 1);
|
|
Input.Environment.SetDefine(TEXT("COMPILER_SUPPORTS_ATTRIBUTES"), (uint32)1);
|
|
|
|
if (Input.Environment.FullPrecisionInPS || (IsValidRef(Input.SharedEnvironment) && Input.SharedEnvironment->FullPrecisionInPS))
|
|
{
|
|
Input.Environment.SetDefine(TEXT("FORCE_FLOATS"), (uint32)1);
|
|
}
|
|
}
|
|
|
|
virtual bool PreprocessShader(const FShaderCompilerInput& Input, const FShaderCompilerEnvironment& Environment, FShaderPreprocessOutput& PreprocessOutput) const override
|
|
{
|
|
CheckFormat(Input.ShaderFormat);
|
|
return ::PreprocessShader(PreprocessOutput, Input, Environment);
|
|
}
|
|
|
|
virtual void CompilePreprocessedShader(const FShaderCompilerInput& Input, const FShaderPreprocessOutput& PreprocessOutput, FShaderCompilerOutput& Output, const FString& WorkingDirectory) const override
|
|
{
|
|
CheckFormat(Input.ShaderFormat);
|
|
CompileOpenGLShader(Input, PreprocessOutput.GetSource(), Output, WorkingDirectory, TranslateFormatNameToEnum(Input.ShaderFormat));
|
|
}
|
|
|
|
virtual const TCHAR* GetPlatformIncludeDirectory() const override
|
|
{
|
|
return TEXT("GL");
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Module for OpenGL shaders
|
|
*/
|
|
|
|
static IShaderFormat* Singleton = nullptr;
|
|
|
|
class FShaderFormatOpenGLModule : public IShaderFormatModule
|
|
{
|
|
public:
|
|
virtual ~FShaderFormatOpenGLModule() override
|
|
{
|
|
delete Singleton;
|
|
Singleton = nullptr;
|
|
}
|
|
virtual IShaderFormat* GetShaderFormat() override
|
|
{
|
|
if (!Singleton)
|
|
{
|
|
Singleton = new FShaderFormatGLSL();
|
|
}
|
|
return Singleton;
|
|
}
|
|
};
|
|
|
|
IMPLEMENT_MODULE( FShaderFormatOpenGLModule, ShaderFormatOpenGL);
|