vkr: add vkr_context_{add,remove,get}_resource

Minor refactor, no real change.

Reviewed-by: Ryan Neph <ryanneph@google.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
macos/master
Chia-I Wu 3 years ago
parent c8b5b487b1
commit 8249c00b02
  1. 8
      src/venus/vkr_context.c
  2. 19
      src/venus/vkr_context.h
  3. 6
      src/venus/vkr_device_memory.c
  4. 7
      src/venus/vkr_transport.c

@ -414,7 +414,7 @@ vkr_context_transfer_3d_locked(struct virgl_context *base,
if (!iov || !iov_count)
return 0;
att = util_hash_table_get(ctx->resource_table, uintptr_to_pointer(res->res_id));
att = vkr_context_get_resource(ctx, res->res_id);
if (!att)
return EINVAL;
@ -476,7 +476,7 @@ vkr_context_attach_resource_locked(struct virgl_context *base, struct virgl_reso
struct vkr_context *ctx = (struct vkr_context *)base;
struct vkr_resource_attachment *att;
att = util_hash_table_get(ctx->resource_table, uintptr_to_pointer(res->res_id));
att = vkr_context_get_resource(ctx, res->res_id);
if (att) {
assert(att->resource == res);
return;
@ -506,7 +506,7 @@ vkr_context_attach_resource_locked(struct virgl_context *base, struct virgl_reso
}
}
util_hash_table_set(ctx->resource_table, uintptr_to_pointer(res->res_id), att);
vkr_context_add_resource(ctx, att);
}
static void
@ -524,7 +524,7 @@ vkr_context_detach_resource(struct virgl_context *base, struct virgl_resource *r
struct vkr_context *ctx = (struct vkr_context *)base;
mtx_lock(&ctx->mutex);
util_hash_table_remove(ctx->resource_table, uintptr_to_pointer(res->res_id));
vkr_context_remove_resource(ctx, res->res_id);
mtx_unlock(&ctx->mutex);
}

@ -65,6 +65,25 @@ struct vkr_context {
char *instance_name;
};
static inline void
vkr_context_add_resource(struct vkr_context *ctx, struct vkr_resource_attachment *att)
{
const uint32_t res_id = att->resource->res_id;
util_hash_table_set(ctx->resource_table, uintptr_to_pointer(res_id), att);
}
static inline void
vkr_context_remove_resource(struct vkr_context *ctx, uint32_t res_id)
{
util_hash_table_remove(ctx->resource_table, uintptr_to_pointer(res_id));
}
static inline struct vkr_resource_attachment *
vkr_context_get_resource(struct vkr_context *ctx, uint32_t res_id)
{
return util_hash_table_get(ctx->resource_table, uintptr_to_pointer(res_id));
}
static inline bool
vkr_context_validate_object_id(struct vkr_context *ctx, vkr_object_id id)
{

@ -81,8 +81,7 @@ vkr_dispatch_vkAllocateMemory(struct vn_dispatch_context *dispatch,
}
if (import_resource_info) {
uint32_t res_id = import_resource_info->resourceId;
struct vkr_resource_attachment *att =
util_hash_table_get(ctx->resource_table, uintptr_to_pointer(res_id));
struct vkr_resource_attachment *att = vkr_context_get_resource(ctx, res_id);
if (!att) {
vkr_cs_decoder_set_fatal(&ctx->decoder);
return;
@ -174,8 +173,7 @@ vkr_dispatch_vkGetMemoryResourcePropertiesMESA(
struct vkr_context *ctx = dispatch->data;
struct vkr_device *dev = vkr_device_from_handle(args->device);
struct vkr_resource_attachment *att =
util_hash_table_get(ctx->resource_table, uintptr_to_pointer(args->resourceId));
struct vkr_resource_attachment *att = vkr_context_get_resource(ctx, args->resourceId);
if (!att) {
vkr_cs_decoder_set_fatal(&ctx->decoder);
return;

@ -20,8 +20,7 @@ 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_cs_decoder_set_fatal(&ctx->decoder);
return;
@ -46,7 +45,7 @@ copy_command_stream(struct vkr_context *ctx, const VkCommandStreamDescriptionMES
struct vkr_resource_attachment *att;
struct virgl_resource *res;
att = util_hash_table_get(ctx->resource_table, uintptr_to_pointer(stream->resourceId));
att = vkr_context_get_resource(ctx, stream->resourceId);
if (!att)
return NULL;
res = att->resource;
@ -235,7 +234,7 @@ 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;

Loading…
Cancel
Save