Files
UnrealEngineUWP/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessCompositeDebugPrimitives.cpp

91 lines
3.8 KiB
C++
Raw Normal View History

Moved rendering the debug draw helper execution to after post process pass to avoid ghosting of TAA/TSR/MB. The EditorPrimitives compositing code was the only PostProcess pass that composited appropriately, but was not setup to accept non-editor draws. DrawDebug also needs to be available to Debug and Development builds, so moving the debug draw calls to this pass directly was not straight forward, and there was no other existing option. SimpleElement draws used by debug were also non-trivial to setup with velocity to compensate for Temporal/Blur passes, so fixing this in the base pass was also not straight forward. Then an additional issue was that the color and depth textures used in post process after temporal passes were mismatched in size (as depth is not necessarily automatically included in the temporal upscale pass). However EditorPrimitives had hard coded temporal upsample depth code in it's main AddEditorPrimitivesPass function. Refactored PostProcessEditorPrimitives code to move the hard coded temporal upscale depth pass to a common file which is protected by UE_ENABLE_DEBUG_DRAWING (which is blocked from compiling in shipping, and works with editor). Also ensured the relevant shader compiles remain protected by these macros. The temporal and populate functions have been slightly rewritten so that a generic temporal history is created rather than an editor only one, and also populate depth can now also output the background colour (to reduce unnecessary draw calls as, depending on the setup, the previous scene may still needs to be drawn to the output color texture). After that refactor, there is a new set of draw debug composite files which now also use the temporal upsample depth code (when color and depth are mismatched, ignored if not), now that it has been isolated into it's own re-usable structure. This means that we can use a simple draw elements call, stripped of all shader variables except the view, to overlay the draw debug primitives on the scene color along with upscaled depth. Also moved draw debug to it's own SimpleElement array in the View to avoid conflating it with other simple element draws (e.g. non-opaque, or ones setup in plugins). This code can be extended for those at a later date if needed though. #jira UE-177222 #rb Jason.Nadro, Massimo.Tristano #preflight 64189a2a3f3d31c94aa0c48d #fyi Guillaume.Abadie [CL 24731449 by Jon Cain in ue5-main branch]
2023-03-21 09:56:41 -04:00
// Copyright Epic Games, Inc. All Rights Reserved.
#include "PostProcess/PostProcessCompositeDebugPrimitives.h"
#if UE_ENABLE_DEBUG_DRAWING
#include "ScenePrivate.h"
BEGIN_SHADER_PARAMETER_STRUCT(FDebugPrimitivesPassParameters, )
SHADER_PARAMETER_STRUCT_INCLUDE(FViewShaderParameters, View)
RENDER_TARGET_BINDING_SLOTS()
END_SHADER_PARAMETER_STRUCT()
FScreenPassTexture AddDebugPrimitivePass(
FRDGBuilder& GraphBuilder,
const FViewInfo& View,
const FCompositePrimitiveInputs& Inputs)
{
check(Inputs.SceneColor.IsValid());
check(Inputs.SceneDepth.IsValid());
RDG_EVENT_SCOPE(GraphBuilder, "CompositeDebugPrimitives");
FScreenPassRenderTarget Output = Inputs.OverrideOutput;
if (!Output.IsValid())
{
Output = FScreenPassRenderTarget::CreateFromInput(GraphBuilder, Inputs.SceneColor, View.GetOverwriteLoadAction(), TEXT("Debug.DrawPrimitivesColor"));
Moved rendering the debug draw helper execution to after post process pass to avoid ghosting of TAA/TSR/MB. The EditorPrimitives compositing code was the only PostProcess pass that composited appropriately, but was not setup to accept non-editor draws. DrawDebug also needs to be available to Debug and Development builds, so moving the debug draw calls to this pass directly was not straight forward, and there was no other existing option. SimpleElement draws used by debug were also non-trivial to setup with velocity to compensate for Temporal/Blur passes, so fixing this in the base pass was also not straight forward. Then an additional issue was that the color and depth textures used in post process after temporal passes were mismatched in size (as depth is not necessarily automatically included in the temporal upscale pass). However EditorPrimitives had hard coded temporal upsample depth code in it's main AddEditorPrimitivesPass function. Refactored PostProcessEditorPrimitives code to move the hard coded temporal upscale depth pass to a common file which is protected by UE_ENABLE_DEBUG_DRAWING (which is blocked from compiling in shipping, and works with editor). Also ensured the relevant shader compiles remain protected by these macros. The temporal and populate functions have been slightly rewritten so that a generic temporal history is created rather than an editor only one, and also populate depth can now also output the background colour (to reduce unnecessary draw calls as, depending on the setup, the previous scene may still needs to be drawn to the output color texture). After that refactor, there is a new set of draw debug composite files which now also use the temporal upsample depth code (when color and depth are mismatched, ignored if not), now that it has been isolated into it's own re-usable structure. This means that we can use a simple draw elements call, stripped of all shader variables except the view, to overlay the draw debug primitives on the scene color along with upscaled depth. Also moved draw debug to it's own SimpleElement array in the View to avoid conflating it with other simple element draws (e.g. non-opaque, or ones setup in plugins). This code can be extended for those at a later date if needed though. #jira UE-177222 #rb Jason.Nadro, Massimo.Tristano #preflight 64189a2a3f3d31c94aa0c48d #fyi Guillaume.Abadie [CL 24731449 by Jon Cain in ue5-main branch]
2023-03-21 09:56:41 -04:00
}
const uint32 NumMSAASamples = Output.Texture->Desc.NumSamples;
//Set sizing values to match the SceneColor size
const FIntRect ViewRect = Output.ViewRect;
FIntPoint Extent = Output.Texture->Desc.Extent;
const FViewInfo* DebugView = CreateCompositePrimitiveView(View, ViewRect, NumMSAASamples);
Moved rendering the debug draw helper execution to after post process pass to avoid ghosting of TAA/TSR/MB. The EditorPrimitives compositing code was the only PostProcess pass that composited appropriately, but was not setup to accept non-editor draws. DrawDebug also needs to be available to Debug and Development builds, so moving the debug draw calls to this pass directly was not straight forward, and there was no other existing option. SimpleElement draws used by debug were also non-trivial to setup with velocity to compensate for Temporal/Blur passes, so fixing this in the base pass was also not straight forward. Then an additional issue was that the color and depth textures used in post process after temporal passes were mismatched in size (as depth is not necessarily automatically included in the temporal upscale pass). However EditorPrimitives had hard coded temporal upsample depth code in it's main AddEditorPrimitivesPass function. Refactored PostProcessEditorPrimitives code to move the hard coded temporal upscale depth pass to a common file which is protected by UE_ENABLE_DEBUG_DRAWING (which is blocked from compiling in shipping, and works with editor). Also ensured the relevant shader compiles remain protected by these macros. The temporal and populate functions have been slightly rewritten so that a generic temporal history is created rather than an editor only one, and also populate depth can now also output the background colour (to reduce unnecessary draw calls as, depending on the setup, the previous scene may still needs to be drawn to the output color texture). After that refactor, there is a new set of draw debug composite files which now also use the temporal upsample depth code (when color and depth are mismatched, ignored if not), now that it has been isolated into it's own re-usable structure. This means that we can use a simple draw elements call, stripped of all shader variables except the view, to overlay the draw debug primitives on the scene color along with upscaled depth. Also moved draw debug to it's own SimpleElement array in the View to avoid conflating it with other simple element draws (e.g. non-opaque, or ones setup in plugins). This code can be extended for those at a later date if needed though. #jira UE-177222 #rb Jason.Nadro, Massimo.Tristano #preflight 64189a2a3f3d31c94aa0c48d #fyi Guillaume.Abadie [CL 24731449 by Jon Cain in ue5-main branch]
2023-03-21 09:56:41 -04:00
//Prepare output textures for composite draw
const FScreenPassTextureViewport OutputViewport(Output);
FRDGTextureRef DebugPrimitiveDepth = CreateCompositeDepthTexture(GraphBuilder, Extent, NumMSAASamples);
//Inputs is const so create a over-ridable texture reference
FScreenPassTexture SceneDepth = Inputs.SceneDepth;
Moved rendering the debug draw helper execution to after post process pass to avoid ghosting of TAA/TSR/MB. The EditorPrimitives compositing code was the only PostProcess pass that composited appropriately, but was not setup to accept non-editor draws. DrawDebug also needs to be available to Debug and Development builds, so moving the debug draw calls to this pass directly was not straight forward, and there was no other existing option. SimpleElement draws used by debug were also non-trivial to setup with velocity to compensate for Temporal/Blur passes, so fixing this in the base pass was also not straight forward. Then an additional issue was that the color and depth textures used in post process after temporal passes were mismatched in size (as depth is not necessarily automatically included in the temporal upscale pass). However EditorPrimitives had hard coded temporal upsample depth code in it's main AddEditorPrimitivesPass function. Refactored PostProcessEditorPrimitives code to move the hard coded temporal upscale depth pass to a common file which is protected by UE_ENABLE_DEBUG_DRAWING (which is blocked from compiling in shipping, and works with editor). Also ensured the relevant shader compiles remain protected by these macros. The temporal and populate functions have been slightly rewritten so that a generic temporal history is created rather than an editor only one, and also populate depth can now also output the background colour (to reduce unnecessary draw calls as, depending on the setup, the previous scene may still needs to be drawn to the output color texture). After that refactor, there is a new set of draw debug composite files which now also use the temporal upsample depth code (when color and depth are mismatched, ignored if not), now that it has been isolated into it's own re-usable structure. This means that we can use a simple draw elements call, stripped of all shader variables except the view, to overlay the draw debug primitives on the scene color along with upscaled depth. Also moved draw debug to it's own SimpleElement array in the View to avoid conflating it with other simple element draws (e.g. non-opaque, or ones setup in plugins). This code can be extended for those at a later date if needed though. #jira UE-177222 #rb Jason.Nadro, Massimo.Tristano #preflight 64189a2a3f3d31c94aa0c48d #fyi Guillaume.Abadie [CL 24731449 by Jon Cain in ue5-main branch]
2023-03-21 09:56:41 -04:00
FVector2f SceneDepthJitter = FVector2f(View.TemporalJitterPixels);
if (IsTemporalAccumulationBasedMethod(View.AntiAliasingMethod))
{
TemporalUpscaleDepthPass(GraphBuilder,
*DebugView,
Inputs.SceneColor,
SceneDepth,
SceneDepthJitter);
Moved rendering the debug draw helper execution to after post process pass to avoid ghosting of TAA/TSR/MB. The EditorPrimitives compositing code was the only PostProcess pass that composited appropriately, but was not setup to accept non-editor draws. DrawDebug also needs to be available to Debug and Development builds, so moving the debug draw calls to this pass directly was not straight forward, and there was no other existing option. SimpleElement draws used by debug were also non-trivial to setup with velocity to compensate for Temporal/Blur passes, so fixing this in the base pass was also not straight forward. Then an additional issue was that the color and depth textures used in post process after temporal passes were mismatched in size (as depth is not necessarily automatically included in the temporal upscale pass). However EditorPrimitives had hard coded temporal upsample depth code in it's main AddEditorPrimitivesPass function. Refactored PostProcessEditorPrimitives code to move the hard coded temporal upscale depth pass to a common file which is protected by UE_ENABLE_DEBUG_DRAWING (which is blocked from compiling in shipping, and works with editor). Also ensured the relevant shader compiles remain protected by these macros. The temporal and populate functions have been slightly rewritten so that a generic temporal history is created rather than an editor only one, and also populate depth can now also output the background colour (to reduce unnecessary draw calls as, depending on the setup, the previous scene may still needs to be drawn to the output color texture). After that refactor, there is a new set of draw debug composite files which now also use the temporal upsample depth code (when color and depth are mismatched, ignored if not), now that it has been isolated into it's own re-usable structure. This means that we can use a simple draw elements call, stripped of all shader variables except the view, to overlay the draw debug primitives on the scene color along with upscaled depth. Also moved draw debug to it's own SimpleElement array in the View to avoid conflating it with other simple element draws (e.g. non-opaque, or ones setup in plugins). This code can be extended for those at a later date if needed though. #jira UE-177222 #rb Jason.Nadro, Massimo.Tristano #preflight 64189a2a3f3d31c94aa0c48d #fyi Guillaume.Abadie [CL 24731449 by Jon Cain in ue5-main branch]
2023-03-21 09:56:41 -04:00
}
//Simple element pixel shaders do not output background color for composite,
//so this allows the background to be drawn to the RT at the same time as depth without adding extra draw calls
PopulateDepthPass(GraphBuilder,
*DebugView,
Inputs.SceneColor,
SceneDepth,
Output.Texture,
Moved rendering the debug draw helper execution to after post process pass to avoid ghosting of TAA/TSR/MB. The EditorPrimitives compositing code was the only PostProcess pass that composited appropriately, but was not setup to accept non-editor draws. DrawDebug also needs to be available to Debug and Development builds, so moving the debug draw calls to this pass directly was not straight forward, and there was no other existing option. SimpleElement draws used by debug were also non-trivial to setup with velocity to compensate for Temporal/Blur passes, so fixing this in the base pass was also not straight forward. Then an additional issue was that the color and depth textures used in post process after temporal passes were mismatched in size (as depth is not necessarily automatically included in the temporal upscale pass). However EditorPrimitives had hard coded temporal upsample depth code in it's main AddEditorPrimitivesPass function. Refactored PostProcessEditorPrimitives code to move the hard coded temporal upscale depth pass to a common file which is protected by UE_ENABLE_DEBUG_DRAWING (which is blocked from compiling in shipping, and works with editor). Also ensured the relevant shader compiles remain protected by these macros. The temporal and populate functions have been slightly rewritten so that a generic temporal history is created rather than an editor only one, and also populate depth can now also output the background colour (to reduce unnecessary draw calls as, depending on the setup, the previous scene may still needs to be drawn to the output color texture). After that refactor, there is a new set of draw debug composite files which now also use the temporal upsample depth code (when color and depth are mismatched, ignored if not), now that it has been isolated into it's own re-usable structure. This means that we can use a simple draw elements call, stripped of all shader variables except the view, to overlay the draw debug primitives on the scene color along with upscaled depth. Also moved draw debug to it's own SimpleElement array in the View to avoid conflating it with other simple element draws (e.g. non-opaque, or ones setup in plugins). This code can be extended for those at a later date if needed though. #jira UE-177222 #rb Jason.Nadro, Massimo.Tristano #preflight 64189a2a3f3d31c94aa0c48d #fyi Guillaume.Abadie [CL 24731449 by Jon Cain in ue5-main branch]
2023-03-21 09:56:41 -04:00
DebugPrimitiveDepth,
SceneDepthJitter,
NumMSAASamples,
true,
Inputs.bUseMetalMSAAHDRDecode);
Moved rendering the debug draw helper execution to after post process pass to avoid ghosting of TAA/TSR/MB. The EditorPrimitives compositing code was the only PostProcess pass that composited appropriately, but was not setup to accept non-editor draws. DrawDebug also needs to be available to Debug and Development builds, so moving the debug draw calls to this pass directly was not straight forward, and there was no other existing option. SimpleElement draws used by debug were also non-trivial to setup with velocity to compensate for Temporal/Blur passes, so fixing this in the base pass was also not straight forward. Then an additional issue was that the color and depth textures used in post process after temporal passes were mismatched in size (as depth is not necessarily automatically included in the temporal upscale pass). However EditorPrimitives had hard coded temporal upsample depth code in it's main AddEditorPrimitivesPass function. Refactored PostProcessEditorPrimitives code to move the hard coded temporal upscale depth pass to a common file which is protected by UE_ENABLE_DEBUG_DRAWING (which is blocked from compiling in shipping, and works with editor). Also ensured the relevant shader compiles remain protected by these macros. The temporal and populate functions have been slightly rewritten so that a generic temporal history is created rather than an editor only one, and also populate depth can now also output the background colour (to reduce unnecessary draw calls as, depending on the setup, the previous scene may still needs to be drawn to the output color texture). After that refactor, there is a new set of draw debug composite files which now also use the temporal upsample depth code (when color and depth are mismatched, ignored if not), now that it has been isolated into it's own re-usable structure. This means that we can use a simple draw elements call, stripped of all shader variables except the view, to overlay the draw debug primitives on the scene color along with upscaled depth. Also moved draw debug to it's own SimpleElement array in the View to avoid conflating it with other simple element draws (e.g. non-opaque, or ones setup in plugins). This code can be extended for those at a later date if needed though. #jira UE-177222 #rb Jason.Nadro, Massimo.Tristano #preflight 64189a2a3f3d31c94aa0c48d #fyi Guillaume.Abadie [CL 24731449 by Jon Cain in ue5-main branch]
2023-03-21 09:56:41 -04:00
//Composite the debug draw elements into the scene
FDebugPrimitivesPassParameters* PassParameters = GraphBuilder.AllocParameters<FDebugPrimitivesPassParameters>();
PassParameters->View = DebugView->GetShaderParameters();
PassParameters->RenderTargets[0] = Output.GetRenderTargetBinding();
PassParameters->RenderTargets[0].SetLoadAction(ERenderTargetLoadAction::ELoad);
PassParameters->RenderTargets.DepthStencil = FDepthStencilBinding(DebugPrimitiveDepth, ERenderTargetLoadAction::ELoad, ERenderTargetLoadAction::ELoad, FExclusiveDepthStencil::DepthWrite_StencilWrite);
GraphBuilder.AddPass(
RDG_EVENT_NAME("DrawDebugPrimitives"),
PassParameters,
ERDGPassFlags::Raster,
[&View, PassParameters, DebugView, OutputViewport](FRHICommandList& RHICmdList)
{
RHICmdList.SetViewport(OutputViewport.Rect.Min.X, OutputViewport.Rect.Min.Y, 0.0f, OutputViewport.Rect.Max.X, OutputViewport.Rect.Max.Y, 1.0f);
FMeshPassProcessorRenderState DrawRenderState;
DrawRenderState.SetDepthStencilAccess(FExclusiveDepthStencil::DepthWrite_StencilWrite);
DrawRenderState.SetBlendState(TStaticBlendState<CW_RGBA, BO_Add, BF_One, BF_One, BO_Add, BF_One, BF_One>::GetRHI());
DrawRenderState.SetDepthStencilState(TStaticDepthStencilState<true, CF_DepthNearOrEqual>::GetRHI());
Moved rendering the debug draw helper execution to after post process pass to avoid ghosting of TAA/TSR/MB. The EditorPrimitives compositing code was the only PostProcess pass that composited appropriately, but was not setup to accept non-editor draws. DrawDebug also needs to be available to Debug and Development builds, so moving the debug draw calls to this pass directly was not straight forward, and there was no other existing option. SimpleElement draws used by debug were also non-trivial to setup with velocity to compensate for Temporal/Blur passes, so fixing this in the base pass was also not straight forward. Then an additional issue was that the color and depth textures used in post process after temporal passes were mismatched in size (as depth is not necessarily automatically included in the temporal upscale pass). However EditorPrimitives had hard coded temporal upsample depth code in it's main AddEditorPrimitivesPass function. Refactored PostProcessEditorPrimitives code to move the hard coded temporal upscale depth pass to a common file which is protected by UE_ENABLE_DEBUG_DRAWING (which is blocked from compiling in shipping, and works with editor). Also ensured the relevant shader compiles remain protected by these macros. The temporal and populate functions have been slightly rewritten so that a generic temporal history is created rather than an editor only one, and also populate depth can now also output the background colour (to reduce unnecessary draw calls as, depending on the setup, the previous scene may still needs to be drawn to the output color texture). After that refactor, there is a new set of draw debug composite files which now also use the temporal upsample depth code (when color and depth are mismatched, ignored if not), now that it has been isolated into it's own re-usable structure. This means that we can use a simple draw elements call, stripped of all shader variables except the view, to overlay the draw debug primitives on the scene color along with upscaled depth. Also moved draw debug to it's own SimpleElement array in the View to avoid conflating it with other simple element draws (e.g. non-opaque, or ones setup in plugins). This code can be extended for those at a later date if needed though. #jira UE-177222 #rb Jason.Nadro, Massimo.Tristano #preflight 64189a2a3f3d31c94aa0c48d #fyi Guillaume.Abadie [CL 24731449 by Jon Cain in ue5-main branch]
2023-03-21 09:56:41 -04:00
DebugView->DebugSimpleElementCollector.DrawBatchedElements(RHICmdList, DrawRenderState, *DebugView, EBlendModeFilter::OpaqueAndMasked, SDPG_World);
DrawRenderState.SetDepthStencilState(TStaticDepthStencilState<true, CF_Always>::GetRHI());
Moved rendering the debug draw helper execution to after post process pass to avoid ghosting of TAA/TSR/MB. The EditorPrimitives compositing code was the only PostProcess pass that composited appropriately, but was not setup to accept non-editor draws. DrawDebug also needs to be available to Debug and Development builds, so moving the debug draw calls to this pass directly was not straight forward, and there was no other existing option. SimpleElement draws used by debug were also non-trivial to setup with velocity to compensate for Temporal/Blur passes, so fixing this in the base pass was also not straight forward. Then an additional issue was that the color and depth textures used in post process after temporal passes were mismatched in size (as depth is not necessarily automatically included in the temporal upscale pass). However EditorPrimitives had hard coded temporal upsample depth code in it's main AddEditorPrimitivesPass function. Refactored PostProcessEditorPrimitives code to move the hard coded temporal upscale depth pass to a common file which is protected by UE_ENABLE_DEBUG_DRAWING (which is blocked from compiling in shipping, and works with editor). Also ensured the relevant shader compiles remain protected by these macros. The temporal and populate functions have been slightly rewritten so that a generic temporal history is created rather than an editor only one, and also populate depth can now also output the background colour (to reduce unnecessary draw calls as, depending on the setup, the previous scene may still needs to be drawn to the output color texture). After that refactor, there is a new set of draw debug composite files which now also use the temporal upsample depth code (when color and depth are mismatched, ignored if not), now that it has been isolated into it's own re-usable structure. This means that we can use a simple draw elements call, stripped of all shader variables except the view, to overlay the draw debug primitives on the scene color along with upscaled depth. Also moved draw debug to it's own SimpleElement array in the View to avoid conflating it with other simple element draws (e.g. non-opaque, or ones setup in plugins). This code can be extended for those at a later date if needed though. #jira UE-177222 #rb Jason.Nadro, Massimo.Tristano #preflight 64189a2a3f3d31c94aa0c48d #fyi Guillaume.Abadie [CL 24731449 by Jon Cain in ue5-main branch]
2023-03-21 09:56:41 -04:00
DebugView->DebugSimpleElementCollector.DrawBatchedElements(RHICmdList, DrawRenderState, *DebugView, EBlendModeFilter::OpaqueAndMasked, SDPG_Foreground);
});
return MoveTemp(Output);
}
#endif