Allow UBO relocs and only emitting uniforms that are actually used.
GC7000Lite has no address register, so upload uniforms to a UBO object to
LOAD from.
I removed the code to check for changes to individual uniforms and just
reupload to entire uniform state when the state is dirty. I think there
was very limited benefit to it and it isn't compatible with relocs.
Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
static void
copy_uniform_state_to_shader(struct etna_compile *c, struct etna_shader_variant *sobj)
{
- uint32_t count = c->imm_size;
+ uint32_t count = c->imm_base + c->imm_size;
struct etna_shader_uniform_info *uinfo = &sobj->uniforms;
- uinfo->const_count = c->imm_base;
uinfo->imm_count = count;
- uinfo->imm_data = mem_dup(c->imm_data, count * sizeof(*c->imm_data));
- uinfo->imm_contents = mem_dup(c->imm_contents, count * sizeof(*c->imm_contents));
+
+ uinfo->imm_data = malloc(count * sizeof(*c->imm_data));
+ for (unsigned i = 0; i < c->imm_base; i++)
+ uinfo->imm_data[i] = i;
+ memcpy(&uinfo->imm_data[c->imm_base], c->imm_data, c->imm_size * sizeof(*c->imm_data));
+
+ uinfo->imm_contents = malloc(count * sizeof(*c->imm_contents));
+ for (unsigned i = 0; i < c->imm_base; i++)
+ uinfo->imm_contents[i] = ETNA_IMMEDIATE_UNIFORM;
+ memcpy(&uinfo->imm_contents[c->imm_base], c->imm_contents, c->imm_size * sizeof(*c->imm_contents));
etna_set_shader_uniforms_dirty_flags(sobj);
}
printf("num loops: %i\n", shader->num_loops);
printf("num temps: %i\n", shader->num_temps);
- printf("num const: %i\n", shader->uniforms.const_count);
printf("immediates:\n");
for (int idx = 0; idx < shader->uniforms.imm_count; ++idx) {
- printf(" [%i].%s = %f (0x%08x)\n",
- (idx + shader->uniforms.const_count) / 4,
+ printf(" [%i].%s = %f (0x%08x) (%d)\n",
+ idx / 4,
tgsi_swizzle_names[idx % 4],
*((float *)&shader->uniforms.imm_data[idx]),
- shader->uniforms.imm_data[idx]);
+ shader->uniforms.imm_data[idx],
+ shader->uniforms.imm_contents[idx]);
}
printf("inputs:\n");
for (int idx = 0; idx < shader->infile.num_reg; ++idx) {
enum etna_immediate_contents {
ETNA_IMMEDIATE_UNUSED = 0,
ETNA_IMMEDIATE_CONSTANT,
+ ETNA_IMMEDIATE_UNIFORM,
ETNA_IMMEDIATE_TEXRECT_SCALE_X,
ETNA_IMMEDIATE_TEXRECT_SCALE_Y,
+ ETNA_IMMEDIATE_UBO0_ADDR,
+ ETNA_IMMEDIATE_UBOMAX_ADDR = ETNA_IMMEDIATE_UBO0_ADDR + 255,
};
struct etna_shader_uniform_info {
enum etna_immediate_contents *imm_contents;
uint32_t *imm_data;
uint32_t imm_count;
- uint32_t const_count;
};
struct etna_context {
size += ctx->vertex_elements->num_elements + 1;
/* uniforms - worst case (2 words per uniform load) */
- size += ctx->shader.vs->uniforms.const_count * 2;
- size += ctx->shader.fs->uniforms.const_count * 2;
+ size += ctx->shader.vs->uniforms.imm_count * 2;
+ size += ctx->shader.fs->uniforms.imm_count * 2;
/* shader */
size += ctx->shader_state.vs_inst_mem_size + 1;
static const uint32_t uniform_dirty_bits =
ETNA_DIRTY_SHADER | ETNA_DIRTY_CONSTBUF;
- if (dirty & (uniform_dirty_bits | ctx->shader.vs->uniforms_dirty_bits))
- etna_uniforms_write(
- ctx, ctx->shader.vs, &ctx->constant_buffer[PIPE_SHADER_VERTEX],
- ctx->shader_state.VS_UNIFORMS, &ctx->shader_state.vs_uniforms_size);
-
- if (dirty & (uniform_dirty_bits | ctx->shader.fs->uniforms_dirty_bits))
- etna_uniforms_write(
- ctx, ctx->shader.fs, &ctx->constant_buffer[PIPE_SHADER_FRAGMENT],
- ctx->shader_state.PS_UNIFORMS, &ctx->shader_state.ps_uniforms_size);
-
/**** Large dynamically-sized state ****/
bool do_uniform_flush = ctx->specs.halti < 5;
if (dirty & (ETNA_DIRTY_SHADER)) {
if (do_uniform_flush)
etna_set_state(stream, VIVS_VS_UNIFORM_CACHE, VIVS_VS_UNIFORM_CACHE_FLUSH);
- etna_set_state_multi(stream, ctx->specs.vs_uniforms_offset,
- ctx->shader_state.vs_uniforms_size,
- ctx->shader_state.VS_UNIFORMS);
+
+ etna_uniforms_write(ctx, ctx->shader.vs, &ctx->constant_buffer[PIPE_SHADER_VERTEX]);
+
if (do_uniform_flush)
etna_set_state(stream, VIVS_VS_UNIFORM_CACHE, VIVS_VS_UNIFORM_CACHE_FLUSH | VIVS_VS_UNIFORM_CACHE_PS);
- etna_set_state_multi(stream, ctx->specs.ps_uniforms_offset,
- ctx->shader_state.ps_uniforms_size,
- ctx->shader_state.PS_UNIFORMS);
-
- /* Copy uniforms to gpu3d, so that incremental updates to uniforms are
- * possible as long as the
- * same shader remains bound */
- memcpy(ctx->gpu3d.VS_UNIFORMS, ctx->shader_state.VS_UNIFORMS,
- ctx->shader_state.vs_uniforms_size * 4);
- memcpy(ctx->gpu3d.PS_UNIFORMS, ctx->shader_state.PS_UNIFORMS,
- ctx->shader_state.ps_uniforms_size * 4);
+
+ etna_uniforms_write(ctx, ctx->shader.fs, &ctx->constant_buffer[PIPE_SHADER_FRAGMENT]);
if (ctx->specs.halti >= 5) {
/* HALTI5 needs to be prompted to pre-fetch shaders */
/* ideally this cache would only be flushed if there are VS uniform changes */
if (do_uniform_flush)
etna_set_state(stream, VIVS_VS_UNIFORM_CACHE, VIVS_VS_UNIFORM_CACHE_FLUSH);
- etna_coalesce_start(stream, &coalesce);
- for (int x = 0; x < ctx->shader.vs->uniforms.const_count; ++x) {
- if (ctx->gpu3d.VS_UNIFORMS[x] != ctx->shader_state.VS_UNIFORMS[x]) {
- etna_coalsence_emit(stream, &coalesce, ctx->specs.vs_uniforms_offset + x*4, ctx->shader_state.VS_UNIFORMS[x]);
- ctx->gpu3d.VS_UNIFORMS[x] = ctx->shader_state.VS_UNIFORMS[x];
- }
- }
- etna_coalesce_end(stream, &coalesce);
+
+ if (dirty & (uniform_dirty_bits | ctx->shader.vs->uniforms_dirty_bits))
+ etna_uniforms_write(ctx, ctx->shader.vs, &ctx->constant_buffer[PIPE_SHADER_VERTEX]);
/* ideally this cache would only be flushed if there are PS uniform changes */
if (do_uniform_flush)
etna_set_state(stream, VIVS_VS_UNIFORM_CACHE, VIVS_VS_UNIFORM_CACHE_FLUSH | VIVS_VS_UNIFORM_CACHE_PS);
- etna_coalesce_start(stream, &coalesce);
- for (int x = 0; x < ctx->shader.fs->uniforms.const_count; ++x) {
- if (ctx->gpu3d.PS_UNIFORMS[x] != ctx->shader_state.PS_UNIFORMS[x]) {
- etna_coalsence_emit(stream, &coalesce, ctx->specs.ps_uniforms_offset + x*4, ctx->shader_state.PS_UNIFORMS[x]);
- ctx->gpu3d.PS_UNIFORMS[x] = ctx->shader_state.PS_UNIFORMS[x];
- }
- }
- etna_coalesce_end(stream, &coalesce);
+
+ if (dirty & (uniform_dirty_bits | ctx->shader.fs->uniforms_dirty_bits))
+ etna_uniforms_write(ctx, ctx->shader.fs, &ctx->constant_buffer[PIPE_SHADER_FRAGMENT]);
}
/**** End of state update ****/
#undef EMIT_STATE
uint32_t GL_VARYING_COMPONENT_USE[2];
uint32_t GL_HALTI5_SH_SPECIALS;
unsigned vs_inst_mem_size;
- unsigned vs_uniforms_size;
unsigned ps_inst_mem_size;
- unsigned ps_uniforms_size;
uint32_t *VS_INST_MEM;
- uint32_t VS_UNIFORMS[ETNA_MAX_UNIFORMS * 4];
uint32_t *PS_INST_MEM;
- uint32_t PS_UNIFORMS[ETNA_MAX_UNIFORMS * 4];
struct etna_reloc PS_INST_ADDR;
struct etna_reloc VS_INST_ADDR;
};
pipe_debug_message(debug, SHADER_INFO, "\n"
"SHADER-DB: %s prog %d/%d: %u instructions %u temps\n"
- "SHADER-DB: %s prog %d/%d: %u immediates %u consts\n"
- "SHADER-DB: %s prog %d/%d: %u loops\n",
+ "SHADER-DB: %s prog %d/%d: %u immediates %u loops\n",
etna_shader_stage(v),
v->shader->id, v->id,
v->code_size,
etna_shader_stage(v),
v->shader->id, v->id,
v->uniforms.imm_count,
- v->uniforms.const_count,
- etna_shader_stage(v),
- v->shader->id, v->id,
v->num_loops);
}
#include "util/u_inlines.h"
#include "util/u_math.h"
#include "util/u_memory.h"
+#include "util/u_upload_mgr.h"
static void
etna_set_stencil_ref(struct pipe_context *pctx, const struct pipe_stencil_ref *sr)
/* there is no support for ARB_uniform_buffer_object */
assert(cb->buffer == NULL && cb->user_buffer != NULL);
+ if (!cb->buffer) {
+ struct pipe_constant_buffer *cb = &ctx->constant_buffer[shader];
+ u_upload_data(pctx->const_uploader, 0, cb->buffer_size, 16, cb->user_buffer, &cb->buffer_offset, &cb->buffer);
+ }
+
ctx->dirty |= ETNA_DIRTY_CONSTBUF;
}
#include "etnaviv_compiler.h"
#include "etnaviv_context.h"
#include "etnaviv_util.h"
+#include "etnaviv_emit.h"
#include "pipe/p_defines.h"
#include "util/u_math.h"
void
etna_uniforms_write(const struct etna_context *ctx,
const struct etna_shader_variant *sobj,
- struct pipe_constant_buffer *cb, uint32_t *uniforms,
- unsigned *size)
+ struct pipe_constant_buffer *cb)
{
+ struct etna_cmd_stream *stream = ctx->stream;
const struct etna_shader_uniform_info *uinfo = &sobj->uniforms;
- bool frag = false;
+ bool frag = (sobj == ctx->shader.fs);
+ uint32_t base = frag ? ctx->specs.ps_uniforms_offset : ctx->specs.vs_uniforms_offset;
- if (cb->user_buffer) {
- unsigned size = MIN2(cb->buffer_size, uinfo->const_count * 4);
+ if (!uinfo->imm_count)
+ return;
- memcpy(uniforms, cb->user_buffer, size);
- }
-
- if (sobj == ctx->shader.fs)
- frag = true;
+ etna_cmd_stream_reserve(stream, align(uinfo->imm_count + 1, 2));
+ etna_emit_load_state(stream, base >> 2, uinfo->imm_count, 0);
for (uint32_t i = 0; i < uinfo->imm_count; i++) {
+ uint32_t val = uinfo->imm_data[i];
+
switch (uinfo->imm_contents[i]) {
case ETNA_IMMEDIATE_CONSTANT:
- uniforms[i + uinfo->const_count] = uinfo->imm_data[i];
+ etna_cmd_stream_emit(stream, val);
+ break;
+
+ case ETNA_IMMEDIATE_UNIFORM:
+ assert(cb->user_buffer && val * 4 < cb->buffer_size);
+ etna_cmd_stream_emit(stream, ((uint32_t*) cb->user_buffer)[val]);
break;
case ETNA_IMMEDIATE_TEXRECT_SCALE_X:
case ETNA_IMMEDIATE_TEXRECT_SCALE_Y:
- uniforms[i + uinfo->const_count] =
- get_texrect_scale(ctx, frag, uinfo->imm_contents[i], uinfo->imm_data[i]);
+ etna_cmd_stream_emit(stream,
+ get_texrect_scale(ctx, frag, uinfo->imm_contents[i], val));
+ break;
+
+ case ETNA_IMMEDIATE_UBO0_ADDR ... ETNA_IMMEDIATE_UBOMAX_ADDR:
+ assert(uinfo->imm_contents[i] == ETNA_IMMEDIATE_UBO0_ADDR);
+ etna_cmd_stream_reloc(stream, &(struct etna_reloc) {
+ .bo = etna_resource(cb->buffer)->bo,
+ .flags = ETNA_RELOC_READ,
+ .offset = cb->buffer_offset + val,
+ });
break;
case ETNA_IMMEDIATE_UNUSED:
- /* nothing to do */
+ etna_cmd_stream_emit(stream, 0);
break;
}
}
- *size = uinfo->const_count + uinfo->imm_count;
+ if ((uinfo->imm_count % 2) == 0)
+ etna_cmd_stream_emit(stream, 0);
}
void
for (uint32_t i = 0; i < sobj->uniforms.imm_count; i++) {
switch (sobj->uniforms.imm_contents[i]) {
- case ETNA_IMMEDIATE_UNUSED:
- case ETNA_IMMEDIATE_CONSTANT:
+ default:
break;
case ETNA_IMMEDIATE_TEXRECT_SCALE_X:
void
etna_uniforms_write(const struct etna_context *ctx,
const struct etna_shader_variant *sobj,
- struct pipe_constant_buffer *cb, uint32_t *uniforms,
- unsigned *size);
+ struct pipe_constant_buffer *cb);
void
etna_set_shader_uniforms_dirty_flags(struct etna_shader_variant *sobj);