Skip to content

Commit

Permalink
vulkan/buf: emit correct host read/write dependencies
Browse files Browse the repository at this point in the history
Inside vk_buf_barrier, we also need to make host-writes available, even
for coherent memory, and even after using FlushMappedMemoryRanges.

Also include the host_read dependency for completeness' sake, just to be
on the safe side.
  • Loading branch information
haasn committed Feb 18, 2023
1 parent c7854aa commit 8c2c957
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/vulkan/gpu_buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ void vk_buf_barrier(pl_gpu gpu, struct vk_cmd *cmd, pl_buf buf,
buf->params.import_handle == PL_HANDLE_HOST_PTR;
bool noncoherent = buf_vk->mem.data && !buf_vk->mem.coherent;
if (needs_flush && noncoherent) {
buf_vk->needs_flush = false;
VK(vk->FlushMappedMemoryRanges(vk->dev, 1, &(struct VkMappedMemoryRange) {
.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
.memory = buf_vk->mem.vkmem,
Expand All @@ -47,6 +46,16 @@ void vk_buf_barrier(pl_gpu gpu, struct vk_cmd *cmd, pl_buf buf,
struct vk_sync_scope last;
last = vk_sem_barrier(vk, cmd, &buf_vk->sem, stage, access, export);

if (needs_flush) {
last.access |= VK_ACCESS_HOST_WRITE_BIT;
last.stage |= VK_PIPELINE_STAGE_HOST_BIT;
}

if (needs_flush || buf_vk->mem.data) {
last.access |= VK_ACCESS_HOST_READ_BIT;
last.stage |= VK_PIPELINE_STAGE_HOST_BIT;
}

// CONCURRENT buffers require transitioning to/from IGNORED, EXCLUSIVE
// buffers require transitioning to/from the concrete QF index
uint32_t qf = vk->pools.num > 1 ? VK_QUEUE_FAMILY_IGNORED : cmd->pool->qf;
Expand All @@ -66,6 +75,7 @@ void vk_buf_barrier(pl_gpu gpu, struct vk_cmd *cmd, pl_buf buf,
1, &barr, 0, NULL);
}

buf_vk->needs_flush = false;
buf_vk->exported = export;
vk_cmd_callback(cmd, (vk_cb) vk_buf_deref, gpu, buf);
}
Expand Down

0 comments on commit 8c2c957

Please sign in to comment.