Renderer: Refactor transient resources (allow access at any time)
This commit is contained in:
committed by
Jérôme Leclercq
parent
de68033a0e
commit
4db5b59ec9
@@ -60,9 +60,9 @@ namespace Nz
|
||||
UpdateObservers();
|
||||
UpdateInstances();
|
||||
|
||||
for (auto& windowPtr : m_windowSwapchains)
|
||||
for (auto& swapchainPtr : m_windowSwapchains)
|
||||
{
|
||||
RenderFrame frame = windowPtr->AcquireFrame();
|
||||
RenderFrame frame = swapchainPtr->AcquireFrame();
|
||||
if (!frame)
|
||||
continue;
|
||||
|
||||
|
||||
@@ -156,22 +156,6 @@ namespace Nz
|
||||
#endif
|
||||
}
|
||||
|
||||
void OpenGLDevice::Execute(const FunctionRef<void(CommandBufferBuilder& builder)>& callback, QueueType /*queueType*/)
|
||||
{
|
||||
const GL::Context* activeContext = GL::Context::GetCurrentContext();
|
||||
if (!activeContext || activeContext->GetDevice() != this)
|
||||
{
|
||||
if (!GL::Context::SetCurrentContext(m_referenceContext.get()))
|
||||
throw std::runtime_error("failed to activate context");
|
||||
}
|
||||
|
||||
OpenGLCommandBuffer commandBuffer; //< TODO: Use a pool and remove default constructor
|
||||
OpenGLCommandBufferBuilder builder(commandBuffer);
|
||||
callback(builder);
|
||||
|
||||
commandBuffer.Execute();
|
||||
}
|
||||
|
||||
const RenderDeviceInfo& OpenGLDevice::GetDeviceInfo() const
|
||||
{
|
||||
return m_deviceInfo;
|
||||
|
||||
@@ -116,4 +116,9 @@ namespace Nz
|
||||
m_context->SwapBuffers();
|
||||
m_currentFrame = (m_currentFrame + 1) % m_renderImage.size();
|
||||
}
|
||||
|
||||
TransientResources& OpenGLSwapchain::Transient()
|
||||
{
|
||||
return *m_renderImage[m_currentFrame];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Renderer module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Renderer/RenderFrame.hpp>
|
||||
#include <Nazara/Renderer/RenderImage.hpp>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
void RenderFrame::Execute(const FunctionRef<void(CommandBufferBuilder& builder)>& callback, QueueTypeFlags queueTypeFlags)
|
||||
{
|
||||
if (!m_image)
|
||||
throw std::runtime_error("frame is either invalid or has already been presented");
|
||||
|
||||
return m_image->Execute(callback, queueTypeFlags);
|
||||
}
|
||||
|
||||
UploadPool& RenderFrame::GetUploadPool()
|
||||
{
|
||||
if (!m_image)
|
||||
throw std::runtime_error("frame is either invalid or has already been presented");
|
||||
|
||||
return m_image->GetUploadPool();
|
||||
}
|
||||
|
||||
void RenderFrame::Present()
|
||||
{
|
||||
if (!m_image)
|
||||
throw std::runtime_error("frame is either invalid or has already been presented");
|
||||
|
||||
m_image->Present();
|
||||
m_image = nullptr;
|
||||
}
|
||||
|
||||
void RenderFrame::SubmitCommandBuffer(CommandBuffer* commandBuffer, QueueTypeFlags queueTypeFlags)
|
||||
{
|
||||
if (!m_image)
|
||||
throw std::runtime_error("frame is either invalid or has already been presented");
|
||||
|
||||
m_image->SubmitCommandBuffer(commandBuffer, queueTypeFlags);
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,15 @@
|
||||
// This file is part of the "Nazara Engine - Renderer module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Renderer/RenderImage.hpp>
|
||||
#include <Nazara/Renderer/TransientResources.hpp>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
RenderImage::~RenderImage()
|
||||
TransientResources::~TransientResources()
|
||||
{
|
||||
FlushReleaseQueue();
|
||||
}
|
||||
|
||||
RenderImage::Releasable::~Releasable() = default;
|
||||
TransientResources::Releasable::~Releasable() = default;
|
||||
}
|
||||
@@ -21,22 +21,6 @@ namespace Nz
|
||||
{
|
||||
VulkanDevice::~VulkanDevice() = default;
|
||||
|
||||
void VulkanDevice::Execute(const FunctionRef<void(CommandBufferBuilder& builder)>& callback, QueueType queueType)
|
||||
{
|
||||
Vk::AutoCommandBuffer commandBuffer = AllocateCommandBuffer(queueType);
|
||||
if (!commandBuffer->Begin(VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT))
|
||||
throw std::runtime_error("failed to begin command buffer: " + TranslateVulkanError(commandBuffer->GetLastErrorCode()));
|
||||
|
||||
VulkanCommandBufferBuilder builder(commandBuffer);
|
||||
callback(builder);
|
||||
|
||||
if (!commandBuffer->End())
|
||||
throw std::runtime_error("failed to build command buffer: " + TranslateVulkanError(commandBuffer->GetLastErrorCode()));
|
||||
|
||||
GetQueue(GetDefaultFamilyIndex(queueType), 0).Submit(commandBuffer);
|
||||
GetQueue(GetDefaultFamilyIndex(queueType), 0).WaitIdle();
|
||||
}
|
||||
|
||||
const RenderDeviceInfo& VulkanDevice::GetDeviceInfo() const
|
||||
{
|
||||
return m_renderDeviceInfo;
|
||||
|
||||
@@ -332,6 +332,11 @@ namespace Nz
|
||||
}
|
||||
}
|
||||
|
||||
TransientResources& VulkanSwapchain::Transient()
|
||||
{
|
||||
return *m_concurrentImageData[m_currentFrame];
|
||||
}
|
||||
|
||||
bool VulkanSwapchain::SetupDepthBuffer()
|
||||
{
|
||||
VkImageCreateInfo imageCreateInfo = {
|
||||
|
||||
Reference in New Issue
Block a user