Graphics/BakedFrameGraph: Handle resize in a better way
This commit is contained in:
parent
c42d18243b
commit
1c482bbde6
|
|
@ -26,6 +26,7 @@ namespace Nz
|
||||||
friend class FrameGraph;
|
friend class FrameGraph;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
BakedFrameGraph() = default;
|
||||||
BakedFrameGraph(const BakedFrameGraph&) = delete;
|
BakedFrameGraph(const BakedFrameGraph&) = delete;
|
||||||
BakedFrameGraph(BakedFrameGraph&&) noexcept = default;
|
BakedFrameGraph(BakedFrameGraph&&) noexcept = default;
|
||||||
~BakedFrameGraph() = default;
|
~BakedFrameGraph() = default;
|
||||||
|
|
@ -35,7 +36,7 @@ namespace Nz
|
||||||
const std::shared_ptr<Texture>& GetAttachmentTexture(std::size_t attachmentIndex) const;
|
const std::shared_ptr<Texture>& GetAttachmentTexture(std::size_t attachmentIndex) const;
|
||||||
const std::shared_ptr<RenderPass>& GetRenderPass(std::size_t passIndex) const;
|
const std::shared_ptr<RenderPass>& GetRenderPass(std::size_t passIndex) const;
|
||||||
|
|
||||||
void Resize(unsigned int width, unsigned int height);
|
bool Resize(unsigned int width, unsigned int height);
|
||||||
|
|
||||||
BakedFrameGraph& operator=(const BakedFrameGraph&) = delete;
|
BakedFrameGraph& operator=(const BakedFrameGraph&) = delete;
|
||||||
BakedFrameGraph& operator=(BakedFrameGraph&&) noexcept = default;
|
BakedFrameGraph& operator=(BakedFrameGraph&&) noexcept = default;
|
||||||
|
|
@ -75,6 +76,7 @@ namespace Nz
|
||||||
std::vector<TextureTransition> transitions;
|
std::vector<TextureTransition> transitions;
|
||||||
FramePass::ExecutionCallback executionCallback;
|
FramePass::ExecutionCallback executionCallback;
|
||||||
Recti renderRect;
|
Recti renderRect;
|
||||||
|
bool forceCommandBufferRegeneration = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TextureData
|
struct TextureData
|
||||||
|
|
@ -91,6 +93,8 @@ namespace Nz
|
||||||
std::vector<TextureData> m_textures;
|
std::vector<TextureData> m_textures;
|
||||||
AttachmentIdToTextureId m_attachmentToTextureMapping;
|
AttachmentIdToTextureId m_attachmentToTextureMapping;
|
||||||
PassIdToPhysicalPassIndex m_passIdToPhysicalPassMapping;
|
PassIdToPhysicalPassIndex m_passIdToPhysicalPassMapping;
|
||||||
|
unsigned int m_height;
|
||||||
|
unsigned int m_width;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,9 @@ namespace Nz
|
||||||
m_passes(std::move(passes)),
|
m_passes(std::move(passes)),
|
||||||
m_textures(std::move(textures)),
|
m_textures(std::move(textures)),
|
||||||
m_attachmentToTextureMapping(std::move(attachmentIdToTextureMapping)),
|
m_attachmentToTextureMapping(std::move(attachmentIdToTextureMapping)),
|
||||||
m_passIdToPhysicalPassMapping(std::move(passIdToPhysicalPassMapping))
|
m_passIdToPhysicalPassMapping(std::move(passIdToPhysicalPassMapping)),
|
||||||
|
m_height(0),
|
||||||
|
m_width(0)
|
||||||
{
|
{
|
||||||
const std::shared_ptr<RenderDevice>& renderDevice = Graphics::Instance()->GetRenderDevice();
|
const std::shared_ptr<RenderDevice>& renderDevice = Graphics::Instance()->GetRenderDevice();
|
||||||
m_commandPool = renderDevice->InstantiateCommandPool(QueueType::Graphics);
|
m_commandPool = renderDevice->InstantiateCommandPool(QueueType::Graphics);
|
||||||
|
|
@ -24,7 +26,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
for (auto& passData : m_passes)
|
for (auto& passData : m_passes)
|
||||||
{
|
{
|
||||||
bool regenerateCommandBuffer = (passData.commandBuffer == nullptr);
|
bool regenerateCommandBuffer = (passData.forceCommandBufferRegeneration || passData.commandBuffer == nullptr);
|
||||||
if (passData.executionCallback)
|
if (passData.executionCallback)
|
||||||
{
|
{
|
||||||
switch (passData.executionCallback())
|
switch (passData.executionCallback())
|
||||||
|
|
@ -33,8 +35,11 @@ namespace Nz
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FramePassExecution::Skip:
|
case FramePassExecution::Skip:
|
||||||
|
if (passData.commandBuffer)
|
||||||
|
{
|
||||||
renderFrame.PushForRelease(std::move(passData.commandBuffer));
|
renderFrame.PushForRelease(std::move(passData.commandBuffer));
|
||||||
passData.commandBuffer.reset();
|
passData.commandBuffer.reset();
|
||||||
|
}
|
||||||
continue; //< Skip the pass
|
continue; //< Skip the pass
|
||||||
|
|
||||||
case FramePassExecution::UpdateAndExecute:
|
case FramePassExecution::UpdateAndExecute:
|
||||||
|
|
@ -46,7 +51,9 @@ namespace Nz
|
||||||
if (!regenerateCommandBuffer)
|
if (!regenerateCommandBuffer)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (passData.commandBuffer)
|
||||||
renderFrame.PushForRelease(std::move(passData.commandBuffer));
|
renderFrame.PushForRelease(std::move(passData.commandBuffer));
|
||||||
|
|
||||||
passData.commandBuffer = m_commandPool->BuildCommandBuffer([&](CommandBufferBuilder& builder)
|
passData.commandBuffer = m_commandPool->BuildCommandBuffer([&](CommandBufferBuilder& builder)
|
||||||
{
|
{
|
||||||
for (auto& textureTransition : passData.transitions)
|
for (auto& textureTransition : passData.transitions)
|
||||||
|
|
@ -68,7 +75,7 @@ namespace Nz
|
||||||
|
|
||||||
first = false;
|
first = false;
|
||||||
|
|
||||||
subpass.commandCallback(builder);
|
subpass.commandCallback(builder, passData.renderRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.EndRenderPass();
|
builder.EndRenderPass();
|
||||||
|
|
@ -76,6 +83,8 @@ namespace Nz
|
||||||
if (!passData.name.empty())
|
if (!passData.name.empty())
|
||||||
builder.EndDebugRegion();
|
builder.EndDebugRegion();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
passData.forceCommandBufferRegeneration = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Submit all commands buffer at once
|
//TODO: Submit all commands buffer at once
|
||||||
|
|
@ -114,8 +123,11 @@ namespace Nz
|
||||||
return m_passes[physicalPassIndex].renderPass;
|
return m_passes[physicalPassIndex].renderPass;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BakedFrameGraph::Resize(unsigned int width, unsigned int height)
|
bool BakedFrameGraph::Resize(unsigned int width, unsigned int height)
|
||||||
{
|
{
|
||||||
|
if (m_width == width && m_height == height)
|
||||||
|
return false;
|
||||||
|
|
||||||
const std::shared_ptr<RenderDevice>& renderDevice = Graphics::Instance()->GetRenderDevice();
|
const std::shared_ptr<RenderDevice>& renderDevice = Graphics::Instance()->GetRenderDevice();
|
||||||
|
|
||||||
// Delete previous textures to make some room in VRAM
|
// Delete previous textures to make some room in VRAM
|
||||||
|
|
@ -162,6 +174,9 @@ namespace Nz
|
||||||
passData.renderRect.Set(0, 0, int(framebufferWidth), int(framebufferHeight));
|
passData.renderRect.Set(0, 0, int(framebufferWidth), int(framebufferHeight));
|
||||||
|
|
||||||
passData.framebuffer = renderDevice->InstantiateFramebuffer(framebufferWidth, framebufferHeight, passData.renderPass, textures);
|
passData.framebuffer = renderDevice->InstantiateFramebuffer(framebufferWidth, framebufferHeight, passData.renderPass, textures);
|
||||||
|
passData.forceCommandBufferRegeneration = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue