From 05554838b096c13a1e5a3fe1e25e28d6c7da96af Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 11 Aug 2017 10:50:37 +1000 Subject: [PATCH] tessellation: add protocol support for set tess state. (v2) This passes the default tessellation factors from the guest to the host. v2: fix warnings Tested-by: Elie Tournier Reviewed-by: Elie Tournier Tested-by: Jakob Bornecrantz --- src/virgl_protocol.h | 4 ++++ src/vrend_decode.c | 19 +++++++++++++++++++ src/vrend_renderer.c | 8 ++++++++ src/vrend_renderer.h | 2 ++ 4 files changed, 33 insertions(+) diff --git a/src/virgl_protocol.h b/src/virgl_protocol.h index 5dc2874..d0e6c49 100644 --- a/src/virgl_protocol.h +++ b/src/virgl_protocol.h @@ -83,6 +83,7 @@ enum virgl_context_cmd { VIRGL_CCMD_CREATE_SUB_CTX, VIRGL_CCMD_DESTROY_SUB_CTX, VIRGL_CCMD_BIND_SHADER, + VIRGL_CCMD_SET_TESS_STATE, }; /* @@ -481,4 +482,7 @@ enum virgl_context_cmd { #define VIRGL_BIND_SHADER_HANDLE 1 #define VIRGL_BIND_SHADER_TYPE 2 +/* tess state */ +#define VIRGL_TESS_STATE_SIZE 6 + #endif diff --git a/src/vrend_decode.c b/src/vrend_decode.c index c7cfd3f..d50f385 100644 --- a/src/vrend_decode.c +++ b/src/vrend_decode.c @@ -1050,6 +1050,22 @@ static int vrend_decode_bind_shader(struct vrend_decode_ctx *ctx, int length) return 0; } +static int vrend_decode_set_tess_state(struct vrend_decode_ctx *ctx, + int length) +{ + float tess_factors[6]; + int i; + + if (length != VIRGL_TESS_STATE_SIZE) + return EINVAL; + + for (i = 0; i < 6; i++) { + tess_factors[i] = uif(get_buf_entry(ctx, i + 1)); + } + vrend_set_tess_state(ctx->grctx, tess_factors); + return 0; +} + static int vrend_decode_set_streamout_targets(struct vrend_decode_ctx *ctx, uint16_t length) { @@ -1272,6 +1288,9 @@ int vrend_decode_block(uint32_t ctx_id, uint32_t *block, int ndw) case VIRGL_CCMD_BIND_SHADER: ret = vrend_decode_bind_shader(gdctx, len); break; + case VIRGL_CCMD_SET_TESS_STATE: + ret = vrend_decode_set_tess_state(gdctx, len); + break; default: ret = EINVAL; } diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c index 52a781d..ff3d64d 100644 --- a/src/vrend_renderer.c +++ b/src/vrend_renderer.c @@ -5791,6 +5791,14 @@ void vrend_set_sample_mask(UNUSED struct vrend_context *ctx, unsigned sample_mas glSampleMaski(0, sample_mask); } +void vrend_set_tess_state(UNUSED struct vrend_context *ctx, const float tess_factors[6]) +{ + if (vrend_state.have_tessellation) { + glPatchParameterfv(GL_PATCH_DEFAULT_OUTER_LEVEL, tess_factors); + glPatchParameterfv(GL_PATCH_DEFAULT_INNER_LEVEL, &tess_factors[4]); + } +} + static void vrend_hw_emit_streamout_targets(UNUSED struct vrend_context *ctx, struct vrend_streamout_object *so_obj) { uint i; diff --git a/src/vrend_renderer.h b/src/vrend_renderer.h index 5554edb..40c8ebd 100644 --- a/src/vrend_renderer.h +++ b/src/vrend_renderer.h @@ -276,6 +276,8 @@ void vrend_set_uniform_buffer(struct vrend_context *ctx, uint32_t shader, uint32_t index, uint32_t offset, uint32_t length, uint32_t res_handle); +void vrend_set_tess_state(struct vrend_context *ctx, const float tess_factors[6]); + void vrend_renderer_fini(void); int vrend_decode_block(uint32_t ctx_id, uint32_t *block, int ndw);