aboutsummaryrefslogtreecommitdiff
path: root/src/venus/vkr_transport.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/venus/vkr_transport.c')
-rw-r--r--src/venus/vkr_transport.c60
1 files changed, 33 insertions, 27 deletions
diff --git a/src/venus/vkr_transport.c b/src/venus/vkr_transport.c
index c0f3e3e9..361c7f31 100644
--- a/src/venus/vkr_transport.c
+++ b/src/venus/vkr_transport.c
@@ -20,15 +20,15 @@ vkr_dispatch_vkSetReplyCommandStreamMESA(
struct vkr_context *ctx = dispatch->data;
struct vkr_resource_attachment *att;
- att = util_hash_table_get(ctx->resource_table,
- uintptr_to_pointer(args->pStream->resourceId));
+ att = vkr_context_get_resource(ctx, args->pStream->resourceId);
if (!att) {
+ vkr_log("failed to set reply stream: invalid res_id %u", args->pStream->resourceId);
vkr_cs_decoder_set_fatal(&ctx->decoder);
return;
}
- vkr_cs_encoder_set_stream(&ctx->encoder, att->resource->iov, att->resource->iov_count,
- args->pStream->offset, args->pStream->size);
+ vkr_cs_encoder_set_stream(&ctx->encoder, att, args->pStream->offset,
+ args->pStream->size);
}
static void
@@ -44,33 +44,37 @@ static void *
copy_command_stream(struct vkr_context *ctx, const VkCommandStreamDescriptionMESA *stream)
{
struct vkr_resource_attachment *att;
- struct virgl_resource *res;
- att = util_hash_table_get(ctx->resource_table, uintptr_to_pointer(stream->resourceId));
- if (!att)
+ att = vkr_context_get_resource(ctx, stream->resourceId);
+ if (!att) {
+ vkr_log("failed to copy command stream: invalid res_id %u", stream->resourceId);
return NULL;
- res = att->resource;
+ }
/* seek to offset */
size_t iov_offset = stream->offset;
const struct iovec *iov = NULL;
- for (int i = 0; i < res->iov_count; i++) {
- if (iov_offset < res->iov[i].iov_len) {
- iov = &res->iov[i];
+ for (int i = 0; i < att->iov_count; i++) {
+ if (iov_offset < att->iov[i].iov_len) {
+ iov = &att->iov[i];
break;
}
- iov_offset -= res->iov[i].iov_len;
+ iov_offset -= att->iov[i].iov_len;
}
- if (!iov)
+ if (!iov) {
+ vkr_log("failed to copy command stream: invalid offset %zu", stream->offset);
return NULL;
+ }
/* XXX until the decoder supports scatter-gather and is robust enough,
* always make a copy in case the caller modifies the commands while we
* parse
*/
uint8_t *data = malloc(stream->size);
- if (!data)
+ if (!data) {
+ vkr_log("failed to copy command stream: malloc(%zu) failed", stream->size);
return NULL;
+ }
uint32_t copied = 0;
while (true) {
@@ -80,7 +84,8 @@ copy_command_stream(struct vkr_context *ctx, const VkCommandStreamDescriptionMES
copied += s;
if (copied == stream->size) {
break;
- } else if (iov == &res->iov[res->iov_count - 1]) {
+ } else if (iov == &att->iov[att->iov_count - 1]) {
+ vkr_log("failed to copy command stream: invalid size %zu", stream->size);
free(data);
return NULL;
}
@@ -99,13 +104,15 @@ vkr_dispatch_vkExecuteCommandStreamsMESA(
{
struct vkr_context *ctx = dispatch->data;
- if (!args->streamCount) {
+ if (unlikely(!args->streamCount)) {
+ vkr_log("failed to execute command streams: no stream specified");
vkr_cs_decoder_set_fatal(&ctx->decoder);
return;
}
/* note that nested vkExecuteCommandStreamsMESA is not allowed */
- if (!vkr_cs_decoder_push_state(&ctx->decoder)) {
+ if (unlikely(!vkr_cs_decoder_push_state(&ctx->decoder))) {
+ vkr_log("failed to execute command streams: nested execution");
vkr_cs_decoder_set_fatal(&ctx->decoder);
return;
}
@@ -154,12 +161,12 @@ lookup_ring(struct vkr_context *ctx, uint64_t ring_id)
static bool
vkr_ring_layout_init(struct vkr_ring_layout *layout,
- struct virgl_resource *res,
+ const struct vkr_resource_attachment *att,
const VkRingCreateInfoMESA *info)
{
/* clang-format off */
*layout = (struct vkr_ring_layout){
- .resource = res,
+ .attachment = att,
.head = VKR_REGION_INIT(info->offset + info->headOffset, sizeof(uint32_t)),
.tail = VKR_REGION_INIT(info->offset + info->tailOffset, sizeof(uint32_t)),
.status = VKR_REGION_INIT(info->offset + info->statusOffset, sizeof(uint32_t)),
@@ -178,7 +185,7 @@ vkr_ring_layout_init(struct vkr_ring_layout *layout,
/* clang-format on */
const struct vkr_region res_size =
- VKR_REGION_INIT(0, vrend_get_iovec_size(res->iov, res->iov_count));
+ VKR_REGION_INIT(0, vrend_get_iovec_size(att->iov, att->iov_count));
if (!vkr_region_is_valid(&res_region) || !vkr_region_is_within(&res_region, &res_size))
return false;
@@ -217,10 +224,9 @@ vkr_ring_layout_init(struct vkr_ring_layout *layout,
}
const size_t buf_size = vkr_region_size(&layout->buffer);
- if (!buf_size || buf_size > VKR_RING_BUFFER_MAX_SIZE ||
- !util_is_power_of_two(buf_size)) {
- vkr_log("ring buffer size (%lu) must be a power of two and not exceed %lu",
- buf_size, VKR_RING_BUFFER_MAX_SIZE);
+ if (buf_size > VKR_RING_BUFFER_MAX_SIZE || !util_is_power_of_two_nonzero(buf_size)) {
+ vkr_log("ring buffer size (%z) must be a power of two and not exceed %lu", buf_size,
+ VKR_RING_BUFFER_MAX_SIZE);
return false;
}
@@ -236,14 +242,14 @@ vkr_dispatch_vkCreateRingMESA(struct vn_dispatch_context *dispatch,
const struct vkr_resource_attachment *att;
struct vkr_ring *ring;
- att = util_hash_table_get(ctx->resource_table, uintptr_to_pointer(info->resourceId));
+ att = vkr_context_get_resource(ctx, info->resourceId);
if (!att) {
vkr_cs_decoder_set_fatal(&ctx->decoder);
return;
}
struct vkr_ring_layout layout;
- if (!vkr_ring_layout_init(&layout, att->resource, info)) {
+ if (!vkr_ring_layout_init(&layout, att, info)) {
vkr_log("vkCreateRingMESA supplied with invalid buffer layout parameters");
vkr_cs_decoder_set_fatal(&ctx->decoder);
return;
@@ -272,7 +278,6 @@ vkr_dispatch_vkDestroyRingMESA(struct vn_dispatch_context *dispatch,
return;
}
- list_del(&ring->head);
vkr_ring_destroy(ring);
}
@@ -314,6 +319,7 @@ vkr_dispatch_vkGetVenusExperimentalFeatureData100000MESA(
.memoryResourceAllocationSize = VK_TRUE,
.globalFencing = VK_FALSE,
.largeRing = VK_TRUE,
+ .syncFdFencing = VK_TRUE,
};
vn_replace_vkGetVenusExperimentalFeatureData100000MESA_args_handle(args);