panfrost: Use the descriptor allocators where appropriate

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9827>
This commit is contained in:
Boris Brezillon 2021-03-25 10:22:32 +01:00
parent 58747cd2f5
commit f23a023a7e
8 changed files with 110 additions and 118 deletions

View file

@ -659,15 +659,14 @@ panfrost_emit_frag_shader_meta(struct panfrost_batch *batch)
struct panfrost_device *dev = pan_device(ctx->base.screen);
unsigned rt_count = MAX2(ctx->pipe_framebuffer.nr_cbufs, 1);
struct panfrost_ptr xfer;
unsigned rt_size;
if (dev->quirks & MIDGARD_SFBD)
rt_size = 0;
else
rt_size = MALI_BLEND_LENGTH;
unsigned desc_size = MALI_RENDERER_STATE_LENGTH + rt_size * rt_count;
xfer = panfrost_pool_alloc_aligned(&batch->pool, desc_size, MALI_RENDERER_STATE_LENGTH);
if (dev->quirks & MIDGARD_SFBD) {
xfer = panfrost_pool_alloc_desc(&batch->pool, RENDERER_STATE);
} else {
xfer = panfrost_pool_alloc_desc_aggregate(&batch->pool,
PAN_DESC(RENDERER_STATE),
PAN_DESC_ARRAY(rt_count, BLEND));
}
struct panfrost_blend_final blend[PIPE_MAX_COLOR_BUFS];
unsigned shader_offset = 0;
@ -734,7 +733,7 @@ panfrost_emit_viewport(struct panfrost_batch *batch)
if (maxx == 0 || maxy == 0)
maxx = maxy = minx = miny = 1;
struct panfrost_ptr T = panfrost_pool_alloc(&batch->pool, MALI_VIEWPORT_LENGTH);
struct panfrost_ptr T = panfrost_pool_alloc_desc(&batch->pool, VIEWPORT);
pan_pack(T.cpu, VIEWPORT, cfg) {
/* [minx, maxx) and [miny, maxy) are exclusive ranges, but
@ -1113,10 +1112,9 @@ panfrost_emit_const_buf(struct panfrost_batch *batch,
unsigned ubo_count = shader->info.ubo_count - (sys_size ? 1 : 0);
unsigned sysval_ubo = sys_size ? ubo_count : ~0;
size_t sz = MALI_UNIFORM_BUFFER_LENGTH * (ubo_count + 1);
struct panfrost_ptr ubos =
panfrost_pool_alloc_aligned(&batch->pool, sz,
MALI_UNIFORM_BUFFER_LENGTH);
panfrost_pool_alloc_desc_array(&batch->pool, ubo_count + 1,
UNIFORM_BUFFER);
uint64_t *ubo_ptr = (uint64_t *) ubos.cpu;
@ -1200,9 +1198,7 @@ panfrost_emit_shared_memory(struct panfrost_batch *batch,
shared_size,
1);
struct panfrost_ptr t =
panfrost_pool_alloc_aligned(&batch->pool,
MALI_LOCAL_STORAGE_LENGTH,
64);
panfrost_pool_alloc_desc(&batch->pool, LOCAL_STORAGE);
pan_pack(t.cpu, LOCAL_STORAGE, ls) {
ls.wls_base_pointer = bo->ptr.gpu;
@ -1273,11 +1269,10 @@ panfrost_emit_texture_descriptors(struct panfrost_batch *batch,
return 0;
if (pan_is_bifrost(device)) {
struct panfrost_ptr T = panfrost_pool_alloc_aligned(&batch->pool,
MALI_BIFROST_TEXTURE_LENGTH *
ctx->sampler_view_count[stage],
MALI_BIFROST_TEXTURE_LENGTH);
struct panfrost_ptr T =
panfrost_pool_alloc_desc_array(&batch->pool,
ctx->sampler_view_count[stage],
BIFROST_TEXTURE);
struct mali_bifrost_texture_packed *out =
(struct mali_bifrost_texture_packed *) T.cpu;
@ -1328,11 +1323,12 @@ panfrost_emit_sampler_descriptors(struct panfrost_batch *batch,
if (!ctx->sampler_count[stage])
return 0;
size_t desc_size = MALI_BIFROST_SAMPLER_LENGTH;
assert(MALI_BIFROST_SAMPLER_LENGTH == MALI_MIDGARD_SAMPLER_LENGTH);
assert(MALI_BIFROST_SAMPLER_ALIGN == MALI_MIDGARD_SAMPLER_ALIGN);
size_t sz = desc_size * ctx->sampler_count[stage];
struct panfrost_ptr T = panfrost_pool_alloc_aligned(&batch->pool, sz, desc_size);
struct panfrost_ptr T =
panfrost_pool_alloc_desc_array(&batch->pool, ctx->sampler_count[stage],
MIDGARD_SAMPLER);
struct mali_midgard_sampler_packed *out = (struct mali_midgard_sampler_packed *) T.cpu;
for (unsigned i = 0; i < ctx->sampler_count[stage]; ++i)
@ -1450,21 +1446,29 @@ panfrost_emit_image_attribs(struct panfrost_batch *batch,
return 0;
}
struct panfrost_device *dev = pan_device(ctx->base.screen);
/* Images always need a MALI_ATTRIBUTE_BUFFER_CONTINUATION_3D */
unsigned attrib_buf_size = MALI_ATTRIBUTE_BUFFER_LENGTH +
MALI_ATTRIBUTE_BUFFER_CONTINUATION_3D_LENGTH;
unsigned bytes_per_image_desc = MALI_ATTRIBUTE_LENGTH + attrib_buf_size;
unsigned attribs_offset = attrib_buf_size * shader->info.attribute_count;
unsigned attr_count = shader->info.attribute_count;
unsigned buf_count = (attr_count * 2) + (pan_is_bifrost(dev) ? 1 : 0);
struct panfrost_ptr ptr =
panfrost_pool_alloc_aligned(&batch->pool,
bytes_per_image_desc * shader->info.attribute_count,
util_next_power_of_two(bytes_per_image_desc));
struct panfrost_ptr bufs =
panfrost_pool_alloc_desc_array(&batch->pool, buf_count, ATTRIBUTE_BUFFER);
emit_image_attribs(batch, type, ptr.cpu + attribs_offset, ptr.cpu, 0);
struct panfrost_ptr attribs =
panfrost_pool_alloc_desc_array(&batch->pool, attr_count, ATTRIBUTE);
*buffers = ptr.gpu;
return ptr.gpu + attribs_offset;
emit_image_attribs(batch, type, attribs.cpu, bufs.cpu, 0);
/* We need an empty attrib buf to stop the prefetching on Bifrost */
if (pan_is_bifrost(dev)) {
pan_pack(bufs.cpu +
((buf_count - 1) * MALI_ATTRIBUTE_BUFFER_LENGTH),
ATTRIBUTE_BUFFER, cfg);
}
*buffers = bufs.gpu;
return attribs.gpu;
}
mali_ptr
@ -1491,13 +1495,13 @@ panfrost_emit_vertex_data(struct panfrost_batch *batch,
return 0;
}
struct panfrost_ptr S = panfrost_pool_alloc_aligned(&batch->pool,
MALI_ATTRIBUTE_BUFFER_LENGTH * nr_bufs,
MALI_ATTRIBUTE_BUFFER_LENGTH * 2);
struct panfrost_ptr T = panfrost_pool_alloc_aligned(&batch->pool,
MALI_ATTRIBUTE_LENGTH * vs->info.attribute_count,
MALI_ATTRIBUTE_LENGTH);
struct panfrost_ptr S =
panfrost_pool_alloc_desc_array(&batch->pool, nr_bufs,
ATTRIBUTE_BUFFER);
struct panfrost_ptr T =
panfrost_pool_alloc_desc_array(&batch->pool,
vs->info.attribute_count,
ATTRIBUTE);
struct mali_attribute_buffer_packed *bufs =
(struct mali_attribute_buffer_packed *) S.cpu;
@ -2082,17 +2086,19 @@ panfrost_emit_varying_descriptor(struct panfrost_batch *batch,
struct panfrost_context *ctx = batch->ctx;
struct panfrost_device *dev = pan_device(ctx->base.screen);
struct panfrost_shader_state *vs, *fs;
size_t vs_size, fs_size;
size_t vs_size;
/* Allocate the varying descriptor */
vs = panfrost_get_shader_state(ctx, PIPE_SHADER_VERTEX);
fs = panfrost_get_shader_state(ctx, PIPE_SHADER_FRAGMENT);
vs_size = MALI_ATTRIBUTE_LENGTH * vs->info.varyings.output_count;
fs_size = MALI_ATTRIBUTE_LENGTH * fs->info.varyings.input_count;
struct panfrost_ptr trans = panfrost_pool_alloc_aligned(
&batch->pool, vs_size + fs_size, MALI_ATTRIBUTE_LENGTH);
struct panfrost_ptr trans =
panfrost_pool_alloc_desc_array(&batch->pool,
vs->info.varyings.output_count +
fs->info.varyings.input_count,
ATTRIBUTE);
struct pipe_stream_output_info *so = &vs->stream_output;
uint16_t point_coord_mask = ctx->rasterizer->base.sprite_coord_enable;
@ -2143,9 +2149,11 @@ panfrost_emit_varying_descriptor(struct panfrost_batch *batch,
}
unsigned xfb_base = pan_xfb_base(present);
struct panfrost_ptr T = panfrost_pool_alloc_aligned(&batch->pool,
MALI_ATTRIBUTE_BUFFER_LENGTH * (xfb_base + ctx->streamout.num_targets + 1),
MALI_ATTRIBUTE_BUFFER_LENGTH * 2);
struct panfrost_ptr T =
panfrost_pool_alloc_desc_array(&batch->pool,
xfb_base +
ctx->streamout.num_targets + 1,
ATTRIBUTE_BUFFER);
struct mali_attribute_buffer_packed *varyings =
(struct mali_attribute_buffer_packed *) T.cpu;

View file

@ -107,9 +107,7 @@ panfrost_launch_grid(struct pipe_context *pipe,
ctx->compute_grid = info;
struct panfrost_ptr t =
panfrost_pool_alloc_aligned(&batch->pool,
MALI_COMPUTE_JOB_LENGTH,
64);
panfrost_pool_alloc_desc(&batch->pool, COMPUTE_JOB);
/* We implement OpenCL inputs as uniforms (or a UBO -- same thing), so
* reuse the graphics path for this by lowering to Gallium */

View file

@ -511,15 +511,11 @@ panfrost_direct_draw(struct panfrost_context *ctx,
ctx->active_prim = info->mode;
struct panfrost_ptr tiler =
panfrost_pool_alloc_aligned(&batch->pool,
pan_is_bifrost(device) ?
MALI_BIFROST_TILER_JOB_LENGTH :
MALI_MIDGARD_TILER_JOB_LENGTH,
64);
pan_is_bifrost(device) ?
panfrost_pool_alloc_desc(&batch->pool, BIFROST_TILER_JOB) :
panfrost_pool_alloc_desc(&batch->pool, MIDGARD_TILER_JOB);
struct panfrost_ptr vertex =
panfrost_pool_alloc_aligned(&batch->pool,
MALI_COMPUTE_JOB_LENGTH,
64);
panfrost_pool_alloc_desc(&batch->pool, COMPUTE_JOB);
unsigned vertex_count = ctx->vertex_count;

View file

@ -88,8 +88,7 @@ panfrost_fragment_job(struct panfrost_batch *batch, bool has_draws)
assert(batch->maxy > batch->miny);
struct panfrost_ptr transfer =
panfrost_pool_alloc_aligned(&batch->pool,
MALI_FRAGMENT_JOB_LENGTH, 64);
panfrost_pool_alloc_desc(&batch->pool, FRAGMENT_JOB);
pan_section_pack(transfer.cpu, FRAGMENT_JOB, HEADER, header) {
header.type = MALI_JOB_TYPE_FRAGMENT;

View file

@ -688,7 +688,7 @@ panfrost_batch_get_bifrost_tiler(struct panfrost_batch *batch, unsigned vertex_c
struct panfrost_device *dev = pan_device(batch->ctx->base.screen);
struct panfrost_ptr t =
panfrost_pool_alloc_aligned(&batch->pool, MALI_BIFROST_TILER_HEAP_LENGTH, 64);
panfrost_pool_alloc_desc(&batch->pool, BIFROST_TILER_HEAP);
pan_pack(t.cpu, BIFROST_TILER_HEAP, heap) {
heap.size = dev->tiler_heap->size;
@ -699,7 +699,7 @@ panfrost_batch_get_bifrost_tiler(struct panfrost_batch *batch, unsigned vertex_c
mali_ptr heap = t.gpu;
t = panfrost_pool_alloc_aligned(&batch->pool, MALI_BIFROST_TILER_LENGTH, 64);
t = panfrost_pool_alloc_desc(&batch->pool, BIFROST_TILER);
pan_pack(t.cpu, BIFROST_TILER, tiler) {
tiler.hierarchy_mask = 0x28;
tiler.fb_width = batch->key.width;
@ -747,17 +747,21 @@ panfrost_batch_reserve_framebuffer(struct panfrost_batch *batch)
* full framebuffer descriptor on Midgard) */
if (!batch->framebuffer.gpu) {
unsigned size = pan_is_bifrost(dev) ?
MALI_LOCAL_STORAGE_LENGTH :
(dev->quirks & MIDGARD_SFBD) ?
MALI_SINGLE_TARGET_FRAMEBUFFER_LENGTH :
MALI_MULTI_TARGET_FRAMEBUFFER_LENGTH;
batch->framebuffer = panfrost_pool_alloc_aligned(&batch->pool, size, 64);
/* Tag the pointer */
if (!pan_is_bifrost(dev) && !(dev->quirks & MIDGARD_SFBD))
if (pan_is_bifrost(dev)) {
batch->framebuffer =
panfrost_pool_alloc_desc(&batch->pool,
LOCAL_STORAGE);
} else if (dev->quirks & MIDGARD_SFBD) {
batch->framebuffer =
panfrost_pool_alloc_desc(&batch->pool,
SINGLE_TARGET_FRAMEBUFFER);
} else {
batch->framebuffer =
panfrost_pool_alloc_desc(&batch->pool,
MULTI_TARGET_FRAMEBUFFER);
/* Tag the pointer */
batch->framebuffer.gpu |= MALI_FBD_TAG_IS_MFBD;
}
}
return batch->framebuffer.gpu;

View file

@ -47,16 +47,6 @@ panfrost_mfbd_has_zs_crc_ext(struct panfrost_batch *batch)
return false;
}
static unsigned
panfrost_mfbd_size(struct panfrost_batch *batch)
{
unsigned rt_count = MAX2(batch->key.nr_cbufs, 1);
return MALI_MULTI_TARGET_FRAMEBUFFER_LENGTH +
(panfrost_mfbd_has_zs_crc_ext(batch) * MALI_ZS_CRC_EXTENSION_LENGTH) +
(rt_count * MALI_RENDER_TARGET_LENGTH);
}
static enum mali_mfbd_color_format
panfrost_mfbd_raw_format(unsigned bits)
{
@ -545,9 +535,14 @@ panfrost_mfbd_fragment(struct panfrost_batch *batch, bool has_draws)
{
struct panfrost_device *dev = pan_device(batch->ctx->base.screen);
unsigned vertex_count = has_draws;
unsigned zs_crc_count = panfrost_mfbd_has_zs_crc_ext(batch) ? 1 : 0;
unsigned rt_count = MAX2(batch->key.nr_cbufs, 1);
struct panfrost_ptr t =
panfrost_pool_alloc_aligned(&batch->pool,
panfrost_mfbd_size(batch), 64);
panfrost_pool_alloc_desc_aggregate(&batch->pool,
PAN_DESC(MULTI_TARGET_FRAMEBUFFER),
PAN_DESC_ARRAY(zs_crc_count, ZS_CRC_EXTENSION),
PAN_DESC_ARRAY(rt_count, RENDER_TARGET));
void *fb = t.cpu, *zs_crc_ext, *rts;
if (panfrost_mfbd_has_zs_crc_ext(batch)) {

View file

@ -209,9 +209,7 @@ mali_ptr
panfrost_sfbd_fragment(struct panfrost_batch *batch, bool has_draws)
{
struct panfrost_ptr t =
panfrost_pool_alloc_aligned(&batch->pool,
MALI_SINGLE_TARGET_FRAMEBUFFER_LENGTH,
64);
panfrost_pool_alloc_desc(&batch->pool, SINGLE_TARGET_FRAMEBUFFER);
void *sfbd = t.cpu;
panfrost_emit_sfdb_local_storage(batch, sfbd, has_draws);

View file

@ -213,7 +213,7 @@ static void
panfrost_load_emit_viewport(struct pan_pool *pool, struct MALI_DRAW *draw,
struct pan_image *image)
{
struct panfrost_ptr t = panfrost_pool_alloc(pool, MALI_VIEWPORT_LENGTH);
struct panfrost_ptr t = panfrost_pool_alloc_desc(pool, VIEWPORT);
unsigned width = u_minify(image->width0, image->first_level);
unsigned height = u_minify(image->height0, image->first_level);
@ -277,10 +277,10 @@ panfrost_load_emit_varying(struct pan_pool *pool, struct MALI_DRAW *draw,
bool padding_buffer = pan_is_bifrost(pool->dev);
struct panfrost_ptr varying =
panfrost_pool_alloc(pool, MALI_ATTRIBUTE_LENGTH);
panfrost_pool_alloc_desc(pool, ATTRIBUTE);
struct panfrost_ptr varying_buffer =
panfrost_pool_alloc(pool, MALI_ATTRIBUTE_BUFFER_LENGTH *
(padding_buffer ? 2 : 1));
panfrost_pool_alloc_desc_array(pool, (padding_buffer ? 2 : 1),
ATTRIBUTE_BUFFER);
pan_pack(varying_buffer.cpu, ATTRIBUTE_BUFFER, cfg) {
cfg.pointer = coordinates;
@ -309,11 +309,10 @@ midgard_load_emit_texture(struct pan_pool *pool, struct MALI_DRAW *draw,
struct pan_image *image)
{
struct panfrost_ptr texture =
panfrost_pool_alloc_aligned(pool,
MALI_MIDGARD_TEXTURE_LENGTH +
sizeof(mali_ptr) * 2 *
MAX2(image->nr_samples, 1),
128);
panfrost_pool_alloc_desc_aggregate(pool,
PAN_DESC(MIDGARD_TEXTURE),
PAN_DESC_ARRAY(MAX2(image->nr_samples, 1),
SURFACE_WITH_STRIDE));
struct panfrost_ptr payload = {
texture.cpu + MALI_MIDGARD_TEXTURE_LENGTH,
@ -321,7 +320,7 @@ midgard_load_emit_texture(struct pan_pool *pool, struct MALI_DRAW *draw,
};
struct panfrost_ptr sampler =
panfrost_pool_alloc(pool, MALI_MIDGARD_SAMPLER_LENGTH);
panfrost_pool_alloc_desc(pool, MIDGARD_SAMPLER);
/* Create the texture descriptor. We partially compute the base address
* ourselves to account for layer, such that the texture descriptor
@ -398,10 +397,9 @@ midgard_load_emit_rsd(struct pan_pool *pool, struct MALI_DRAW *draw,
unsigned loc)
{
struct panfrost_ptr t =
panfrost_pool_alloc_aligned(pool,
MALI_RENDERER_STATE_LENGTH +
8 * MALI_BLEND_LENGTH,
128);
panfrost_pool_alloc_desc_aggregate(pool,
PAN_DESC(RENDERER_STATE),
PAN_DESC_ARRAY(8, BLEND));
bool srgb = util_format_is_srgb(image->format);
pan_pack(t.cpu, RENDERER_STATE, cfg) {
@ -457,9 +455,8 @@ panfrost_load_midg(struct pan_pool *pool,
unsigned loc)
{
struct panfrost_ptr t =
panfrost_pool_alloc_aligned(pool,
MALI_MIDGARD_TILER_JOB_LENGTH,
64);
panfrost_pool_alloc_desc(pool, MIDGARD_TILER_JOB);
pan_section_pack(t.cpu, MIDGARD_TILER_JOB, DRAW, cfg) {
cfg.texture_descriptor_is_64b = true;
cfg.draw_descriptor_is_64b = true;
@ -496,13 +493,12 @@ bifrost_load_emit_texture(struct pan_pool *pool, struct MALI_DRAW *draw,
struct pan_image *image)
{
struct panfrost_ptr texture =
panfrost_pool_alloc_aligned(pool,
MALI_BIFROST_TEXTURE_LENGTH +
sizeof(mali_ptr) * 2 *
MAX2(image->nr_samples, 1),
128);
panfrost_pool_alloc_desc_aggregate(pool,
PAN_DESC(BIFROST_TEXTURE),
PAN_DESC_ARRAY(MAX2(image->nr_samples, 1),
SURFACE_WITH_STRIDE));
struct panfrost_ptr sampler =
panfrost_pool_alloc(pool, MALI_BIFROST_SAMPLER_LENGTH);
panfrost_pool_alloc_desc(pool, BIFROST_SAMPLER);
struct panfrost_ptr payload = {
.cpu = texture.cpu + MALI_BIFROST_TEXTURE_LENGTH,
.gpu = texture.gpu + MALI_BIFROST_TEXTURE_LENGTH,
@ -607,10 +603,9 @@ bifrost_load_emit_rsd(struct pan_pool *pool, struct MALI_DRAW *draw,
unsigned loc)
{
struct panfrost_ptr t =
panfrost_pool_alloc_aligned(pool,
MALI_RENDERER_STATE_LENGTH +
8 * MALI_BLEND_LENGTH,
128);
panfrost_pool_alloc_desc_aggregate(pool,
PAN_DESC(RENDERER_STATE),
PAN_DESC_ARRAY(8, BLEND));
pan_pack(t.cpu, RENDERER_STATE, cfg) {
panfrost_load_prepare_rsd(pool, &cfg, image, loc);
@ -650,9 +645,8 @@ panfrost_load_bifrost(struct pan_pool *pool,
unsigned loc)
{
struct panfrost_ptr t =
panfrost_pool_alloc_aligned(pool,
MALI_BIFROST_TILER_JOB_LENGTH,
64);
panfrost_pool_alloc_desc(pool, BIFROST_TILER_JOB);
pan_section_pack(t.cpu, BIFROST_TILER_JOB, DRAW, cfg) {
cfg.four_components_per_vertex = true;
cfg.draw_descriptor_is_64b = true;