Changeset 27232

Timestamp:
Nov 18, 2022, 8:59:18 PM (20 months ago)
Author:
Vladislav Belov
Message:

Moves post processing out of scene rendering to avoid framebuffer pass duplicate.

Comments By: phosit, Stan

Differential Revision: https://code.wildfiregames.com/D4827

Location:
ps/trunk/source
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/source/graphics/GameView.cpp

    r26250 r27232  
    234234}
    235235
    236 void CGameView::Render()
    237 {
    238     g_Renderer.GetSceneRenderer().RenderScene(g_Renderer.GetDeviceCommandContext(), *this);
     236void CGameView::Prepare(
     237    Renderer::Backend::IDeviceCommandContext* deviceCommandContext)
     238{
     239    g_Renderer.GetSceneRenderer().PrepareScene(deviceCommandContext, *this);
     240}
     241
     242void CGameView::Render(
     243    Renderer::Backend::IDeviceCommandContext* deviceCommandContext)
     244{
     245    g_Renderer.GetSceneRenderer().RenderScene(deviceCommandContext);
     246}
     247
     248void CGameView::RenderOverlays(
     249    Renderer::Backend::IDeviceCommandContext* deviceCommandContext)
     250{
     251    g_Renderer.GetSceneRenderer().RenderSceneOverlays(deviceCommandContext);
    239252}
    240253
  • ps/trunk/source/graphics/GameView.h

    r26249 r27232  
    1919#define INCLUDED_GAMEVIEW
    2020
     21
    2122#include "renderer/Scene.h"
    2223#include "simulation2/system/Entity.h"
     
    3839public:
    3940    CGameView(CGame *pGame);
    40     ~CGameView();
     41    ~CGameView();
    4142
    4243    void SetViewport(const SViewPort& vp);
     
    5455
    5556    void BeginFrame();
    56     void Render();
     57    void Prepare(Renderer::Backend::IDeviceCommandContext* deviceCommandContext);
     58    void Render(Renderer::Backend::IDeviceCommandContext* deviceCommandContext);
     59    void RenderOverlays(Renderer::Backend::IDeviceCommandContext* deviceCommandContext);
    5760
    5861    InReaction HandleEvent(const SDL_Event_* ev);
  • ps/trunk/source/renderer/Renderer.cpp

    r27184 r27232  
    464464    if (g_Game && g_Game->IsGameStarted())
    465465    {
    466         g_Game->GetView()->Render();
    467     }
    468 
    469     m->deviceCommandContext->BeginFramebufferPass(
    470         m->deviceCommandContext->GetDevice()->GetCurrentBackbuffer());
     466        g_Game->GetView()->Prepare(m->deviceCommandContext.get());
     467
     468        m->deviceCommandContext->SetGraphicsPipelineState(
     469            Renderer::Backend::MakeDefaultGraphicsPipelineStateDesc());
     470
     471        CPostprocManager& postprocManager = g_Renderer.GetPostprocManager();
     472        if (postprocManager.IsEnabled())
     473        {
     474            // We have to update the post process manager with real near/far planes
     475            // that we use for the scene rendering.
     476            postprocManager.SetDepthBufferClipPlanes(
     477                m->sceneRenderer.GetViewCamera().GetNearPlane(),
     478                m->sceneRenderer.GetViewCamera().GetFarPlane()
     479            );
     480            postprocManager.Initialize();
     481            postprocManager.CaptureRenderOutput(m->deviceCommandContext.get());
     482        }
     483        else
     484        {
     485            m->deviceCommandContext->BeginFramebufferPass(
     486                m->deviceCommandContext->GetDevice()->GetCurrentBackbuffer());
     487        }
     488
     489        g_Game->GetView()->Render(m->deviceCommandContext.get());
     490
     491        if (postprocManager.IsEnabled())
     492        {
     493            m->deviceCommandContext->EndFramebufferPass();
     494
     495            if (postprocManager.IsMultisampleEnabled())
     496                postprocManager.ResolveMultisampleFramebuffer(m->deviceCommandContext.get());
     497
     498            postprocManager.ApplyPostproc(m->deviceCommandContext.get());
     499            postprocManager.ReleaseRenderOutput(m->deviceCommandContext.get());
     500
     501            m->deviceCommandContext->BeginFramebufferPass(
     502                m->deviceCommandContext->GetDevice()->GetCurrentBackbuffer());
     503        }
     504
     505        g_Game->GetView()->RenderOverlays(m->deviceCommandContext.get());
     506    }
     507    else
     508    {
     509        m->deviceCommandContext->BeginFramebufferPass(
     510            m->deviceCommandContext->GetDevice()->GetCurrentBackbuffer());
     511    }
    471512
    472513    // If we're in Atlas game view, render special tools
  • ps/trunk/source/renderer/SceneRenderer.cpp

    r27207 r27232  
    5252#include "renderer/OverlayRenderer.h"
    5353#include "renderer/ParticleRenderer.h"
    54 #include "renderer/PostprocManager.h"
    5554#include "renderer/Renderer.h"
    5655#include "renderer/RenderingOptions.h"
     
    758757}
    759758
    760 // RenderSubmissions: force rendering of any batched objects
    761 void CSceneRenderer::RenderSubmissions(
     759void CSceneRenderer::PrepareSubmissions(
    762760    Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
    763761    const CBoundingBoxAligned& waterScissor)
    764762{
    765     PROFILE3("render submissions");
    766     GPU_SCOPED_LABEL(deviceCommandContext, "Render submissions");
     763    PROFILE3(" submissions");
     764    GPU_SCOPED_LABEL(deviceCommandContext, " submissions");
    767765
    768766    m->skyManager.LoadAndUploadSkyTexturesIfNeeded(deviceCommandContext);
     
    774772
    775773    CShaderDefines context = m->globalContext;
    776 
    777     int cullGroup = CULL_DEFAULT;
    778774
    779775    // Set the camera
     
    830826
    831827            if (g_RenderingOptions.GetWaterFancyEffects())
    832                 m->terrainRenderer.RenderWaterFoamOccluders(deviceCommandContext, cullGroup);
     828                m->terrainRenderer.RenderWaterFoamOccluders(deviceCommandContext, );
    833829        }
    834830    }
    835 
    836     deviceCommandContext->SetGraphicsPipelineState(
    837         Renderer::Backend::MakeDefaultGraphicsPipelineStateDesc());
    838 
    839     CPostprocManager& postprocManager = g_Renderer.GetPostprocManager();
    840     if (postprocManager.IsEnabled())
    841     {
    842         // We have to update the post process manager with real near/far planes
    843         // that we use for the scene rendering.
    844         postprocManager.SetDepthBufferClipPlanes(
    845             m_ViewCamera.GetNearPlane(), m_ViewCamera.GetFarPlane()
    846         );
    847         postprocManager.Initialize();
    848         postprocManager.CaptureRenderOutput(deviceCommandContext);
    849     }
    850     else
    851     {
    852         deviceCommandContext->BeginFramebufferPass(
    853             deviceCommandContext->GetDevice()->GetCurrentBackbuffer());
    854     }
     831}
     832
     833void CSceneRenderer::RenderSubmissions(
     834    Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
     835    const CBoundingBoxAligned& waterScissor)
     836{
     837    PROFILE3("render submissions");
     838    GPU_SCOPED_LABEL(deviceCommandContext, "Render submissions");
     839
     840    CShaderDefines context = m->globalContext;
     841
     842    constexpr int cullGroup = CULL_DEFAULT;
    855843
    856844    {
     
    913901    }
    914902
    915     if (postprocManager.IsEnabled())
    916     {
    917         deviceCommandContext->EndFramebufferPass();
    918 
    919         if (g_Renderer.GetPostprocManager().IsMultisampleEnabled())
    920             g_Renderer.GetPostprocManager().ResolveMultisampleFramebuffer(deviceCommandContext);
    921 
    922         postprocManager.ApplyPostproc(deviceCommandContext);
    923         postprocManager.ReleaseRenderOutput(deviceCommandContext);
    924         deviceCommandContext->BeginFramebufferPass(
    925             deviceCommandContext->GetDevice()->GetCurrentBackbuffer());
    926     }
    927 
    928     if (g_RenderingOptions.GetSilhouettes())
    929     {
    930         RenderSilhouettes(deviceCommandContext, context);
    931     }
    932 
    933903    // render debug lines
    934904    if (g_RenderingOptions.GetDisplayFrustum())
     
    939909
    940910    m->silhouetteRenderer.RenderDebugBounds(deviceCommandContext);
    941     m->silhouetteRenderer.RenderDebugOverlays(deviceCommandContext);
    942 
    943     // render overlays that should appear on top of all other objects
    944     m->overlayRenderer.RenderForegroundOverlays(deviceCommandContext, m_ViewCamera);
    945 
    946     deviceCommandContext->EndFramebufferPass();
    947911}
    948912
     
    10941058}
    10951059
    1096 // Render the given scene
    1097 void CSceneRenderer::RenderScene(
     1060void CSceneRenderer::PrepareScene(
    10981061    Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Scene& scene)
    10991062{
     
    11321095    }
    11331096
    1134     CBoundingBoxAligned waterScissor;
    11351097    if (m->waterManager.m_RenderWater)
    11361098    {
    1137         waterScissor = m->terrainRenderer.ScissorWater(CULL_DEFAULT, m_ViewCamera);
    1138 
    1139         if (waterScissor.GetVolume() > 0 && m->waterManager.WillRenderFancyWater())
     1099        aterScissor = m->terrainRenderer.ScissorWater(CULL_DEFAULT, m_ViewCamera);
     1100
     1101        if (aterScissor.GetVolume() > 0 && m->waterManager.WillRenderFancyWater())
    11401102        {
    11411103            if (g_RenderingOptions.GetWaterReflection())
     
    11441106
    11451107                CCamera reflectionCamera;
    1146                 ComputeReflectionCamera(reflectionCamera, waterScissor);
     1108                ComputeReflectionCamera(reflectionCamera, aterScissor);
    11471109
    11481110                scene.EnumerateObjects(reflectionCamera.GetFrustum(), this);
     
    11541116
    11551117                CCamera refractionCamera;
    1156                 ComputeRefractionCamera(refractionCamera, waterScissor);
     1118                ComputeRefractionCamera(refractionCamera, aterScissor);
    11571119
    11581120                scene.EnumerateObjects(refractionCamera.GetFrustum(), this);
     
    11631125        }
    11641126    }
     1127
     1128
    11651129
    11661130    m_CurrentCullGroup = -1;
    11671131
    1168     RenderSubmissions(deviceCommandContext, waterScissor);
    1169 
    1170     m_CurrentScene = NULL;
     1132    PrepareSubmissions(deviceCommandContext, m_WaterScissor);
     1133}
     1134
     1135void CSceneRenderer::RenderScene(
     1136    Renderer::Backend::IDeviceCommandContext* deviceCommandContext)
     1137{
     1138    ENSURE(m_CurrentScene);
     1139    RenderSubmissions(deviceCommandContext, m_WaterScissor);
     1140}
     1141
     1142void CSceneRenderer::RenderSceneOverlays(
     1143    Renderer::Backend::IDeviceCommandContext* deviceCommandContext)
     1144{
     1145    if (g_RenderingOptions.GetSilhouettes())
     1146    {
     1147        RenderSilhouettes(deviceCommandContext, m->globalContext);
     1148    }
     1149
     1150    m->silhouetteRenderer.RenderDebugOverlays(deviceCommandContext);
     1151
     1152    // Render overlays that should appear on top of all other objects.
     1153    m->overlayRenderer.RenderForegroundOverlays(deviceCommandContext, m_ViewCamera);
     1154
     1155    m_CurrentScene = nullptr;
    11711156}
    11721157
  • ps/trunk/source/renderer/SceneRenderer.h

    r26858 r27232  
    2222#include "graphics/ShaderDefines.h"
    2323#include "graphics/ShaderProgramPtr.h"
     24
    2425#include "ps/Singleton.h"
    2526#include "renderer/backend/IDeviceCommandContext.h"
     
    9596
    9697    /**
    97      * Render the given scene immediately.
    98      * @param scene a Scene object describing what should be rendered.
    99      */
    100     void RenderScene(Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Scene& scene);
     98     * Enumerate and submit all objects of the given scene which should be rendered.
     99     * Must be called before RenderScene.
     100     */
     101    void PrepareScene(
     102        Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Scene& scene);
     103
     104    /**
     105     * Render submitted objects of the previously given scene.
     106     */
     107    void RenderScene(
     108        Renderer::Backend::IDeviceCommandContext* deviceCommandContext);
     109
     110    /**
     111     * Render overlays of the previously given scene.
     112     * Must be called after RenderScene.
     113     */
     114    void RenderSceneOverlays(
     115        Renderer::Backend::IDeviceCommandContext* deviceCommandContext);
    101116
    102117    /**
     
    194209    void SubmitNonRecursive(CModel* model) override;
    195210
     211
     212
     213
     214
     215
     216
     217
    196218    // render any batched objects
    197219    void RenderSubmissions(
     
    273295    int m_CurrentCullGroup;
    274296
     297
     298
    275299    // current lighting setup
    276300    CLightEnv* m_LightEnv;
  • ps/trunk/source/tools/atlas/GameInterface/ActorViewer.cpp

    r27111 r27232  
    4545#include "ps/ProfileViewer.h"
    4646#include "ps/VideoMode.h"
     47
     48
    4749#include "renderer/Renderer.h"
    4850#include "renderer/RenderingOptions.h"
     
    510512    // TODO: ActorViewer should reuse CRenderer code and not duplicate it.
    511513
     514
     515
    512516    // Set simulation context for rendering purposes
    513     g_Renderer.GetSceneRenderer().SetSimulation(&m.Simulation2);
     517    .SetSimulation(&m.Simulation2);
    514518
    515519    // Find the centre of the interesting region, in the middle of the patch
     
    527531    camera.UpdateFrustum();
    528532
    529     g_Renderer.GetSceneRenderer().SetSceneCamera(camera, camera);
     533    .SetSceneCamera(camera, camera);
    530534
    531535    g_Renderer.BeginFrame();
    532536
    533     g_Renderer.GetSceneRenderer().RenderScene(g_Renderer.GetDeviceCommandContext(), m);
    534 
    535     {
    536         CCanvas2D canvas(g_xres, g_yres, g_VideoMode.GetScale(), g_Renderer.GetDeviceCommandContext());
     537    Renderer::Backend::IDeviceCommandContext* deviceCommandContext =
     538        g_Renderer.GetDeviceCommandContext();
     539
     540    sceneRenderer.PrepareScene(deviceCommandContext, m);
     541
     542    deviceCommandContext->BeginFramebufferPass(
     543        deviceCommandContext->GetDevice()->GetCurrentBackbuffer());
     544
     545    sceneRenderer.RenderScene(deviceCommandContext);
     546    sceneRenderer.RenderSceneOverlays(deviceCommandContext);
     547
     548    {
     549        CCanvas2D canvas(g_xres, g_yres, g_VideoMode.GetScale(), deviceCommandContext);
    537550        g_Logger->Render(canvas);
    538551        g_ProfileViewer.RenderProfile(canvas);
    539552    }
     553
     554
    540555
    541556    g_Renderer.EndFrame();
Note: See TracChangeset for help on using the changeset viewer.