Adds everything
This commit is contained in:
57
Plugins/DLSS/Source/DLSSUtility/DLSSUtility.Build.cs
Normal file
57
Plugins/DLSS/Source/DLSSUtility/DLSSUtility.Build.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2020 - 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
*
|
||||
* NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
|
||||
* property and proprietary rights in and to this material, related
|
||||
* documentation and any modifications thereto. Any use, reproduction,
|
||||
* disclosure or distribution of this material and related documentation
|
||||
* without an express license agreement from NVIDIA CORPORATION or
|
||||
* its affiliates is strictly prohibited.
|
||||
*/
|
||||
|
||||
using UnrealBuildTool;
|
||||
using System.IO;
|
||||
|
||||
public class DLSSUtility : ModuleRules
|
||||
{
|
||||
public DLSSUtility(ReadOnlyTargetRules Target) : base(Target)
|
||||
{
|
||||
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
|
||||
|
||||
PublicIncludePaths.AddRange(
|
||||
new string[] {
|
||||
}
|
||||
);
|
||||
|
||||
PrivateIncludePaths.AddRange(
|
||||
new string[] {
|
||||
Path.Combine(EngineDirectory,"Source/Runtime/Renderer/Private"),
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
PublicDependencyModuleNames.AddRange(
|
||||
new string[]
|
||||
{
|
||||
"Core",
|
||||
"RenderCore",
|
||||
"Renderer",
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
PrivateDependencyModuleNames.AddRange(
|
||||
new string[]
|
||||
{
|
||||
"Engine",
|
||||
"RHI",
|
||||
"Projects"
|
||||
}
|
||||
);
|
||||
|
||||
// 4.x and early access 5.0 engines used FVector2D type instead of FVector2f type for shader parameters
|
||||
bool bEngineUsesFVector2D = (Target.Version.MajorVersion == 4) || (Target.Version.BranchName == "++UE5+Release-5.0-EarlyAccess");
|
||||
PrivateDefinitions.Add(string.Format("DLSS_ENGINE_USES_FVECTOR2D={0}", bEngineUsesFVector2D ? "1" : "0"));
|
||||
}
|
||||
}
|
||||
42
Plugins/DLSS/Source/DLSSUtility/Private/DLSSUtility.cpp
Normal file
42
Plugins/DLSS/Source/DLSSUtility/Private/DLSSUtility.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2020 NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* NVIDIA Corporation and its licensors retain all intellectual property and proprietary
|
||||
* rights in and to this software, related documentation and any modifications thereto.
|
||||
* Any use, reproduction, disclosure or distribution of this software and related
|
||||
* documentation without an express license agreement from NVIDIA Corporation is strictly
|
||||
* prohibited.
|
||||
*
|
||||
* TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED *AS IS*
|
||||
* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS OR IMPLIED,
|
||||
* INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS BE LIABLE FOR ANY
|
||||
* SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF
|
||||
* BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
|
||||
* INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGES.
|
||||
*/
|
||||
|
||||
#include "DLSSUtility.h"
|
||||
#include "Modules/ModuleManager.h"
|
||||
#include "Interfaces/IPluginManager.h"
|
||||
#include "ShaderCore.h"
|
||||
|
||||
#define LOCTEXT_NAMESPACE "FDLSSUtilityModule"
|
||||
|
||||
void FDLSSUtilityModule::StartupModule()
|
||||
{
|
||||
FString PluginShaderDir = FPaths::Combine(IPluginManager::Get().FindPlugin(TEXT("DLSS"))->GetBaseDir(), TEXT("Shaders"));
|
||||
AddShaderSourceDirectoryMapping(TEXT("/Plugin/DLSS"), PluginShaderDir);
|
||||
|
||||
}
|
||||
|
||||
void FDLSSUtilityModule::ShutdownModule()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#undef LOCTEXT_NAMESPACE
|
||||
|
||||
IMPLEMENT_MODULE(FDLSSUtilityModule, DLSSUtility)
|
||||
153
Plugins/DLSS/Source/DLSSUtility/Private/VelocityCombinePass.cpp
Normal file
153
Plugins/DLSS/Source/DLSSUtility/Private/VelocityCombinePass.cpp
Normal file
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Copyright (c) 2020 - 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
*
|
||||
* NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
|
||||
* property and proprietary rights in and to this material, related
|
||||
* documentation and any modifications thereto. Any use, reproduction,
|
||||
* disclosure or distribution of this material and related documentation
|
||||
* without an express license agreement from NVIDIA CORPORATION or
|
||||
* its affiliates is strictly prohibited.
|
||||
*/
|
||||
|
||||
#include "VelocityCombinePass.h"
|
||||
|
||||
|
||||
const int32 kVelocityCombineComputeTileSizeX = FComputeShaderUtils::kGolden2DGroupSize;
|
||||
const int32 kVelocityCombineComputeTileSizeY = FComputeShaderUtils::kGolden2DGroupSize;
|
||||
|
||||
|
||||
class FDilateMotionVectorsDim : SHADER_PERMUTATION_BOOL("DILATE_MOTION_VECTORS");
|
||||
|
||||
class FVelocityCombineCS : public FGlobalShader
|
||||
{
|
||||
public:
|
||||
static bool ShouldCompilePermutation(const FGlobalShaderPermutationParameters& Parameters)
|
||||
{
|
||||
// Only cook for the platforms/RHIs where DLSS is supported, which is DX11,DX12 and Vulkan [on Win64]
|
||||
return IsFeatureLevelSupported(Parameters.Platform, ERHIFeatureLevel::SM5) &&
|
||||
IsPCPlatform(Parameters.Platform) && (
|
||||
IsVulkanSM5Platform(Parameters.Platform) ||
|
||||
#if (ENGINE_MAJOR_VERSION == 4) && (ENGINE_MINOR_VERSION == 26)
|
||||
IsD3DPlatform(Parameters.Platform, false));
|
||||
#else
|
||||
IsD3DPlatform(Parameters.Platform));
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
static void ModifyCompilationEnvironment(const FGlobalShaderPermutationParameters& Parameters, FShaderCompilerEnvironment& OutEnvironment)
|
||||
{
|
||||
FGlobalShader::ModifyCompilationEnvironment(Parameters, OutEnvironment);
|
||||
OutEnvironment.SetDefine(TEXT("THREADGROUP_SIZEX"), kVelocityCombineComputeTileSizeX);
|
||||
OutEnvironment.SetDefine(TEXT("THREADGROUP_SIZEY"), kVelocityCombineComputeTileSizeY);
|
||||
}
|
||||
using FPermutationDomain = TShaderPermutationDomain<FDilateMotionVectorsDim>;
|
||||
|
||||
DECLARE_GLOBAL_SHADER(FVelocityCombineCS);
|
||||
SHADER_USE_PARAMETER_STRUCT(FVelocityCombineCS, FGlobalShader);
|
||||
|
||||
BEGIN_SHADER_PARAMETER_STRUCT(FParameters, )
|
||||
// Input images
|
||||
SHADER_PARAMETER_RDG_TEXTURE(Texture2D, VelocityTexture)
|
||||
SHADER_PARAMETER_SAMPLER(SamplerState, VelocityTextureSampler)
|
||||
SHADER_PARAMETER_STRUCT(FScreenPassTextureViewportParameters, Velocity)
|
||||
|
||||
SHADER_PARAMETER_RDG_TEXTURE(Texture2D, DepthTexture)
|
||||
SHADER_PARAMETER_SAMPLER(SamplerState, DepthTextureSampler)
|
||||
|
||||
#if DLSS_ENGINE_USES_FVECTOR2D
|
||||
SHADER_PARAMETER(FVector2D, TemporalJitterPixels)
|
||||
#else
|
||||
SHADER_PARAMETER(FVector2f, TemporalJitterPixels)
|
||||
#endif
|
||||
|
||||
SHADER_PARAMETER_STRUCT_REF(FViewUniformShaderParameters, View)
|
||||
|
||||
// Output images
|
||||
SHADER_PARAMETER_RDG_TEXTURE_UAV(RWTexture2D, OutVelocityCombinedTexture)
|
||||
SHADER_PARAMETER_STRUCT(FScreenPassTextureViewportParameters, CombinedVelocity)
|
||||
|
||||
END_SHADER_PARAMETER_STRUCT()
|
||||
};
|
||||
|
||||
|
||||
IMPLEMENT_GLOBAL_SHADER(FVelocityCombineCS, "/Plugin/DLSS/Private/VelocityCombine.usf", "VelocityCombineMain", SF_Compute);
|
||||
|
||||
FRDGTextureRef AddVelocityCombinePass(
|
||||
FRDGBuilder& GraphBuilder,
|
||||
const FViewInfo& View,
|
||||
FRDGTextureRef InSceneDepthTexture,
|
||||
FRDGTextureRef InVelocityTexture,
|
||||
bool bDilateMotionVectors
|
||||
)
|
||||
{
|
||||
const FIntRect InputViewRect = View.ViewRect;
|
||||
const FIntRect OutputViewRect = FIntRect( FIntPoint::ZeroValue, bDilateMotionVectors ? View.GetSecondaryViewRectSize() : View.ViewRect.Size());
|
||||
|
||||
FRDGTextureDesc CombinedVelocityDesc = FRDGTextureDesc::Create2D(
|
||||
OutputViewRect.Size(),
|
||||
PF_G16R16F,
|
||||
FClearValueBinding::Black,
|
||||
TexCreate_ShaderResource | TexCreate_UAV);
|
||||
const TCHAR* OutputName = TEXT("DLSSCombinedVelocity");
|
||||
|
||||
FRDGTextureRef CombinedVelocityTexture = GraphBuilder.CreateTexture(
|
||||
CombinedVelocityDesc,
|
||||
OutputName);
|
||||
|
||||
FVelocityCombineCS::FParameters* PassParameters = GraphBuilder.AllocParameters<FVelocityCombineCS::FParameters>();
|
||||
|
||||
// input velocity
|
||||
{
|
||||
PassParameters->VelocityTexture = InVelocityTexture;
|
||||
PassParameters->VelocityTextureSampler = TStaticSamplerState<SF_Point>::GetRHI();
|
||||
|
||||
// we use InSceneDepthTexture here and not InVelocityTexture since the latter can be a 1x1 black texture
|
||||
check(InVelocityTexture->Desc.Extent == FIntPoint(1, 1) || InVelocityTexture->Desc.Extent == InSceneDepthTexture->Desc.Extent);
|
||||
FScreenPassTextureViewport velocityViewport(InSceneDepthTexture, InputViewRect);
|
||||
FScreenPassTextureViewportParameters velocityViewportParameters = GetScreenPassTextureViewportParameters(velocityViewport);
|
||||
PassParameters->Velocity = velocityViewportParameters;
|
||||
}
|
||||
// input depth
|
||||
{
|
||||
PassParameters->DepthTexture = InSceneDepthTexture;
|
||||
PassParameters->DepthTextureSampler = TStaticSamplerState<SF_Point>::GetRHI();
|
||||
}
|
||||
// output combined velocity
|
||||
{
|
||||
PassParameters->OutVelocityCombinedTexture = GraphBuilder.CreateUAV(CombinedVelocityTexture);
|
||||
|
||||
FScreenPassTextureViewport CombinedVelocityViewport(CombinedVelocityTexture, OutputViewRect);
|
||||
FScreenPassTextureViewportParameters CombinedVelocityViewportParameters = GetScreenPassTextureViewportParameters(CombinedVelocityViewport);
|
||||
PassParameters->CombinedVelocity = CombinedVelocityViewportParameters;
|
||||
}
|
||||
|
||||
// various state
|
||||
{
|
||||
|
||||
#if ENGINE_MAJOR_VERSION < 5
|
||||
PassParameters->TemporalJitterPixels = View.TemporalJitterPixels;
|
||||
#else
|
||||
PassParameters->TemporalJitterPixels = FVector2f(View.TemporalJitterPixels); // LWC_TODO: Precision loss
|
||||
#endif
|
||||
PassParameters->View = View.ViewUniformBuffer;
|
||||
}
|
||||
|
||||
FVelocityCombineCS::FPermutationDomain PermutationVector;
|
||||
PermutationVector.Set<FDilateMotionVectorsDim>(bDilateMotionVectors);
|
||||
|
||||
TShaderMapRef<FVelocityCombineCS> ComputeShader(View.ShaderMap, PermutationVector);
|
||||
|
||||
FComputeShaderUtils::AddPass(
|
||||
GraphBuilder,
|
||||
RDG_EVENT_NAME("Velocity Combine%s (%dx%d -> %dx%d)",
|
||||
bDilateMotionVectors ? TEXT(" Dilate") : TEXT(""),
|
||||
InputViewRect.Width(), InputViewRect.Height(),
|
||||
OutputViewRect.Width(), OutputViewRect.Height()
|
||||
),
|
||||
ComputeShader,
|
||||
PassParameters,
|
||||
FComputeShaderUtils::GetGroupCount(OutputViewRect.Size(), FComputeShaderUtils::kGolden2DGroupSize));
|
||||
|
||||
return CombinedVelocityTexture;
|
||||
}
|
||||
35
Plugins/DLSS/Source/DLSSUtility/Public/DLSSUtility.h
Normal file
35
Plugins/DLSS/Source/DLSSUtility/Public/DLSSUtility.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2020 NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* NVIDIA Corporation and its licensors retain all intellectual property and proprietary
|
||||
* rights in and to this software, related documentation and any modifications thereto.
|
||||
* Any use, reproduction, disclosure or distribution of this software and related
|
||||
* documentation without an express license agreement from NVIDIA Corporation is strictly
|
||||
* prohibited.
|
||||
*
|
||||
* TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED *AS IS*
|
||||
* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS OR IMPLIED,
|
||||
* INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS BE LIABLE FOR ANY
|
||||
* SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF
|
||||
* BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
|
||||
* INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGES.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Modules/ModuleManager.h"
|
||||
|
||||
|
||||
class FDLSSUtilityModule final : public IModuleInterface
|
||||
{
|
||||
public:
|
||||
|
||||
/** IModuleInterface implementation */
|
||||
virtual void StartupModule() override;
|
||||
virtual void ShutdownModule() override;
|
||||
|
||||
private:
|
||||
};
|
||||
34
Plugins/DLSS/Source/DLSSUtility/Public/VelocityCombinePass.h
Normal file
34
Plugins/DLSS/Source/DLSSUtility/Public/VelocityCombinePass.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2020 NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* NVIDIA Corporation and its licensors retain all intellectual property and proprietary
|
||||
* rights in and to this software, related documentation and any modifications thereto.
|
||||
* Any use, reproduction, disclosure or distribution of this software and related
|
||||
* documentation without an express license agreement from NVIDIA Corporation is strictly
|
||||
* prohibited.
|
||||
*
|
||||
* TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED *AS IS*
|
||||
* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS OR IMPLIED,
|
||||
* INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS BE LIABLE FOR ANY
|
||||
* SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF
|
||||
* BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
|
||||
* INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGES.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "RendererInterface.h"
|
||||
#include "ScreenPass.h"
|
||||
|
||||
|
||||
extern DLSSUTILITY_API FRDGTextureRef AddVelocityCombinePass(
|
||||
FRDGBuilder& GraphBuilder,
|
||||
const FViewInfo& View,
|
||||
FRDGTextureRef InSceneDepthTexture,
|
||||
FRDGTextureRef InVelocityTexture,
|
||||
bool bDilateMotionVectors
|
||||
);
|
||||
Reference in New Issue
Block a user