Files
dan elksnitis 6286f1559f [shaders]
- Remove the condition causing SCW to automatically exit after a single job if HLSLcc was used. This doesn't appear to be beneficial; HLSLcc uses a lot of memory but does not appear to leak it, so we're wasting time spinning up new processes unnecessarily here. This allows us to deprecated the associated field in the compiler output and function in IShaderFormat.
- Strip out compiler invocations stats; this was not accurate in some cases and it was decided after discussion that at this point the effort to fix the problems was not worth the utility we get from it.

#rb Jason.Nadro
#rb Laura.Hermanns

[CL 26256807 by dan elksnitis in 5.3 branch]
2023-06-27 10:08:04 -04:00

115 lines
2.5 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
//
#include "ShaderFormatOpenGL.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"));
class FShaderFormatGLSL : public IShaderFormat
{
enum
{
/** Version for shader format, this becomes part of the DDC key. */
UE_SHADER_GLSL_VER = 107,
};
void CheckFormat(FName Format) const
{
check(Format == NAME_GLSL_150_ES3_1 || Format == NAME_GLSL_ES3_1_ANDROID);
}
public:
virtual uint32 GetVersion(FName Format) const override
{
CheckFormat(Format);
uint32 GLSLVersion = 0;
if (Format == NAME_GLSL_150_ES3_1 || Format == NAME_GLSL_ES3_1_ANDROID)
{
GLSLVersion = UE_SHADER_GLSL_VER;
}
else
{
check(0);
}
uint32 Version = ((HLSLCC_VersionMinor & 0xff) << 8) | (GLSLVersion & 0xff);
#if UE_OPENGL_SHADER_COMPILER_ALLOW_DEAD_CODE_REMOVAL
Version = HashCombine(Version, 0x75E2FE85);
#endif // UE_OPENGL_SHADER_COMPILER_ALLOW_DEAD_CODE_REMOVAL
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 CompileShader(FName Format, const struct FShaderCompilerInput& Input, struct FShaderCompilerOutput& Output,const FString& WorkingDirectory) const override
{
CheckFormat(Format);
GLSLVersion Version = TranslateFormatNameToEnum(Format);
FOpenGLFrontend Frontend;
// the frontend will run the cross compiler
Frontend.CompileShader(Input, Output, WorkingDirectory, Version);
}
virtual const TCHAR* GetPlatformIncludeDirectory() const
{
return TEXT("GL");
}
};
/**
* Module for OpenGL shaders
*/
static IShaderFormat* Singleton = NULL;
class FShaderFormatOpenGLModule : public IShaderFormatModule
{
public:
virtual ~FShaderFormatOpenGLModule()
{
delete Singleton;
Singleton = NULL;
}
virtual IShaderFormat* GetShaderFormat()
{
if (!Singleton)
{
Singleton = new FShaderFormatGLSL();
}
return Singleton;
}
};
IMPLEMENT_MODULE( FShaderFormatOpenGLModule, ShaderFormatOpenGL);