Skip to content

Commit

Permalink
VulkanRenderer Moved GetCurrentSwapChainRenderTarget() to RendererAPI…
Browse files Browse the repository at this point in the history
…::PerViewportData 10/28/2024 | 24w44a1
  • Loading branch information
GamesTrap committed Oct 28, 2024
1 parent 5b88e51 commit 598aec4
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 25 deletions.
4 changes: 4 additions & 0 deletions SITREPS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion TRAP/src/Core/Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -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{};

//-------------------------------------------------------------------------------------------------------------------//

Expand Down
21 changes: 16 additions & 5 deletions TRAP/src/Graphics/API/RendererAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void TRAP::Graphics::RendererAPI::OnPostUpdate()

if(data->RenderScale != 1.0f)
{
TRAP::Ref<RenderTarget> outputTarget = data->SwapChain->GetRenderTargets()[data->CurrentSwapChainImageIndex];
TRAP::Ref<RenderTarget> outputTarget = data->GetCurrentSwapchainRenderTarget();

GetRenderer()->RenderScalePass(*data->InternalRenderTargets[data->CurrentSwapChainImageIndex],
*outputTarget, *win);
Expand All @@ -202,7 +202,7 @@ void TRAP::Graphics::RendererAPI::OnPostUpdate()

if(s_perViewportData->RenderScale != 1.0f)
{
TRAP::Ref<RenderTarget> outputTarget = s_perViewportData->RenderTargets[s_perViewportData->CurrentSwapChainImageIndex];
TRAP::Ref<RenderTarget> outputTarget = s_perViewportData->GetCurrentSwapchainRenderTarget();

GetRenderer()->RenderScalePass(*s_perViewportData->InternalRenderTargets[s_perViewportData->CurrentSwapChainImageIndex],
*outputTarget);
Expand Down Expand Up @@ -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<u32>::max(),
Expand All @@ -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<u32>::max(),
Expand Down Expand Up @@ -779,3 +779,14 @@ TRAP::Graphics::RendererAPI::PerViewportData::~PerViewportData()
return s_perViewportData->ImageIndex;
}
#endif /*TRAP_HEADLESS_MODE*/

//-------------------------------------------------------------------------------------------------------------------//

[[nodiscard]] TRAP::Ref<TRAP::Graphics::RenderTarget> TRAP::Graphics::RendererAPI::PerViewportData::GetCurrentSwapchainRenderTarget() const
{
#ifndef TRAP_HEADLESS_MODE
return SwapChain->GetRenderTargets()[CurrentSwapChainImageIndex];
#else
return RenderTargets[CurrentSwapChainImageIndex];
#endif
}
2 changes: 2 additions & 0 deletions TRAP/src/Graphics/API/RendererAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -2839,6 +2839,8 @@ namespace TRAP::Graphics
/// @brief Move assignment operator.
PerViewportData& operator=(PerViewportData &&) noexcept = default;

[[nodiscard]] TRAP::Ref<TRAP::Graphics::RenderTarget> GetCurrentSwapchainRenderTarget() const;

#ifndef TRAP_HEADLESS_MODE
TRAP::Window* Window{};
#endif /*TRAP_HEADLESS_MODE*/
Expand Down
23 changes: 6 additions & 17 deletions TRAP/src/Graphics/API/Vulkan/VulkanRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,17 +300,6 @@ namespace

//-------------------------------------------------------------------------------------------------------------------//

[[nodiscard]] TRAP::Ref<TRAP::Graphics::RenderTarget> 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<typename T>
[[nodiscard]] std::vector<T> MapRenderTarget(const TRAP::Ref<TRAP::Graphics::Queue>& graphicsQueue,
Expand Down Expand Up @@ -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<GraphicsPipelineDesc>(p.GraphicsPipelineDesc.Pipeline).ShadingRateTexture = GetShadingRateTexture(p);

Expand All @@ -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*/

Expand Down Expand Up @@ -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<RenderTarget> presentRenderTarget = GetCurrentSwapchainRenderTarget(p);
const TRAP::Ref<RenderTarget> presentRenderTarget = p.GetCurrentSwapchainRenderTarget();
const TRAP::Ref<RenderTarget>& MSAARenderTarget = p.InternalRenderTargets[p.CurrentSwapChainImageIndex];

Graphics::RendererAPI::GetRenderer()->MSAAResolvePass(*MSAARenderTarget, *presentRenderTarget, p.GraphicCommandBuffers[p.ImageIndex]);
Expand All @@ -719,7 +708,7 @@ void TRAP::Graphics::API::VulkanRenderer::EndGraphicRecording(PerViewportData& p
p.GraphicCommandBuffers[p.ImageIndex]->BindRenderTargets({}, nullptr, nullptr, nullptr, nullptr,
std::numeric_limits<u32>::max(),
std::numeric_limits<u32>::max(), nullptr);
const TRAP::Ref<RenderTarget> presentRenderTarget = GetCurrentSwapchainRenderTarget(p);
const TRAP::Ref<RenderTarget> presentRenderTarget = p.GetCurrentSwapchainRenderTarget();
const RenderTargetBarrier barrier{*presentRenderTarget, ResourceState::RenderTarget, ResourceState::Present};
p.GraphicCommandBuffers[p.ImageIndex]->ResourceBarrier(nullptr, nullptr, &barrier);
#else
Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion TRAP/src/Layers/ImGui/ImGuiLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion TRAP/src/Log/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -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] ";
Expand Down

0 comments on commit 598aec4

Please sign in to comment.