Add RenderingUpscaleLocation for customizing upscaler location in render pipeline

This commit is contained in:
Wojciech Figat
2022-12-13 11:51:31 +01:00
parent ee019510ca
commit c17477abff
6 changed files with 91 additions and 23 deletions

View File

@@ -182,6 +182,22 @@ API_ENUM(Attributes="Flags") enum class ActorsSources
DECLARE_ENUM_OPERATORS(ActorsSources);
/// <summary>
/// The Post Process effect rendering location within the rendering pipeline.
/// </summary>
API_ENUM() enum class RenderingUpscaleLocation
{
/// <summary>
/// The up-scaling happens directly to the output buffer (backbuffer) after post processing and anti-aliasing.
/// </summary>
AfterAntiAliasingPass = 0,
/// <summary>
/// The up-scaling happens before the post processing after scene rendering (after geometry, lighting, volumetrics, transparency and SSR/SSAO).
/// </summary>
BeforePostProcessingPass = 1,
};
/// <summary>
/// Render task which draws scene actors into the output buffer.
/// </summary>
@@ -244,6 +260,11 @@ public:
/// </summary>
API_FIELD() float RenderingPercentage = 1.0f;
/// <summary>
/// The image resolution upscale location within rendering pipeline. Unused if RenderingPercentage is 1.
/// </summary>
API_FIELD() RenderingUpscaleLocation UpscaleLocation = RenderingUpscaleLocation::AfterAntiAliasingPass;
public:
/// <summary>
/// The custom set of actors to render.

View File

@@ -205,11 +205,6 @@ GPUTexture* ColorGradingPass::RenderLUT(RenderContext& renderContext)
context->SetRenderTarget(lut->View());
context->DrawFullscreenTriangle();
}
// TODO: this could run in async during scene rendering or sth
const Viewport viewport = renderContext.Task->GetViewport();
context->SetViewportAndScissors(viewport);
context->UnBindSR(0);
return lut;

View File

@@ -265,8 +265,8 @@ void MotionBlurPass::Render(RenderContext& renderContext, GPUTexture*& input, GP
ASSERT(motionVectors);
auto context = GPUDevice::Instance->GetMainContext();
MotionBlurSettings& settings = renderContext.List->Settings.MotionBlur;
const int32 screenWidth = renderContext.Buffers->GetWidth();
const int32 screenHeight = renderContext.Buffers->GetHeight();
const int32 screenWidth = input->Width();
const int32 screenHeight = input->Height();
const int32 motionVectorsWidth = screenWidth / static_cast<int32>(settings.MotionVectorsResolution);
const int32 motionVectorsHeight = screenHeight / static_cast<int32>(settings.MotionVectorsResolution);
if ((renderContext.View.Flags & ViewFlags::MotionBlur) == 0 ||

View File

@@ -482,8 +482,7 @@ void PostProcessingPass::Render(RenderContext& renderContext, GPUTexture* input,
context->BindSR(7, colorGradingLutView);
// Composite final frame during single pass (done in full resolution)
auto viewport = renderContext.Task->GetViewport();
context->SetViewportAndScissors(viewport);
context->SetViewportAndScissors((float)output->Width(), (float)output->Height());
context->SetRenderTarget(*output);
context->SetState(_psComposite.Get(compositePermutationIndex));
context->DrawFullscreenTriangle();

View File

@@ -122,12 +122,10 @@ void RendererService::Dispose()
SAFE_DELETE_GPU_RESOURCE(IMaterial::BindParameters::PerViewConstants);
}
void RenderAntiAliasingPass(RenderContext& renderContext, GPUTexture* input, GPUTextureView* output)
void RenderAntiAliasingPass(RenderContext& renderContext, GPUTexture* input, GPUTextureView* output, const Viewport& outputViewport)
{
auto context = GPUDevice::Instance->GetMainContext();
auto screenSize = renderContext.View.ScreenSize;
context->SetViewportAndScissors(screenSize.X, screenSize.Y);
context->SetViewportAndScissors(outputViewport);
const auto aaMode = renderContext.List->Settings.AntiAliasing.Mode;
if (aaMode == AntialiasingMode::FastApproximateAntialiasing)
{
@@ -554,6 +552,27 @@ void RenderInner(SceneRenderTask* task, RenderContext& renderContext, RenderCont
Swap(frameBuffer, tempBuffer);
}
// Upscaling after scene rendering but before post processing
bool useUpscaling = task->RenderingPercentage < 1.0f;
const Viewport outputViewport = task->GetOutputViewport();
if (useUpscaling && task->UpscaleLocation == RenderingUpscaleLocation::BeforePostProcessingPass)
{
useUpscaling = false;
RenderTargetPool::Release(tempBuffer);
tempDesc.Width = (int32)outputViewport.Width;
tempDesc.Height = (int32)outputViewport.Height;
tempBuffer = RenderTargetPool::Get(tempDesc);
context->ResetSR();
if (renderContext.List->HasAnyPostFx(renderContext, PostProcessEffectLocation::CustomUpscale))
renderContext.List->RunCustomPostFxPass(context, renderContext, PostProcessEffectLocation::CustomUpscale, frameBuffer, tempBuffer);
else
MultiScaler::Instance()->Upscale(context, outputViewport, frameBuffer, tempBuffer->View());
if (tempBuffer->Width() == tempDesc.Width)
Swap(frameBuffer, tempBuffer);
RenderTargetPool::Release(tempBuffer);
tempBuffer = RenderTargetPool::Get(tempDesc);
}
// Depth of Field
auto dofTemporary = DepthOfFieldPass::Instance()->Render(renderContext, frameBuffer);
frameBuffer = dofTemporary ? dofTemporary : frameBuffer;
@@ -591,7 +610,7 @@ void RenderInner(SceneRenderTask* task, RenderContext& renderContext, RenderCont
{
context->ResetRenderTarget();
context->SetRenderTarget(task->GetOutputView());
context->SetViewportAndScissors(task->GetOutputViewport());
context->SetViewportAndScissors(outputViewport);
MotionBlurPass::Instance()->RenderDebug(renderContext, frameBuffer->View());
RenderTargetPool::Release(tempBuffer);
RenderTargetPool::Release(frameBuffer);
@@ -599,35 +618,58 @@ void RenderInner(SceneRenderTask* task, RenderContext& renderContext, RenderCont
}
// Anti Aliasing
if (!renderContext.List->HasAnyPostFx(renderContext, PostProcessEffectLocation::AfterAntiAliasingPass, MaterialPostFxLocation::AfterAntiAliasingPass) && Math::IsOne(task->RenderingPercentage))
GPUTextureView* outputView = task->GetOutputView();
if (!renderContext.List->HasAnyPostFx(renderContext, PostProcessEffectLocation::AfterAntiAliasingPass, MaterialPostFxLocation::AfterAntiAliasingPass) && !useUpscaling)
{
// AA -> Back Buffer
RenderAntiAliasingPass(renderContext, frameBuffer, task->GetOutputView());
RenderAntiAliasingPass(renderContext, frameBuffer, outputView, outputViewport);
}
else
{
// AA -> PostFx
RenderAntiAliasingPass(renderContext, frameBuffer, *tempBuffer);
RenderAntiAliasingPass(renderContext, frameBuffer, *tempBuffer, Viewport(Float2(renderContext.View.ScreenSize)));
context->ResetRenderTarget();
Swap(frameBuffer, tempBuffer);
renderContext.List->RunCustomPostFxPass(context, renderContext, PostProcessEffectLocation::AfterAntiAliasingPass, frameBuffer, tempBuffer);
renderContext.List->RunMaterialPostFxPass(context, renderContext, MaterialPostFxLocation::AfterAntiAliasingPass, frameBuffer, tempBuffer);
// PostFx -> (up-scaling) -> Back Buffer
if (task->RenderingPercentage >= 1.0f)
if (!useUpscaling)
{
PROFILE_GPU("Copy frame");
context->SetRenderTarget(task->GetOutputView());
context->SetViewportAndScissors(task->GetOutputViewport());
context->SetRenderTarget(outputView);
context->SetViewportAndScissors(outputViewport);
context->Draw(frameBuffer);
}
else if (renderContext.List->HasAnyPostFx(renderContext, PostProcessEffectLocation::CustomUpscale, MaterialPostFxLocation::MAX))
else if (renderContext.List->HasAnyPostFx(renderContext, PostProcessEffectLocation::CustomUpscale))
{
renderContext.List->RunCustomPostFxPass(context, renderContext, PostProcessEffectLocation::CustomUpscale, frameBuffer, frameBuffer);
if (outputView->GetParent()->Is<GPUTexture>())
{
// Upscale directly to the output texture
auto outputTexture = (GPUTexture*)outputView->GetParent();
renderContext.List->RunCustomPostFxPass(context, renderContext, PostProcessEffectLocation::CustomUpscale, frameBuffer, outputTexture);
if (frameBuffer == (GPUTexture*)outputView->GetParent())
Swap(frameBuffer, outputTexture);
}
else
{
// Use temporary buffer for upscaled frame if GetOutputView is owned by GPUSwapChain
RenderTargetPool::Release(tempBuffer);
tempDesc.Width = (int32)outputViewport.Width;
tempDesc.Height = (int32)outputViewport.Height;
tempBuffer = RenderTargetPool::Get(tempDesc);
renderContext.List->RunCustomPostFxPass(context, renderContext, PostProcessEffectLocation::CustomUpscale, frameBuffer, tempBuffer);
{
PROFILE_GPU("Copy frame");
context->SetRenderTarget(outputView);
context->SetViewportAndScissors(outputViewport);
context->Draw(frameBuffer);
}
}
}
else
{
MultiScaler::Instance()->Upscale(context, task->GetOutputViewport(), frameBuffer, task->GetOutputView());
MultiScaler::Instance()->Upscale(context, outputViewport, frameBuffer, outputView);
}
}