Files
UnrealEngineUWP/Engine/Source/Developer/VulkanShaderFormat/Private/VulkanShaderFormat.h
Rolando Caloca 5b82f15def Copying //UE4/Dev-RenderPlat-Staging@11388153 to //UE4/Main
#rb none
#rnx

[CL 11388545 by Rolando Caloca in Main branch]
2020-02-12 13:27:19 -05:00

166 lines
3.8 KiB
C

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "hlslcc.h"
enum class EVulkanShaderVersion
{
ES3_1,
ES3_1_NOUB,
ES3_1_ANDROID,
ES3_1_ANDROID_NOUB,
SM5,
SM5_NOUB,
};
inline bool HasRealUBs(EVulkanShaderVersion Version)
{
switch(Version)
{
case EVulkanShaderVersion::ES3_1:
case EVulkanShaderVersion::ES3_1_ANDROID:
case EVulkanShaderVersion::SM5:
return true;
case EVulkanShaderVersion::ES3_1_NOUB:
case EVulkanShaderVersion::ES3_1_ANDROID_NOUB:
case EVulkanShaderVersion::SM5_NOUB:
return false;
default:
check(0);
break;
}
return true;
}
extern void DoCompileVulkanShader(const struct FShaderCompilerInput& Input,struct FShaderCompilerOutput& Output,const class FString& WorkingDirectory, EVulkanShaderVersion Version);
// Hold information to be able to call the compilers
struct FCompilerInfo
{
const struct FShaderCompilerInput& Input;
FString WorkingDirectory;
FString Profile;
uint32 CCFlags;
EHlslShaderFrequency Frequency;
bool bDebugDump;
FString BaseSourceFilename;
FCompilerInfo(const struct FShaderCompilerInput& InInput, const FString& InWorkingDirectory, EHlslShaderFrequency InFrequency);
};
struct FSpirv
{
TArray<uint32> Data;
struct FEntry
{
FEntry() = default;
FEntry(const FString& InName, int32 InBinding)
: Name(InName)
, Binding(InBinding)
{
}
FString Name;
int32 Binding = -1;
uint32 DescriptorSet = UINT32_MAX;
// Index into the Spirv Word containing the descriptor set decoration
uint32 WordDescriptorSetIndex = UINT32_MAX;
// Index into the Spirv Word containing the binding index decoration
uint32 WordBindingIndex = UINT32_MAX;
};
TArray<FEntry> ReflectionInfo;
uint32 OffsetToMainName = 0;
uint32 OffsetToEntryPoint = 0;
uint32 CRC = 0;
int32 FindBinding(const FString& Name, bool bOuter = false) const
{
for (const FEntry& Entry : ReflectionInfo)
{
if (Entry.Name == Name)
{
if (Entry.Binding == -1 && !bOuter)
{
// Try the outer group variable; eg
// layout(set=0,binding=0) buffer CulledObjectBounds_BUFFER { vec4 CulledObjectBounds[]; };
FString OuterName = Name;
OuterName += TEXT("_BUFFER");
return FindBinding(OuterName, true);
}
return Entry.Binding;
}
}
if (!bOuter)
{
for (const FEntry& Entry : ReflectionInfo)
{
if (Entry.Name.StartsWith(Name) && Entry.Name.Len() > Name.Len() && Entry.Name[Name.Len()] == (TCHAR)'.')
{
// Try the outer group variable; eg
// layout(set=0, binding=0) buffer MainAndPostPassPersistentStates_BUFFER { FPersistentState MainAndPostPassPersistentStates[]; };
FString OuterName = Name;
OuterName += TEXT("_BUFFER");
return FindBinding(OuterName, true);
}
}
}
return -1;
}
const FEntry* GetEntryByBindingIndex(int32 BindingIndex) const
{
for (int32 Index = 0; Index < ReflectionInfo.Num(); ++Index)
{
if (ReflectionInfo[Index].Binding == BindingIndex)
{
return &ReflectionInfo[Index];
}
}
return nullptr;
}
FEntry* GetEntry(const FString& Name)
{
for (int32 Index = 0; Index < ReflectionInfo.Num(); ++Index)
{
if (ReflectionInfo[Index].Name == Name)
{
return &ReflectionInfo[Index];
}
}
return nullptr;
}
FEntry const* GetEntry(const FString& Name) const
{
for (int32 Index = 0; Index < ReflectionInfo.Num(); ++Index)
{
if (ReflectionInfo[Index].Name == Name)
{
return &ReflectionInfo[Index];
}
}
return nullptr;
}
};
// Updates all reflection entries in the specified SPIR-V module.
extern bool PathSpirvReflectionEntriesAndEntryPoint(FSpirv& OutSpirv);
// Generates SPIR-V out of the specified GLSL source code.
extern bool GenerateSpirv(const ANSICHAR* Source, FCompilerInfo& CompilerInfo, FString& OutErrors, const FString& DumpDebugInfoPath, FSpirv& OutSpirv);