Renderer: Fix MRT support
This commit is contained in:
@@ -85,6 +85,7 @@ namespace Nz
|
||||
m_commandBuffer.BeginRenderPass(beginInfo);
|
||||
|
||||
m_currentRenderPass = &vkRenderPass;
|
||||
m_currentSubpassIndex = 0;
|
||||
}
|
||||
|
||||
void VulkanCommandBufferBuilder::BindIndexBuffer(Nz::AbstractBuffer* indexBuffer, UInt64 offset)
|
||||
@@ -101,7 +102,7 @@ namespace Nz
|
||||
|
||||
const VulkanRenderPipeline& vkBinding = static_cast<const VulkanRenderPipeline&>(pipeline);
|
||||
|
||||
m_commandBuffer.BindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, vkBinding.Get(m_currentRenderPass->GetRenderPass()));
|
||||
m_commandBuffer.BindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, vkBinding.Get(*m_currentRenderPass, m_currentSubpassIndex));
|
||||
}
|
||||
|
||||
void VulkanCommandBufferBuilder::BindShaderBinding(const ShaderBinding& binding)
|
||||
@@ -160,6 +161,7 @@ namespace Nz
|
||||
void VulkanCommandBufferBuilder::NextSubpass()
|
||||
{
|
||||
m_commandBuffer.NextSubpass();
|
||||
m_currentSubpassIndex++;
|
||||
}
|
||||
|
||||
void VulkanCommandBufferBuilder::PreTransferBarrier()
|
||||
|
||||
@@ -19,20 +19,31 @@ namespace Nz
|
||||
m_pipelineCreateInfo = BuildCreateInfo(m_pipelineInfo);
|
||||
}
|
||||
|
||||
VkPipeline VulkanRenderPipeline::Get(const Vk::RenderPass& renderPass) const
|
||||
VkPipeline VulkanRenderPipeline::Get(const VulkanRenderPass& renderPass, std::size_t subpassIndex) const
|
||||
{
|
||||
if (auto it = m_pipelines.find(renderPass); it != m_pipelines.end())
|
||||
const Vk::RenderPass& renderPassHandle = renderPass.GetRenderPass();
|
||||
|
||||
// Use color attachment count as a key
|
||||
const auto& subpasses = renderPass.GetSubpassDescriptions();
|
||||
assert(subpassIndex < subpasses.size());
|
||||
|
||||
std::size_t colorAttachmentCount = subpasses[subpassIndex].colorAttachment.size();
|
||||
|
||||
std::pair<VkRenderPass, std::size_t> key = { renderPassHandle, colorAttachmentCount };
|
||||
|
||||
if (auto it = m_pipelines.find(key); it != m_pipelines.end())
|
||||
return it->second;
|
||||
|
||||
// Copy create info to make Get re-entrant
|
||||
UpdateCreateInfo(colorAttachmentCount);
|
||||
|
||||
VkGraphicsPipelineCreateInfo pipelineCreateInfo = m_pipelineCreateInfo.pipelineInfo;
|
||||
pipelineCreateInfo.renderPass = renderPass;
|
||||
pipelineCreateInfo.renderPass = renderPassHandle;
|
||||
|
||||
Vk::Pipeline newPipeline;
|
||||
if (!newPipeline.CreateGraphics(*m_device, pipelineCreateInfo))
|
||||
return VK_NULL_HANDLE;
|
||||
|
||||
auto it = m_pipelines.emplace(renderPass, std::move(newPipeline)).first;
|
||||
auto it = m_pipelines.emplace(key, std::move(newPipeline)).first;
|
||||
return it->second;
|
||||
}
|
||||
|
||||
@@ -269,4 +280,20 @@ namespace Nz
|
||||
|
||||
return createInfo;
|
||||
}
|
||||
|
||||
void VulkanRenderPipeline::UpdateCreateInfo(std::size_t colorBufferCount) const
|
||||
{
|
||||
// TODO: Add support for independent blend
|
||||
std::size_t previousSize = m_pipelineCreateInfo.colorBlendAttachmentState.size();
|
||||
if (previousSize < colorBufferCount)
|
||||
{
|
||||
assert(!m_pipelineCreateInfo.colorBlendAttachmentState.empty());
|
||||
|
||||
m_pipelineCreateInfo.colorBlendAttachmentState.resize(colorBufferCount);
|
||||
for (std::size_t i = previousSize; i < colorBufferCount; ++i)
|
||||
m_pipelineCreateInfo.colorBlendAttachmentState[i] = m_pipelineCreateInfo.colorBlendAttachmentState.front();
|
||||
}
|
||||
|
||||
m_pipelineCreateInfo.stateData->colorBlendState = BuildColorBlendInfo(m_pipelineInfo, m_pipelineCreateInfo.colorBlendAttachmentState);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user