2019-12-26 15:32:37 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
2016-09-30 21:21:09 -04:00
# pragma once
2022-07-20 12:03:45 -04:00
# include "Containers/Array.h"
# include "Containers/Map.h"
# include "Containers/UnrealString.h"
2016-11-23 15:48:37 -05:00
# include "CoreMinimal.h"
2022-07-20 12:03:45 -04:00
# include "HAL/Platform.h"
2016-09-30 21:21:09 -04:00
# include "RHIDefinitions.h"
2022-07-20 12:03:45 -04:00
# include "Templates/SharedPointer.h"
2016-09-30 21:21:09 -04:00
# include "hlslcc.h"
2022-07-20 12:03:45 -04:00
class FArchive ;
2016-11-23 15:48:37 -05:00
# if PLATFORM_WINDOWS
2018-01-20 11:19:29 -05:00
# include "Windows/WindowsHWrapper.h"
2016-11-23 15:48:37 -05:00
# endif
2022-07-20 12:03:45 -04:00
class FShaderCompilerFlags ;
2016-11-23 15:48:37 -05:00
struct FShaderCompilerInput ;
struct FShaderCompilerOutput ;
enum GLSLVersion
2016-09-30 21:21:09 -04:00
{
2020-01-24 18:07:01 -05:00
GLSL_150_REMOVED ,
2020-10-29 13:38:15 -04:00
GLSL_430_REMOVED ,
2020-02-12 13:27:19 -05:00
GLSL_ES2_REMOVED ,
GLSL_ES2_WEBGL_REMOVED ,
2020-01-24 18:07:01 -05:00
GLSL_150_ES2_DEPRECATED , // ES2 Emulation
GLSL_150_ES2_NOUB_DEPRECATED , // ES2 Emulation with NoUBs
2016-09-30 21:21:09 -04:00
GLSL_150_ES3_1 , // ES3.1 Emulation
2020-01-24 18:07:01 -05:00
GLSL_ES2_IOS_REMOVED ,
2020-10-29 13:38:15 -04:00
GLSL_310_ES_EXT_REMOVED ,
2016-09-30 21:21:09 -04:00
GLSL_ES3_1_ANDROID ,
2016-11-21 20:27:58 -05:00
GLSL_SWITCH ,
GLSL_SWITCH_FORWARD ,
2016-09-30 21:21:09 -04:00
GLSL_MAX
} ;
class SHADERFORMATOPENGL_API FOpenGLFrontend
{
public :
virtual ~ FOpenGLFrontend ( )
{
}
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)
virtual bool OutputTrueParameterNames ( )
{
return false ;
}
virtual bool IsSM5 ( GLSLVersion Version )
{
2020-10-29 13:38:15 -04:00
return false ;
2016-09-30 21:21:09 -04:00
}
// what is the max number of samplers the shader platform can use?
virtual uint32 GetMaxSamplers ( GLSLVersion Version ) ;
2021-11-07 23:43:01 -05:00
virtual uint32 CalculateCrossCompilerFlags ( GLSLVersion Version , const bool bFullPrecisionInPS , const FShaderCompilerFlags & CompilerFlags ) ;
2016-09-30 21:21:09 -04:00
// set up compilation information like defines and HlslCompileTarget
virtual void SetupPerVersionCompilationEnvironment ( GLSLVersion Version , class FShaderCompilerDefinitions & AdditionalDefines , EHlslCompileTarget & HlslCompilerTarget ) ;
virtual void ConvertOpenGLVersionFromGLSLVersion ( GLSLVersion InVersion , int & OutMajorVersion , int & OutMinorVersion ) ;
// create the compiling backend
virtual struct FGlslCodeBackend * CreateBackend ( GLSLVersion Version , uint32 CCFlags , EHlslCompileTarget HlslCompilerTarget ) ;
// create the language spec
2020-03-13 11:36:26 -04:00
virtual class FGlslLanguageSpec * CreateLanguageSpec ( GLSLVersion Version , bool bDefaultPrecisionIsHalf ) ;
2016-09-30 21:21:09 -04:00
// Allow a subclass to perform additional work on the cross compiled source code
virtual bool PostProcessShaderSource ( GLSLVersion Version , EShaderFrequency Frequency , const ANSICHAR * ShaderSource ,
2017-06-09 17:44:13 -04:00
uint32 SourceLen , class FShaderParameterMap & ParameterMap , TMap < FString , FString > & BindingNameMap , TArray < struct FShaderCompilerError > & Errors ,
const FShaderCompilerInput & ShaderInput )
2016-09-30 21:21:09 -04:00
{
return true ;
}
// allow subclass to write out different output, returning true if it did write everything it needed
virtual bool OptionalSerializeOutputAndReturnIfSerialized ( FArchive & Ar )
{
return false ;
}
void BuildShaderOutput ( FShaderCompilerOutput & ShaderOutput , const FShaderCompilerInput & ShaderInput , const ANSICHAR * InShaderSource , int32 SourceLen , GLSLVersion Version ) ;
void PrecompileShader ( FShaderCompilerOutput & ShaderOutput , const FShaderCompilerInput & ShaderInput , const ANSICHAR * ShaderSource , GLSLVersion Version , EHlslShaderFrequency Frequency ) ;
2018-05-23 21:04:31 -04:00
bool PlatformSupportsOfflineCompilation ( const GLSLVersion ShaderVersion ) const ;
// fills device capabilities in 'offline', mostly hardcoded values
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()
TSharedPtr < ANSICHAR > PrepareCodeForOfflineCompilation ( GLSLVersion ShaderVersion , EShaderFrequency Frequency , const ANSICHAR * InShaderSource ) const ;
void CompileOffline ( const FShaderCompilerInput & ShaderInput , FShaderCompilerOutput & Output , const GLSLVersion ShaderVersion , const ANSICHAR * InShaderSource ) ;
// based on ShaderVersion decides what platform specific compiler to use
void PlatformCompileOffline ( const FShaderCompilerInput & Input , FShaderCompilerOutput & ShaderOutput , const ANSICHAR * ShaderSource , const GLSLVersion ShaderVersion ) ;
2016-11-23 15:48:37 -05:00
} ;