Files
UnrealEngineUWP/Engine/Source/Developer/iOS/MetalShaderFormat/Private/MetalShaderFormat.cpp
Rolando Caloca ccaa39a49e UE4 - Metal fixes
- Fix SV_VertexID & InstanceID usage
- Fix for gl_FragDepth & prep for MRTs

[CL 2270944 by Rolando Caloca in Main branch]
2014-08-25 15:32:11 -04:00

85 lines
2.0 KiB
C++

// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
#include "MetalShaderFormat.h"
#include "Core.h"
#include "ModuleInterface.h"
#include "ModuleManager.h"
#include "TargetPlatform.h"
#include "ShaderCore.h"
#include "hlslcc.h"
static FName NAME_SF_METAL(TEXT("SF_METAL"));
class FMetalShaderFormat : public IShaderFormat
{
enum
{
HEADER_VERSION = 6,
};
struct FVersion
{
uint16 HLSLCCMajor : 3;
uint16 HLSLCCMinor : 7;
uint16 Format : 5;
uint16 OfflineCompiled : 1;
};
public:
virtual uint16 GetVersion(FName Format) const override
{
static_assert(sizeof(FVersion) == sizeof(uint16), "Out of bits!");
union
{
FVersion Version;
uint16 Raw;
} Version;
Version.Version.Format = HEADER_VERSION;
Version.Version.HLSLCCMajor = HLSLCC_VersionMajor;
Version.Version.HLSLCCMinor = HLSLCC_VersionMinor;
Version.Version.OfflineCompiled = METAL_OFFLINE_COMPILE;
// Check that we didn't overwrite any bits
check(Version.Version.Format == HEADER_VERSION);
check(Version.Version.HLSLCCMajor == HLSLCC_VersionMajor);
check(Version.Version.HLSLCCMinor == HLSLCC_VersionMinor);
check(Version.Version.OfflineCompiled == METAL_OFFLINE_COMPILE);
return Version.Raw;
}
virtual void GetSupportedFormats(TArray<FName>& OutFormats) const
{
OutFormats.Add(NAME_SF_METAL);
}
virtual void CompileShader(FName Format, const struct FShaderCompilerInput& Input, struct FShaderCompilerOutput& Output,const FString& WorkingDirectory) const
{
check(Format == NAME_SF_METAL);
CompileShader_Metal(Input, Output, WorkingDirectory);
}
};
/**
* Module for OpenGL shaders
*/
static IShaderFormat* Singleton = NULL;
class FMetalShaderFormatModule : public IShaderFormatModule
{
public:
virtual ~FMetalShaderFormatModule()
{
delete Singleton;
Singleton = NULL;
}
virtual IShaderFormat* GetShaderFormat()
{
if (!Singleton)
{
Singleton = new FMetalShaderFormat();
}
return Singleton;
}
};
IMPLEMENT_MODULE( FMetalShaderFormatModule, MetalShaderFormat);