Vulkan: Use recommended access flags for image layout transitions.

This commit is contained in:
BearOso 2024-10-17 13:48:46 -05:00
parent 71f2ba2d7e
commit 39c0f8418b
2 changed files with 14 additions and 11 deletions

View File

@ -74,11 +74,11 @@ void PipelineImage::generate_mipmaps(vk::CommandBuffer cmd)
.setImage(image) .setImage(image)
.setOldLayout(vk::ImageLayout::eShaderReadOnlyOptimal) .setOldLayout(vk::ImageLayout::eShaderReadOnlyOptimal)
.setNewLayout(vk::ImageLayout::eTransferSrcOptimal) .setNewLayout(vk::ImageLayout::eTransferSrcOptimal)
.setSrcAccessMask(vk::AccessFlagBits::eColorAttachmentWrite) .setSrcAccessMask(vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eInputAttachmentRead)
.setDstAccessMask(vk::AccessFlagBits::eTransferRead) .setDstAccessMask(vk::AccessFlagBits::eTransferRead)
.setSubresourceRange(srr(0)); .setSubresourceRange(srr(0));
cmd.pipelineBarrier(vk::PipelineStageFlagBits::eAllGraphics, cmd.pipelineBarrier(vk::PipelineStageFlagBits::eVertexShader | vk::PipelineStageFlagBits::eFragmentShader,
vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eTransfer,
{}, {}, {}, image_memory_barrier); {}, {}, {}, image_memory_barrier);
@ -139,7 +139,7 @@ void PipelineImage::generate_mipmaps(vk::CommandBuffer cmd)
image_memory_barrier image_memory_barrier
.setOldLayout(vk::ImageLayout::eTransferSrcOptimal) .setOldLayout(vk::ImageLayout::eTransferSrcOptimal)
.setNewLayout(vk::ImageLayout::eShaderReadOnlyOptimal) .setNewLayout(vk::ImageLayout::eShaderReadOnlyOptimal)
.setSrcAccessMask(vk::AccessFlagBits::eTransferWrite) .setSrcAccessMask(vk::AccessFlagBits::eTransferRead)
.setDstAccessMask(vk::AccessFlagBits::eShaderRead) .setDstAccessMask(vk::AccessFlagBits::eShaderRead)
.setSubresourceRange(srr(base_level)); .setSubresourceRange(srr(base_level));
@ -163,7 +163,7 @@ void PipelineImage::generate_mipmaps(vk::CommandBuffer cmd)
void PipelineImage::barrier(vk::CommandBuffer cmd) void PipelineImage::barrier(vk::CommandBuffer cmd)
{ {
cmd.pipelineBarrier(vk::PipelineStageFlagBits::eAllGraphics, cmd.pipelineBarrier(vk::PipelineStageFlagBits::eBottomOfPipe,
vk::PipelineStageFlagBits::eFragmentShader, vk::PipelineStageFlagBits::eFragmentShader,
{}, {}, {}, {}); {}, {}, {}, {});
} }
@ -178,7 +178,7 @@ void PipelineImage::clear(vk::CommandBuffer cmd)
.setOldLayout(vk::ImageLayout::eUndefined) .setOldLayout(vk::ImageLayout::eUndefined)
.setNewLayout(vk::ImageLayout::eTransferDstOptimal) .setNewLayout(vk::ImageLayout::eTransferDstOptimal)
.setSrcAccessMask(vk::AccessFlagBits::eShaderRead) .setSrcAccessMask(vk::AccessFlagBits::eShaderRead)
.setDstAccessMask(vk::AccessFlagBits::eTransferWrite | vk::AccessFlagBits::eTransferRead); .setDstAccessMask(vk::AccessFlagBits::eTransferWrite);
cmd.pipelineBarrier(vk::PipelineStageFlagBits::eFragmentShader, cmd.pipelineBarrier(vk::PipelineStageFlagBits::eFragmentShader,
vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eTransfer,

View File

@ -476,7 +476,7 @@ bool ShaderChain::do_frame_without_swap(uint8_t *data, int width, int height, in
.setImage(context->swapchain->get_image()) .setImage(context->swapchain->get_image())
.setOldLayout(vk::ImageLayout::ePresentSrcKHR) .setOldLayout(vk::ImageLayout::ePresentSrcKHR)
.setNewLayout(vk::ImageLayout::eTransferSrcOptimal) .setNewLayout(vk::ImageLayout::eTransferSrcOptimal)
.setSrcAccessMask(vk::AccessFlagBits::eColorAttachmentWrite) .setSrcAccessMask(vk::AccessFlagBits::eNone)
.setDstAccessMask(vk::AccessFlagBits::eTransferRead) .setDstAccessMask(vk::AccessFlagBits::eTransferRead)
.setSubresourceRange(vk::ImageSubresourceRange(vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1)); .setSubresourceRange(vk::ImageSubresourceRange(vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1));
@ -498,16 +498,19 @@ bool ShaderChain::do_frame_without_swap(uint8_t *data, int width, int height, in
.setSrcAccessMask(vk::AccessFlagBits::eTransferWrite) .setSrcAccessMask(vk::AccessFlagBits::eTransferWrite)
.setDstAccessMask(vk::AccessFlagBits::eShaderRead) .setDstAccessMask(vk::AccessFlagBits::eShaderRead)
.setSubresourceRange(vk::ImageSubresourceRange(vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1)); .setSubresourceRange(vk::ImageSubresourceRange(vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1));
cmd.pipelineBarrier(vk::PipelineStageFlagBits::eTransfer,
vk::PipelineStageFlagBits::eVertexShader | vk::PipelineStageFlagBits::eFragmentShader,
{}, {}, {}, image_memory_barrier[0]);
image_memory_barrier[1] image_memory_barrier[1]
.setOldLayout(vk::ImageLayout::eTransferSrcOptimal) .setOldLayout(vk::ImageLayout::eTransferSrcOptimal)
.setNewLayout(vk::ImageLayout::ePresentSrcKHR) .setNewLayout(vk::ImageLayout::ePresentSrcKHR)
.setSrcAccessMask(vk::AccessFlagBits::eTransferWrite) .setSrcAccessMask(vk::AccessFlagBits::eTransferRead)
.setDstAccessMask(vk::AccessFlagBits::eMemoryRead) .setDstAccessMask(vk::AccessFlagBits::eNone)
.setSubresourceRange(vk::ImageSubresourceRange(vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1)); .setSubresourceRange(vk::ImageSubresourceRange(vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1));
cmd.pipelineBarrier(vk::PipelineStageFlagBits::eTransfer, cmd.pipelineBarrier(vk::PipelineStageFlagBits::eTransfer,
vk::PipelineStageFlagBits::eAllGraphics, vk::PipelineStageFlagBits::eBottomOfPipe,
{}, {}, {}, image_memory_barrier); {}, {}, {}, image_memory_barrier[1]);
frame.image.current_layout = vk::ImageLayout::eTransferDstOptimal; frame.image.current_layout = vk::ImageLayout::eTransferDstOptimal;
} }