llvmpipe: add ssbo support to compute shaders
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
This commit is contained in:
@@ -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;
|
||||
|
@@ -905,6 +905,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)
|
||||
{
|
||||
@@ -936,6 +954,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)
|
||||
{
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user