From 8958fbd29e2b4f8cce76158ce573f6d3455fa9a6 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Tue, 7 Jul 2020 15:20:35 -0400 Subject: [PATCH] panfrost: Expose pool-based allocation API Pass pools instead of batches, and rename in terms of pools instead of transient memory for consistency while we're find-and-replacing. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/gallium/drivers/panfrost/pan_allocate.c | 25 ++++++------ src/gallium/drivers/panfrost/pan_allocate.h | 5 +-- src/gallium/drivers/panfrost/pan_cmdstream.c | 40 +++++++++---------- src/gallium/drivers/panfrost/pan_fragment.c | 2 +- src/gallium/drivers/panfrost/pan_job.c | 4 +- src/gallium/drivers/panfrost/pan_mfbd.c | 2 +- src/gallium/drivers/panfrost/pan_scoreboard.c | 4 +- src/gallium/drivers/panfrost/pan_sfbd.c | 2 +- 8 files changed, 41 insertions(+), 43 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_allocate.c b/src/gallium/drivers/panfrost/pan_allocate.c index d9cbd0c3fb1..7c87836959a 100644 --- a/src/gallium/drivers/panfrost/pan_allocate.c +++ b/src/gallium/drivers/panfrost/pan_allocate.c @@ -56,7 +56,7 @@ panfrost_create_pool(void *memctx, struct panfrost_device *dev) } struct panfrost_transfer -panfrost_allocate_transient(struct panfrost_batch *batch, size_t sz) +panfrost_pool_alloc(struct pan_pool *pool, size_t sz) { /* Pad the size */ sz = ALIGN_POT(sz, ALIGNMENT); @@ -66,15 +66,15 @@ panfrost_allocate_transient(struct panfrost_batch *batch, size_t sz) unsigned offset = 0; - bool fits_in_current = (batch->pool.transient_offset + sz) < TRANSIENT_SLAB_SIZE; + bool fits_in_current = (pool->transient_offset + sz) < TRANSIENT_SLAB_SIZE; - if (likely(batch->pool.transient_bo && fits_in_current)) { + if (likely(pool->transient_bo && fits_in_current)) { /* We can reuse the current BO, so get it */ - bo = batch->pool.transient_bo; + bo = pool->transient_bo; /* Use the specified offset */ - offset = batch->pool.transient_offset; - batch->pool.transient_offset = offset + sz; + offset = pool->transient_offset; + pool->transient_offset = offset + sz; } else { size_t bo_sz = sz < TRANSIENT_SLAB_SIZE ? TRANSIENT_SLAB_SIZE : ALIGN_POT(sz, 4096); @@ -86,18 +86,18 @@ panfrost_allocate_transient(struct panfrost_batch *batch, size_t sz) * flags to this function and keep the read/write, * fragment/vertex+tiler pools separate. */ - bo = pan_bo_create(batch->pool.dev, bo_sz, 0); + bo = pan_bo_create(pool->dev, bo_sz, 0); uintptr_t flags = PAN_BO_ACCESS_PRIVATE | PAN_BO_ACCESS_RW | PAN_BO_ACCESS_VERTEX_TILER | PAN_BO_ACCESS_FRAGMENT; - _mesa_hash_table_insert(batch->pool.bos, bo, (void *) flags); + _mesa_hash_table_insert(pool->bos, bo, (void *) flags); if (sz < TRANSIENT_SLAB_SIZE) { - batch->pool.transient_bo = bo; - batch->pool.transient_offset = offset + sz; + pool->transient_bo = bo; + pool->transient_offset = offset + sz; } } @@ -111,10 +111,9 @@ panfrost_allocate_transient(struct panfrost_batch *batch, size_t sz) } mali_ptr -panfrost_upload_transient(struct panfrost_batch *batch, const void *data, - size_t sz) +panfrost_pool_upload(struct pan_pool *pool, const void *data, size_t sz) { - struct panfrost_transfer transfer = panfrost_allocate_transient(batch, sz); + struct panfrost_transfer transfer = panfrost_pool_alloc(pool, sz); memcpy(transfer.cpu, data, sz); return transfer.gpu; } diff --git a/src/gallium/drivers/panfrost/pan_allocate.h b/src/gallium/drivers/panfrost/pan_allocate.h index 1f30ee143b6..fa41d4c87c4 100644 --- a/src/gallium/drivers/panfrost/pan_allocate.h +++ b/src/gallium/drivers/panfrost/pan_allocate.h @@ -66,10 +66,9 @@ struct panfrost_transfer { }; struct panfrost_transfer -panfrost_allocate_transient(struct panfrost_batch *batch, size_t sz); +panfrost_pool_alloc(struct pan_pool *pool, size_t sz); mali_ptr -panfrost_upload_transient(struct panfrost_batch *batch, const void *data, - size_t sz); +panfrost_pool_upload(struct pan_pool *pool, const void *data, size_t sz); #endif /* __PAN_ALLOCATE_H__ */ diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index d50121afb44..fd2e72b2b1f 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -64,7 +64,7 @@ panfrost_vt_emit_shared_memory(struct panfrost_context *ctx, .scratchpad = panfrost_batch_get_scratchpad(batch, shift, dev->thread_tls_alloc, dev->core_count)->gpu, .shared_workgroup_count = ~0, }; - postfix->shared_memory = panfrost_upload_transient(batch, &shared, sizeof(shared)); + postfix->shared_memory = panfrost_pool_upload(&batch->pool, &shared, sizeof(shared)); } static void @@ -81,7 +81,7 @@ panfrost_vt_attach_framebuffer(struct panfrost_context *ctx, sizeof(struct mali_single_framebuffer) : sizeof(struct mali_framebuffer); - batch->framebuffer = panfrost_allocate_transient(batch, size); + batch->framebuffer = panfrost_pool_alloc(&batch->pool, size); /* Tag the pointer */ if (!(dev->quirks & MIDGARD_SFBD)) @@ -231,7 +231,7 @@ panfrost_get_index_buffer_bounded(struct panfrost_context *ctx, } else { /* Otherwise, we need to upload to transient memory */ const uint8_t *ibuf8 = (const uint8_t *) info->index.user; - out = panfrost_upload_transient(batch, ibuf8 + offset, + out = panfrost_pool_upload(&batch->pool, ibuf8 + offset, info->count * info->index_size); } @@ -934,7 +934,7 @@ panfrost_emit_shader_meta(struct panfrost_batch *batch, panfrost_frag_shader_meta_init(ctx, &meta, rts); - xfer = panfrost_allocate_transient(batch, desc_size); + xfer = panfrost_pool_alloc(&batch->pool, desc_size); memcpy(xfer.cpu, &meta, sizeof(meta)); memcpy(xfer.cpu + sizeof(meta), rts, rt_size * rt_count); @@ -944,7 +944,7 @@ panfrost_emit_shader_meta(struct panfrost_batch *batch, shader_ptr = xfer.gpu; } else { - shader_ptr = panfrost_upload_transient(batch, &meta, + shader_ptr = panfrost_pool_upload(&batch->pool, &meta, sizeof(meta)); } @@ -1071,7 +1071,7 @@ panfrost_emit_viewport(struct panfrost_batch *batch, mvp.viewport1[0] + 1, mvp.viewport1[1] + 1); - tiler_postfix->viewport = panfrost_upload_transient(batch, &mvp, + tiler_postfix->viewport = panfrost_pool_upload(&batch->pool, &mvp, sizeof(mvp)); } @@ -1094,7 +1094,7 @@ panfrost_map_constant_buffer_gpu(struct panfrost_batch *batch, * PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT */ return rsrc->bo->gpu + cb->buffer_offset; } else if (cb->user_buffer) { - return panfrost_upload_transient(batch, + return panfrost_pool_upload(&batch->pool, cb->user_buffer + cb->buffer_offset, cb->buffer_size); @@ -1299,7 +1299,7 @@ panfrost_emit_const_buf(struct panfrost_batch *batch, size_t sys_size = sizeof(float) * 4 * ss->sysval_count; size_t uniform_size = has_uniforms ? (buf->cb[0].buffer_size) : 0; size_t size = sys_size + uniform_size; - struct panfrost_transfer transfer = panfrost_allocate_transient(batch, + struct panfrost_transfer transfer = panfrost_pool_alloc(&batch->pool, size); /* Upload sysvals requested by the shader */ @@ -1345,7 +1345,7 @@ panfrost_emit_const_buf(struct panfrost_batch *batch, ubos[ubo] = MALI_MAKE_UBO(aligned / bytes_per_field, gpu); } - mali_ptr ubufs = panfrost_upload_transient(batch, ubos, sz); + mali_ptr ubufs = panfrost_pool_upload(&batch->pool, ubos, sz); postfix->uniforms = transfer.gpu; postfix->uniform_buffers = ubufs; @@ -1378,7 +1378,7 @@ panfrost_emit_shared_memory(struct panfrost_batch *batch, .shared_shift = util_logbase2(single_size) - 1 }; - vtp->postfix.shared_memory = panfrost_upload_transient(batch, &shared, + vtp->postfix.shared_memory = panfrost_pool_upload(&batch->pool, &shared, sizeof(shared)); } @@ -1454,7 +1454,7 @@ panfrost_emit_texture_descriptors(struct panfrost_batch *batch, memcpy(&descriptors[i], view->bifrost_descriptor, sizeof(*view->bifrost_descriptor)); } - postfix->textures = panfrost_upload_transient(batch, + postfix->textures = panfrost_pool_upload(&batch->pool, descriptors, sizeof(struct bifrost_texture_descriptor) * ctx->sampler_view_count[stage]); @@ -1471,7 +1471,7 @@ panfrost_emit_texture_descriptors(struct panfrost_batch *batch, trampolines[i] = panfrost_get_tex_desc(batch, stage, view); } - postfix->textures = panfrost_upload_transient(batch, + postfix->textures = panfrost_pool_upload(&batch->pool, trampolines, sizeof(uint64_t) * ctx->sampler_view_count[stage]); @@ -1492,7 +1492,7 @@ panfrost_emit_sampler_descriptors(struct panfrost_batch *batch, if (device->quirks & IS_BIFROST) { size_t desc_size = sizeof(struct bifrost_sampler_descriptor); size_t transfer_size = desc_size * ctx->sampler_count[stage]; - struct panfrost_transfer transfer = panfrost_allocate_transient(batch, + struct panfrost_transfer transfer = panfrost_pool_alloc(&batch->pool, transfer_size); struct bifrost_sampler_descriptor *desc = (struct bifrost_sampler_descriptor *)transfer.cpu; @@ -1503,7 +1503,7 @@ panfrost_emit_sampler_descriptors(struct panfrost_batch *batch, } else { size_t desc_size = sizeof(struct mali_sampler_descriptor); size_t transfer_size = desc_size * ctx->sampler_count[stage]; - struct panfrost_transfer transfer = panfrost_allocate_transient(batch, + struct panfrost_transfer transfer = panfrost_pool_alloc(&batch->pool, transfer_size); struct mali_sampler_descriptor *desc = (struct mali_sampler_descriptor *)transfer.cpu; @@ -1526,7 +1526,7 @@ panfrost_emit_vertex_attr_meta(struct panfrost_batch *batch, struct panfrost_vertex_state *so = ctx->vertex; panfrost_vertex_state_upd_attr_offs(ctx, vertex_postfix); - vertex_postfix->attribute_meta = panfrost_upload_transient(batch, so->hw, + vertex_postfix->attribute_meta = panfrost_pool_upload(&batch->pool, so->hw, sizeof(*so->hw) * PAN_MAX_ATTRIBUTE); } @@ -1635,7 +1635,7 @@ panfrost_emit_vertex_data(struct panfrost_batch *batch, /* Upload whatever we emitted and go */ - vertex_postfix->attributes = panfrost_upload_transient(batch, attrs, + vertex_postfix->attributes = panfrost_pool_upload(&batch->pool, attrs, k * sizeof(*attrs)); } @@ -1648,7 +1648,7 @@ panfrost_emit_varyings(struct panfrost_batch *batch, union mali_attr *slot, slot->size = stride * count; slot->shift = slot->extra_flags = 0; - struct panfrost_transfer transfer = panfrost_allocate_transient(batch, + struct panfrost_transfer transfer = panfrost_pool_alloc(&batch->pool, slot->size); slot->elements = transfer.gpu | MALI_ATTR_LINEAR; @@ -2063,7 +2063,7 @@ panfrost_emit_varying_descriptor(struct panfrost_batch *batch, vs_size = sizeof(struct mali_attr_meta) * vs->varying_count; fs_size = sizeof(struct mali_attr_meta) * fs->varying_count; - struct panfrost_transfer trans = panfrost_allocate_transient(batch, + struct panfrost_transfer trans = panfrost_pool_alloc(&batch->pool, vs_size + fs_size); @@ -2111,7 +2111,7 @@ panfrost_emit_varying_descriptor(struct panfrost_batch *batch, } unsigned xfb_base = pan_xfb_base(present); - struct panfrost_transfer T = panfrost_allocate_transient(batch, + struct panfrost_transfer T = panfrost_pool_alloc(&batch->pool, sizeof(union mali_attr) * (xfb_base + ctx->streamout.num_targets)); union mali_attr *varyings = (union mali_attr *) T.cpu; @@ -2277,5 +2277,5 @@ panfrost_emit_sample_locations(struct panfrost_batch *batch) 0, 0, }; - return panfrost_upload_transient(batch, locations, 96 * sizeof(uint16_t)); + return panfrost_pool_upload(&batch->pool, locations, 96 * sizeof(uint16_t)); } diff --git a/src/gallium/drivers/panfrost/pan_fragment.c b/src/gallium/drivers/panfrost/pan_fragment.c index 94a64d7a4bd..0b37fec07c0 100644 --- a/src/gallium/drivers/panfrost/pan_fragment.c +++ b/src/gallium/drivers/panfrost/pan_fragment.c @@ -100,7 +100,7 @@ panfrost_fragment_job(struct panfrost_batch *batch, bool has_draws) .framebuffer = framebuffer, }; - struct panfrost_transfer transfer = panfrost_allocate_transient(batch, sizeof(header) + sizeof(payload)); + struct panfrost_transfer transfer = panfrost_pool_alloc(&batch->pool, sizeof(header) + sizeof(payload)); memcpy(transfer.cpu, &header, sizeof(header)); memcpy(transfer.cpu + sizeof(header), &payload, sizeof(payload)); return transfer.gpu; diff --git a/src/gallium/drivers/panfrost/pan_job.c b/src/gallium/drivers/panfrost/pan_job.c index 0945a9cef67..82596f3d9b1 100644 --- a/src/gallium/drivers/panfrost/pan_job.c +++ b/src/gallium/drivers/panfrost/pan_job.c @@ -751,10 +751,10 @@ panfrost_batch_get_tiler_meta(struct panfrost_batch *batch, unsigned vertex_coun .flags = 0x0, .width = MALI_POSITIVE(batch->key.width), .height = MALI_POSITIVE(batch->key.height), - .tiler_heap_meta = panfrost_upload_transient(batch, &tiler_heap_meta, sizeof(tiler_heap_meta)), + .tiler_heap_meta = panfrost_pool_upload(&batch->pool, &tiler_heap_meta, sizeof(tiler_heap_meta)), }; - batch->tiler_meta = panfrost_upload_transient(batch, &tiler_meta, sizeof(tiler_meta)); + batch->tiler_meta = panfrost_pool_upload(&batch->pool, &tiler_meta, sizeof(tiler_meta)); return batch->tiler_meta; } diff --git a/src/gallium/drivers/panfrost/pan_mfbd.c b/src/gallium/drivers/panfrost/pan_mfbd.c index 558ba866c56..8ac5491b8b6 100644 --- a/src/gallium/drivers/panfrost/pan_mfbd.c +++ b/src/gallium/drivers/panfrost/pan_mfbd.c @@ -400,7 +400,7 @@ panfrost_mfbd_upload(struct panfrost_batch *batch, sizeof(struct mali_render_target) * 4; struct panfrost_transfer m_f_trans = - panfrost_allocate_transient(batch, total_sz); + panfrost_pool_alloc(&batch->pool, total_sz); /* Do the transfer */ diff --git a/src/gallium/drivers/panfrost/pan_scoreboard.c b/src/gallium/drivers/panfrost/pan_scoreboard.c index 4141f9c19c4..7023ebc4385 100644 --- a/src/gallium/drivers/panfrost/pan_scoreboard.c +++ b/src/gallium/drivers/panfrost/pan_scoreboard.c @@ -147,7 +147,7 @@ panfrost_new_job( if (inject) job.next_job = batch->first_job; - struct panfrost_transfer transfer = panfrost_allocate_transient(batch, sizeof(job) + payload_size); + struct panfrost_transfer transfer = panfrost_pool_alloc(&batch->pool, sizeof(job) + payload_size); memcpy(transfer.cpu, &job, sizeof(job)); memcpy(transfer.cpu + sizeof(job), payload, payload_size); @@ -199,7 +199,7 @@ panfrost_scoreboard_initialize_tiler(struct panfrost_batch *batch) .value_descriptor = MALI_WRITE_VALUE_ZERO, }; - struct panfrost_transfer transfer = panfrost_allocate_transient(batch, sizeof(job) + sizeof(payload)); + struct panfrost_transfer transfer = panfrost_pool_alloc(&batch->pool, sizeof(job) + sizeof(payload)); memcpy(transfer.cpu, &job, sizeof(job)); memcpy(transfer.cpu + sizeof(job), &payload, sizeof(payload)); diff --git a/src/gallium/drivers/panfrost/pan_sfbd.c b/src/gallium/drivers/panfrost/pan_sfbd.c index 769fbd79e3f..a08a6f3e8f7 100644 --- a/src/gallium/drivers/panfrost/pan_sfbd.c +++ b/src/gallium/drivers/panfrost/pan_sfbd.c @@ -266,5 +266,5 @@ panfrost_sfbd_fragment(struct panfrost_batch *batch, bool has_draws) fb.format.unk2 |= MALI_SFBD_FORMAT_MSAA_B; } - return panfrost_upload_transient(batch, &fb, sizeof(fb)); + return panfrost_pool_upload(&batch->pool, &fb, sizeof(fb)); } -- 2.30.2