diff options
author | Dave Airlie <airlied@redhat.com> | 2015-01-21 16:01:35 +1300 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2015-01-21 16:22:45 +1300 |
commit | c346da48ebf1a8fccf03b65921b203d1f7c75b52 (patch) | |
tree | d965206b661b7f666da5a6ed84f1075894618366 | |
parent | 581251567d083435e1f9572c08f73f3d4c1ac57f (diff) |
renderer: move to only one create shader interface
-rw-r--r-- | src/gallium/renderer/vrend_decode.c | 19 | ||||
-rw-r--r-- | src/gallium/renderer/vrend_renderer.c | 55 | ||||
-rw-r--r-- | src/gallium/renderer/vrend_renderer.h | 15 |
3 files changed, 39 insertions, 50 deletions
diff --git a/src/gallium/renderer/vrend_decode.c b/src/gallium/renderer/vrend_decode.c index 7fa0fb21115..f5041f3f795 100644 --- a/src/gallium/renderer/vrend_decode.c +++ b/src/gallium/renderer/vrend_decode.c @@ -65,13 +65,17 @@ static int vrend_decode_create_shader(struct vrend_decode_ctx *ctx, uint32_t typ uint32_t handle, uint16_t length) { - struct pipe_shader_state *state = CALLOC_STRUCT(pipe_shader_state); + struct pipe_shader_state *state; struct tgsi_token *tokens; - int i; + int i, ret; uint32_t shader_offset; unsigned num_tokens; uint8_t *shd_text; - + + if (length < 3) + return EINVAL; + + state = CALLOC_STRUCT(pipe_shader_state); if (!state) return ENOMEM; @@ -115,16 +119,11 @@ static int vrend_decode_create_shader(struct vrend_decode_ctx *ctx, uint32_t typ state->tokens = tokens; - if (type == VIRGL_OBJECT_GS) - vrend_create_gs(ctx->grctx, handle, state); - else if (type == VIRGL_OBJECT_FS) - vrend_create_fs(ctx->grctx, handle, state); - else - vrend_create_vs(ctx->grctx, handle, state); + ret = vrend_create_shader(ctx->grctx, handle, state, type); free(tokens); free(state); - return 0; + return ret; } static int vrend_decode_create_stream_output_target(struct vrend_decode_ctx *ctx, uint32_t handle, uint16_t length) diff --git a/src/gallium/renderer/vrend_renderer.c b/src/gallium/renderer/vrend_renderer.c index 1bf513f4e10..3e2a37c9e57 100644 --- a/src/gallium/renderer/vrend_renderer.c +++ b/src/gallium/renderer/vrend_renderer.c @@ -1847,48 +1847,45 @@ static void *vrend_create_shader_state(struct vrend_context *ctx, pipe_reference_init(&sel->reference, 1); r = vrend_shader_select(ctx, sel, NULL); - if (r) + if (r) { + vrend_destroy_shader_selector(sel); return NULL; + } return sel; } -void vrend_create_vs(struct vrend_context *ctx, - uint32_t handle, - const struct pipe_shader_state *vs) +static inline int shader_type_to_pipe_type(int type) { - struct vrend_shader_selector *sel; - - sel = vrend_create_shader_state(ctx, vs, PIPE_SHADER_VERTEX); - - vrend_renderer_object_insert(ctx, sel, sizeof(*sel), handle, VIRGL_OBJECT_VS); - - return; + switch (type) { + case VIRGL_OBJECT_GS: + return PIPE_SHADER_GEOMETRY; + case VIRGL_OBJECT_VS: + return PIPE_SHADER_VERTEX; + case VIRGL_OBJECT_FS: + return PIPE_SHADER_FRAGMENT; + } + return 0; } -void vrend_create_gs(struct vrend_context *ctx, - uint32_t handle, - const struct pipe_shader_state *gs) +int vrend_create_shader(struct vrend_context *ctx, + uint32_t handle, const struct pipe_shader_state *ss, + int type) { struct vrend_shader_selector *sel; + int ret_handle; - sel = vrend_create_shader_state(ctx, gs, PIPE_SHADER_GEOMETRY); - - vrend_renderer_object_insert(ctx, sel, sizeof(*sel), handle, VIRGL_OBJECT_GS); - - return; -} - -void vrend_create_fs(struct vrend_context *ctx, - uint32_t handle, - const struct pipe_shader_state *fs) -{ - struct vrend_shader_selector *sel; + sel = vrend_create_shader_state(ctx, ss, shader_type_to_pipe_type(type)); + if (sel == NULL) + return ENOMEM; - sel = vrend_create_shader_state(ctx, fs, PIPE_SHADER_FRAGMENT); + ret_handle = vrend_renderer_object_insert(ctx, sel, sizeof(*sel), handle, type); + if (ret_handle == 0) { + vrend_destroy_shader_selector(sel); + return ENOMEM; + } - vrend_renderer_object_insert(ctx, sel, sizeof(*sel), handle, VIRGL_OBJECT_FS); + return 0; - return; } void vrend_bind_vs(struct vrend_context *ctx, diff --git a/src/gallium/renderer/vrend_renderer.h b/src/gallium/renderer/vrend_renderer.h index 9af47ef9b2f..979c64d531a 100644 --- a/src/gallium/renderer/vrend_renderer.h +++ b/src/gallium/renderer/vrend_renderer.h @@ -90,17 +90,10 @@ void vrend_renderer_init(struct vrend_if_cbs *cbs); void vrend_insert_format(struct vrend_format_table *entry, uint32_t bindings); void vrend_insert_format_swizzle(int override_format, struct vrend_format_table *entry, uint32_t bindings, uint8_t swizzle[4]); -void vrend_create_vs(struct vrend_context *ctx, - uint32_t handle, - const struct pipe_shader_state *vs); - -void vrend_create_gs(struct vrend_context *ctx, - uint32_t handle, - const struct pipe_shader_state *gs); - -void vrend_create_fs(struct vrend_context *ctx, - uint32_t handle, - const struct pipe_shader_state *vs); +int vrend_create_shader(struct vrend_context *ctx, + uint32_t handle, + const struct pipe_shader_state *vs, + int type); void vrend_bind_vs(struct vrend_context *ctx, uint32_t handle); |