#include "etnaviv_query.h"
#include "etnaviv_query_hw.h"
#include "etnaviv_rasterizer.h"
+#include "etnaviv_resource.h"
#include "etnaviv_screen.h"
#include "etnaviv_shader.h"
#include "etnaviv_state.h"
#include "pipe/p_context.h"
#include "pipe/p_state.h"
+#include "util/hash_table.h"
#include "util/u_blitter.h"
#include "util/u_helpers.h"
#include "util/u_memory.h"
{
struct etna_context *ctx = etna_context(pctx);
+ mtx_lock(&ctx->lock);
+ if (ctx->used_resources_read) {
+
+ /*
+ * There should be no resources tracked in the context when it's being
+ * destroyed. Be sure there are none to avoid memory leaks on buggy
+ * programs.
+ */
+ set_foreach(ctx->used_resources_read, entry) {
+ struct etna_resource *rsc = (struct etna_resource *)entry->key;
+
+ _mesa_set_remove_key(rsc->pending_ctx, ctx);
+ }
+ _mesa_set_destroy(ctx->used_resources_read, NULL);
+
+ }
+ if (ctx->used_resources_write) {
+
+ /*
+ * There should be no resources tracked in the context when it's being
+ * destroyed. Be sure there are none to avoid memory leaks on buggy
+ * programs.
+ */
+ set_foreach(ctx->used_resources_write, entry) {
+ struct etna_resource *rsc = (struct etna_resource *)entry->key;
+
+ _mesa_set_remove_key(rsc->pending_ctx, ctx);
+ }
+ _mesa_set_destroy(ctx->used_resources_write, NULL);
+
+ }
+ mtx_unlock(&ctx->lock);
+
+ if (ctx->dummy_rt)
+ etna_bo_del(ctx->dummy_rt);
+
+ util_copy_framebuffer_state(&ctx->framebuffer_s, NULL);
+
if (ctx->primconvert)
util_primconvert_destroy(ctx->primconvert);
if (ctx->in_fence_fd != -1)
close(ctx->in_fence_fd);
+ mtx_destroy(&ctx->lock);
+
FREE(pctx);
}
if (info->index_size) {
indexbuf = info->has_user_indices ? NULL : info->index.resource;
if (info->has_user_indices &&
- !util_upload_index_buffer(pctx, info, &indexbuf, &index_offset)) {
+ !util_upload_index_buffer(pctx, info, &indexbuf, &index_offset, 4)) {
BUG("Index buffer upload failed.");
return;
}
}
ctx->dirty |= ETNA_DIRTY_INDEX_BUFFER;
- struct etna_shader_key key = {};
- struct etna_surface *cbuf = etna_surface(pfb->cbufs[0]);
+ struct etna_shader_key key = {
+ .front_ccw = ctx->rasterizer->front_ccw,
+ };
- if (cbuf) {
- struct etna_resource *res = etna_resource(cbuf->base.texture);
-
- key.frag_rb_swap = !!translate_rs_format_rb_swap(res->base.format);
- }
+ if (pfb->cbufs[0])
+ key.frag_rb_swap = !!translate_pe_format_rb_swap(pfb->cbufs[0]->format);
if (!etna_get_vs(ctx, key) || !etna_get_fs(ctx, key)) {
BUG("compiled shaders are not okay");
if (!etna_state_update(ctx))
return;
+ mtx_lock(&ctx->lock);
+
/*
* Figure out the buffers/features we need:
*/
}
/* Mark constant buffers as being read */
- resource_read(ctx, ctx->constant_buffer[PIPE_SHADER_VERTEX].buffer);
- resource_read(ctx, ctx->constant_buffer[PIPE_SHADER_FRAGMENT].buffer);
+ for (unsigned i = 0; i < ETNA_MAX_CONST_BUF; i++) {
+ resource_read(ctx, ctx->constant_buffer[PIPE_SHADER_VERTEX][i].buffer);
+ resource_read(ctx, ctx->constant_buffer[PIPE_SHADER_FRAGMENT][i].buffer);
+ }
/* Mark VBOs as being read */
- for (i = 0; i < ctx->vertex_buffer.count; i++) {
+ foreach_bit(i, ctx->vertex_buffer.enabled_mask) {
assert(!ctx->vertex_buffer.vb[i].is_user_buffer);
resource_read(ctx, ctx->vertex_buffer.vb[i].buffer.resource);
}
resource_read(ctx, indexbuf);
/* Mark textures as being read */
- for (i = 0; i < PIPE_MAX_SAMPLERS; i++)
- if (ctx->sampler_view[i])
- resource_read(ctx, ctx->sampler_view[i]->texture);
+ for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
+ if (ctx->sampler_view[i]) {
+ resource_read(ctx, ctx->sampler_view[i]->texture);
+
+ /* if texture was modified since the last update,
+ * we need to clear the texture cache and possibly
+ * resolve/update ts
+ */
+ etna_update_sampler_source(ctx->sampler_view[i], i);
+ }
+ }
list_for_each_entry(struct etna_hw_query, hq, &ctx->active_hw_queries, node)
resource_written(ctx, hq->prsc);
if (ctx->specs.halti >= 2) {
/* On HALTI2+ (GC3000 and higher) only use instanced drawing commands, as the blob does */
- etna_draw_instanced(ctx->stream, info->index_size, draw_mode, 1,
+ etna_draw_instanced(ctx->stream, info->index_size, draw_mode, info->instance_count,
info->count, info->index_size ? info->index_bias : info->start);
} else {
if (info->index_size)
* draw op has caused the hang. */
etna_stall(ctx->stream, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE);
}
+ mtx_unlock(&ctx->lock);
if (DBG_ENABLED(ETNA_DBG_FLUSH_ALL))
pctx->flush(pctx, NULL, 0);
- if (ctx->framebuffer.cbuf)
- etna_resource(ctx->framebuffer.cbuf->texture)->seqno++;
- if (ctx->framebuffer.zsbuf)
- etna_resource(ctx->framebuffer.zsbuf->texture)->seqno++;
+ if (ctx->framebuffer_s.cbufs[0])
+ etna_resource(ctx->framebuffer_s.cbufs[0]->texture)->seqno++;
+ if (ctx->framebuffer_s.zsbuf)
+ etna_resource(ctx->framebuffer_s.zsbuf->texture)->seqno++;
if (info->index_size && indexbuf != info->index.resource)
pipe_resource_reference(&indexbuf, NULL);
}
+static void
+etna_reset_gpu_state(struct etna_context *ctx)
+{
+ struct etna_cmd_stream *stream = ctx->stream;
+
+ etna_set_state(stream, VIVS_GL_API_MODE, VIVS_GL_API_MODE_OPENGL);
+ etna_set_state(stream, VIVS_GL_VERTEX_ELEMENT_CONFIG, 0x00000001);
+ /* blob sets this to 0x40000031 on GC7000, seems to make no difference,
+ * but keep it in mind if depth behaves strangely. */
+ etna_set_state(stream, VIVS_RA_EARLY_DEPTH, 0x00000031);
+ etna_set_state(stream, VIVS_PA_W_CLIP_LIMIT, 0x34000001);
+ etna_set_state(stream, VIVS_PA_FLAGS, 0x00000000); /* blob sets ZCONVERT_BYPASS on GC3000+, this messes up z for us */
+ etna_set_state(stream, VIVS_PA_VIEWPORT_UNK00A80, 0x38a01404);
+ etna_set_state(stream, VIVS_PA_VIEWPORT_UNK00A84, fui(8192.0));
+ etna_set_state(stream, VIVS_PA_ZFARCLIPPING, 0x00000000);
+ etna_set_state(stream, VIVS_RA_HDEPTH_CONTROL, 0x00007000);
+ etna_set_state(stream, VIVS_PS_CONTROL_EXT, 0x00000000);
+
+ /* There is no HALTI0 specific state */
+ if (ctx->specs.halti >= 1) { /* Only on HALTI1+ */
+ etna_set_state(stream, VIVS_VS_HALTI1_UNK00884, 0x00000808);
+ }
+ if (ctx->specs.halti >= 2) { /* Only on HALTI2+ */
+ etna_set_state(stream, VIVS_RA_UNK00E0C, 0x00000000);
+ }
+ if (ctx->specs.halti >= 3) { /* Only on HALTI3+ */
+ etna_set_state(stream, VIVS_PS_HALTI3_UNK0103C, 0x76543210);
+ }
+ if (ctx->specs.halti >= 4) { /* Only on HALTI4+ */
+ etna_set_state(stream, VIVS_PS_MSAA_CONFIG, 0x6fffffff & 0xf70fffff & 0xfff6ffff &
+ 0xffff6fff & 0xfffff6ff & 0xffffff7f);
+ etna_set_state(stream, VIVS_PE_HALTI4_UNK014C0, 0x00000000);
+ }
+ if (ctx->specs.halti >= 5) { /* Only on HALTI5+ */
+ etna_set_state(stream, VIVS_NTE_DESCRIPTOR_UNK14C40, 0x00000001);
+ etna_set_state(stream, VIVS_FE_HALTI5_UNK007D8, 0x00000002);
+ etna_set_state(stream, VIVS_FE_HALTI5_ID_CONFIG, 0x00000000);
+ etna_set_state(stream, VIVS_PS_SAMPLER_BASE, 0x00000000);
+ etna_set_state(stream, VIVS_VS_SAMPLER_BASE, 0x00000020);
+ etna_set_state(stream, VIVS_SH_CONFIG, VIVS_SH_CONFIG_RTNE_ROUNDING);
+ } else { /* Only on pre-HALTI5 */
+ etna_set_state(stream, VIVS_GL_UNK03834, 0x00000000);
+ etna_set_state(stream, VIVS_GL_UNK03838, 0x00000000);
+ etna_set_state(stream, VIVS_GL_UNK03854, 0x00000000);
+ }
+
+ if (!ctx->specs.use_blt) {
+ /* Enable SINGLE_BUFFER for resolve, if supported */
+ etna_set_state(stream, VIVS_RS_SINGLE_BUFFER, COND(ctx->specs.single_buffer, VIVS_RS_SINGLE_BUFFER_ENABLE));
+ }
+
+ if (ctx->specs.halti >= 5) {
+ /* TXDESC cache flush - do this once at the beginning, as texture
+ * descriptors are only written by the CPU once, then patched by the kernel
+ * before command stream submission. It does not need flushing if the
+ * referenced image data changes.
+ */
+ etna_set_state(stream, VIVS_NTE_DESCRIPTOR_FLUSH, 0);
+ etna_set_state(stream, VIVS_GL_FLUSH_CACHE,
+ VIVS_GL_FLUSH_CACHE_DESCRIPTOR_UNK12 |
+ VIVS_GL_FLUSH_CACHE_DESCRIPTOR_UNK13);
+
+ /* Icache invalidate (should do this on shader change?) */
+ etna_set_state(stream, VIVS_VS_ICACHE_INVALIDATE,
+ VIVS_VS_ICACHE_INVALIDATE_UNK0 | VIVS_VS_ICACHE_INVALIDATE_UNK1 |
+ VIVS_VS_ICACHE_INVALIDATE_UNK2 | VIVS_VS_ICACHE_INVALIDATE_UNK3 |
+ VIVS_VS_ICACHE_INVALIDATE_UNK4);
+ }
+
+ ctx->dirty = ~0L;
+ ctx->dirty_sampler_views = ~0L;
+}
+
static void
etna_flush(struct pipe_context *pctx, struct pipe_fence_handle **fence,
enum pipe_flush_flags flags)
struct etna_context *ctx = etna_context(pctx);
int out_fence_fd = -1;
+ mtx_lock(&ctx->lock);
+
list_for_each_entry(struct etna_hw_query, hq, &ctx->active_hw_queries, node)
etna_hw_query_suspend(hq, ctx);
- etna_cmd_stream_flush2(ctx->stream, ctx->in_fence_fd,
- (flags & PIPE_FLUSH_FENCE_FD) ? &out_fence_fd :
- NULL);
+ etna_cmd_stream_flush(ctx->stream, ctx->in_fence_fd,
+ (flags & PIPE_FLUSH_FENCE_FD) ? &out_fence_fd : NULL);
list_for_each_entry(struct etna_hw_query, hq, &ctx->active_hw_queries, node)
etna_hw_query_resume(hq, ctx);
if (fence)
*fence = etna_fence_create(pctx, out_fence_fd);
-}
-static void
-etna_cmd_stream_reset_notify(struct etna_cmd_stream *stream, void *priv)
-{
- struct etna_context *ctx = priv;
- struct etna_resource *rsc, *rsc_tmp;
+ /*
+ * Go through all _resources_ pending in this _context_ and mark them as
+ * not pending in this _context_ anymore, since they were just flushed.
+ */
+ set_foreach(ctx->used_resources_read, entry) {
+ struct etna_resource *rsc = (struct etna_resource *)entry->key;
+ struct pipe_resource *referenced = &rsc->base;
- etna_set_state(stream, VIVS_GL_API_MODE, VIVS_GL_API_MODE_OPENGL);
- etna_set_state(stream, VIVS_GL_VERTEX_ELEMENT_CONFIG, 0x00000001);
- etna_set_state(stream, VIVS_RA_EARLY_DEPTH, 0x00000031);
- etna_set_state(stream, VIVS_PA_W_CLIP_LIMIT, 0x34000001);
- etna_set_state(stream, VIVS_PA_FLAGS, 0x00000000); /* blob sets ZCONVERT_BYPASS on GC3000, this messes up z for us */
- etna_set_state(stream, VIVS_RA_UNK00E0C, 0x00000000);
- etna_set_state(stream, VIVS_PA_VIEWPORT_UNK00A80, 0x38a01404);
- etna_set_state(stream, VIVS_PA_VIEWPORT_UNK00A84, fui(8192.0));
- etna_set_state(stream, VIVS_PA_ZFARCLIPPING, 0x00000000);
- etna_set_state(stream, VIVS_PE_ALPHA_COLOR_EXT0, 0x00000000);
- etna_set_state(stream, VIVS_PE_ALPHA_COLOR_EXT1, 0x00000000);
- etna_set_state(stream, VIVS_RA_HDEPTH_CONTROL, 0x00007000);
- etna_set_state(stream, VIVS_PE_STENCIL_CONFIG_EXT2, 0x00000000);
- etna_set_state(stream, VIVS_GL_UNK03834, 0x00000000);
- etna_set_state(stream, VIVS_GL_UNK03838, 0x00000000);
- etna_set_state(stream, VIVS_GL_UNK03854, 0x00000000);
- etna_set_state(stream, VIVS_PS_CONTROL_EXT, 0x00000000);
+ _mesa_set_remove_key(rsc->pending_ctx, ctx);
- if (!ctx->specs.use_blt) {
- /* Enable SINGLE_BUFFER for resolve, if supported */
- etna_set_state(stream, VIVS_RS_SINGLE_BUFFER, COND(ctx->specs.single_buffer, VIVS_RS_SINGLE_BUFFER_ENABLE));
+ /* if resource has no pending ctx's reset its status */
+ if (_mesa_set_next_entry(rsc->pending_ctx, NULL) == NULL)
+ rsc->status &= ~ETNA_PENDING_READ;
+
+ pipe_resource_reference(&referenced, NULL);
}
+ _mesa_set_clear(ctx->used_resources_read, NULL);
- ctx->dirty = ~0L;
+ set_foreach(ctx->used_resources_write, entry) {
+ struct etna_resource *rsc = (struct etna_resource *)entry->key;
+ struct pipe_resource *referenced = &rsc->base;
+
+ _mesa_set_remove_key(rsc->pending_ctx, ctx);
- /* go through all the used resources and clear their status flag */
- LIST_FOR_EACH_ENTRY_SAFE(rsc, rsc_tmp, &ctx->used_resources, list)
- {
- debug_assert(rsc->status != 0);
- rsc->status = 0;
- rsc->pending_ctx = NULL;
- list_delinit(&rsc->list);
+ /* if resource has no pending ctx's reset its status */
+ if (_mesa_set_next_entry(rsc->pending_ctx, NULL) == NULL)
+ rsc->status &= ~ETNA_PENDING_WRITE;
+
+ pipe_resource_reference(&referenced, NULL);
}
+ _mesa_set_clear(ctx->used_resources_write, NULL);
+
+ etna_reset_gpu_state(ctx);
+ mtx_unlock(&ctx->lock);
+}
+
+static void
+etna_context_force_flush(struct etna_cmd_stream *stream, void *priv)
+{
+ struct pipe_context *pctx = priv;
+
+ pctx->flush(pctx, NULL, 0);
- assert(LIST_IS_EMPTY(&ctx->used_resources));
}
static void
pctx->const_uploader = pctx->stream_uploader;
screen = etna_screen(pscreen);
- ctx->stream = etna_cmd_stream_new(screen->pipe, 0x2000, &etna_cmd_stream_reset_notify, ctx);
+ ctx->stream = etna_cmd_stream_new(screen->pipe, 0x2000,
+ &etna_context_force_flush, pctx);
if (ctx->stream == NULL)
goto fail;
+ ctx->used_resources_read = _mesa_set_create(NULL, _mesa_hash_pointer,
+ _mesa_key_pointer_equal);
+ if (!ctx->used_resources_read)
+ goto fail;
+
+ ctx->used_resources_write = _mesa_set_create(NULL, _mesa_hash_pointer,
+ _mesa_key_pointer_equal);
+ if (!ctx->used_resources_write)
+ goto fail;
+
+ mtx_init(&ctx->lock, mtx_recursive);
+
/* context ctxate setup */
ctx->specs = screen->specs;
ctx->screen = screen;
/* need some sane default in case state tracker doesn't set some state: */
ctx->sample_mask = 0xffff;
- list_inithead(&ctx->used_resources);
-
/* Set sensible defaults for state */
- etna_cmd_stream_reset_notify(ctx->stream, ctx);
+ etna_reset_gpu_state(ctx);
ctx->in_fence_fd = -1;
1 << PIPE_PRIM_LINES |
1 << PIPE_PRIM_LINE_STRIP |
1 << PIPE_PRIM_TRIANGLES |
- 1 << PIPE_PRIM_TRIANGLE_STRIP |
1 << PIPE_PRIM_TRIANGLE_FAN;
+ /* TODO: The bug relates only to indexed draws, but here we signal
+ * that there is no support for triangle strips at all. This should
+ * be refined.
+ */
+ if (VIV_FEATURE(ctx->screen, chipMinorFeatures2, BUG_FIXES8))
+ ctx->prim_hwsupport |= 1 << PIPE_PRIM_TRIANGLE_STRIP;
+
if (VIV_FEATURE(ctx->screen, chipMinorFeatures2, LINE_LOOP))
ctx->prim_hwsupport |= 1 << PIPE_PRIM_LINE_LOOP;
slab_create_child(&ctx->transfer_pool, &screen->transfer_pool);
list_inithead(&ctx->active_hw_queries);
+ /* create dummy RT buffer, used when rendering with no color buffer */
+ ctx->dummy_rt = etna_bo_new(ctx->screen->dev, 64 * 64 * 4,
+ DRM_ETNA_GEM_CACHE_WC);
+ if (!ctx->dummy_rt)
+ goto fail;
+
+ ctx->dummy_rt_reloc.bo = ctx->dummy_rt;
+ ctx->dummy_rt_reloc.offset = 0;
+ ctx->dummy_rt_reloc.flags = ETNA_RELOC_READ | ETNA_RELOC_WRITE;
+
+ if (screen->specs.halti >= 5) {
+ /* Create an empty dummy texture descriptor */
+ ctx->dummy_desc_bo = etna_bo_new(ctx->screen->dev, 0x100, DRM_ETNA_GEM_CACHE_WC);
+ if (!ctx->dummy_desc_bo)
+ goto fail;
+ uint32_t *buf = etna_bo_map(ctx->dummy_desc_bo);
+ etna_bo_cpu_prep(ctx->dummy_desc_bo, DRM_ETNA_PREP_WRITE);
+ memset(buf, 0, 0x100);
+ etna_bo_cpu_fini(ctx->dummy_desc_bo);
+ ctx->DUMMY_DESC_ADDR.bo = ctx->dummy_desc_bo;
+ ctx->DUMMY_DESC_ADDR.offset = 0;
+ ctx->DUMMY_DESC_ADDR.flags = ETNA_RELOC_READ;
+ }
+
return pctx;
fail: