virgl: make virgl_renderer_ctx_{attach,detach}_resource generic

Add and use virgl_context::{attach,detach}_resource callbacks.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
macos/master
Chia-I Wu 5 years ago
parent 13468e4443
commit a78c1a96f9
  1. 5
      src/virgl_context.h
  2. 10
      src/virglrenderer.c
  3. 16
      src/vrend_decode.c
  4. 19
      src/vrend_renderer.c
  5. 4
      src/vrend_renderer.h

@ -31,6 +31,11 @@ struct virgl_context {
uint32_t ctx_id; uint32_t ctx_id;
void (*destroy)(struct virgl_context *ctx); void (*destroy)(struct virgl_context *ctx);
void (*attach_resource)(struct virgl_context *ctx,
uint32_t res_id);
void (*detach_resource)(struct virgl_context *ctx,
uint32_t res_id);
}; };
int int

@ -178,12 +178,18 @@ void virgl_renderer_force_ctx_0(void)
void virgl_renderer_ctx_attach_resource(int ctx_id, int res_handle) void virgl_renderer_ctx_attach_resource(int ctx_id, int res_handle)
{ {
vrend_renderer_attach_res_ctx(ctx_id, res_handle); struct virgl_context *ctx = virgl_context_lookup(ctx_id);
if (!ctx)
return;
ctx->attach_resource(ctx, res_handle);
} }
void virgl_renderer_ctx_detach_resource(int ctx_id, int res_handle) void virgl_renderer_ctx_detach_resource(int ctx_id, int res_handle)
{ {
vrend_renderer_detach_res_ctx(ctx_id, res_handle); struct virgl_context *ctx = virgl_context_lookup(ctx_id);
if (!ctx)
return;
ctx->detach_resource(ctx, res_handle);
} }
int virgl_renderer_resource_get_info(int res_handle, int virgl_renderer_resource_get_info(int res_handle,

@ -1455,6 +1455,20 @@ static void vrend_decode_ctx_destroy(struct virgl_context *ctx)
free(dctx); free(dctx);
} }
static void vrend_decode_ctx_attach_resource(struct virgl_context *ctx,
uint32_t res_id)
{
struct vrend_decode_ctx *dctx = (struct vrend_decode_ctx *)ctx;
vrend_renderer_attach_res_ctx(dctx->grctx, res_id);
}
static void vrend_decode_ctx_detach_resource(struct virgl_context *ctx,
uint32_t res_id)
{
struct vrend_decode_ctx *dctx = (struct vrend_decode_ctx *)ctx;
vrend_renderer_detach_res_ctx(dctx->grctx, res_id);
}
int vrend_decode_block(uint32_t ctx_id, uint32_t *block, int ndw) int vrend_decode_block(uint32_t ctx_id, uint32_t *block, int ndw)
{ {
struct vrend_decode_ctx *gdctx; struct vrend_decode_ctx *gdctx;
@ -1650,6 +1664,8 @@ static void vrend_decode_ctx_init_base(struct vrend_decode_ctx *dctx,
ctx->ctx_id = ctx_id; ctx->ctx_id = ctx_id;
ctx->destroy = vrend_decode_ctx_destroy; ctx->destroy = vrend_decode_ctx_destroy;
ctx->attach_resource = vrend_decode_ctx_attach_resource;
ctx->detach_resource = vrend_decode_ctx_detach_resource;
} }
void vrend_decode_reset(bool ctx_0_only) void vrend_decode_reset(bool ctx_0_only)

@ -663,7 +663,6 @@ static void vrend_patch_blend_state(struct vrend_context *ctx);
static void vrend_update_frontface_state(struct vrend_context *ctx); static void vrend_update_frontface_state(struct vrend_context *ctx);
static void vrender_get_glsl_version(int *glsl_version); static void vrender_get_glsl_version(int *glsl_version);
static void vrend_destroy_resource_object(void *obj_ptr); static void vrend_destroy_resource_object(void *obj_ptr);
static void vrend_renderer_detach_res_ctx_p(struct vrend_context *ctx, int res_handle);
static void vrend_destroy_program(struct vrend_linked_shader_program *ent); static void vrend_destroy_program(struct vrend_linked_shader_program *ent);
static void vrend_apply_sampler_state(struct vrend_context *ctx, static void vrend_apply_sampler_state(struct vrend_context *ctx,
struct vrend_resource *res, struct vrend_resource *res,
@ -6776,7 +6775,7 @@ void vrend_renderer_resource_unref(uint32_t res_handle)
/* remove from any contexts */ /* remove from any contexts */
LIST_FOR_EACH_ENTRY(ctx, &vrend_state.active_ctx_list, ctx_entry) { LIST_FOR_EACH_ENTRY(ctx, &vrend_state.active_ctx_list, ctx_entry) {
vrend_renderer_detach_res_ctx_p(ctx, res->handle); vrend_renderer_detach_res_ctx(ctx, res->handle);
} }
vrend_resource_remove(res->handle); vrend_resource_remove(res->handle);
@ -10046,13 +10045,11 @@ void *vrend_renderer_resource_get_priv(uint32_t res_handle)
return res->priv; return res->priv;
} }
void vrend_renderer_attach_res_ctx(int ctx_id, int resource_id) void vrend_renderer_attach_res_ctx(struct vrend_context *ctx, int resource_id)
{ {
struct vrend_context *ctx = vrend_lookup_renderer_ctx(ctx_id);
struct vrend_resource *res; struct vrend_resource *res;
if (!ctx) assert(ctx);
return;
res = vrend_resource_lookup(resource_id, 0); res = vrend_resource_lookup(resource_id, 0);
if (!res) if (!res)
@ -10061,7 +10058,7 @@ void vrend_renderer_attach_res_ctx(int ctx_id, int resource_id)
vrend_object_insert_nofree(ctx->res_hash, res, sizeof(*res), resource_id, 1, false); vrend_object_insert_nofree(ctx->res_hash, res, sizeof(*res), resource_id, 1, false);
} }
static void vrend_renderer_detach_res_ctx_p(struct vrend_context *ctx, int res_handle) void vrend_renderer_detach_res_ctx(struct vrend_context *ctx, int res_handle)
{ {
struct vrend_resource *res; struct vrend_resource *res;
res = vrend_object_lookup(ctx->res_hash, res_handle, 1); res = vrend_object_lookup(ctx->res_hash, res_handle, 1);
@ -10071,14 +10068,6 @@ static void vrend_renderer_detach_res_ctx_p(struct vrend_context *ctx, int res_h
vrend_object_remove(ctx->res_hash, res_handle, 1); vrend_object_remove(ctx->res_hash, res_handle, 1);
} }
void vrend_renderer_detach_res_ctx(int ctx_id, int res_handle)
{
struct vrend_context *ctx = vrend_lookup_renderer_ctx(ctx_id);
if (!ctx)
return;
vrend_renderer_detach_res_ctx_p(ctx, res_handle);
}
static struct vrend_resource *vrend_renderer_ctx_res_lookup(struct vrend_context *ctx, int res_handle) static struct vrend_resource *vrend_renderer_ctx_res_lookup(struct vrend_context *ctx, int res_handle)
{ {
struct vrend_resource *res = vrend_object_lookup(ctx->res_hash, res_handle, 1); struct vrend_resource *res = vrend_object_lookup(ctx->res_hash, res_handle, 1);

@ -394,8 +394,8 @@ void vrend_renderer_force_ctx_0(void);
void vrend_renderer_get_rect(int resource_id, struct iovec *iov, unsigned int num_iovs, void vrend_renderer_get_rect(int resource_id, struct iovec *iov, unsigned int num_iovs,
uint32_t offset, int x, int y, int width, int height); uint32_t offset, int x, int y, int width, int height);
void vrend_renderer_attach_res_ctx(int ctx_id, int resource_id); void vrend_renderer_attach_res_ctx(struct vrend_context *ctx, int resource_id);
void vrend_renderer_detach_res_ctx(int ctx_id, int resource_id); void vrend_renderer_detach_res_ctx(struct vrend_context *ctx, int resource_id);
struct vrend_context_tweaks *vrend_get_context_tweaks(struct vrend_context *ctx); struct vrend_context_tweaks *vrend_get_context_tweaks(struct vrend_context *ctx);

Loading…
Cancel
Save