asahi: don't allocate for USC words

let the driver.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29247>
This commit is contained in:
Alyssa Rosenzweig 2024-04-19 22:08:41 -04:00
parent 06d59d3f5c
commit 7dcd5f1f02
2 changed files with 27 additions and 24 deletions

View File

@ -6,20 +6,19 @@
#pragma once
#include "asahi/genxml/agx_pack.h"
#include "asahi/lib/pool.h"
/* Opaque structure representing a USC program being constructed */
struct agx_usc_builder {
struct agx_ptr T;
uint8_t *head;
#ifndef NDEBUG
uint8_t *begin;
size_t size;
#endif
};
static struct agx_usc_builder
agx_alloc_usc_control(struct agx_pool *pool, unsigned num_reg_bindings)
static inline unsigned
agx_usc_size(unsigned num_reg_bindings)
{
STATIC_ASSERT(AGX_USC_UNIFORM_HIGH_LENGTH == AGX_USC_UNIFORM_LENGTH);
STATIC_ASSERT(AGX_USC_TEXTURE_LENGTH == AGX_USC_UNIFORM_LENGTH);
@ -33,24 +32,27 @@ agx_alloc_usc_control(struct agx_pool *pool, unsigned num_reg_bindings)
size += MAX2(AGX_USC_NO_PRESHADER_LENGTH, AGX_USC_PRESHADER_LENGTH);
size += AGX_USC_FRAGMENT_PROPERTIES_LENGTH;
struct agx_usc_builder b = {
.T = agx_pool_alloc_aligned(pool, size, 64),
return size;
}
static struct agx_usc_builder
agx_usc_builder(void *out, ASSERTED size_t size)
{
return (struct agx_usc_builder){
.head = out,
#ifndef NDEBUG
.begin = out,
.size = size,
#endif
};
b.head = (uint8_t *)b.T.cpu;
return b;
}
static bool
agx_usc_builder_validate(struct agx_usc_builder *b, size_t size)
{
#ifndef NDEBUG
assert(((b->head - (uint8_t *)b->T.cpu) + size) <= b->size);
assert(((b->head - b->begin) + size) <= b->size);
#endif
return true;
@ -93,13 +95,6 @@ agx_usc_uniform(struct agx_usc_builder *b, unsigned start_halfs,
}
}
static uint32_t
agx_usc_fini(struct agx_usc_builder *b)
{
assert(b->T.gpu <= (1ull << 32) && "pipelines must be in low memory");
return b->T.gpu;
}
static void
agx_usc_shared_none(struct agx_usc_builder *b)
{

View File

@ -2903,8 +2903,14 @@ agx_build_pipeline(struct agx_batch *batch, struct agx_compiled_shader *cs,
struct agx_context *ctx = batch->ctx;
unsigned constant_push_ranges =
DIV_ROUND_UP(cs->b.info.immediate_size_16, 64);
struct agx_usc_builder b = agx_alloc_usc_control(
&batch->pipeline_pool, constant_push_ranges + cs->push_range_count + 2);
size_t usc_size =
agx_usc_size(constant_push_ranges + cs->push_range_count + 2);
struct agx_ptr t =
agx_pool_alloc_aligned(&batch->pipeline_pool, usc_size, 64);
struct agx_usc_builder b = agx_usc_builder(t.cpu, usc_size);
enum pipe_shader_type stage = cs->stage;
@ -3028,7 +3034,7 @@ agx_build_pipeline(struct agx_batch *batch, struct agx_compiled_shader *cs,
;
}
return agx_usc_fini(&b);
return t.gpu;
}
struct asahi_bg_eot
@ -3078,8 +3084,10 @@ agx_build_bg_eot(struct agx_batch *batch, bool store, bool partial_render)
}
/* Begin building the pipeline */
struct agx_usc_builder b =
agx_alloc_usc_control(&batch->pipeline_pool, 3 + PIPE_MAX_COLOR_BUFS);
size_t usc_size = agx_usc_size(3 + PIPE_MAX_COLOR_BUFS);
struct agx_ptr t =
agx_pool_alloc_aligned(&batch->pipeline_pool, usc_size, 64);
struct agx_usc_builder b = agx_usc_builder(t.cpu, usc_size);
bool needs_sampler = false;
unsigned uniforms = 0;
@ -3206,7 +3214,7 @@ agx_build_bg_eot(struct agx_batch *batch, bool store, bool partial_render)
;
}
struct asahi_bg_eot ret = {.usc = agx_usc_fini(&b)};
struct asahi_bg_eot ret = {.usc = t.gpu};
agx_pack(&ret.counts, COUNTS, cfg) {
cfg.uniforms = shader->info.push_count;