panfrost: Move sampler/tex descs emission helpers to pan_cmdstream.c

Move panfrost_upload_texture_descriptors() and
panfrost_upload_sampler_descriptors() to pan_cmdstream.c where other
cmdstream related helpers live. While at it, change their prototype
and name to make it consistent with the other helpers and prepare
things for ctx->payloads[] removal.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4083>
This commit is contained in:
Boris Brezillon
2020-03-05 18:43:13 +01:00
parent 2b946a1d2b
commit 8e0a08bc8e
3 changed files with 82 additions and 80 deletions
@@ -977,3 +977,71 @@ panfrost_emit_shared_memory(struct panfrost_batch *batch,
vtp->postfix.shared_memory = panfrost_upload_transient(batch, &shared,
sizeof(shared));
}
static mali_ptr
panfrost_get_tex_desc(struct panfrost_batch *batch,
enum pipe_shader_type st,
struct panfrost_sampler_view *view)
{
if (!view)
return (mali_ptr) 0;
struct pipe_sampler_view *pview = &view->base;
struct panfrost_resource *rsrc = pan_resource(pview->texture);
/* Add the BO to the job so it's retained until the job is done. */
panfrost_batch_add_bo(batch, rsrc->bo,
PAN_BO_ACCESS_SHARED | PAN_BO_ACCESS_READ |
panfrost_bo_access_for_stage(st));
panfrost_batch_add_bo(batch, view->bo,
PAN_BO_ACCESS_SHARED | PAN_BO_ACCESS_READ |
panfrost_bo_access_for_stage(st));
return view->bo->gpu;
}
void
panfrost_emit_texture_descriptors(struct panfrost_batch *batch,
enum pipe_shader_type stage,
struct midgard_payload_vertex_tiler *vtp)
{
struct panfrost_context *ctx = batch->ctx;
if (!ctx->sampler_view_count[stage])
return;
uint64_t trampolines[PIPE_MAX_SHADER_SAMPLER_VIEWS];
for (int i = 0; i < ctx->sampler_view_count[stage]; ++i)
trampolines[i] = panfrost_get_tex_desc(batch, stage,
ctx->sampler_views[stage][i]);
vtp->postfix.texture_trampoline = panfrost_upload_transient(batch,
trampolines,
sizeof(uint64_t) *
ctx->sampler_view_count[stage]);
}
void
panfrost_emit_sampler_descriptors(struct panfrost_batch *batch,
enum pipe_shader_type stage,
struct midgard_payload_vertex_tiler *vtp)
{
struct panfrost_context *ctx = batch->ctx;
if (!ctx->sampler_count[stage])
return;
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,
transfer_size);
struct mali_sampler_descriptor *desc = (struct mali_sampler_descriptor *)transfer.cpu;
for (int i = 0; i < ctx->sampler_count[stage]; ++i)
desc[i] = ctx->samplers[stage][i]->hw;
vtp->postfix.sampler_descriptor = transfer.gpu;
}
@@ -66,4 +66,14 @@ panfrost_emit_shared_memory(struct panfrost_batch *batch,
const struct pipe_grid_info *info,
struct midgard_payload_vertex_tiler *vtp);
void
panfrost_emit_texture_descriptors(struct panfrost_batch *batch,
enum pipe_shader_type stage,
struct midgard_payload_vertex_tiler *vtp);
void
panfrost_emit_sampler_descriptors(struct panfrost_batch *batch,
enum pipe_shader_type stage,
struct midgard_payload_vertex_tiler *vtp);
#endif /* __PAN_CMDSTREAM_H__ */
+4 -80
View File
@@ -262,82 +262,6 @@ panfrost_stage_attributes(struct panfrost_context *ctx)
ctx->payloads[PIPE_SHADER_VERTEX].postfix.attribute_meta = transfer.gpu;
}
static void
panfrost_upload_sampler_descriptors(struct panfrost_context *ctx)
{
struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
size_t desc_size = sizeof(struct mali_sampler_descriptor);
for (int t = 0; t <= PIPE_SHADER_FRAGMENT; ++t) {
mali_ptr upload = 0;
if (ctx->sampler_count[t]) {
size_t transfer_size = desc_size * ctx->sampler_count[t];
struct panfrost_transfer transfer =
panfrost_allocate_transient(batch, transfer_size);
struct mali_sampler_descriptor *desc =
(struct mali_sampler_descriptor *) transfer.cpu;
for (int i = 0; i < ctx->sampler_count[t]; ++i)
desc[i] = ctx->samplers[t][i]->hw;
upload = transfer.gpu;
}
ctx->payloads[t].postfix.sampler_descriptor = upload;
}
}
static mali_ptr
panfrost_upload_tex(
struct panfrost_context *ctx,
enum pipe_shader_type st,
struct panfrost_sampler_view *view)
{
if (!view)
return (mali_ptr) 0;
struct pipe_sampler_view *pview = &view->base;
struct panfrost_resource *rsrc = pan_resource(pview->texture);
/* Add the BO to the job so it's retained until the job is done. */
struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
panfrost_batch_add_bo(batch, rsrc->bo,
PAN_BO_ACCESS_SHARED | PAN_BO_ACCESS_READ |
panfrost_bo_access_for_stage(st));
panfrost_batch_add_bo(batch, view->bo,
PAN_BO_ACCESS_SHARED | PAN_BO_ACCESS_READ |
panfrost_bo_access_for_stage(st));
return view->bo->gpu;
}
static void
panfrost_upload_texture_descriptors(struct panfrost_context *ctx)
{
struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
for (int t = 0; t <= PIPE_SHADER_FRAGMENT; ++t) {
mali_ptr trampoline = 0;
if (ctx->sampler_view_count[t]) {
uint64_t trampolines[PIPE_MAX_SHADER_SAMPLER_VIEWS];
for (int i = 0; i < ctx->sampler_view_count[t]; ++i)
trampolines[i] =
panfrost_upload_tex(ctx, t, ctx->sampler_views[t][i]);
trampoline = panfrost_upload_transient(batch, trampolines, sizeof(uint64_t) * ctx->sampler_view_count[t]);
}
ctx->payloads[t].postfix.texture_trampoline = trampoline;
}
}
/* Compute number of UBOs active (more specifically, compute the highest UBO
* number addressable -- if there are gaps, include them in the count anyway).
* We always include UBO #0 in the count, since we *need* uniforms enabled for
@@ -382,11 +306,11 @@ panfrost_emit_for_draw(struct panfrost_context *ctx)
if (ctx->vertex)
panfrost_stage_attributes(ctx);
panfrost_upload_sampler_descriptors(ctx);
panfrost_upload_texture_descriptors(ctx);
for (int i = 0; i <= PIPE_SHADER_FRAGMENT; ++i)
for (int i = 0; i <= PIPE_SHADER_FRAGMENT; ++i) {
panfrost_emit_sampler_descriptors(batch, i, &ctx->payloads[i]);
panfrost_emit_texture_descriptors(batch, i, &ctx->payloads[i]);
panfrost_emit_const_buf(batch, i, &ctx->payloads[i]);
}
/* TODO: Upload the viewport somewhere more appropriate */