mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-30 05:40:13 +01:00
panfrost: Use push constants for indirect draws
Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com> Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16916>
This commit is contained in:
parent
43884a9b09
commit
f227fb6da2
1 changed files with 16 additions and 80 deletions
|
|
@ -142,7 +142,7 @@ struct indirect_draw_context {
|
|||
mali_ptr varying_mem;
|
||||
};
|
||||
|
||||
/* Indirect draw shader inputs. Those are stored in a UBO. */
|
||||
/* Indirect draw shader inputs. Those are stored in FAU. */
|
||||
|
||||
struct indirect_draw_inputs {
|
||||
/* indirect_draw_context pointer */
|
||||
|
|
@ -175,26 +175,13 @@ struct indirect_draw_inputs {
|
|||
uint32_t draw_buf_stride;
|
||||
uint32_t restart_index;
|
||||
uint32_t attrib_count;
|
||||
};
|
||||
|
||||
static nir_ssa_def *
|
||||
get_input_data(nir_builder *b, unsigned offset, unsigned size)
|
||||
{
|
||||
assert(!(offset & 0x3));
|
||||
assert(size && !(size & 0x3));
|
||||
|
||||
return nir_load_ubo(b, 1, size,
|
||||
nir_imm_int(b, 0),
|
||||
nir_imm_int(b, offset),
|
||||
.align_mul = 4,
|
||||
.align_offset = 0,
|
||||
.range_base = 0,
|
||||
.range = ~0);
|
||||
}
|
||||
} PACKED;
|
||||
|
||||
#define get_input_field(b, name) \
|
||||
get_input_data(b, offsetof(struct indirect_draw_inputs, name), \
|
||||
sizeof(((struct indirect_draw_inputs *)0)->name) * 8)
|
||||
nir_load_push_constant(b, \
|
||||
1, sizeof(((struct indirect_draw_inputs *)0)->name) * 8, \
|
||||
nir_imm_int(b, 0), \
|
||||
.base = offsetof(struct indirect_draw_inputs, name))
|
||||
|
||||
static nir_ssa_def *
|
||||
get_address(nir_builder *b, nir_ssa_def *base, nir_ssa_def *offset)
|
||||
|
|
@ -374,11 +361,6 @@ init_shader_builder(struct indirect_draw_shader_builder *builder,
|
|||
",idvs" : "");
|
||||
}
|
||||
|
||||
nir_builder *b = &builder->b;
|
||||
nir_variable_create(b->shader, nir_var_mem_ubo,
|
||||
glsl_uint_type(), "inputs");
|
||||
b->shader->info.num_ubos++;
|
||||
|
||||
extract_inputs(builder);
|
||||
}
|
||||
|
||||
|
|
@ -1136,6 +1118,7 @@ create_indirect_draw_shader(struct panfrost_device *dev,
|
|||
struct panfrost_compile_inputs inputs = {
|
||||
.gpu_id = dev->gpu_id,
|
||||
.fixed_sysval_ubo = -1,
|
||||
.no_ubo_to_push = true,
|
||||
};
|
||||
struct pan_shader_info shader_info;
|
||||
struct util_dynarray binary;
|
||||
|
|
@ -1147,6 +1130,9 @@ create_indirect_draw_shader(struct panfrost_device *dev,
|
|||
assert(!shader_info.wls_size);
|
||||
assert(!shader_info.sysvals.sysval_count);
|
||||
|
||||
shader_info.push.count =
|
||||
DIV_ROUND_UP(sizeof(struct indirect_draw_inputs), 4);
|
||||
|
||||
unsigned shader_id = get_shader_id(flags, index_size, index_min_max_search);
|
||||
struct pan_indirect_draw_shader *draw_shader =
|
||||
&dev->indirect_draw_shaders.shaders[shader_id];
|
||||
|
|
@ -1203,45 +1189,6 @@ get_tls(const struct panfrost_device *dev)
|
|||
(PAN_INDIRECT_DRAW_NUM_SHADERS * pan_size(RENDERER_STATE));
|
||||
}
|
||||
|
||||
static mali_ptr
|
||||
get_ubos(struct pan_pool *pool,
|
||||
const struct indirect_draw_inputs *inputs)
|
||||
{
|
||||
struct panfrost_ptr inputs_buf =
|
||||
pan_pool_alloc_aligned(pool, sizeof(*inputs), 16);
|
||||
|
||||
memcpy(inputs_buf.cpu, inputs, sizeof(*inputs));
|
||||
|
||||
struct panfrost_ptr ubos_buf =
|
||||
pan_pool_alloc_desc(pool, UNIFORM_BUFFER);
|
||||
|
||||
pan_pack(ubos_buf.cpu, UNIFORM_BUFFER, cfg) {
|
||||
cfg.entries = DIV_ROUND_UP(sizeof(*inputs), 16);
|
||||
cfg.pointer = inputs_buf.gpu;
|
||||
}
|
||||
|
||||
return ubos_buf.gpu;
|
||||
}
|
||||
|
||||
static mali_ptr
|
||||
get_push_uniforms(struct pan_pool *pool,
|
||||
const struct pan_indirect_draw_shader *shader,
|
||||
const struct indirect_draw_inputs *inputs)
|
||||
{
|
||||
if (!shader->push.count)
|
||||
return 0;
|
||||
|
||||
struct panfrost_ptr push_consts_buf =
|
||||
pan_pool_alloc_aligned(pool, shader->push.count * 4, 16);
|
||||
uint32_t *out = push_consts_buf.cpu;
|
||||
uint8_t *in = (uint8_t *)inputs;
|
||||
|
||||
for (unsigned i = 0; i < shader->push.count; ++i)
|
||||
memcpy(out + i, in + shader->push.words[i].offset, 4);
|
||||
|
||||
return push_consts_buf.gpu;
|
||||
}
|
||||
|
||||
static void
|
||||
panfrost_indirect_draw_alloc_deps(struct panfrost_device *dev)
|
||||
{
|
||||
|
|
@ -1284,8 +1231,7 @@ panfrost_emit_index_min_max_search(struct pan_pool *pool,
|
|||
struct pan_scoreboard *scoreboard,
|
||||
const struct pan_indirect_draw_info *draw_info,
|
||||
const struct indirect_draw_inputs *inputs,
|
||||
struct indirect_draw_context *draw_ctx,
|
||||
mali_ptr ubos)
|
||||
struct indirect_draw_context *draw_ctx)
|
||||
{
|
||||
struct panfrost_device *dev = pool->dev;
|
||||
unsigned index_size = draw_info->index_size;
|
||||
|
|
@ -1296,10 +1242,6 @@ panfrost_emit_index_min_max_search(struct pan_pool *pool,
|
|||
mali_ptr rsd =
|
||||
get_renderer_state(dev, draw_info->flags,
|
||||
draw_info->index_size, true);
|
||||
unsigned shader_id =
|
||||
get_shader_id(draw_info->flags, draw_info->index_size, true);
|
||||
const struct pan_indirect_draw_shader *shader =
|
||||
&dev->indirect_draw_shaders.shaders[shader_id];
|
||||
struct panfrost_ptr job =
|
||||
pan_pool_alloc_desc(pool, COMPUTE_JOB);
|
||||
void *invocation =
|
||||
|
|
@ -1316,8 +1258,8 @@ panfrost_emit_index_min_max_search(struct pan_pool *pool,
|
|||
cfg.draw_descriptor_is_64b = true;
|
||||
cfg.state = rsd;
|
||||
cfg.thread_storage = get_tls(pool->dev);
|
||||
cfg.uniform_buffers = ubos;
|
||||
cfg.push_uniforms = get_push_uniforms(pool, shader, inputs);
|
||||
cfg.push_uniforms =
|
||||
pan_pool_upload_aligned(pool, inputs, sizeof(*inputs), 16);
|
||||
}
|
||||
|
||||
return panfrost_add_job(pool, scoreboard, MALI_JOB_TYPE_COMPUTE,
|
||||
|
|
@ -1385,12 +1327,6 @@ GENX(panfrost_emit_indirect_draw)(struct pan_pool *pool,
|
|||
inputs.min_max_ctx = min_max_ctx_ptr.gpu;
|
||||
}
|
||||
|
||||
unsigned shader_id =
|
||||
get_shader_id(draw_info->flags, draw_info->index_size, false);
|
||||
const struct pan_indirect_draw_shader *shader =
|
||||
&dev->indirect_draw_shaders.shaders[shader_id];
|
||||
mali_ptr ubos = get_ubos(pool, &inputs);
|
||||
|
||||
void *invocation =
|
||||
pan_section_ptr(job.cpu, COMPUTE_JOB, INVOCATION);
|
||||
panfrost_pack_work_groups_compute(invocation,
|
||||
|
|
@ -1405,14 +1341,14 @@ GENX(panfrost_emit_indirect_draw)(struct pan_pool *pool,
|
|||
cfg.draw_descriptor_is_64b = true;
|
||||
cfg.state = rsd;
|
||||
cfg.thread_storage = get_tls(pool->dev);
|
||||
cfg.uniform_buffers = ubos;
|
||||
cfg.push_uniforms = get_push_uniforms(pool, shader, &inputs);
|
||||
cfg.push_uniforms =
|
||||
pan_pool_upload_aligned(pool, &inputs, sizeof(inputs), 16);
|
||||
}
|
||||
|
||||
unsigned global_dep = draw_info->last_indirect_draw;
|
||||
unsigned local_dep =
|
||||
panfrost_emit_index_min_max_search(pool, scoreboard, draw_info,
|
||||
&inputs, &draw_ctx, ubos);
|
||||
&inputs, &draw_ctx);
|
||||
|
||||
if (!ctx->cpu) {
|
||||
*ctx = draw_ctx_ptr;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue