Skip to content

Commit

Permalink
vulkan/gpu_buf: avoid segfault with unusually aligned size_base
Browse files Browse the repository at this point in the history
This patch prevents a segmentation fault that occurs when size_base is
not a multiple of max_transfer. If size_base is larger than the
max_transfer value but is not a multiple of it, the last iteration of
the loop will transfer too much. It needs to transfer how much is
remaining of size_base.

Note that the PL_MIN behaves identically when size_base is less than
max_transfer, because xfer will never be nonzero in that scenario.

Signed-off-by: Leo Izen <[email protected]>
  • Loading branch information
Traneptora committed Jan 26, 2024
1 parent 34e019b commit 741b604
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/vulkan/gpu_buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ void vk_buf_write(pl_gpu gpu, pl_buf buf, size_t offset,
for (size_t xfer = 0; xfer < size_base; xfer += max_transfer) {
vk->CmdUpdateBuffer(cmd->buf, buf_vk->mem.buf,
buf_offset + xfer,
PL_MIN(size_base, max_transfer),
PL_MIN(size_base - xfer, max_transfer),
(void *) ((uint8_t *) data + xfer));
}

Expand Down

0 comments on commit 741b604

Please sign in to comment.