virgl: pass virgl_resource to virgl_context callbacks

Pass virgl_resource to virgl_context::{attach,detach}_resource.
This allows us to move virgl_resource_lookup up from vrend to
virglrenderer.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
macos/master
Chia-I Wu 5 years ago
parent 29c103d729
commit a775fc837e
  1. 6
      src/virgl_context.h
  2. 10
      src/virglrenderer.c
  3. 15
      src/vrend_decode.c
  4. 20
      src/vrend_renderer.c
  5. 8
      src/vrend_renderer.h

@ -28,6 +28,8 @@
#include <stddef.h>
#include <stdint.h>
struct virgl_resource;
/**
* Base class for renderer contexts. For example, vrend_decode_ctx is a
* subclass of virgl_context.
@ -38,9 +40,9 @@ struct virgl_context {
void (*destroy)(struct virgl_context *ctx);
void (*attach_resource)(struct virgl_context *ctx,
uint32_t res_id);
struct virgl_resource *res);
void (*detach_resource)(struct virgl_context *ctx,
uint32_t res_id);
struct virgl_resource *res);
int (*submit_cmd)(struct virgl_context *ctx,
const void *buffer,

@ -211,17 +211,19 @@ void virgl_renderer_force_ctx_0(void)
void virgl_renderer_ctx_attach_resource(int ctx_id, int res_handle)
{
struct virgl_context *ctx = virgl_context_lookup(ctx_id);
if (!ctx)
struct virgl_resource *res = virgl_resource_lookup(res_handle);
if (!ctx || !res)
return;
ctx->attach_resource(ctx, res_handle);
ctx->attach_resource(ctx, res);
}
void virgl_renderer_ctx_detach_resource(int ctx_id, int res_handle)
{
struct virgl_context *ctx = virgl_context_lookup(ctx_id);
if (!ctx)
struct virgl_resource *res = virgl_resource_lookup(res_handle);
if (!ctx || !res)
return;
ctx->detach_resource(ctx, res_handle);
ctx->detach_resource(ctx, res);
}
int virgl_renderer_resource_get_info(int res_handle,

@ -32,6 +32,7 @@
#include "pipe/p_state.h"
#include "pipe/p_shader_tokens.h"
#include "virgl_context.h"
#include "virgl_resource.h"
#include "vrend_renderer.h"
#include "vrend_object.h"
#include "tgsi/tgsi_text.h"
@ -1424,17 +1425,23 @@ static void vrend_decode_ctx_destroy(struct virgl_context *ctx)
}
static void vrend_decode_ctx_attach_resource(struct virgl_context *ctx,
uint32_t res_id)
struct virgl_resource *res)
{
struct vrend_decode_ctx *dctx = (struct vrend_decode_ctx *)ctx;
vrend_renderer_attach_res_ctx(dctx->grctx, res_id);
/* in the future, we should import to create the pipe resource */
if (!res->pipe_resource)
return;
vrend_renderer_attach_res_ctx(dctx->grctx, res->res_id,
res->pipe_resource);
}
static void vrend_decode_ctx_detach_resource(struct virgl_context *ctx,
uint32_t res_id)
struct virgl_resource *res)
{
struct vrend_decode_ctx *dctx = (struct vrend_decode_ctx *)ctx;
vrend_renderer_detach_res_ctx(dctx->grctx, res_id);
vrend_renderer_detach_res_ctx(dctx->grctx, res->res_id);
}
static int vrend_decode_ctx_submit_cmd(struct virgl_context *ctx,

@ -10051,22 +10051,18 @@ void vrend_renderer_get_rect(int res_handle, struct iovec *iov, unsigned int num
vrend_renderer_transfer_iov(&transfer_info, VIRGL_TRANSFER_FROM_HOST);
}
void vrend_renderer_attach_res_ctx(struct vrend_context *ctx, int resource_id)
void vrend_renderer_attach_res_ctx(struct vrend_context *ctx,
uint32_t res_id,
struct pipe_resource *pres)
{
struct vrend_resource *res;
assert(ctx);
res = vrend_renderer_res_lookup(resource_id);
if (!res)
return;
vrend_ctx_resource_insert(ctx->res_hash, resource_id, res);
struct vrend_resource *res = (struct vrend_resource *)pres;
vrend_ctx_resource_insert(ctx->res_hash, res_id, res);
}
void vrend_renderer_detach_res_ctx(struct vrend_context *ctx, int res_handle)
void vrend_renderer_detach_res_ctx(struct vrend_context *ctx,
uint32_t res_id)
{
vrend_ctx_resource_remove(ctx->res_hash, res_handle);
vrend_ctx_resource_remove(ctx->res_hash, res_id);
}
static struct vrend_resource *vrend_renderer_ctx_res_lookup(struct vrend_context *ctx, int res_handle)

@ -392,8 +392,12 @@ void vrend_renderer_force_ctx_0(void);
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);
void vrend_renderer_attach_res_ctx(struct vrend_context *ctx, int resource_id);
void vrend_renderer_detach_res_ctx(struct vrend_context *ctx, int resource_id);
void vrend_renderer_attach_res_ctx(struct vrend_context *ctx,
uint32_t res_id,
struct pipe_resource *pres);
void vrend_renderer_detach_res_ctx(struct vrend_context *ctx,
uint32_t res_id);
struct vrend_context_tweaks *vrend_get_context_tweaks(struct vrend_context *ctx);

Loading…
Cancel
Save