struct ir3_ubo_range range[IR3_MAX_CONSTANT_BUFFERS];
uint32_t size;
uint32_t lower_count;
+ uint32_t cmdstream_size; /* for per-gen backend to stash required cmdstream size */
};
if (ctx->dirty_shader[PIPE_SHADER_VERTEX] & DIRTY_CONST) {
struct fd_ringbuffer *vsconstobj = fd_submit_new_ringbuffer(
- ctx->batch->submit, 0x1000, FD_RINGBUFFER_STREAMING);
+ ctx->batch->submit, vp->shader->ubo_state.cmdstream_size,
+ FD_RINGBUFFER_STREAMING);
ir3_emit_user_consts(ctx->screen, vp, vsconstobj,
&ctx->constbuf[PIPE_SHADER_VERTEX]);
if (ctx->dirty_shader[PIPE_SHADER_FRAGMENT] & DIRTY_CONST) {
struct fd_ringbuffer *fsconstobj = fd_submit_new_ringbuffer(
- ctx->batch->submit, 0x1000, FD_RINGBUFFER_STREAMING);
+ ctx->batch->submit, fp->shader->ubo_state.cmdstream_size,
+ FD_RINGBUFFER_STREAMING);
ir3_emit_user_consts(ctx->screen, fp, fsconstobj,
&ctx->constbuf[PIPE_SHADER_FRAGMENT]);
{
struct fd_context *ctx = fd_context(pctx);
struct ir3_compiler *compiler = ctx->screen->compiler;
- return ir3_shader_create(compiler, cso, type, &ctx->debug, pctx->screen);
+ struct ir3_shader *shader =
+ ir3_shader_create(compiler, cso, type, &ctx->debug, pctx->screen);
+ unsigned packets, size;
+
+ /* pre-calculate size required for userconst stateobj: */
+ ir3_user_consts_size(&shader->ubo_state, &packets, &size);
+
+ /* also account for UBO addresses: */
+ packets += 1;
+ size += 2 * shader->const_state.num_ubos;
+
+ unsigned sizedwords = (4 * packets) + size;
+ shader->ubo_state.cmdstream_size = sizedwords * 4;
+
+ return shader;
}
static void *
offset, size, user_buffer, buffer);
}
+/**
+ * Indirectly calculates size of cmdstream needed for ir3_emit_user_consts().
+ * Returns number of packets, and total size of all the payload.
+ *
+ * The value can be a worst-case, ie. some shader variants may not read all
+ * consts, etc.
+ *
+ * Returns size in dwords.
+ */
+void
+ir3_user_consts_size(struct ir3_ubo_analysis_state *state,
+ unsigned *packets, unsigned *size)
+{
+ *packets = *size = 0;
+
+ for (uint32_t i = 0; i < ARRAY_SIZE(state->range); i++) {
+ if (state->range[i].start < state->range[i].end) {
+ *size += state->range[i].end - state->range[i].start;
+ (*packets)++;
+ }
+ }
+}
+
void
ir3_emit_user_consts(struct fd_screen *screen, const struct ir3_shader_variant *v,
struct fd_ringbuffer *ring, struct fd_constbuf_stateobj *constbuf)
struct fd_shaderbuf_stateobj;
struct fd_shaderimg_stateobj;
+void ir3_user_consts_size(struct ir3_ubo_analysis_state *state,
+ unsigned *packets, unsigned *size);
void ir3_emit_user_consts(struct fd_screen *screen, const struct ir3_shader_variant *v,
struct fd_ringbuffer *ring, struct fd_constbuf_stateobj *constbuf);
void ir3_emit_ubos(struct fd_screen *screen, const struct ir3_shader_variant *v,