virgl: add virgl_renderer_context_create_with_flags

Comparing to virgl_renderer_context_create, it allows flags to be
specified.  flags can only be used to specify the capset id in this
commit, but that may change in the future.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Isaac Bosompem <mrisaacb@google.com>
macos/master
Chia-I Wu 4 years ago
parent e47df7f941
commit d3fd5413c1
  1. 3
      src/virgl_context.h
  2. 40
      src/virglrenderer.c
  3. 7
      src/virglrenderer.h

@ -29,6 +29,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include "virglrenderer_hw.h"
#include "virgl_resource.h" #include "virgl_resource.h"
struct vrend_transfer_info; struct vrend_transfer_info;
@ -54,6 +55,8 @@ struct virgl_context_blob {
struct virgl_context { struct virgl_context {
uint32_t ctx_id; uint32_t ctx_id;
enum virgl_renderer_capset capset_id;
void (*destroy)(struct virgl_context *ctx); void (*destroy)(struct virgl_context *ctx);
void (*attach_resource)(struct virgl_context *ctx, void (*attach_resource)(struct virgl_context *ctx,

@ -165,24 +165,46 @@ void virgl_renderer_fill_caps(uint32_t set, uint32_t version,
} }
} }
int virgl_renderer_context_create(uint32_t handle, uint32_t nlen, const char *name) int virgl_renderer_context_create_with_flags(uint32_t ctx_id,
uint32_t ctx_flags,
uint32_t nlen,
const char *name)
{ {
const enum virgl_renderer_capset capset_id =
ctx_flags & VIRGL_RENDERER_CONTEXT_FLAG_CAPSET_ID_MASK;
struct virgl_context *ctx; struct virgl_context *ctx;
int ret; int ret;
TRACE_FUNC(); TRACE_FUNC();
/* user context id must be greater than 0 */ /* user context id must be greater than 0 */
if (handle == 0) if (ctx_id == 0)
return EINVAL; return EINVAL;
if (virgl_context_lookup(handle)) /* unsupported flags */
return 0; if (ctx_flags & ~VIRGL_RENDERER_CONTEXT_FLAG_CAPSET_ID_MASK)
return EINVAL;
ctx = virgl_context_lookup(ctx_id);
if (ctx) {
return ctx->capset_id == capset_id ? 0 : EINVAL;
}
ctx = vrend_renderer_context_create(handle, nlen, name); switch (capset_id) {
case VIRGL_RENDERER_CAPSET_VIRGL:
case VIRGL_RENDERER_CAPSET_VIRGL2:
ctx = vrend_renderer_context_create(ctx_id, nlen, name);
break;
default:
return EINVAL;
break;
}
if (!ctx) if (!ctx)
return ENOMEM; return ENOMEM;
ctx->ctx_id = ctx_id;
ctx->capset_id = capset_id;
ret = virgl_context_add(ctx); ret = virgl_context_add(ctx);
if (ret) { if (ret) {
ctx->destroy(ctx); ctx->destroy(ctx);
@ -192,6 +214,14 @@ int virgl_renderer_context_create(uint32_t handle, uint32_t nlen, const char *na
return 0; return 0;
} }
int virgl_renderer_context_create(uint32_t handle, uint32_t nlen, const char *name)
{
return virgl_renderer_context_create_with_flags(handle,
VIRGL_RENDERER_CAPSET_VIRGL2,
nlen,
name);
}
void virgl_renderer_context_destroy(uint32_t handle) void virgl_renderer_context_destroy(uint32_t handle)
{ {
TRACE_FUNC(); TRACE_FUNC();

@ -256,6 +256,13 @@ VIRGL_EXPORT int virgl_renderer_execute(void *execute_args, uint32_t execute_siz
*/ */
#ifdef VIRGL_RENDERER_UNSTABLE_APIS #ifdef VIRGL_RENDERER_UNSTABLE_APIS
#define VIRGL_RENDERER_CONTEXT_FLAG_CAPSET_ID_MASK 0xff
VIRGL_EXPORT int virgl_renderer_context_create_with_flags(uint32_t ctx_id,
uint32_t ctx_flags,
uint32_t nlen,
const char *name);
#define VIRGL_RENDERER_BLOB_MEM_GUEST 0x0001 #define VIRGL_RENDERER_BLOB_MEM_GUEST 0x0001
#define VIRGL_RENDERER_BLOB_MEM_HOST3D 0x0002 #define VIRGL_RENDERER_BLOB_MEM_HOST3D 0x0002
#define VIRGL_RENDERER_BLOB_MEM_HOST3D_GUEST 0x0003 #define VIRGL_RENDERER_BLOB_MEM_HOST3D_GUEST 0x0003

Loading…
Cancel
Save