From 61ed09c7ea41e559219c772f18ea00942d54d30a Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Mon, 4 Jan 2016 23:56:08 +0100 Subject: [PATCH] gallium/cso: add support for compute shaders MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Changes from v2: - removed cso_{save,restore}_compute_shader() functions and the compute_shader_saved variable because disabling compute shaders for meta ops is not currently needed Signed-off-by: Samuel Pitoiset Reviewed-by: Ilia Mirkin Reviewed-by: Marek Olšák --- src/gallium/auxiliary/cso_cache/cso_context.c | 30 +++++++++++++++++++ src/gallium/auxiliary/cso_cache/cso_context.h | 4 +++ 2 files changed, 34 insertions(+) diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c index 6b29b20c53e..79ae75306bf 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.c +++ b/src/gallium/auxiliary/cso_cache/cso_context.c @@ -69,6 +69,7 @@ struct cso_context { boolean has_geometry_shader; boolean has_tessellation; + boolean has_compute_shader; boolean has_streamout; struct pipe_sampler_view *fragment_views[PIPE_MAX_SHADER_SAMPLER_VIEWS]; @@ -106,6 +107,7 @@ struct cso_context { void *geometry_shader, *geometry_shader_saved; void *tessctrl_shader, *tessctrl_shader_saved; void *tesseval_shader, *tesseval_shader_saved; + void *compute_shader; void *velements, *velements_saved; struct pipe_query *render_condition, *render_condition_saved; uint render_condition_mode, render_condition_mode_saved; @@ -272,6 +274,10 @@ struct cso_context *cso_create_context( struct pipe_context *pipe ) PIPE_SHADER_CAP_MAX_INSTRUCTIONS) > 0) { ctx->has_tessellation = TRUE; } + if (pipe->screen->get_shader_param(pipe->screen, PIPE_SHADER_COMPUTE, + PIPE_SHADER_CAP_MAX_INSTRUCTIONS) > 0) { + ctx->has_compute_shader = TRUE; + } if (pipe->screen->get_param(pipe->screen, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS) != 0) { ctx->has_streamout = TRUE; @@ -333,6 +339,10 @@ void cso_destroy_context( struct cso_context *ctx ) ctx->pipe->bind_tes_state(ctx->pipe, NULL); ctx->pipe->set_constant_buffer(ctx->pipe, PIPE_SHADER_TESS_EVAL, 0, NULL); } + if (ctx->has_compute_shader) { + ctx->pipe->bind_compute_state(ctx->pipe, NULL); + ctx->pipe->set_constant_buffer(ctx->pipe, PIPE_SHADER_COMPUTE, 0, NULL); + } ctx->pipe->bind_vertex_elements_state( ctx->pipe, NULL ); if (ctx->has_streamout) @@ -907,6 +917,26 @@ void cso_restore_tesseval_shader(struct cso_context *ctx) ctx->tesseval_shader_saved = NULL; } +void cso_set_compute_shader_handle(struct cso_context *ctx, void *handle) +{ + assert(ctx->has_compute_shader || !handle); + + if (ctx->has_compute_shader && ctx->compute_shader != handle) { + ctx->compute_shader = handle; + ctx->pipe->bind_compute_state(ctx->pipe, handle); + } +} + +void cso_delete_compute_shader(struct cso_context *ctx, void *handle) +{ + if (handle == ctx->compute_shader) { + /* unbind before deleting */ + ctx->pipe->bind_compute_state(ctx->pipe, NULL); + ctx->compute_shader = NULL; + } + ctx->pipe->delete_compute_state(ctx->pipe, handle); +} + enum pipe_error cso_set_vertex_elements(struct cso_context *ctx, unsigned count, diff --git a/src/gallium/auxiliary/cso_cache/cso_context.h b/src/gallium/auxiliary/cso_cache/cso_context.h index f0a27390d17..ec9112b493a 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.h +++ b/src/gallium/auxiliary/cso_cache/cso_context.h @@ -151,6 +151,10 @@ void cso_save_tesseval_shader(struct cso_context *cso); void cso_restore_tesseval_shader(struct cso_context *cso); +void cso_set_compute_shader_handle(struct cso_context *ctx, void *handle); +void cso_delete_compute_shader(struct cso_context *ctx, void *handle); + + void cso_set_framebuffer(struct cso_context *cso, const struct pipe_framebuffer_state *fb); void cso_save_framebuffer(struct cso_context *cso); -- 2.30.2