1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-02-07 16:54:14 +01:00

[dxvk] Use dynamic rendering directly for render target clears

This commit is contained in:
Philip Rebohle 2022-07-03 13:12:40 +02:00
parent 605fef10b4
commit f57a6d485b
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99

View File

@ -1936,9 +1936,27 @@ namespace dxvk {
if (m_execBarriers.isImageDirty(imageView->image(), imageView->imageSubresources(), DxvkAccess::Write)) if (m_execBarriers.isImageDirty(imageView->image(), imageView->imageSubresources(), DxvkAccess::Write))
m_execBarriers.recordCommands(m_cmd); m_execBarriers.recordCommands(m_cmd);
// Set up and bind a temporary framebuffer // Set up a temporary render pass to execute the clear
DxvkRenderTargets attachments; VkImageLayout imageLayout = ((clearAspects | discardAspects) & VK_IMAGE_ASPECT_COLOR_BIT)
DxvkRenderPassOps ops; ? imageView->pickLayout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)
: imageView->pickLayout(VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
VkRenderingAttachmentInfoKHR attachmentInfo = { VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR };
attachmentInfo.imageView = imageView->handle();
attachmentInfo.imageLayout = imageLayout;
attachmentInfo.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
attachmentInfo.clearValue = clearValue;
VkRenderingAttachmentInfoKHR stencilInfo = attachmentInfo;
VkExtent3D extent = imageView->mipLevelExtent(0);
VkRenderingInfoKHR renderingInfo = { VK_STRUCTURE_TYPE_RENDERING_INFO_KHR };
renderingInfo.renderArea.extent = { extent.width, extent.height };
renderingInfo.layerCount = imageView->info().numLayers;
VkImageLayout loadLayout;
VkImageLayout storeLayout;
VkPipelineStageFlags clearStages = 0; VkPipelineStageFlags clearStages = 0;
VkAccessFlags clearAccess = 0; VkAccessFlags clearAccess = 0;
@ -1947,28 +1965,55 @@ namespace dxvk {
clearStages |= VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; clearStages |= VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
clearAccess |= VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; clearAccess |= VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
attachments.color[0].view = imageView; attachmentInfo.loadOp = colorOp.loadOp;
attachments.color[0].layout = imageView->pickLayout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
ops.colorOps[0] = colorOp; renderingInfo.colorAttachmentCount = 1;
renderingInfo.pColorAttachments = &attachmentInfo;
loadLayout = colorOp.loadLayout;
storeLayout = colorOp.storeLayout;
} else { } else {
clearStages |= VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT clearStages |= VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
| VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT; | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT;
clearAccess |= VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; clearAccess |= VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
attachments.depth.view = imageView; if (imageView->info().aspect & VK_IMAGE_ASPECT_DEPTH_BIT) {
attachments.depth.layout = imageView->pickLayout(VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); renderingInfo.pDepthAttachment = &attachmentInfo;
attachmentInfo.loadOp = depthOp.loadOpD;
ops.depthOps = depthOp;
} }
ops.barrier.srcStages = clearStages; if (imageView->info().aspect & VK_IMAGE_ASPECT_STENCIL_BIT) {
ops.barrier.srcAccess = clearAccess; renderingInfo.pStencilAttachment = &stencilInfo;
ops.barrier.dstStages = imageView->imageInfo().stages; stencilInfo.loadOp = depthOp.loadOpS;
ops.barrier.dstAccess = imageView->imageInfo().access; }
this->renderPassBindFramebuffer(makeFramebufferInfo(attachments), ops, 1, &clearValue); loadLayout = depthOp.loadLayout;
this->renderPassUnbindFramebuffer(); storeLayout = depthOp.storeLayout;
}
if (loadLayout != imageLayout) {
m_execAcquires.accessImage(
imageView->image(),
imageView->imageSubresources(),
loadLayout, clearStages, 0,
imageLayout, clearStages, clearAccess);
m_execAcquires.recordCommands(m_cmd);
}
m_cmd->cmdBeginRendering(&renderingInfo);
m_cmd->cmdEndRendering();
m_execBarriers.accessImage(
imageView->image(),
imageView->imageSubresources(),
imageLayout, clearStages, clearAccess,
storeLayout,
imageView->imageInfo().stages,
imageView->imageInfo().access);
m_cmd->trackResource<DxvkAccess::None>(imageView);
m_cmd->trackResource<DxvkAccess::Write>(imageView->image());
} else { } else {
// Perform the operation when starting the next render pass // Perform the operation when starting the next render pass
if ((clearAspects | discardAspects) & VK_IMAGE_ASPECT_COLOR_BIT) { if ((clearAspects | discardAspects) & VK_IMAGE_ASPECT_COLOR_BIT) {