diff --git a/Plugins/GameFeatures/ShooterCore/Content/Experiences/B_ShooterGame_Elimination.uasset b/Plugins/GameFeatures/ShooterCore/Content/Experiences/B_ShooterGame_Elimination.uasset index bc2b455b..80c7c83b 100644 --- a/Plugins/GameFeatures/ShooterCore/Content/Experiences/B_ShooterGame_Elimination.uasset +++ b/Plugins/GameFeatures/ShooterCore/Content/Experiences/B_ShooterGame_Elimination.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fe9e047562ad4645e4fc98696672ee1f8e9ff4a61e4a4b1cc440e6c1c30f0aab -size 11414 +oid sha256:d560527d0c8d9b3e638d06665c5f1376d8239441c83268fa35c97cf63ed9f497 +size 11675 diff --git a/Plugins/StyleTransfer/Shaders/Private/OutputTensorToSceneColor.usf b/Plugins/StyleTransfer/Shaders/Private/OutputTensorToSceneColor.usf index e0af32a0..47fa3a25 100644 --- a/Plugins/StyleTransfer/Shaders/Private/OutputTensorToSceneColor.usf +++ b/Plugins/StyleTransfer/Shaders/Private/OutputTensorToSceneColor.usf @@ -6,26 +6,27 @@ RWTexture2D OutputTexture; Buffer InputTensor; -[numthreads(1, 1, 1)] +[numthreads(THREADGROUP_SIZE_X, THREADGROUP_SIZE_Y, THREADGROUP_SIZE_Z)] void OutputTensorToSceneColorCS(in const uint3 DispatchThreadID : SV_DispatchThreadID) { - const uint GlobalIndex = DispatchThreadID.x; uint TensorVolume; InputTensor.GetDimensions(TensorVolume); + uint2 TextureSize = 0; + OutputTexture.GetDimensions(TextureSize.x, TextureSize.y); + + // note that the input tensor has shape (1, Y, X, C) + // which is why we need to flip the indexing + const uint PixelIndex = DispatchThreadID.x * TextureSize.y + DispatchThreadID.x; + const uint GlobalIndex = PixelIndex * 3; + if (GlobalIndex >= TensorVolume) { return; } - uint2 TextureSize = 0; - OutputTexture.GetDimensions(TextureSize.x, TextureSize.y); - const uint PixelIndex = GlobalIndex / 3; - const uint ChannelIndex = GlobalIndex % 3; - const uint MajorIndex = PixelIndex / TextureSize.x; - const uint MinorIndex = PixelIndex % TextureSize.x; - const uint2 TextureCoords = uint2(MajorIndex, MinorIndex); + const uint2 TextureCoords = uint2(DispatchThreadID.y, DispatchThreadID.x); OutputTexture[TextureCoords] = float4( InputTensor[GlobalIndex + 0], InputTensor[GlobalIndex + 1], diff --git a/Plugins/StyleTransfer/Shaders/Private/SceneColorToInputTensor.usf b/Plugins/StyleTransfer/Shaders/Private/SceneColorToInputTensor.usf index 72ce6ffe..ec794534 100644 --- a/Plugins/StyleTransfer/Shaders/Private/SceneColorToInputTensor.usf +++ b/Plugins/StyleTransfer/Shaders/Private/SceneColorToInputTensor.usf @@ -3,24 +3,28 @@ #include "/Engine/Public/Platform.ush" Texture2D InputTexture; +SamplerState InputTextureSampler; RWBuffer OutputUAV; +uint2 OutputDimensions; // X = InputTensor.GetSize(1), Y = InputTensor.GetSize(2) -> this does not correspond to input texture XY +float2 HalfPixelUV; [numthreads(THREADGROUP_SIZE_X, THREADGROUP_SIZE_Y, THREADGROUP_SIZE_Z)] void SceneColorToInputTensorCS(in const uint3 DispatchThreadID : SV_DispatchThreadID) { - uint2 TexelCoordinate = DispatchThreadID.xy; - - const uint GlobalIndex = TexelCoordinate.x * TexelCoordinate.y * 3; - - uint TensorVolume; - OutputUAV.GetDimensions(TensorVolume); - - if (GlobalIndex >= TensorVolume) + const uint2 OutputUAVTexelCoordinate = DispatchThreadID.xy; + if(any(OutputUAVTexelCoordinate > OutputDimensions)) { return; } - float4 TextureValue = InputTexture[DispatchThreadID.xy]; + const uint GlobalIndex = (OutputUAVTexelCoordinate.x * OutputDimensions.x + OutputUAVTexelCoordinate.y) * 3; + + // note that the input tensor has shape (1, Y, X, C) + // which is why we need to flip the indexing + const float2 UV = OutputUAVTexelCoordinate.yx / OutputDimensions.yx + HalfPixelUV; + + const float4 TextureValue = InputTexture.SampleLevel(InputTextureSampler, UV, 0); + OutputUAV[GlobalIndex + 0] = TextureValue.r; OutputUAV[GlobalIndex + 1] = TextureValue.g; OutputUAV[GlobalIndex + 2] = TextureValue.b; diff --git a/Plugins/StyleTransfer/Source/StyleTransfer/Private/StyleTransferSceneViewExtension.cpp b/Plugins/StyleTransfer/Source/StyleTransfer/Private/StyleTransferSceneViewExtension.cpp index 96d474b3..38a6295b 100644 --- a/Plugins/StyleTransfer/Source/StyleTransfer/Private/StyleTransferSceneViewExtension.cpp +++ b/Plugins/StyleTransfer/Source/StyleTransfer/Private/StyleTransferSceneViewExtension.cpp @@ -35,17 +35,17 @@ OutType CastNarrowingSafe(InType InValue) } -FStyleTransferSceneViewExtension::FStyleTransferSceneViewExtension(const FAutoRegister& AutoRegister, FViewportClient* AssociatedViewportClient, UNeuralNetwork* InStyleTransferNetwork) +FStyleTransferSceneViewExtension::FStyleTransferSceneViewExtension(const FAutoRegister& AutoRegister, FViewportClient* AssociatedViewportClient, UNeuralNetwork* InStyleTransferNetwork, int32 InInferenceContext) : FSceneViewExtensionBase(AutoRegister) , StyleTransferNetwork(InStyleTransferNetwork) , LinkedViewportClient(AssociatedViewportClient) + , InferenceContext(InInferenceContext) { ensure(InStyleTransferNetwork->GetDeviceType() == ENeuralDeviceType::GPU); } void FStyleTransferSceneViewExtension::SetupViewFamily(FSceneViewFamily& InViewFamily) { - InferenceContext = StyleTransferNetwork->CreateInferenceContext(); } void FStyleTransferSceneViewExtension::SubscribeToPostProcessingPass(EPostProcessingPass PassId, @@ -79,30 +79,8 @@ FScreenPassTexture FStyleTransferSceneViewExtension::PostProcessPassAfterTonemap RDG_EVENT_SCOPE(GraphBuilder, "StyleTransfer"); - FScreenPassRenderTarget BackBufferRenderTarget; - - // If the override output is provided it means that this is the last pass in post processing. - if (InOutInputs.OverrideOutput.IsValid()) - { - BackBufferRenderTarget = InOutInputs.OverrideOutput; - } - else - { - // Reusing the same output description for our back buffer as SceneColor when it's not overriden - FRDGTextureDesc OutputDesc = SceneColor.Texture->Desc; - OutputDesc.Flags |= TexCreate_RenderTargetable; - FLinearColor ClearColor(0., 0., 0., 0.); - OutputDesc.ClearValue = FClearValueBinding(ClearColor); - - FRDGTexture* BackBufferRenderTargetTexture = GraphBuilder.CreateTexture( - OutputDesc, TEXT("BackBufferRenderTargetTexture")); - BackBufferRenderTarget = FScreenPassRenderTarget(BackBufferRenderTargetTexture, SceneColor.ViewRect, - ERenderTargetLoadAction::EClear); - } - //Get input and output viewports. Backbuffer could be targeting a different region than input viewport const FScreenPassTextureViewport SceneColorViewport(SceneColor); - const FScreenPassTextureViewport BackBufferViewport(BackBufferRenderTarget); FScreenPassRenderTarget SceneColorRenderTarget(SceneColor, ERenderTargetLoadAction::ELoad); @@ -112,15 +90,29 @@ FScreenPassTexture FStyleTransferSceneViewExtension::PostProcessPassAfterTonemap /*AddDrawScreenPass(GraphBuilder, RDG_EVENT_NAME("ProcessOCIOColorSpaceXfrm"), ViewInfo, BackBufferViewport, SceneColorViewport, OCIOPixelShader, Parameters);*/ + const FNeuralTensor& StyleTransferContentInputTensor = StyleTransferNetwork->GetInputTensorForContext(InferenceContext, 0); + + const FIntVector InputTensorDimensions = { + CastNarrowingSafe(StyleTransferContentInputTensor.GetSize(1)), + CastNarrowingSafe(StyleTransferContentInputTensor.GetSize(2)), + CastNarrowingSafe(StyleTransferContentInputTensor.GetSize(3)), + }; + const FIntPoint SceneColorRenderTargetDimensions = SceneColorRenderTarget.Texture->Desc.Extent; + + FRDGBufferRef StyleTransferContentInputBuffer = GraphBuilder.RegisterExternalBuffer(StyleTransferContentInputTensor.GetPooledBuffer()); auto SceneColorToInputTensorParameters = GraphBuilder.AllocParameters(); - FNeuralTensor InputTensor = StyleTransferNetwork->GetInputTensor(); - SceneColorToInputTensorParameters->TensorVolume = CastNarrowingSafe(InputTensor.Num()); + SceneColorToInputTensorParameters->TensorVolume = CastNarrowingSafe(StyleTransferContentInputTensor.Num()); SceneColorToInputTensorParameters->InputTexture = SceneColorRenderTarget.Texture; - SceneColorToInputTensorParameters->OutputUAV = InputTensor.GetBufferUAVRef(); - FIntVector SceneColorToInputTensorGroupCount; + SceneColorToInputTensorParameters->InputTextureSampler = TStaticSamplerState::GetRHI(); + SceneColorToInputTensorParameters->OutputUAV = GraphBuilder.CreateUAV(StyleTransferContentInputBuffer); + SceneColorToInputTensorParameters->OutputDimensions = {InputTensorDimensions.X, InputTensorDimensions.Y}; + SceneColorToInputTensorParameters->HalfPixelUV = FVector2f(0.5f / SceneColorRenderTargetDimensions.X, 0.5 / SceneColorRenderTargetDimensions.Y); + FIntVector SceneColorToInputTensorGroupCount = FComputeShaderUtils::GetGroupCount( + {InputTensorDimensions.X, InputTensorDimensions.Y, 1}, + FSceneColorToInputTensorCS::ThreadGroupSize + ); TShaderMapRef SceneColorToInputTensorCS(GetGlobalShaderMap(GMaxRHIFeatureLevel)); - ClearUnusedGraphResources(SceneColorToInputTensorCS, SceneColorToInputTensorParameters); GraphBuilder.AddPass( RDG_EVENT_NAME("SceneColorToInputTensor"), SceneColorToInputTensorParameters, @@ -132,17 +124,39 @@ FScreenPassTexture FStyleTransferSceneViewExtension::PostProcessPassAfterTonemap } ); - StyleTransferNetwork->GetInputDataPointerMutableForContext(InferenceContext, 0); + + const FNeuralTensor& StyleTransferOutputTensor = StyleTransferNetwork->GetOutputTensorForContext(InferenceContext, 0); + FIntVector OutputTensorDimensions = { + CastNarrowingSafe(StyleTransferOutputTensor.GetSize(1)), + CastNarrowingSafe(StyleTransferOutputTensor.GetSize(2)), + CastNarrowingSafe(StyleTransferOutputTensor.GetSize(3)), + }; + // Reusing the same output description for our back buffer as SceneColor + FRDGTextureDesc OutputDesc = SceneColor.Texture->Desc; + // this is flipped because the Output tensor has the vertical dimension first + // while unreal has the horizontal dimension first + OutputDesc.Extent = {OutputTensorDimensions[1], OutputTensorDimensions[0]}; + OutputDesc.Flags |= TexCreate_RenderTargetable | TexCreate_UAV; + FLinearColor ClearColor(0., 0., 0., 0.); + OutputDesc.ClearValue = FClearValueBinding(ClearColor); + FRDGTexture* StyleTransferRenderTargetTexture = GraphBuilder.CreateTexture( + OutputDesc, TEXT("StyleTransferRenderTargetTexture")); + TSharedPtr StyleTransferOutputTarget = MakeShared(StyleTransferRenderTargetTexture, SceneColor.ViewRect, + ERenderTargetLoadAction::EClear); + StyleTransferNetwork->Run(GraphBuilder, InferenceContext); + FRDGBufferRef StyleTransferOutputBuffer = GraphBuilder.RegisterExternalBuffer(StyleTransferContentInputTensor.GetPooledBuffer()); + auto OutputTensorToSceneColorParameters = GraphBuilder.AllocParameters(); - FNeuralTensor OutputTensor = StyleTransferNetwork->GetOutputTensor(0); - OutputTensorToSceneColorParameters->InputTensor = OutputTensor.GetBufferSRVRef(); - OutputTensorToSceneColorParameters->OutputTexture = GraphBuilder.CreateUAV(SceneColorRenderTarget.Texture); - FIntVector OutputTensorToSceneColorGroupCount; + OutputTensorToSceneColorParameters->InputTensor = GraphBuilder.CreateSRV(StyleTransferOutputBuffer, EPixelFormat::PF_FloatRGB); + OutputTensorToSceneColorParameters->OutputTexture = GraphBuilder.CreateUAV(StyleTransferRenderTargetTexture); + FIntVector OutputTensorToSceneColorGroupCount = FComputeShaderUtils::GetGroupCount( + {OutputTensorDimensions.X, OutputTensorDimensions.Y, 1}, + FOutputTensorToSceneColorCS::ThreadGroupSize + ); TShaderMapRef OutputTensorToSceneColorCS(GetGlobalShaderMap(GMaxRHIFeatureLevel)); - ClearUnusedGraphResources(OutputTensorToSceneColorCS, OutputTensorToSceneColorParameters); GraphBuilder.AddPass( RDG_EVENT_NAME("OutputTensorToSceneColor"), OutputTensorToSceneColorParameters, @@ -154,5 +168,19 @@ FScreenPassTexture FStyleTransferSceneViewExtension::PostProcessPassAfterTonemap } ); - return MoveTemp(BackBufferRenderTarget); + + TSharedPtr BackBufferRenderTarget; + // If the override output is provided it means that this is the last pass in post processing. + if (InOutInputs.OverrideOutput.IsValid()) + { + BackBufferRenderTarget = MakeShared(InOutInputs.OverrideOutput); + // @todo: do not use copy. Resample the styled 1920x960 texture to the fullscreen texture by drawing into the texture + AddCopyTexturePass(GraphBuilder, StyleTransferRenderTargetTexture, BackBufferRenderTarget->Texture); + } + else + { + BackBufferRenderTarget = StyleTransferOutputTarget; + } + + return MoveTemp(*BackBufferRenderTarget); } diff --git a/Plugins/StyleTransfer/Source/StyleTransfer/Private/StyleTransferSubsystem.cpp b/Plugins/StyleTransfer/Source/StyleTransfer/Private/StyleTransferSubsystem.cpp index e46b26b0..6ec57390 100644 --- a/Plugins/StyleTransfer/Source/StyleTransfer/Private/StyleTransferSubsystem.cpp +++ b/Plugins/StyleTransfer/Source/StyleTransfer/Private/StyleTransferSubsystem.cpp @@ -4,6 +4,7 @@ #include "StyleTransferSubsystem.h" #include "NeuralNetwork.h" +#include "RenderGraphUtils.h" #include "StyleTransferSceneViewExtension.h" void UStyleTransferSubsystem::Initialize(FSubsystemCollectionBase& Collection) @@ -15,14 +16,16 @@ void UStyleTransferSubsystem::Initialize(FSubsystemCollectionBase& Collection) if (StyleTransferNetwork->IsLoaded()) { - if (StyleTransferNetwork->IsGPUSupported()) + for (int32 i = 0; i < StyleTransferNetwork->GetInputTensorNumber(); ++i) { - StyleTransferNetwork->SetDeviceType(ENeuralDeviceType::GPU); - } - else - { - StyleTransferNetwork->SetDeviceType(ENeuralDeviceType::CPU); + const FNeuralTensor& InputTensor = StyleTransferNetwork->GetInputTensor(i); + if (InputTensor.GetName() != "style_params") + continue; + + StyleTransferStyleParamsInputIndex = i; + break; } + StyleTransferNetwork->SetDeviceType(ENeuralDeviceType::GPU, ENeuralDeviceType::GPU, ENeuralDeviceType::GPU); } else { @@ -32,14 +35,7 @@ void UStyleTransferSubsystem::Initialize(FSubsystemCollectionBase& Collection) if (StylePredictionNetwork->IsLoaded()) { - if (StylePredictionNetwork->IsGPUSupported()) - { - StylePredictionNetwork->SetDeviceType(ENeuralDeviceType::GPU); - } - else - { - StylePredictionNetwork->SetDeviceType(ENeuralDeviceType::CPU); - } + StyleTransferNetwork->SetDeviceType(ENeuralDeviceType::GPU, ENeuralDeviceType::GPU, ENeuralDeviceType::GPU); } else { @@ -50,19 +46,32 @@ void UStyleTransferSubsystem::Initialize(FSubsystemCollectionBase& Collection) void UStyleTransferSubsystem::Deinitialize() { StyleTransferSceneViewExtension.Reset(); - StylePredictionNetwork->DestroyInferenceContext(StylePredictionInferenceContext); + if(StylePredictionInferenceContext != INDEX_NONE) + { + StylePredictionNetwork->DestroyInferenceContext(StylePredictionInferenceContext); + } + if(StyleTransferInferenceContext != INDEX_NONE) + { + StyleTransferNetwork->DestroyInferenceContext(StyleTransferInferenceContext); + } Super::Deinitialize(); } void UStyleTransferSubsystem::StartStylizingViewport(FViewportClient* ViewportClient) { - StyleTransferSceneViewExtension = FSceneViewExtensions::NewExtension(ViewportClient, StyleTransferNetwork); StylePredictionInferenceContext = StylePredictionNetwork->CreateInferenceContext(); + checkf(StylePredictionInferenceContext != INDEX_NONE, TEXT("Could not create inference context for StylePredictionNetwork")); + StyleTransferInferenceContext = StyleTransferNetwork->CreateInferenceContext(); + checkf(StyleTransferInferenceContext != INDEX_NONE, TEXT("Could not create inference context for StyleTransferNetwork")); + + StyleTransferSceneViewExtension = FSceneViewExtensions::NewExtension(ViewportClient, StyleTransferNetwork, StyleTransferInferenceContext); } -void UStyleTransferSubsystem::UpdateStyle(FNeuralTensor StyleImage) +void UStyleTransferSubsystem::UpdateStyle(const FNeuralTensor& StyleImage) { + checkf(StyleTransferSceneViewExtension.IsValid(), TEXT("Can not update style while not stylizing")); + StylePredictionNetwork->SetInputFromArrayCopy(StyleImage.GetArrayCopy()); ENQUEUE_RENDER_COMMAND(StylePrediction)([this](FRHICommandListImmediate& RHICommandList) @@ -71,7 +80,17 @@ void UStyleTransferSubsystem::UpdateStyle(FNeuralTensor StyleImage) StylePredictionNetwork->Run(GraphBuilder, StylePredictionInferenceContext); - // @todo: copy output of style prediction network to input of style transfer network + const FNeuralTensor& OutputStyleParams = StylePredictionNetwork->GetOutputTensorForContext(StylePredictionInferenceContext, 0); + const FNeuralTensor& InputStyleParams = StyleTransferNetwork->GetInputTensorForContext(StyleTransferInferenceContext, StyleTransferStyleParamsInputIndex); + + FRDGBufferRef OutputStyleParamsBuffer = GraphBuilder.RegisterExternalBuffer(OutputStyleParams.GetPooledBuffer()); + FRDGBufferRef InputStyleParamsBuffer = GraphBuilder.RegisterExternalBuffer(InputStyleParams.GetPooledBuffer()); + const uint64 NumBytes = OutputStyleParams.NumInBytes(); + check(OutputStyleParamsBuffer->GetSize() == InputStyleParamsBuffer->GetSize()); + check(OutputStyleParamsBuffer->GetSize() == OutputStyleParams.NumInBytes()); + check(InputStyleParamsBuffer->GetSize() == InputStyleParams.NumInBytes()); + + AddCopyBufferPass(GraphBuilder, InputStyleParamsBuffer, OutputStyleParamsBuffer); GraphBuilder.Execute(); }); diff --git a/Plugins/StyleTransfer/Source/StyleTransfer/Public/StyleTransferSceneViewExtension.h b/Plugins/StyleTransfer/Source/StyleTransfer/Public/StyleTransferSceneViewExtension.h index 5c9f3038..6da3daca 100644 --- a/Plugins/StyleTransfer/Source/StyleTransfer/Public/StyleTransferSceneViewExtension.h +++ b/Plugins/StyleTransfer/Source/StyleTransfer/Public/StyleTransferSceneViewExtension.h @@ -9,7 +9,7 @@ public: using Ptr = TSharedPtr; using Ref = TSharedRef; - FStyleTransferSceneViewExtension(const FAutoRegister& AutoRegister, FViewportClient* AssociatedViewportClient, UNeuralNetwork* InStyleTransferNetwork); + FStyleTransferSceneViewExtension(const FAutoRegister& AutoRegister, FViewportClient* AssociatedViewportClient, UNeuralNetwork* InStyleTransferNetwork, int32 InInferenceContext); // - ISceneViewExtension virtual void SubscribeToPostProcessingPass(EPostProcessingPass Pass, FAfterPassCallbackDelegateArray& InOutPassCallbacks, bool bIsPassEnabled) override; diff --git a/Plugins/StyleTransfer/Source/StyleTransfer/Public/StyleTransferSubsystem.h b/Plugins/StyleTransfer/Source/StyleTransfer/Public/StyleTransferSubsystem.h index 1686e2f2..d65be25f 100644 --- a/Plugins/StyleTransfer/Source/StyleTransfer/Public/StyleTransferSubsystem.h +++ b/Plugins/StyleTransfer/Source/StyleTransfer/Public/StyleTransferSubsystem.h @@ -25,7 +25,7 @@ public: void StartStylizingViewport(FViewportClient* ViewportClient); - void UpdateStyle(FNeuralTensor StyleImage); + void UpdateStyle(const FNeuralTensor& StyleImage); private: FStyleTransferSceneViewExtension::Ptr StyleTransferSceneViewExtension; @@ -36,5 +36,8 @@ private: UPROPERTY() TObjectPtr StylePredictionNetwork; - int32 StylePredictionInferenceContext = -1; + int32 StylePredictionInferenceContext = INDEX_NONE; + int32 StyleTransferInferenceContext = INDEX_NONE; + + int32 StyleTransferStyleParamsInputIndex = INDEX_NONE; }; diff --git a/Plugins/StyleTransfer/Source/StyleTransferShaders/Private/OutputTensorToSceneColorCS.cpp b/Plugins/StyleTransfer/Source/StyleTransferShaders/Private/OutputTensorToSceneColorCS.cpp index bf2589f0..b2dbacf3 100644 --- a/Plugins/StyleTransfer/Source/StyleTransferShaders/Private/OutputTensorToSceneColorCS.cpp +++ b/Plugins/StyleTransfer/Source/StyleTransferShaders/Private/OutputTensorToSceneColorCS.cpp @@ -3,11 +3,15 @@ #include "OutputTensorToSceneColorCS.h" #include "Utils.h" - +const FIntVector FOutputTensorToSceneColorCS::ThreadGroupSize{8, 8, 1}; void FOutputTensorToSceneColorCS::ModifyCompilationEnvironment(const FGlobalShaderPermutationParameters& Parameters, FShaderCompilerEnvironment& OutEnvironment) { FGlobalShader::ModifyCompilationEnvironment(Parameters, OutEnvironment); + + OutEnvironment.SetDefine(TEXT("THREADGROUP_SIZE_X"), ThreadGroupSize.X); + OutEnvironment.SetDefine(TEXT("THREADGROUP_SIZE_Y"), ThreadGroupSize.Y); + OutEnvironment.SetDefine(TEXT("THREADGROUP_SIZE_Z"), ThreadGroupSize.Z); } IMPLEMENT_GLOBAL_SHADER(FOutputTensorToSceneColorCS, "/Plugins/StyleTransfer/Shaders/Private/OutputTensorToSceneColor.usf", "OutputTensorToSceneColorCS", SF_Compute); // Path defined in StyleTransferModule.cpp \ No newline at end of file diff --git a/Plugins/StyleTransfer/Source/StyleTransferShaders/Private/SceneColorToInputTensorCS.cpp b/Plugins/StyleTransfer/Source/StyleTransferShaders/Private/SceneColorToInputTensorCS.cpp index 0252df9d..1cec857c 100644 --- a/Plugins/StyleTransfer/Source/StyleTransferShaders/Private/SceneColorToInputTensorCS.cpp +++ b/Plugins/StyleTransfer/Source/StyleTransferShaders/Private/SceneColorToInputTensorCS.cpp @@ -3,15 +3,16 @@ #include "SceneColorToInputTensorCS.h" #include "Utils.h" +const FIntVector FSceneColorToInputTensorCS::ThreadGroupSize{8, 8, 1}; void FSceneColorToInputTensorCS::ModifyCompilationEnvironment(const FGlobalShaderPermutationParameters& Parameters, FShaderCompilerEnvironment& OutEnvironment) { FGlobalShader::ModifyCompilationEnvironment(Parameters, OutEnvironment); - OutEnvironment.SetDefine(TEXT("THREADGROUP_SIZE_X"), THREADGROUP_SIZE_X); - OutEnvironment.SetDefine(TEXT("THREADGROUP_SIZE_Y"), THREADGROUP_SIZE_Y); - OutEnvironment.SetDefine(TEXT("THREADGROUP_SIZE_Z"), 1); + OutEnvironment.SetDefine(TEXT("THREADGROUP_SIZE_X"), ThreadGroupSize.X); + OutEnvironment.SetDefine(TEXT("THREADGROUP_SIZE_Y"), ThreadGroupSize.Y); + OutEnvironment.SetDefine(TEXT("THREADGROUP_SIZE_Z"), ThreadGroupSize.Z); } IMPLEMENT_GLOBAL_SHADER(FSceneColorToInputTensorCS, diff --git a/Plugins/StyleTransfer/Source/StyleTransferShaders/Public/OutputTensorToSceneColorCS.h b/Plugins/StyleTransfer/Source/StyleTransferShaders/Public/OutputTensorToSceneColorCS.h index 787b4765..7c0ff926 100644 --- a/Plugins/StyleTransfer/Source/StyleTransferShaders/Public/OutputTensorToSceneColorCS.h +++ b/Plugins/StyleTransfer/Source/StyleTransferShaders/Public/OutputTensorToSceneColorCS.h @@ -16,9 +16,11 @@ class STYLETRANSFERSHADERS_API FOutputTensorToSceneColorCS : public FGlobalShade DECLARE_GLOBAL_SHADER(FOutputTensorToSceneColorCS); SHADER_USE_PARAMETER_STRUCT(FOutputTensorToSceneColorCS, FGlobalShader) + static const FIntVector ThreadGroupSize; + BEGIN_SHADER_PARAMETER_STRUCT(FParameters, ) SHADER_PARAMETER(uint32, TensorVolume) - SHADER_PARAMETER_RDG_BUFFER_SRV(Buffer, InputTensor) + SHADER_PARAMETER_RDG_BUFFER_SRV(Buffer, InputTensor) SHADER_PARAMETER_RDG_TEXTURE_UAV(RWTexture2D, OutputTexture) END_SHADER_PARAMETER_STRUCT() diff --git a/Plugins/StyleTransfer/Source/StyleTransferShaders/Public/SceneColorToInputTensorCS.h b/Plugins/StyleTransfer/Source/StyleTransferShaders/Public/SceneColorToInputTensorCS.h index 0697145c..6e86d50a 100644 --- a/Plugins/StyleTransfer/Source/StyleTransferShaders/Public/SceneColorToInputTensorCS.h +++ b/Plugins/StyleTransfer/Source/StyleTransferShaders/Public/SceneColorToInputTensorCS.h @@ -16,8 +16,9 @@ class STYLETRANSFERSHADERS_API FSceneColorToInputTensorCS : public FGlobalShader DECLARE_GLOBAL_SHADER(FSceneColorToInputTensorCS); SHADER_USE_PARAMETER_STRUCT(FSceneColorToInputTensorCS, FGlobalShader) - static const uint32 THREADGROUP_SIZE_X = 8; - static const uint32 THREADGROUP_SIZE_Y = 8; + + static const FIntVector ThreadGroupSize; + BEGIN_SHADER_PARAMETER_STRUCT(FParameters, ) // Input variables @@ -26,6 +27,9 @@ class STYLETRANSFERSHADERS_API FSceneColorToInputTensorCS : public FGlobalShader SHADER_PARAMETER_RDG_BUFFER_UAV(RWBuffer, OutputUAV) // Optional SRV/UAV variables SHADER_PARAMETER_RDG_TEXTURE(Texture2D, InputTexture) + SHADER_PARAMETER_SAMPLER(SamplerState, InputTextureSampler) + SHADER_PARAMETER(FIntPoint, OutputDimensions) + SHADER_PARAMETER(FVector2f, HalfPixelUV) END_SHADER_PARAMETER_STRUCT() // - FShader diff --git a/Source/LyraEditor.Target.cs b/Source/LyraEditor.Target.cs index c5ccf406..0b4ada0a 100644 --- a/Source/LyraEditor.Target.cs +++ b/Source/LyraEditor.Target.cs @@ -16,5 +16,7 @@ public class LyraEditorTarget : TargetRules // This is used for touch screen development along with the "Unreal Remote 2" app EnablePlugins.Add("RemoteSession"); + + IncludeOrderVersion = EngineIncludeOrderVersion.Latest; } } diff --git a/Source/LyraEditor/Validation/EditorValidator.cpp b/Source/LyraEditor/Validation/EditorValidator.cpp index 4fc518c6..1addd5ee 100644 --- a/Source/LyraEditor/Validation/EditorValidator.cpp +++ b/Source/LyraEditor/Validation/EditorValidator.cpp @@ -1,8 +1,8 @@ // Copyright Epic Games, Inc. All Rights Reserved. #include "EditorValidator.h" -#include "AssetRegistry/AssetData.h" -#include "AssetRegistry/AssetRegistryModule.h" +#include "AssetData.h" +#include "AssetRegistryModule.h" #include "Logging/MessageLog.h" #include "MessageLogModule.h" #include "Misc/ConfigCacheIni.h" @@ -435,16 +435,16 @@ void UEditorValidator::GetChangedAssetsForCode(IAssetRegistry& AssetRegistry, co if (UClass* ModifiedClass = ModifiedClassPtr.Get()) { // This finds all native derived blueprints, both direct subclasses, or subclasses of subclasses. - TSet DerivedClassNames; - TArray ClassNames; - ClassNames.Add(ModifiedClass->GetClassPathName()); - AssetRegistry.GetDerivedClassNames(ClassNames, TSet(), DerivedClassNames); + TSet DerivedClassNames; + TArray ClassNames; + ClassNames.Add(ModifiedClass->GetFName()); + AssetRegistry.GetDerivedClassNames(ClassNames, TSet(), DerivedClassNames); UE_LOG(LogLyraEditor, Display, TEXT("Validating Subclasses of %s in %s + %s"), *ModifiedClass->GetName(), *ChangedHeaderModule, *ChangedHeaderReleativeToModule); FARFilter Filter; Filter.bRecursiveClasses = true; - Filter.ClassPaths.Add(UBlueprintCore::StaticClass()->GetClassPathName()); + Filter.ClassNames.Add(UBlueprintCore::StaticClass()->GetFName()); // We enumerate all assets to find any blueprints who inherit from native classes directly - or // from other blueprints. @@ -460,7 +460,7 @@ void UEditorValidator::GetChangedAssetsForCode(IAssetRegistry& AssetRegistry, co { const FString ClassObjectPath = FPackageName::ExportTextPathToObjectPath(ClassFromData); const FString ClassName = FPackageName::ObjectPathToObjectName(ClassObjectPath); - if (DerivedClassNames.Contains(FTopLevelAssetPath(ClassName))) + if (DerivedClassNames.Contains(FName(*ClassName))) { UE_LOG(LogLyraEditor, Display, TEXT("\tAdding %s To Validate"), *PackageName); diff --git a/Source/LyraGame/GameFeatures/GameFeatureAction_StyleTransfer.cpp b/Source/LyraGame/GameFeatures/GameFeatureAction_StyleTransfer.cpp new file mode 100644 index 00000000..b9533d8f --- /dev/null +++ b/Source/LyraGame/GameFeatures/GameFeatureAction_StyleTransfer.cpp @@ -0,0 +1,25 @@ + + +#include "GameFeatureAction_StyleTransfer.h" + +#include "StyleTransferSubsystem.h" + +void UGameFeatureAction_StyleTransfer::OnGameFeatureActivating(FGameFeatureActivatingContext& Context) +{ + Super::OnGameFeatureActivating(Context); +} + +void UGameFeatureAction_StyleTransfer::OnGameFeatureDeactivating(FGameFeatureDeactivatingContext& Context) +{ + Super::OnGameFeatureDeactivating(Context); + + // @todo shutdown cleanly +} + +void UGameFeatureAction_StyleTransfer::AddToWorld(const FWorldContext& WorldContext, const FGameFeatureStateChangeContext& ChangeContext) +{ + auto* StyleTransferSubsystem = WorldContext.OwningGameInstance->GetSubsystem(); + + UGameViewportClient* GameViewportClient = WorldContext.GameViewport; + StyleTransferSubsystem->StartStylizingViewport(GameViewportClient); +} diff --git a/Source/LyraGame/GameFeatures/GameFeatureAction_StyleTransfer.h b/Source/LyraGame/GameFeatures/GameFeatureAction_StyleTransfer.h new file mode 100644 index 00000000..000ae52b --- /dev/null +++ b/Source/LyraGame/GameFeatures/GameFeatureAction_StyleTransfer.h @@ -0,0 +1,22 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFeatureAction_WorldActionBase.h" +#include "UObject/Object.h" +#include "GameFeatureAction_StyleTransfer.generated.h" + +/** + * + */ +UCLASS() +class LYRAGAME_API UGameFeatureAction_StyleTransfer : public UGameFeatureAction_WorldActionBase +{ + GENERATED_BODY() +public: + virtual void OnGameFeatureActivating(FGameFeatureActivatingContext& Context) override; + virtual void OnGameFeatureDeactivating(FGameFeatureDeactivatingContext& Context) override; +private: + virtual void AddToWorld(const FWorldContext& WorldContext, const FGameFeatureStateChangeContext& ChangeContext) override; +};