freedreno/a6xx: defer userconst cmdstream size calculation
authorRob Clark <robdclark@chromium.org>
Sun, 14 Jun 2020 19:33:54 +0000 (12:33 -0700)
committerMarge Bot <eric+marge@anholt.net>
Fri, 19 Jun 2020 13:16:57 +0000 (13:16 +0000)
The `ubo_state` will also need to move to `ir3_shader_variant`.  But we
can prepare for that and simplify things a bit if we calculate the
cmdstream on first emit, once we already have the appropriate variant.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5508>

src/gallium/drivers/freedreno/a6xx/fd6_const.c
src/gallium/drivers/freedreno/a6xx/fd6_const.h
src/gallium/drivers/freedreno/a6xx/fd6_program.c

index 57931991f4f7fe8feca52cad5de296e89fa0e400..ad67378a27ca4d39dcf349cba8159f8c0610a5bc 100644 (file)
@@ -277,6 +277,28 @@ fd6_emit_ubos(struct fd_context *ctx, const struct ir3_shader_variant *v,
        }
 }
 
+static unsigned
+user_consts_cmdstream_size(struct ir3_shader_variant *v)
+{
+       struct ir3_ubo_analysis_state *ubo_state = &v->shader->ubo_state;
+
+       if (unlikely(!ubo_state->cmdstream_size)) {
+               unsigned packets, size;
+
+               /* pre-calculate size required for userconst stateobj: */
+               ir3_user_consts_size(ubo_state, &packets, &size);
+
+               /* also account for UBO addresses: */
+               packets += 1;
+               size += 2 * v->shader->num_ubos;
+
+               unsigned sizedwords = (4 * packets) + size;
+               ubo_state->cmdstream_size = sizedwords * 4;
+       }
+
+       return ubo_state->cmdstream_size;
+}
+
 static void
 emit_user_consts(struct fd6_emit *emit)
 {
@@ -284,7 +306,7 @@ emit_user_consts(struct fd6_emit *emit)
                        PIPE_SHADER_VERTEX, PIPE_SHADER_TESS_CTRL, PIPE_SHADER_TESS_EVAL,
                        PIPE_SHADER_GEOMETRY, PIPE_SHADER_FRAGMENT,
        };
-       const struct ir3_shader_variant *variants[] = {
+       struct ir3_shader_variant *variants[] = {
                        emit->vs, emit->hs, emit->ds, emit->gs, emit->fs,
        };
        struct fd_context *ctx = emit->ctx;
@@ -293,7 +315,7 @@ emit_user_consts(struct fd6_emit *emit)
        for (unsigned i = 0; i < ARRAY_SIZE(types); i++) {
                if (!variants[i])
                        continue;
-               sz += variants[i]->shader->ubo_state.cmdstream_size;
+               sz += user_consts_cmdstream_size(variants[i]);
        }
 
        struct fd_ringbuffer *constobj = fd_submit_new_ringbuffer(
@@ -360,13 +382,6 @@ fd6_emit_immediates(struct fd_screen *screen, const struct ir3_shader_variant *v
        ir3_emit_immediates(screen, v, ring);
 }
 
-void
-fd6_user_consts_size(struct ir3_ubo_analysis_state *state,
-               unsigned *packets, unsigned *size)
-{
-       ir3_user_consts_size(state, packets, size);
-}
-
 void
 fd6_emit_link_map(struct fd_screen *screen,
                const struct ir3_shader_variant *producer,
index 3583abcf541417e6ff2e8af8dda670818fa21294..aa5b7293e771e4e751a089f248bbe4dcba2448d1 100644 (file)
@@ -35,8 +35,6 @@ void fd6_emit_cs_consts(const struct ir3_shader_variant *v, struct fd_ringbuffer
                struct fd_context *ctx, const struct pipe_grid_info *info);
 void fd6_emit_immediates(struct fd_screen *screen, const struct ir3_shader_variant *v,
                struct fd_ringbuffer *ring);
-void fd6_user_consts_size(struct ir3_ubo_analysis_state *state,
-               unsigned *packets, unsigned *size);
 void fd6_emit_link_map(struct fd_screen *screen,
                const struct ir3_shader_variant *producer,
                const struct ir3_shader_variant *v, struct fd_ringbuffer *ring);
index 8d63e26005af4e2c4fdb641f5f52d7dbf91b5af2..3a8f480a3cc5a886430e4abd2bff16ceea6f503c 100644 (file)
@@ -1057,20 +1057,7 @@ static const struct ir3_cache_funcs cache_funcs = {
 static void *
 fd6_shader_state_create(struct pipe_context *pctx, const struct pipe_shader_state *cso)
 {
-       struct ir3_shader *shader = ir3_shader_state_create(pctx, cso);
-       unsigned packets, size;
-
-       /* pre-calculate size required for userconst stateobj: */
-       fd6_user_consts_size(&shader->ubo_state, &packets, &size);
-
-       /* also account for UBO addresses: */
-       packets += 1;
-       size += 2 * shader->num_ubos;
-
-       unsigned sizedwords = (4 * packets) + size;
-       shader->ubo_state.cmdstream_size = sizedwords * 4;
-
-       return shader;
+       return ir3_shader_state_create(pctx, cso);
 }
 
 static void