From b16105b25cd60bbcf288c2ed1aa25a5e7cc0080e Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Fri, 27 Mar 2020 17:10:43 -0700 Subject: [PATCH] vrend: simplify vrend_object_insert Remove the unused length argument. Remove unused vrend_object_insert_nofree as well now that context resource management is not built on top of vrend_object. Signed-off-by: Chia-I Wu Tested-by: Gurchetan Singh Reviewed-by: Gurchetan Singh --- src/vrend_decode.c | 6 +++--- src/vrend_object.c | 29 +++++++++-------------------- src/vrend_object.h | 10 ++++------ src/vrend_renderer.c | 18 +++++++++--------- src/vrend_renderer.h | 2 +- 5 files changed, 26 insertions(+), 39 deletions(-) diff --git a/src/vrend_decode.c b/src/vrend_decode.c index 39e2954..fc683d7 100644 --- a/src/vrend_decode.c +++ b/src/vrend_decode.c @@ -470,7 +470,7 @@ static int vrend_decode_create_blend(struct vrend_decode_ctx *ctx, uint32_t hand blend_state->rt[i].colormask = (tmp >> 27) & 0xf; } - tmp = vrend_renderer_object_insert(ctx->grctx, blend_state, sizeof(struct pipe_blend_state), handle, + tmp = vrend_renderer_object_insert(ctx->grctx, blend_state, handle, VIRGL_OBJECT_BLEND); if (tmp == 0) { FREE(blend_state); @@ -514,7 +514,7 @@ static int vrend_decode_create_dsa(struct vrend_decode_ctx *ctx, uint32_t handle tmp = get_buf_entry(ctx, VIRGL_OBJ_DSA_ALPHA_REF); dsa_state->alpha.ref_value = uif(tmp); - tmp = vrend_renderer_object_insert(ctx->grctx, dsa_state, sizeof(struct pipe_depth_stencil_alpha_state), handle, + tmp = vrend_renderer_object_insert(ctx->grctx, dsa_state, handle, VIRGL_OBJECT_DSA); if (tmp == 0) { FREE(dsa_state); @@ -580,7 +580,7 @@ static int vrend_decode_create_rasterizer(struct vrend_decode_ctx *ctx, uint32_t rs_state->offset_scale = uif(get_buf_entry(ctx, VIRGL_OBJ_RS_OFFSET_SCALE)); rs_state->offset_clamp = uif(get_buf_entry(ctx, VIRGL_OBJ_RS_OFFSET_CLAMP)); - tmp = vrend_renderer_object_insert(ctx->grctx, rs_state, sizeof(struct pipe_rasterizer_state), handle, + tmp = vrend_renderer_object_insert(ctx->grctx, rs_state, handle, VIRGL_OBJECT_RASTERIZER); if (tmp == 0) { FREE(rs_state); diff --git a/src/vrend_object.c b/src/vrend_object.c index ec30842..7025cd9 100644 --- a/src/vrend_object.c +++ b/src/vrend_object.c @@ -42,21 +42,19 @@ struct vrend_object { enum virgl_object_type type; uint32_t handle; void *data; - bool free_data; }; static void free_object(void *value) { struct vrend_object *obj = value; - if (obj->free_data) { - if (obj_types[obj->type].unref) - obj_types[obj->type].unref(obj->data); - else { - /* for objects with no callback just free them */ - free(obj->data); - } + if (obj_types[obj->type].unref) + obj_types[obj->type].unref(obj->data); + else { + /* for objects with no callback just free them */ + free(obj->data); } + free(obj); } @@ -94,9 +92,9 @@ void vrend_ctx_resource_fini_table(struct util_hash_table *res_hash) } uint32_t -vrend_object_insert_nofree(struct util_hash_table *handle_hash, - void *data, UNUSED uint32_t length, uint32_t handle, - enum virgl_object_type type, bool free_data) +vrend_object_insert(struct util_hash_table *handle_hash, + void *data, uint32_t handle, + enum virgl_object_type type) { struct vrend_object *obj = CALLOC_STRUCT(vrend_object); @@ -105,19 +103,10 @@ vrend_object_insert_nofree(struct util_hash_table *handle_hash, obj->handle = handle; obj->data = data; obj->type = type; - obj->free_data = free_data; util_hash_table_set(handle_hash, intptr_to_pointer(obj->handle), obj); return obj->handle; } -uint32_t -vrend_object_insert(struct util_hash_table *handle_hash, - void *data, uint32_t length, uint32_t handle, enum virgl_object_type type) -{ - return vrend_object_insert_nofree(handle_hash, data, length, - handle, type, true); -} - void vrend_object_remove(struct util_hash_table *handle_hash, uint32_t handle, UNUSED enum virgl_object_type type) diff --git a/src/vrend_object.h b/src/vrend_object.h index 5323304..5cc8eba 100644 --- a/src/vrend_object.h +++ b/src/vrend_object.h @@ -34,12 +34,10 @@ void vrend_object_fini_ctx_table(struct util_hash_table *ctx_hash); void vrend_object_remove(struct util_hash_table *handle_hash, uint32_t handle, enum virgl_object_type obj); void *vrend_object_lookup(struct util_hash_table *handle_hash, uint32_t handle, enum virgl_object_type obj); -uint32_t vrend_object_insert(struct util_hash_table *handle_hash, void *data, uint32_t length, uint32_t handle, enum virgl_object_type type); -uint32_t vrend_object_insert_nofree(struct util_hash_table *handle_hash, - void *data, uint32_t length, - uint32_t handle, - enum virgl_object_type type, - bool free_data); +uint32_t vrend_object_insert(struct util_hash_table *handle_hash, + void *data, + uint32_t handle, + enum virgl_object_type type); void vrend_object_set_destroy_callback(int type, void (*cb)(void *)); diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c index 8c98fde..bb5c39f 100644 --- a/src/vrend_renderer.c +++ b/src/vrend_renderer.c @@ -1811,7 +1811,7 @@ int vrend_create_surface(struct vrend_context *ctx, vrend_resource_reference(&surf->texture, res); - ret_handle = vrend_renderer_object_insert(ctx, surf, sizeof(*surf), handle, VIRGL_OBJECT_SURFACE); + ret_handle = vrend_renderer_object_insert(ctx, surf, handle, VIRGL_OBJECT_SURFACE); if (ret_handle == 0) { FREE(surf); return ENOMEM; @@ -1974,7 +1974,7 @@ int vrend_create_sampler_state(struct vrend_context *ctx, glSamplerParameteri(state->ids[i], GL_TEXTURE_SRGB_DECODE_EXT, i == 0 ? GL_SKIP_DECODE_EXT : GL_DECODE_EXT); } } - ret_handle = vrend_renderer_object_insert(ctx, state, sizeof(struct vrend_sampler_state), handle, + ret_handle = vrend_renderer_object_insert(ctx, state, handle, VIRGL_OBJECT_SAMPLER_STATE); if (!ret_handle) { if (has_feature(feat_samplers)) @@ -2178,7 +2178,7 @@ int vrend_create_sampler_view(struct vrend_context *ctx, } } - ret_handle = vrend_renderer_object_insert(ctx, view, sizeof(*view), handle, VIRGL_OBJECT_SAMPLER_VIEW); + ret_handle = vrend_renderer_object_insert(ctx, view, handle, VIRGL_OBJECT_SAMPLER_VIEW); if (ret_handle == 0) { FREE(view); return ENOMEM; @@ -2664,7 +2664,7 @@ int vrend_create_vertex_elements_state(struct vrend_context *ctx, glEnableVertexAttribArray(i); } } - ret_handle = vrend_renderer_object_insert(ctx, v, sizeof(struct vrend_vertex_element), handle, + ret_handle = vrend_renderer_object_insert(ctx, v, handle, VIRGL_OBJECT_VERTEX_ELEMENTS); if (!ret_handle) { FREE(v); @@ -3527,7 +3527,7 @@ int vrend_create_shader(struct vrend_context *ctx, } if (new_shader) { - ret_handle = vrend_renderer_object_insert(ctx, sel, sizeof(*sel), handle, VIRGL_OBJECT_SHADER); + ret_handle = vrend_renderer_object_insert(ctx, sel, handle, VIRGL_OBJECT_SHADER); if (ret_handle == 0) { ret = ENOMEM; goto error; @@ -8940,9 +8940,9 @@ vrend_renderer_object_destroy(struct vrend_context *ctx, uint32_t handle) } uint32_t vrend_renderer_object_insert(struct vrend_context *ctx, void *data, - uint32_t size, uint32_t handle, enum virgl_object_type type) + uint32_t handle, enum virgl_object_type type) { - return vrend_object_insert(ctx->sub->object_hash, data, size, handle, type); + return vrend_object_insert(ctx->sub->object_hash, data, handle, type); } int vrend_create_query(struct vrend_context *ctx, uint32_t handle, @@ -9031,7 +9031,7 @@ int vrend_create_query(struct vrend_context *ctx, uint32_t handle, glGenQueries(1, &q->id); - ret_handle = vrend_renderer_object_insert(ctx, q, sizeof(struct vrend_query), handle, + ret_handle = vrend_renderer_object_insert(ctx, q, handle, VIRGL_OBJECT_QUERY); if (!ret_handle) { FREE(q); @@ -9313,7 +9313,7 @@ int vrend_create_so_target(struct vrend_context *ctx, target->sub_ctx = ctx->sub; vrend_resource_reference(&target->buffer, res); - ret_handle = vrend_renderer_object_insert(ctx, target, sizeof(*target), handle, + ret_handle = vrend_renderer_object_insert(ctx, target, handle, VIRGL_OBJECT_STREAMOUT_TARGET); if (ret_handle == 0) { FREE(target); diff --git a/src/vrend_renderer.h b/src/vrend_renderer.h index 34a8c54..bd91913 100644 --- a/src/vrend_renderer.h +++ b/src/vrend_renderer.h @@ -342,7 +342,7 @@ void vrend_renderer_check_fences(void); bool vrend_hw_switch_context(struct vrend_context *ctx, bool now); uint32_t vrend_renderer_object_insert(struct vrend_context *ctx, void *data, - uint32_t size, uint32_t handle, enum virgl_object_type type); + uint32_t handle, enum virgl_object_type type); void vrend_renderer_object_destroy(struct vrend_context *ctx, uint32_t handle); int vrend_create_query(struct vrend_context *ctx, uint32_t handle,