From 598aec45b49a71c483b8e6ba9a653558635e62c2 Mon Sep 17 00:00:00 2001 From: GamesTrap Date: Mon, 28 Oct 2024 02:20:44 +0100 Subject: [PATCH] VulkanRenderer Moved GetCurrentSwapChainRenderTarget() to RendererAPI::PerViewportData 10/28/2024 | 24w44a1 --- SITREPS.txt | 4 ++++ TRAP/src/Core/Base.h | 2 +- TRAP/src/Graphics/API/RendererAPI.cpp | 21 +++++++++++++---- TRAP/src/Graphics/API/RendererAPI.h | 2 ++ .../Graphics/API/Vulkan/VulkanRenderer.cpp | 23 +++++-------------- TRAP/src/Layers/ImGui/ImGuiLayer.cpp | 2 +- TRAP/src/Log/Log.h | 2 +- 7 files changed, 31 insertions(+), 25 deletions(-) diff --git a/SITREPS.txt b/SITREPS.txt index 31d9a95c0..254266e17 100644 --- a/SITREPS.txt +++ b/SITREPS.txt @@ -5328,3 +5328,7 @@ SITREP 10/25/2024|24w43b2 SITREP 10/27/2024|24w43b3 - Changed TRAP Engine version to 24w43b3(0.11.30) - Update-Dependencies Use correct branch for QuiteOKImage ~<5 mins + +SITREP 10/28/2024|24w44a1 + - Changed TRAP Engine version to 24w44a1(0.11.31) + - VulkanRenderer Moved GetCurrentSwapChainRenderTarget() to RendererAPI::PerViewportData ~<5 mins diff --git a/TRAP/src/Core/Base.h b/TRAP/src/Core/Base.h index 7f9cc3412..e433135b1 100644 --- a/TRAP/src/Core/Base.h +++ b/TRAP/src/Core/Base.h @@ -77,7 +77,7 @@ //-------------------------------------------------------------------------------------------------------------------// /// @brief TRAP version number created with TRAP_MAKE_VERSION -inline constexpr TRAP::SemanticVersion<0, 11, 30> TRAP_VERSION{}; +inline constexpr TRAP::SemanticVersion<0, 11, 31> TRAP_VERSION{}; //-------------------------------------------------------------------------------------------------------------------// diff --git a/TRAP/src/Graphics/API/RendererAPI.cpp b/TRAP/src/Graphics/API/RendererAPI.cpp index 7c6b8d8cb..72a38245e 100644 --- a/TRAP/src/Graphics/API/RendererAPI.cpp +++ b/TRAP/src/Graphics/API/RendererAPI.cpp @@ -191,7 +191,7 @@ void TRAP::Graphics::RendererAPI::OnPostUpdate() if(data->RenderScale != 1.0f) { - TRAP::Ref outputTarget = data->SwapChain->GetRenderTargets()[data->CurrentSwapChainImageIndex]; + TRAP::Ref outputTarget = data->GetCurrentSwapchainRenderTarget(); GetRenderer()->RenderScalePass(*data->InternalRenderTargets[data->CurrentSwapChainImageIndex], *outputTarget, *win); @@ -202,7 +202,7 @@ void TRAP::Graphics::RendererAPI::OnPostUpdate() if(s_perViewportData->RenderScale != 1.0f) { - TRAP::Ref outputTarget = s_perViewportData->RenderTargets[s_perViewportData->CurrentSwapChainImageIndex]; + TRAP::Ref outputTarget = s_perViewportData->GetCurrentSwapchainRenderTarget(); GetRenderer()->RenderScalePass(*s_perViewportData->InternalRenderTargets[s_perViewportData->CurrentSwapChainImageIndex], *outputTarget); @@ -379,7 +379,7 @@ void TRAP::Graphics::RendererAPI::StartRenderPass(const Window& window) if((viewportData->RenderScale != 1.0f || viewportData->CurrentAntiAliasing == RendererAPI::AntiAliasing::MSAA) && viewportData->State == PerWindowState::PreUpdate) renderTarget = viewportData->InternalRenderTargets[viewportData->CurrentSwapChainImageIndex]; else - renderTarget = viewportData->SwapChain->GetRenderTargets()[viewportData->CurrentSwapChainImageIndex]; + renderTarget = viewportData->GetCurrentSwapchainRenderTarget(); GetRenderer()->BindRenderTarget(renderTarget.get(), nullptr, nullptr, nullptr, nullptr, std::numeric_limits::max(), @@ -394,9 +394,9 @@ void TRAP::Graphics::RendererAPI::StartRenderPass() //Get correct RenderTarget if((s_perViewportData->RenderScale != 1.0f || s_perViewportData->CurrentAntiAliasing == RendererAPI::AntiAliasing::MSAA) && s_perViewportData->State == PerWindowState::PreUpdate) - renderTarget = s_perViewportData->InternalRenderTargets[s_perViewportData->ImageIndex]; + renderTarget = s_perViewportData->InternalRenderTargets[s_perViewportData->CurrentSwapChainImageIndex]; else - renderTarget = s_perViewportData->RenderTargets[s_perViewportData->ImageIndex]; + renderTarget = s_perViewportData->GetCurrentSwapchainRenderTarget(); GetRenderer()->BindRenderTarget(renderTarget.get(), nullptr, nullptr, nullptr, nullptr, std::numeric_limits::max(), @@ -779,3 +779,14 @@ TRAP::Graphics::RendererAPI::PerViewportData::~PerViewportData() return s_perViewportData->ImageIndex; } #endif /*TRAP_HEADLESS_MODE*/ + +//-------------------------------------------------------------------------------------------------------------------// + +[[nodiscard]] TRAP::Ref TRAP::Graphics::RendererAPI::PerViewportData::GetCurrentSwapchainRenderTarget() const +{ +#ifndef TRAP_HEADLESS_MODE + return SwapChain->GetRenderTargets()[CurrentSwapChainImageIndex]; +#else + return RenderTargets[CurrentSwapChainImageIndex]; +#endif +} diff --git a/TRAP/src/Graphics/API/RendererAPI.h b/TRAP/src/Graphics/API/RendererAPI.h index 5f1a22457..5d5e8b787 100644 --- a/TRAP/src/Graphics/API/RendererAPI.h +++ b/TRAP/src/Graphics/API/RendererAPI.h @@ -2839,6 +2839,8 @@ namespace TRAP::Graphics /// @brief Move assignment operator. PerViewportData& operator=(PerViewportData &&) noexcept = default; + [[nodiscard]] TRAP::Ref GetCurrentSwapchainRenderTarget() const; + #ifndef TRAP_HEADLESS_MODE TRAP::Window* Window{}; #endif /*TRAP_HEADLESS_MODE*/ diff --git a/TRAP/src/Graphics/API/Vulkan/VulkanRenderer.cpp b/TRAP/src/Graphics/API/Vulkan/VulkanRenderer.cpp index eaaa4b8e9..3949d7e2e 100644 --- a/TRAP/src/Graphics/API/Vulkan/VulkanRenderer.cpp +++ b/TRAP/src/Graphics/API/Vulkan/VulkanRenderer.cpp @@ -300,17 +300,6 @@ namespace //-------------------------------------------------------------------------------------------------------------------// - [[nodiscard]] TRAP::Ref GetCurrentSwapchainRenderTarget(const TRAP::Graphics::RendererAPI::PerViewportData& p) - { -#ifndef TRAP_HEADLESS_MODE - return p.SwapChain->GetRenderTargets()[p.CurrentSwapChainImageIndex]; -#else - return p.RenderTargets[p.CurrentSwapChainImageIndex]; -#endif - } - - //-------------------------------------------------------------------------------------------------------------------// - //Helper function to generate screenshot data. See CaptureScreenshot. template [[nodiscard]] std::vector MapRenderTarget(const TRAP::Ref& graphicsQueue, @@ -636,7 +625,7 @@ void TRAP::Graphics::API::VulkanRenderer::StartGraphicRecording(PerViewportData& if(p.RenderScale != 1.0f || p.CurrentAntiAliasing == RendererAPI::AntiAliasing::MSAA) bindRenderTarget = p.InternalRenderTargets[p.CurrentSwapChainImageIndex]; else - bindRenderTarget = GetCurrentSwapchainRenderTarget(p); + bindRenderTarget = p.GetCurrentSwapchainRenderTarget(); std::get(p.GraphicsPipelineDesc.Pipeline).ShadingRateTexture = GetShadingRateTexture(p); @@ -648,7 +637,7 @@ void TRAP::Graphics::API::VulkanRenderer::StartGraphicRecording(PerViewportData& BeginGPUFrameProfile(QueueType::Graphics, p); #ifndef TRAP_HEADLESS_MODE - const RenderTargetBarrier swapChainBarrier{*GetCurrentSwapchainRenderTarget(p), ResourceState::Present, ResourceState::RenderTarget}; + const RenderTargetBarrier swapChainBarrier{*p.GetCurrentSwapchainRenderTarget(), ResourceState::Present, ResourceState::RenderTarget}; p.GraphicCommandBuffers[p.ImageIndex]->ResourceBarrier(nullptr, nullptr, &swapChainBarrier); #endif /*TRAP_HEADLESS_MODE*/ @@ -708,7 +697,7 @@ void TRAP::Graphics::API::VulkanRenderer::EndGraphicRecording(PerViewportData& p if(p.CurrentAntiAliasing == RendererAPI::AntiAliasing::MSAA && p.RenderScale == 1.0f) //Inject MSAA resolve pass { - const TRAP::Ref presentRenderTarget = GetCurrentSwapchainRenderTarget(p); + const TRAP::Ref presentRenderTarget = p.GetCurrentSwapchainRenderTarget(); const TRAP::Ref& MSAARenderTarget = p.InternalRenderTargets[p.CurrentSwapChainImageIndex]; Graphics::RendererAPI::GetRenderer()->MSAAResolvePass(*MSAARenderTarget, *presentRenderTarget, p.GraphicCommandBuffers[p.ImageIndex]); @@ -719,7 +708,7 @@ void TRAP::Graphics::API::VulkanRenderer::EndGraphicRecording(PerViewportData& p p.GraphicCommandBuffers[p.ImageIndex]->BindRenderTargets({}, nullptr, nullptr, nullptr, nullptr, std::numeric_limits::max(), std::numeric_limits::max(), nullptr); - const TRAP::Ref presentRenderTarget = GetCurrentSwapchainRenderTarget(p); + const TRAP::Ref presentRenderTarget = p.GetCurrentSwapchainRenderTarget(); const RenderTargetBarrier barrier{*presentRenderTarget, ResourceState::RenderTarget, ResourceState::Present}; p.GraphicCommandBuffers[p.ImageIndex]->ResourceBarrier(nullptr, nullptr, &barrier); #else @@ -1598,7 +1587,7 @@ void TRAP::Graphics::API::VulkanRenderer::Clear(const ClearBufferType clearType) if(p.RenderScale != 1.0f || p.CurrentAntiAliasing == RendererAPI::AntiAliasing::MSAA) renderTarget = p.InternalRenderTargets[p.CurrentSwapChainImageIndex]; else - renderTarget = GetCurrentSwapchainRenderTarget(p); + renderTarget = p.GetCurrentSwapchainRenderTarget(); const CommandBuffer* const cmdBuffer = p.GraphicCommandBuffers[p.ImageIndex]; @@ -2352,7 +2341,7 @@ void TRAP::Graphics::API::VulkanRenderer::ReflexMarker([[maybe_unused]] const u3 const PerViewportData& p = *GETPERVIEWPORTDATA; - const u32 lastFrame = (p.ImageIndex - 1) % RendererAPI::ImageCount; + const u32 lastFrame = (p.ImageIndex - 1) % RendererAPI::ImageCount; //BUG This must be the previous value of p.CurrentSwapChainImageIndex (#294) //Wait for queues to finish s_computeQueue->WaitQueueIdle(); diff --git a/TRAP/src/Layers/ImGui/ImGuiLayer.cpp b/TRAP/src/Layers/ImGui/ImGuiLayer.cpp index d9be38ece..c596d8493 100644 --- a/TRAP/src/Layers/ImGui/ImGuiLayer.cpp +++ b/TRAP/src/Layers/ImGui/ImGuiLayer.cpp @@ -312,7 +312,7 @@ void TRAP::ImGuiLayer::Begin() if(aaMethod == TRAP::Graphics::RendererAPI::AntiAliasing::MSAA && viewportData.RenderScale == 1.0f) //MSAA and no RenderScale rT = viewportData.InternalRenderTargets[viewportData.CurrentSwapChainImageIndex]; else - rT = viewportData.SwapChain->GetRenderTargets()[viewportData.CurrentSwapChainImageIndex]; + rT = viewportData.GetCurrentSwapchainRenderTarget(); //Cant use TRAP::Graphics::RenderCommand::StartRenderPass() here, because it would also bind the shading rate image vkCmdBuffer->BindRenderTargets({ *rT }, nullptr, nullptr, nullptr, nullptr, diff --git a/TRAP/src/Log/Log.h b/TRAP/src/Log/Log.h index 874ab6f00..5ee7c4a0c 100644 --- a/TRAP/src/Log/Log.h +++ b/TRAP/src/Log/Log.h @@ -155,7 +155,7 @@ namespace TRAP /// @threadsafe void Clear() noexcept; - static constexpr auto WindowVersion = "[24w43b3]"; + static constexpr auto WindowVersion = "[24w44a1]"; static constexpr auto WindowPrefix = "[Window] "; static constexpr auto WindowIconPrefix = "[Window][Icon] "; static constexpr auto ConfigPrefix = "[Config] ";