hot-fix: buffers resolve barriers fixed
Some checks are pending
Build and Release / reuse (push) Waiting to run
Build and Release / clang-format (push) Waiting to run
Build and Release / get-info (push) Waiting to run
Build and Release / windows-sdl (push) Blocked by required conditions
Build and Release / windows-qt (push) Blocked by required conditions
Build and Release / macos-sdl (push) Blocked by required conditions
Build and Release / macos-qt (push) Blocked by required conditions
Build and Release / linux-sdl (push) Blocked by required conditions
Build and Release / linux-qt (push) Blocked by required conditions
Build and Release / pre-release (push) Blocked by required conditions

This commit is contained in:
psucien 2025-01-06 22:50:09 +01:00
parent 6f3c767b99
commit 5559f35905
2 changed files with 38 additions and 38 deletions

View file

@ -119,19 +119,23 @@ public:
return buffer; return buffer;
} }
std::optional<vk::BufferMemoryBarrier2> GetBarrier(vk::AccessFlagBits2 dst_acess_mask, std::optional<vk::BufferMemoryBarrier2> GetBarrier(
vk::PipelineStageFlagBits2 dst_stage) { vk::Flags<vk::AccessFlagBits2> dst_acess_mask, vk::PipelineStageFlagBits2 dst_stage,
u32 offset = 0) {
if (dst_acess_mask == access_mask && stage == dst_stage) { if (dst_acess_mask == access_mask && stage == dst_stage) {
return {}; return {};
} }
DEBUG_ASSERT(offset < size_bytes);
auto barrier = vk::BufferMemoryBarrier2{ auto barrier = vk::BufferMemoryBarrier2{
.srcStageMask = stage, .srcStageMask = stage,
.srcAccessMask = access_mask, .srcAccessMask = access_mask,
.dstStageMask = dst_stage, .dstStageMask = dst_stage,
.dstAccessMask = dst_acess_mask, .dstAccessMask = dst_acess_mask,
.buffer = buffer.buffer, .buffer = buffer.buffer,
.size = size_bytes, .offset = offset,
.size = size_bytes - offset,
}; };
access_mask = dst_acess_mask; access_mask = dst_acess_mask;
stage = dst_stage; stage = dst_stage;
@ -150,8 +154,10 @@ public:
Vulkan::Scheduler* scheduler; Vulkan::Scheduler* scheduler;
MemoryUsage usage; MemoryUsage usage;
UniqueBuffer buffer; UniqueBuffer buffer;
vk::AccessFlagBits2 access_mask{vk::AccessFlagBits2::eNone}; vk::Flags<vk::AccessFlagBits2> access_mask{
vk::PipelineStageFlagBits2 stage{vk::PipelineStageFlagBits2::eNone}; vk::AccessFlagBits2::eMemoryRead | vk::AccessFlagBits2::eMemoryWrite |
vk::AccessFlagBits2::eTransferRead | vk::AccessFlagBits2::eTransferWrite};
vk::PipelineStageFlagBits2 stage{vk::PipelineStageFlagBits2::eAllCommands};
}; };
class StreamBuffer : public Buffer { class StreamBuffer : public Buffer {

View file

@ -479,43 +479,36 @@ void BufferCache::JoinOverlap(BufferId new_buffer_id, BufferId overlap_id,
}; };
scheduler.EndRendering(); scheduler.EndRendering();
const auto cmdbuf = scheduler.CommandBuffer(); const auto cmdbuf = scheduler.CommandBuffer();
const std::array pre_barriers = {
vk::BufferMemoryBarrier2{ boost::container::static_vector<vk::BufferMemoryBarrier2, 2> pre_barriers{};
.srcStageMask = vk::PipelineStageFlagBits2::eAllCommands, if (auto src_barrier = overlap.GetBarrier(vk::AccessFlagBits2::eTransferRead,
.srcAccessMask = vk::AccessFlagBits2::eMemoryRead | vk::AccessFlagBits2::eMemoryWrite, vk::PipelineStageFlagBits2::eTransfer)) {
.dstStageMask = vk::PipelineStageFlagBits2::eTransfer, pre_barriers.push_back(*src_barrier);
.dstAccessMask = vk::AccessFlagBits2::eTransferRead, }
.buffer = overlap.Handle(), if (auto dst_barrier =
.offset = 0, new_buffer.GetBarrier(vk::AccessFlagBits2::eTransferWrite,
.size = overlap.SizeBytes(), vk::PipelineStageFlagBits2::eTransfer, dst_base_offset)) {
}, pre_barriers.push_back(*dst_barrier);
}; }
const std::array post_barriers = {
vk::BufferMemoryBarrier2{
.srcStageMask = vk::PipelineStageFlagBits2::eTransfer,
.srcAccessMask = vk::AccessFlagBits2::eTransferRead,
.dstStageMask = vk::PipelineStageFlagBits2::eAllCommands,
.dstAccessMask = vk::AccessFlagBits2::eMemoryWrite,
.buffer = overlap.Handle(),
.offset = 0,
.size = overlap.SizeBytes(),
},
vk::BufferMemoryBarrier2{
.srcStageMask = vk::PipelineStageFlagBits2::eTransfer,
.srcAccessMask = vk::AccessFlagBits2::eTransferWrite,
.dstStageMask = vk::PipelineStageFlagBits2::eAllCommands,
.dstAccessMask = vk::AccessFlagBits2::eMemoryRead | vk::AccessFlagBits2::eMemoryWrite,
.buffer = new_buffer.Handle(),
.offset = dst_base_offset,
.size = overlap.SizeBytes(),
},
};
cmdbuf.pipelineBarrier2(vk::DependencyInfo{ cmdbuf.pipelineBarrier2(vk::DependencyInfo{
.dependencyFlags = vk::DependencyFlagBits::eByRegion, .dependencyFlags = vk::DependencyFlagBits::eByRegion,
.bufferMemoryBarrierCount = 1, .bufferMemoryBarrierCount = static_cast<u32>(pre_barriers.size()),
.pBufferMemoryBarriers = pre_barriers.data(), .pBufferMemoryBarriers = pre_barriers.data(),
}); });
cmdbuf.copyBuffer(overlap.Handle(), new_buffer.Handle(), copy); cmdbuf.copyBuffer(overlap.Handle(), new_buffer.Handle(), copy);
boost::container::static_vector<vk::BufferMemoryBarrier2, 2> post_barriers{};
if (auto src_barrier =
overlap.GetBarrier(vk::AccessFlagBits2::eMemoryRead | vk::AccessFlagBits2::eMemoryWrite,
vk::PipelineStageFlagBits2::eAllCommands)) {
post_barriers.push_back(*src_barrier);
}
if (auto dst_barrier = new_buffer.GetBarrier(
vk::AccessFlagBits2::eMemoryRead | vk::AccessFlagBits2::eMemoryWrite,
vk::PipelineStageFlagBits2::eAllCommands, dst_base_offset)) {
post_barriers.push_back(*dst_barrier);
}
cmdbuf.pipelineBarrier2(vk::DependencyInfo{ cmdbuf.pipelineBarrier2(vk::DependencyInfo{
.dependencyFlags = vk::DependencyFlagBits::eByRegion, .dependencyFlags = vk::DependencyFlagBits::eByRegion,
.bufferMemoryBarrierCount = static_cast<u32>(post_barriers.size()), .bufferMemoryBarrierCount = static_cast<u32>(post_barriers.size()),
@ -626,7 +619,8 @@ void BufferCache::SynchronizeBuffer(Buffer& buffer, VAddr device_addr, u32 size,
const auto cmdbuf = scheduler.CommandBuffer(); const auto cmdbuf = scheduler.CommandBuffer();
const vk::BufferMemoryBarrier2 pre_barrier = { const vk::BufferMemoryBarrier2 pre_barrier = {
.srcStageMask = vk::PipelineStageFlagBits2::eAllCommands, .srcStageMask = vk::PipelineStageFlagBits2::eAllCommands,
.srcAccessMask = vk::AccessFlagBits2::eMemoryRead, .srcAccessMask = vk::AccessFlagBits2::eMemoryRead | vk::AccessFlagBits2::eMemoryWrite |
vk::AccessFlagBits2::eTransferRead | vk::AccessFlagBits2::eTransferWrite,
.dstStageMask = vk::PipelineStageFlagBits2::eTransfer, .dstStageMask = vk::PipelineStageFlagBits2::eTransfer,
.dstAccessMask = vk::AccessFlagBits2::eTransferWrite, .dstAccessMask = vk::AccessFlagBits2::eTransferWrite,
.buffer = buffer.Handle(), .buffer = buffer.Handle(),