diff options
-rw-r--r-- | src/gallium/drivers/etnaviv/etnaviv_compiler.c | 23 | ||||
-rw-r--r-- | src/gallium/drivers/etnaviv/etnaviv_context.h | 4 | ||||
-rw-r--r-- | src/gallium/drivers/etnaviv/etnaviv_emit.c | 55 | ||||
-rw-r--r-- | src/gallium/drivers/etnaviv/etnaviv_internal.h | 4 | ||||
-rw-r--r-- | src/gallium/drivers/etnaviv/etnaviv_shader.c | 6 | ||||
-rw-r--r-- | src/gallium/drivers/etnaviv/etnaviv_state.c | 6 | ||||
-rw-r--r-- | src/gallium/drivers/etnaviv/etnaviv_uniforms.c | 49 | ||||
-rw-r--r-- | src/gallium/drivers/etnaviv/etnaviv_uniforms.h | 3 |
8 files changed, 71 insertions, 79 deletions
diff --git a/src/gallium/drivers/etnaviv/etnaviv_compiler.c b/src/gallium/drivers/etnaviv/etnaviv_compiler.c index f89c46eff66..474e3d23405 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_compiler.c +++ b/src/gallium/drivers/etnaviv/etnaviv_compiler.c @@ -2265,13 +2265,20 @@ etna_compile_check_limits(struct etna_compile *c) 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); } @@ -2486,14 +2493,14 @@ etna_dump_shader(const struct etna_shader_variant *shader) 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) { diff --git a/src/gallium/drivers/etnaviv/etnaviv_context.h b/src/gallium/drivers/etnaviv/etnaviv_context.h index a79d739100d..e1ce66b5dff 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_context.h +++ b/src/gallium/drivers/etnaviv/etnaviv_context.h @@ -88,15 +88,17 @@ struct etna_shader_state { 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 { diff --git a/src/gallium/drivers/etnaviv/etnaviv_emit.c b/src/gallium/drivers/etnaviv/etnaviv_emit.c index 05223ff2062..93f4b369a30 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_emit.c +++ b/src/gallium/drivers/etnaviv/etnaviv_emit.c @@ -105,8 +105,8 @@ required_stream_size(struct etna_context *ctx) 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; @@ -583,16 +583,6 @@ etna_emit_state(struct etna_context *ctx) 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)) { @@ -672,22 +662,13 @@ etna_emit_state(struct etna_context *ctx) 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 */ @@ -699,26 +680,16 @@ etna_emit_state(struct etna_context *ctx) /* 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 diff --git a/src/gallium/drivers/etnaviv/etnaviv_internal.h b/src/gallium/drivers/etnaviv/etnaviv_internal.h index c5b2dc14b1a..c8897e4ad92 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_internal.h +++ b/src/gallium/drivers/etnaviv/etnaviv_internal.h @@ -262,13 +262,9 @@ struct compiled_shader_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; }; diff --git a/src/gallium/drivers/etnaviv/etnaviv_shader.c b/src/gallium/drivers/etnaviv/etnaviv_shader.c index d2d736bdee5..479c88bb44d 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_shader.c +++ b/src/gallium/drivers/etnaviv/etnaviv_shader.c @@ -293,8 +293,7 @@ dump_shader_info(struct etna_shader_variant *v, struct pipe_debug_callback *debu 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, @@ -302,9 +301,6 @@ dump_shader_info(struct etna_shader_variant *v, struct pipe_debug_callback *debu 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); } diff --git a/src/gallium/drivers/etnaviv/etnaviv_state.c b/src/gallium/drivers/etnaviv/etnaviv_state.c index 8df00ab1db2..4884865e78d 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_state.c +++ b/src/gallium/drivers/etnaviv/etnaviv_state.c @@ -42,6 +42,7 @@ #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) @@ -96,6 +97,11 @@ etna_set_constant_buffer(struct pipe_context *pctx, /* 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; } diff --git a/src/gallium/drivers/etnaviv/etnaviv_uniforms.c b/src/gallium/drivers/etnaviv/etnaviv_uniforms.c index a8d970d185a..22dbd6dbae1 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_uniforms.c +++ b/src/gallium/drivers/etnaviv/etnaviv_uniforms.c @@ -29,6 +29,7 @@ #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" @@ -60,40 +61,55 @@ get_texrect_scale(const struct etna_context *ctx, bool frag, 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 @@ -103,8 +119,7 @@ etna_set_shader_uniforms_dirty_flags(struct etna_shader_variant *sobj) 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: diff --git a/src/gallium/drivers/etnaviv/etnaviv_uniforms.h b/src/gallium/drivers/etnaviv/etnaviv_uniforms.h index 1dacd2a85d8..119d96bc1d6 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_uniforms.h +++ b/src/gallium/drivers/etnaviv/etnaviv_uniforms.h @@ -36,8 +36,7 @@ struct pipe_constant_buffer; 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); |