Files
UnrealEngineUWP/Engine/Source/Developer/VulkanShaderFormat/Private/VulkanShaderFormat.cpp
Marcus Wassmer fb641b18e9 Copying //UE4/Dev-Rendering to //UE4/Dev-Main (Source: //UE4/Dev-Rendering @ 3169859)
#lockdown Nick.Penwarden
#rb none

==========================
MAJOR FEATURES + CHANGES
==========================

Change 3134663 on 2016/09/21 by Chris.Bunner

	Merging Dev-MaterialLayers to Dev-Rendering, CL 3134208. Initial material attribute extensibility changes.
	#jira UE-34347

Change 3142292 on 2016/09/27 by Rolando.Caloca

	DR - hlslcc - Fix for warning X3206: implicit truncation of vector type causing error
	#jira UE-31438

Change 3143557 on 2016/09/28 by Rolando.Caloca

	DR - Back out changelist 3142292

Change 3145354 on 2016/09/29 by Benjamin.Hyder

	Updating Tm-ContactShadows

Change 3154832 on 2016/10/07 by Rolando.Caloca

	DR - vk - Fix crash on framebuffers with missing textures

Change 3154838 on 2016/10/07 by Rolando.Caloca

	DR - vk - Enable clip distance

Change 3154840 on 2016/10/07 by Rolando.Caloca

	DR - Remove branch per codereview

Change 3155118 on 2016/10/07 by Rolando.Caloca

	DR - vk - Compute pipeline fixes

Change 3155129 on 2016/10/07 by Rolando.Caloca

	DR - Added draw events for reflection captures

Change 3155167 on 2016/10/07 by Rolando.Caloca

	DR - Use shader clear for platforms that can't use viewport or scissor

Change 3155168 on 2016/10/07 by Rolando.Caloca

	DR - vk - Added submit gpu
	- Some fixes for Geometry and Compute

Change 3155595 on 2016/10/07 by Rolando.Caloca

	DR - vk - Use new render pass system

Change 3155720 on 2016/10/07 by Rolando.Caloca

	DR - vk - static analysis fix

Change 3155732 on 2016/10/07 by Rolando.Caloca

	DR - Fix clears for platforms that can't use viewports, excluderects or scissor on clear

Change 3156787 on 2016/10/10 by Rolando.Caloca

	DR - Fix mem leaks

Change 3156805 on 2016/10/10 by Rolando.Caloca

	DR - Improve check msg per licensee

Change 3156815 on 2016/10/10 by Rolando.Caloca

	DR - Fix infinite recursion

Change 3157041 on 2016/10/10 by Rolando.Caloca

	DR - vk - Fix key access from multiple threads

Change 3158253 on 2016/10/11 by Rolando.Caloca

	DR - Fix comment
	#jira UE-37128
	PR #2852

Change 3158606 on 2016/10/11 by Rolando.Caloca

	DR - vk - Accessors

Change 3160418 on 2016/10/12 by Daniel.Wright

	Lightmap textures are now outered to UMapBuildDataRegistry so that the UMapBuildDataRegistry can be moved in the content browser

Change 3160644 on 2016/10/12 by Arne.Schober

	DR - [UE-32613] - OpenGL used to have custom code in the compiler to modify the source so that the same data and matricies can be used as DirectX, unfortunately that causes precission problem. Fortunately there is an extension available (glClipControl) which enables DirectX behaviour in OpenGL and it is widely supported. We only tested Linux and Windows and therfore only default enable on those platforms.

Change 3161219 on 2016/10/13 by Luke.Thatcher

	[RENDERING] [!] Fix incorrect shader used in GPU Benchmark causing crash in OpenGL.

Change 3161838 on 2016/10/13 by Daniel.Wright

	Fixed level getting added to the dirty list twice when legacy lightmaps are present

Change 3161884 on 2016/10/13 by Arne.Schober

	DR - Fix Mac and DCC build

Change 3162206 on 2016/10/13 by Chris.Bunner

	Merging Dev-MaterialLayers to Dev-Rendering, CL 3161593:
	Material expressions; Trig, fast-trig, saturate, round, truncate, pre-skinned normal.
	Added CustomEyeTangent to material attributes.
	Resolved some hard-coded attribute typing and other minor fixes.

Change 3162491 on 2016/10/13 by Chris.Bunner

	Merging Dev-MaterialLayers to Dev-Rendering, CL 3162397:
	More fixed type-casting on material attributes.
	Swapped compiler::forcecast booleans to flags (and fixed a regression).

Change 3163266 on 2016/10/14 by Daniel.Wright

	Fixed sublevels with legacy lighting data being added to the dirty packages list redundantly

Change 3163524 on 2016/10/14 by Mark.Satterthwaite

	Bring over specific changes from Unicorn branch that increases the size of shader optional data so that it is considerably more useful.

Change 3163529 on 2016/10/14 by Mark.Satterthwaite

	Move the Metal shader source code and compilation path into the newly enlarged shader optional data.

Change 3163553 on 2016/10/14 by Mark.Satterthwaite

	Speculative fix for FORT-31590 also seen by a licensee - the Metal command buffer handler will be called from a dispatch queue thread that won't be registered with the stats system.
	#jira FORT-31590

Change 3163562 on 2016/10/14 by Mark.Satterthwaite

	Tidy up and extend the Metal debugging options:
	- Added rhi.Metal.BufferScribble which when enabled will fill freed buffer regions with 0xCD to help identify any areas where we are writing to a buffer while it is still being processed on the GPU.
	- Added rhi.Metal.BufferZeroFill which will zero-fill newly allocated buffer regions before any other data is read/written. Useful for catching cases where we might be reading uninitialised memory.
	- Added rhi.Metal.ResourcePurgeOnDelete which will purge the backing store of resources prior to releasing them back to the system or the respective pool. This will make any use-after-free conditions much more likely.
	- Added rhi.Metal.ResourceDeferDeleteNumFrames to defer releasing resources to the system or the resource pool by the specified number of frames (in addition to the current policy of waiting for the current end of frame & command-buffer completion). Useful for tracking down resource lifetime errors.
	- Fixed a number of bugs related to the modifications to vertex stream handling and addition of the SetShaderBytes API.
	- Track the start & end of FRingBuffer ranges - it appeared that the ring-buffer usage was invalid but it was in fact only my assumptions about the range that needed to be scribbled for rhi.Metal.BufferScribble. There is still the possibility that command-buffers that are implicitly parallelised by the driver may cause the ring-buffer range tracking to go awry - but with our data dependencies and the separation of the async. compute context I don't believe this is likely.
	- Fix up the "nometalv2" flag so that we can disable the features only available on iOS/tvOS-10/macOS-10.12 on newer devices to save having to reboot all the time.
	- Fixed the flickering geometry when enabling rhi.Metal.RuntimeDebugLevel=4 which breaks render passes into separate command-buffers - the occlusion query was waiting on the wrong command buffer in this case.

Change 3163752 on 2016/10/14 by Mark.Satterthwaite

	Add missing parenthesis to fix compile error on iOS.

Change 3164151 on 2016/10/16 by Benjamin.Hyder

	Submitting TM-AutoLOD level to QAGame

	#jira UE-29618

Change 3164190 on 2016/10/16 by Uriel.Doyon

	Materials now hold texture streaming data in the form of (UV scale X UV channel) for each texture.
	This data can be disabled through "r.Streaming.UseMaterialData"
	Defined a common framework in MeshComponent for texture streaming, used by both StaticMeshes and SkeletalMeshes.
	Simplified component interface for using the texture streaming build framework.
	Removed intermediate texture streaming build data from the static mesh components.
	Fixed shader compilation errors with the decals (from merge with main).

Change 3164636 on 2016/10/17 by Rolando.Caloca

	DR - vk - Fix validation spam

Change 3164679 on 2016/10/17 by Arne.Schober

	DR - [OR-28457] Part1, Scene View Refactoring - Removed Previous VewMatrices from SceneInfo and pass in Previous and Current ViewMatrices into Uniform Buffer creation to uniform UseCase for Shadows and CustomDepth, Fixed a Bug in Shadows with help of Daniel where the SceneView was copied unnecessary copied again. Also simplified the code in that area.

Change 3164705 on 2016/10/17 by Daniel.Wright

	When new levels are loaded, only the Indirect Lighting Cache Allocations intersecting the level's light probes are updated to minimize hitches.  This optimization requires a lighting build to compute PrecomputedLightVolume bounds.

Change 3164834 on 2016/10/17 by Daniel.Wright

	Support directional light dynamic shadows in any channel with forward shading, which can happen with multiple shadow casting stationary directional lights (even though only the lighting of one will appear)

Change 3164870 on 2016/10/17 by Arne.Schober

	DR - [OR-28457] Part2, Custom Depth Jitter - Allowed to overwite the viewconstant buffer in the custom depth pass. There ia also a new Project Setting available. The default constructor of the ContextDataType has been explicitly deleted to enforce compile errors when the templated code like the StaticMeshDrawList accidently tries to create a context without ViewUniformBuffer.

Change 3164949 on 2016/10/17 by Rolando.Caloca

	DR - vk - First version of pooled occlusion queries

Change 3165100 on 2016/10/17 by Rolando.Caloca

	DR - vk - Added driver version for Nvidia. AMD doesn't have one yet.

Change 3165160 on 2016/10/17 by Rolando.Caloca

	DR - vk - Fix for queries not ready

Change 3165230 on 2016/10/17 by Rolando.Caloca

	DR - vk - More fixes for occlusion queries

Change 3165839 on 2016/10/18 by Rolando.Caloca

	DR - hlslcc - Fix default parameters getting wrong values

Change 3166029 on 2016/10/18 by Rolando.Caloca

	DR - Switch some clears to DrawClearQuad()

Change 3166066 on 2016/10/18 by Mark.Satterthwaite

	Update ShaderVersion due to CL #3163524

Change 3166067 on 2016/10/18 by Mark.Satterthwaite

	Update Mac hlslcc for RCO's 3165839.

Change 3166370 on 2016/10/18 by Brian.Karis

	Improved hair AA

Change 3166389 on 2016/10/18 by Uriel.Doyon

	Fixed lightmap having bigger resolutions than the engine can handle
	#jira UE-34737
	#review-3166193 @daniel.wright

Change 3166495 on 2016/10/18 by Rolando.Caloca

	DR - vk - Fix occlusion queries

Change 3166516 on 2016/10/18 by Arne.Schober

	DR - Fix shaderbuild issue

Change 3166650 on 2016/10/18 by Rolando.Caloca

	DR - vk - Enable GRHISupportsFirstInstance

Change 3166799 on 2016/10/18 by Arne.Schober

	DR - [OR-28508] - The velocity Rendering pass was missing the adjustment for the PDO

Change 3167855 on 2016/10/19 by Rolando.Caloca

	DR - vk - Implemented texture streaming

Change 3168365 on 2016/10/19 by Rolando.Caloca

	DR - Fix static analysis

Change 3168405 on 2016/10/19 by Mark.Satterthwaite

	Fix the optional shader data changes from Unicorn to prevent FindOptionalData from erronesouly testing against the trailing optional data size, which can match the tag for optional data entries if you are unlucky.
	#jira UE-37489

Change 3169467 on 2016/10/20 by Arne.Schober

	DR - UE-28039 - Fixed flickering cached shadows on dynamic objects: Adding preshadows whose depths are cached so that GatherDynamicMeshElements will still happen, which is necessary for preshadow receiver stenciling.

Change 3169478 on 2016/10/20 by Arne.Schober

	DR - UE-28039 - missing comment

Change 3169845 on 2016/10/20 by Arne.Schober

	DR - UE-35937 - readd Merged out check

Change 3169859 on 2016/10/20 by Rolando.Caloca

	DR - vk - Stop popping up dialog on every run as the device name in the API doesn't match our driver database

[CL 3170066 by Marcus Wassmer in Main branch]
2016-10-20 20:09:22 -04:00

130 lines
3.4 KiB
C++

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
// .
#include "VulkanShaderFormat.h"
#include "Core.h"
#include "ModuleInterface.h"
#include "ModuleManager.h"
#include "TargetPlatform.h"
#include "hlslcc.h"
#include "ShaderCore.h"
static FName NAME_VULKAN_ES3_1_ANDROID(TEXT("SF_VULKAN_ES31_ANDROID"));
static FName NAME_VULKAN_ES3_1(TEXT("SF_VULKAN_ES31"));
static FName NAME_VULKAN_ES3_1_UB(TEXT("SF_VULKAN_ES31_UB"));
static FName NAME_VULKAN_SM4(TEXT("SF_VULKAN_SM4"));
static FName NAME_VULKAN_SM5(TEXT("SF_VULKAN_SM5"));
class FShaderFormatVulkan : public IShaderFormat
{
enum
{
UE_SHADER_VULKAN_ES3_1_VER = 7,
UE_SHADER_VULKAN_ES3_1_ANDROID_VER = 7,
UE_SHADER_VULKAN_ES3_1_UB_VER = 7,
UE_SHADER_VULKAN_SM4_VER = 7,
UE_SHADER_VULKAN_SM5_VER = 7,
};
int32 InternalGetVersion(FName Format) const
{
if (Format == NAME_VULKAN_SM4)
{
return UE_SHADER_VULKAN_SM4_VER;
}
else if (Format == NAME_VULKAN_SM5)
{
return UE_SHADER_VULKAN_SM5_VER;
}
else if (Format == NAME_VULKAN_ES3_1_ANDROID)
{
return UE_SHADER_VULKAN_ES3_1_ANDROID_VER;
}
else if (Format == NAME_VULKAN_ES3_1)
{
return UE_SHADER_VULKAN_ES3_1_VER;
}
else if (Format == NAME_VULKAN_ES3_1_UB)
{
return UE_SHADER_VULKAN_ES3_1_UB_VER;
}
check(0);
return -1;
}
public:
virtual uint16 GetVersion(FName Format) const override
{
const uint8 HLSLCCVersion = ((HLSLCC_VersionMajor & 0x0f) << 4) | (HLSLCC_VersionMinor & 0x0f);
const uint16 Version = ((HLSLCCVersion & 0xff) << 8) | (InternalGetVersion(Format) & 0xff);
return Version;
}
virtual void GetSupportedFormats(TArray<FName>& OutFormats) const
{
OutFormats.Add(NAME_VULKAN_SM4);
OutFormats.Add(NAME_VULKAN_SM5);
OutFormats.Add(NAME_VULKAN_ES3_1_ANDROID);
OutFormats.Add(NAME_VULKAN_ES3_1);
OutFormats.Add(NAME_VULKAN_ES3_1_UB);
}
virtual void CompileShader(FName Format, const struct FShaderCompilerInput& Input, struct FShaderCompilerOutput& Output,const FString& WorkingDirectory) const
{
check(InternalGetVersion(Format) >= 0);
if (Format == NAME_VULKAN_ES3_1)
{
CompileShader_Windows_Vulkan(Input, Output, WorkingDirectory, EVulkanShaderVersion::ES3_1);
}
else if (Format == NAME_VULKAN_ES3_1_ANDROID)
{
CompileShader_Windows_Vulkan(Input, Output, WorkingDirectory, EVulkanShaderVersion::ES3_1_ANDROID);
}
else if (Format == NAME_VULKAN_ES3_1_UB)
{
CompileShader_Windows_Vulkan(Input, Output, WorkingDirectory, EVulkanShaderVersion::ES3_1_UB);
}
else if (Format == NAME_VULKAN_SM4)
{
CompileShader_Windows_Vulkan(Input, Output, WorkingDirectory, EVulkanShaderVersion::SM4);
}
else if (Format == NAME_VULKAN_SM5)
{
CompileShader_Windows_Vulkan(Input, Output, WorkingDirectory, EVulkanShaderVersion::SM5);
}
}
//virtual bool CreateLanguage(FName Format, ILanguageSpec*& OutSpec, FCodeBackend*& OutBackend, uint32 InHlslCompileFlags) override
//{
// OutSpec = new FVulkanLanguageSpec(false);
// OutBackend = new FVulkanCodeBackend(InHlslCompileFlags, HCT_FeatureLevelSM4);
// return false;
//}
};
/**
* Module for Vulkan shaders
*/
static IShaderFormat* Singleton = NULL;
class FVulkanShaderFormatModule : public IShaderFormatModule
{
public:
virtual ~FVulkanShaderFormatModule()
{
delete Singleton;
Singleton = NULL;
}
virtual IShaderFormat* GetShaderFormat()
{
if (!Singleton)
{
Singleton = new FShaderFormatVulkan();
}
return Singleton;
}
};
IMPLEMENT_MODULE( FVulkanShaderFormatModule, VulkanShaderFormat);