venus: ensure shmem is attached to renderer before use for guest vram

For guest vram, there's already roundtrip to protect device memory alloc
ordering. This change adds the same protection for shmem used in below
scenarios and optimize to wait for new shmem only.
- reply shmem
- indirect upload shmem
- cmd stream shmem

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28147>
This commit is contained in:
Yiwei Zhang 2024-03-13 00:00:12 -07:00 committed by Marge Bot
parent 72b124031b
commit d56f65f7ca
4 changed files with 29 additions and 0 deletions

View file

@ -1037,6 +1037,9 @@ vn_cmd_submit(struct vn_command_buffer *cmd)
return;
}
if (vn_cs_encoder_needs_roundtrip(&cmd->cs))
vn_ring_roundtrip(ring);
if (vn_ring_submit_command_simple(ring, &cmd->cs) != VK_SUCCESS) {
cmd->state = VN_COMMAND_BUFFER_STATE_INVALID;
return;

View file

@ -296,3 +296,19 @@ vn_cs_encoder_commit(struct vn_cs_encoder *enc)
vn_cs_encoder_sanity_check(enc);
}
bool
vn_cs_encoder_needs_roundtrip(struct vn_cs_encoder *enc)
{
if (!enc->instance->renderer->info.has_guest_vram)
return false;
/* check pinned shmems for new shmem allocs */
for (uint32_t i = 0; i < enc->buffer_count; i++) {
const struct vn_renderer_shmem *shmem = enc->buffers[i].shmem;
if (shmem && !shmem->cache_timestamp)
return true;
}
return false;
}

View file

@ -192,6 +192,9 @@ vn_cs_encoder_write(struct vn_cs_encoder *enc,
void
vn_cs_encoder_commit(struct vn_cs_encoder *enc);
bool
vn_cs_encoder_needs_roundtrip(struct vn_cs_encoder *enc);
static inline void
vn_cs_decoder_init(struct vn_cs_decoder *dec, const void *data, size_t size)
{

View file

@ -569,6 +569,9 @@ vn_ring_cs_upload_locked(struct vn_ring *ring, const struct vn_cs_encoder *cs)
vn_cs_encoder_write(upload, cs_size, cs_data, cs_size);
vn_cs_encoder_commit(upload);
if (vn_cs_encoder_needs_roundtrip(upload))
vn_ring_roundtrip(ring);
return upload;
}
@ -657,6 +660,10 @@ vn_ring_submit_command(struct vn_ring *ring,
ring->instance, submit->reply_size, &reply_offset);
if (!submit->reply_shmem)
return;
if (ring->instance->renderer->info.has_guest_vram &&
!submit->reply_shmem->cache_timestamp)
vn_ring_roundtrip(ring);
}
mtx_lock(&ring->mutex);