diff options
author | Dave Airlie <[email protected]> | 2019-08-27 15:21:48 +1000 |
---|---|---|
committer | Dave Airlie <[email protected]> | 2019-09-04 15:22:20 +1000 |
commit | 45a8cf95f21d7fe2c50091b82ac6f8c9ab57bab7 (patch) | |
tree | 2c287c88fe4c576d5ada4da6f148c08229a1d4e1 /src | |
parent | 6ea8e9b415b31aede0c337bba0591271b9253c27 (diff) |
llvmpipe: add ssbo support to compute shaders
Reviewed-by: Roland Scheidegger <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/gallium/drivers/llvmpipe/lp_state.h | 1 | ||||
-rw-r--r-- | src/gallium/drivers/llvmpipe/lp_state_cs.c | 53 | ||||
-rw-r--r-- | src/gallium/drivers/llvmpipe/lp_state_cs.h | 5 | ||||
-rw-r--r-- | src/gallium/drivers/llvmpipe/lp_state_fs.c | 2 |
4 files changed, 61 insertions, 0 deletions
diff --git a/src/gallium/drivers/llvmpipe/lp_state.h b/src/gallium/drivers/llvmpipe/lp_state.h index 7138e6d74b7..be7eeec811e 100644 --- a/src/gallium/drivers/llvmpipe/lp_state.h +++ b/src/gallium/drivers/llvmpipe/lp_state.h @@ -63,6 +63,7 @@ #define LP_CSNEW_CONSTANTS 0x2 #define LP_CSNEW_SAMPLER 0x4 #define LP_CSNEW_SAMPLER_VIEW 0x8 +#define LP_CSNEW_SSBOS 0x10 struct vertex_info; struct pipe_context; diff --git a/src/gallium/drivers/llvmpipe/lp_state_cs.c b/src/gallium/drivers/llvmpipe/lp_state_cs.c index 32bbdd2e6cf..43760852826 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_cs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_cs.c @@ -906,6 +906,24 @@ lp_csctx_set_cs_constants(struct lp_cs_context *csctx, } static void +lp_csctx_set_cs_ssbos(struct lp_cs_context *csctx, + unsigned num, + struct pipe_shader_buffer *buffers) +{ + int i; + LP_DBG(DEBUG_SETUP, "%s %p\n", __FUNCTION__, (void *)buffers); + + assert (num <= ARRAY_SIZE(csctx->ssbos)); + + for (i = 0; i < num; ++i) { + util_copy_shader_buffer(&csctx->ssbos[i].current, &buffers[i]); + } + for (; i < ARRAY_SIZE(csctx->ssbos); i++) { + util_copy_shader_buffer(&csctx->ssbos[i].current, NULL); + } +} + +static void update_csctx_consts(struct llvmpipe_context *llvmpipe) { struct lp_cs_context *csctx = llvmpipe->csctx; @@ -937,6 +955,31 @@ update_csctx_consts(struct llvmpipe_context *llvmpipe) } static void +update_csctx_ssbo(struct llvmpipe_context *llvmpipe) +{ + struct lp_cs_context *csctx = llvmpipe->csctx; + int i; + for (i = 0; i < ARRAY_SIZE(csctx->ssbos); ++i) { + struct pipe_resource *buffer = csctx->ssbos[i].current.buffer; + const ubyte *current_data = NULL; + + if (!buffer) + continue; + /* resource buffer */ + current_data = (ubyte *) llvmpipe_resource_data(buffer); + if (current_data) { + current_data += csctx->ssbos[i].current.buffer_offset; + + csctx->cs.current.jit_context.ssbos[i] = (const uint32_t *)current_data; + csctx->cs.current.jit_context.num_ssbos[i] = csctx->ssbos[i].current.buffer_size; + } else { + csctx->cs.current.jit_context.ssbos[i] = NULL; + csctx->cs.current.jit_context.num_ssbos[i] = 0; + } + } +} + +static void llvmpipe_cs_update_derived(struct llvmpipe_context *llvmpipe) { if (llvmpipe->cs_dirty & (LP_CSNEW_CS)) @@ -949,6 +992,13 @@ llvmpipe_cs_update_derived(struct llvmpipe_context *llvmpipe) update_csctx_consts(llvmpipe); } + if (llvmpipe->cs_dirty & LP_CSNEW_SSBOS) { + lp_csctx_set_cs_ssbos(llvmpipe->csctx, + ARRAY_SIZE(llvmpipe->ssbos[PIPE_SHADER_COMPUTE]), + llvmpipe->ssbos[PIPE_SHADER_COMPUTE]); + update_csctx_ssbo(llvmpipe); + } + if (llvmpipe->cs_dirty & LP_CSNEW_SAMPLER_VIEW) lp_csctx_set_sampler_views(llvmpipe->csctx, llvmpipe->num_sampler_views[PIPE_SHADER_COMPUTE], @@ -1057,6 +1107,9 @@ lp_csctx_destroy(struct lp_cs_context *csctx) for (i = 0; i < ARRAY_SIZE(csctx->constants); i++) { pipe_resource_reference(&csctx->constants[i].current.buffer, NULL); } + for (i = 0; i < ARRAY_SIZE(csctx->ssbos); i++) { + pipe_resource_reference(&csctx->ssbos[i].current.buffer, NULL); + } FREE(csctx); } diff --git a/src/gallium/drivers/llvmpipe/lp_state_cs.h b/src/gallium/drivers/llvmpipe/lp_state_cs.h index 031c1d317ea..fd72950a927 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_cs.h +++ b/src/gallium/drivers/llvmpipe/lp_state_cs.h @@ -106,6 +106,11 @@ struct lp_cs_context { unsigned stored_size; const void *stored_data; } constants[LP_MAX_TGSI_CONST_BUFFERS]; + + /** compute shader buffers */ + struct { + struct pipe_shader_buffer current; + } ssbos[LP_MAX_TGSI_SHADER_BUFFERS]; }; struct lp_cs_context *lp_csctx_create(struct pipe_context *pipe); diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c index cf0e15e6d10..91dee27deba 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c @@ -3203,6 +3203,8 @@ llvmpipe_set_shader_buffers(struct pipe_context *pipe, data += buffer->buffer_offset; draw_set_mapped_shader_buffer(llvmpipe->draw, shader, i, data, size); + } else if (shader == PIPE_SHADER_COMPUTE) { + llvmpipe->cs_dirty |= LP_CSNEW_SSBOS; } else if (shader == PIPE_SHADER_FRAGMENT) { llvmpipe->dirty |= LP_NEW_FS_SSBOS; } |