etnaviv: enable texture upload memory throttling
[mesa.git] / src / gallium / drivers / etnaviv / etnaviv_context.c
index f2f709cbf24f1365d2d282d075f59c80822d29ec..df8c00c55563618f079a6ca9e4a31ec2d598b76f 100644 (file)
@@ -34,7 +34,9 @@
 #include "etnaviv_emit.h"
 #include "etnaviv_fence.h"
 #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"
@@ -46,6 +48,7 @@
 
 #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"
@@ -59,6 +62,44 @@ etna_context_destroy(struct pipe_context *pctx)
 {
    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);
 
@@ -73,6 +114,11 @@ etna_context_destroy(struct pipe_context *pctx)
 
    slab_destroy_child(&ctx->transfer_pool);
 
+   if (ctx->in_fence_fd != -1)
+      close(ctx->in_fence_fd);
+
+   mtx_destroy(&ctx->lock);
+
    FREE(pctx);
 }
 
@@ -89,7 +135,7 @@ etna_update_state_for_draw(struct etna_context *ctx, const struct pipe_draw_info
     *   buffer state as dirty
     */
 
-   if (info->indexed) {
+   if (info->index_size) {
       uint32_t new_control = ctx->index_buffer.FE_INDEX_STREAM_CONTROL;
 
       if (info->primitive_restart)
@@ -146,12 +192,16 @@ etna_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
    uint32_t draw_mode;
    unsigned i;
 
+   if (!info->count_from_stream_output && !info->indirect &&
+       !info->primitive_restart &&
+       !u_trim_pipe_prim(info->mode, (unsigned*)&info->count))
+      return;
+
    if (ctx->vertex_elements == NULL || ctx->vertex_elements->num_elements == 0)
       return; /* Nothing to do */
 
    if (!(ctx->prim_hwsupport & (1 << info->mode))) {
       struct primconvert_context *primconvert = ctx->primconvert;
-      util_primconvert_save_index_buffer(primconvert, &ctx->index_buffer.ib);
       util_primconvert_save_rasterizer_state(primconvert, ctx->rasterizer);
       util_primconvert_draw_vbo(primconvert, info);
       return;
@@ -170,27 +220,42 @@ etna_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
    }
 
    /* Upload a user index buffer. */
-   struct pipe_index_buffer ibuffer_saved = {};
-   if (info->indexed && ctx->index_buffer.ib.user_buffer &&
-       !util_save_and_upload_index_buffer(pctx, info, &ctx->index_buffer.ib,
-                                          &ibuffer_saved)) {
-      BUG("Index buffer upload failed.");
-      return;
-   }
+   unsigned index_offset = 0;
+   struct pipe_resource *indexbuf = NULL;
+
+   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, 4)) {
+         BUG("Index buffer upload failed.");
+         return;
+      }
+      /* Add start to index offset, when rendering indexed */
+      index_offset += info->start * info->index_size;
 
-   if (info->indexed && !ctx->index_buffer.FE_INDEX_STREAM_BASE_ADDR.bo) {
-      BUG("Unsupported or no index buffer");
-      return;
-   }
+      ctx->index_buffer.FE_INDEX_STREAM_BASE_ADDR.bo = etna_resource(indexbuf)->bo;
+      ctx->index_buffer.FE_INDEX_STREAM_BASE_ADDR.offset = index_offset;
+      ctx->index_buffer.FE_INDEX_STREAM_BASE_ADDR.flags = ETNA_RELOC_READ;
+      ctx->index_buffer.FE_INDEX_STREAM_CONTROL = translate_index_size(info->index_size);
 
-   struct etna_shader_key key = {};
-   struct etna_surface *cbuf = etna_surface(pfb->cbufs[0]);
+      if (!ctx->index_buffer.FE_INDEX_STREAM_BASE_ADDR.bo) {
+         BUG("Unsupported or no index buffer");
+         return;
+      }
+   } else {
+      ctx->index_buffer.FE_INDEX_STREAM_BASE_ADDR.bo = 0;
+      ctx->index_buffer.FE_INDEX_STREAM_BASE_ADDR.offset = 0;
+      ctx->index_buffer.FE_INDEX_STREAM_BASE_ADDR.flags = 0;
+      ctx->index_buffer.FE_INDEX_STREAM_CONTROL = 0;
+   }
+   ctx->dirty |= ETNA_DIRTY_INDEX_BUFFER;
 
-   if (cbuf) {
-      struct etna_resource *res = etna_resource(cbuf->base.texture);
+   struct etna_shader_key key = {
+      .front_ccw = ctx->rasterizer->front_ccw,
+   };
 
-      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");
@@ -201,6 +266,8 @@ etna_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
    if (!etna_state_update(ctx))
       return;
 
+   mtx_lock(&ctx->lock);
+
    /*
     * Figure out the buffers/features we need:
     */
@@ -221,22 +288,35 @@ etna_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
    }
 
    /* 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++) {
-      assert(!ctx->vertex_buffer.vb[i].user_buffer);
-      resource_read(ctx, ctx->vertex_buffer.vb[i].buffer);
+   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);
    }
 
    /* Mark index buffer as being read */
-   resource_read(ctx, ctx->index_buffer.ib.buffer);
+   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);
 
    ctx->stats.prims_emitted += u_reduced_prims_for_vertices(info->mode, info->count);
    ctx->stats.draw_calls++;
@@ -247,10 +327,16 @@ etna_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
    /* First, sync state, then emit DRAW_PRIMITIVES or DRAW_INDEXED_PRIMITIVES */
    etna_emit_state(ctx);
 
-   if (info->indexed)
-      etna_draw_indexed_primitives(ctx->stream, draw_mode, info->start, prims, info->index_bias);
-   else
-      etna_draw_primitives(ctx->stream, draw_mode, info->start, prims);
+   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, info->instance_count,
+         info->count, info->index_size ? info->index_bias : info->start);
+   } else {
+      if (info->index_size)
+         etna_draw_indexed_primitives(ctx->stream, draw_mode, 0, prims, info->index_bias);
+      else
+         etna_draw_primitives(ctx->stream, draw_mode, info->start, prims);
+   }
 
    if (DBG_ENABLED(ETNA_DBG_DRAW_STALL)) {
       /* Stall the FE after every draw operation.  This allows better
@@ -258,16 +344,90 @@ etna_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
        * 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 (info->indexed && ibuffer_saved.user_buffer)
-      pctx->set_index_buffer(pctx, &ibuffer_saved);
+   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
@@ -275,39 +435,65 @@ 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_flush(ctx->stream);
+   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);
-}
+      *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);
+      _mesa_set_remove_key(rsc->pending_ctx, ctx);
 
-   /* 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;
 
-   ctx->dirty = ~0L;
+      pipe_resource_reference(&referenced, NULL);
+   }
+   _mesa_set_clear(ctx->used_resources_read, NULL);
 
-   /* 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);
+   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);
+
+      /* 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
@@ -341,25 +527,40 @@ etna_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
    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;
 
    pctx->destroy = etna_context_destroy;
    pctx->draw_vbo = etna_draw_vbo;
    pctx->flush = etna_flush;
    pctx->set_debug_callback = etna_set_debug_callback;
+   pctx->create_fence_fd = etna_create_fence_fd;
+   pctx->fence_server_sync = etna_fence_server_sync;
 
    /* creation of compile states */
    pctx->create_blend_state = etna_blend_state_create;
@@ -383,9 +584,15 @@ etna_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
                          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;
 
@@ -394,6 +601,31 @@ etna_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
       goto fail;
 
    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;