Files
UnrealEngineUWP/Engine/Source/Developer/VulkanShaderFormat/Private/VulkanShaderFormat.h
Marc Audy 9753392e2b Merge UE5/RES CL# 15462083 to UE5/Main
This represents UE4/Main @ 15414221

[CL 15463811 by Marc Audy in ue5-main branch]
2021-02-18 18:13:28 -04:00

142 lines
3.3 KiB
C

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "hlslcc.h"
enum class EVulkanShaderVersion
{
ES3_1,
ES3_1_ANDROID,
SM5,
};
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 PatchSpirvReflectionEntriesAndEntryPoint(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);