anv/device: keep track of 'device lost' state
[mesa.git] / src / intel / vulkan / anv_batch_chain.c
index 6f05867ff71dc29bfe332fbc604d0a23523d4523..5d7abc68b32fa87ac257738ff843e0deed1dda9a 100644 (file)
@@ -29,7 +29,6 @@
 
 #include "anv_private.h"
 
-#include "genxml/gen7_pack.h"
 #include "genxml/gen8_pack.h"
 
 #include "util/debug.h"
@@ -141,7 +140,7 @@ anv_reloc_list_grow(struct anv_reloc_list *list,
    return VK_SUCCESS;
 }
 
-uint64_t
+VkResult
 anv_reloc_list_add(struct anv_reloc_list *list,
                    const VkAllocationCallbacks *alloc,
                    uint32_t offset, struct anv_bo *target_bo, uint32_t delta)
@@ -152,8 +151,9 @@ anv_reloc_list_add(struct anv_reloc_list *list,
    const uint32_t domain =
       target_bo->is_winsys_bo ? I915_GEM_DOMAIN_RENDER : 0;
 
-   anv_reloc_list_grow(list, alloc, 1);
-   /* TODO: Handle failure */
+   VkResult result = anv_reloc_list_grow(list, alloc, 1);
+   if (result != VK_SUCCESS)
+      return result;
 
    /* XXX: Can we use I915_EXEC_HANDLE_LUT? */
    index = list->num_relocs++;
@@ -167,16 +167,17 @@ anv_reloc_list_add(struct anv_reloc_list *list,
    entry->write_domain = domain;
    VG(VALGRIND_CHECK_MEM_IS_DEFINED(entry, sizeof(*entry)));
 
-   return target_bo->offset + delta;
+   return VK_SUCCESS;
 }
 
-static void
+static VkResult
 anv_reloc_list_append(struct anv_reloc_list *list,
                       const VkAllocationCallbacks *alloc,
                       struct anv_reloc_list *other, uint32_t offset)
 {
-   anv_reloc_list_grow(list, alloc, other->num_relocs);
-   /* TODO: Handle failure */
+   VkResult result = anv_reloc_list_grow(list, alloc, other->num_relocs);
+   if (result != VK_SUCCESS)
+      return result;
 
    memcpy(&list->relocs[list->num_relocs], &other->relocs[0],
           other->num_relocs * sizeof(other->relocs[0]));
@@ -187,6 +188,7 @@ anv_reloc_list_append(struct anv_reloc_list *list,
       list->relocs[i + list->num_relocs].offset += offset;
 
    list->num_relocs += other->num_relocs;
+   return VK_SUCCESS;
 }
 
 /*-----------------------------------------------------------------------*
@@ -196,8 +198,13 @@ anv_reloc_list_append(struct anv_reloc_list *list,
 void *
 anv_batch_emit_dwords(struct anv_batch *batch, int num_dwords)
 {
-   if (batch->next + num_dwords * 4 > batch->end)
-      batch->extend_cb(batch, batch->user_data);
+   if (batch->next + num_dwords * 4 > batch->end) {
+      VkResult result = batch->extend_cb(batch, batch->user_data);
+      if (result != VK_SUCCESS) {
+         anv_batch_set_error(batch, result);
+         return NULL;
+      }
+   }
 
    void *p = batch->next;
 
@@ -211,8 +218,14 @@ uint64_t
 anv_batch_emit_reloc(struct anv_batch *batch,
                      void *location, struct anv_bo *bo, uint32_t delta)
 {
-   return anv_reloc_list_add(batch->relocs, batch->alloc,
-                             location - batch->start, bo, delta);
+   VkResult result = anv_reloc_list_add(batch->relocs, batch->alloc,
+                                        location - batch->start, bo, delta);
+   if (result != VK_SUCCESS) {
+      anv_batch_set_error(batch, result);
+      return 0;
+   }
+
+   return bo->offset + delta;
 }
 
 void
@@ -223,8 +236,13 @@ anv_batch_emit_batch(struct anv_batch *batch, struct anv_batch *other)
    size = other->next - other->start;
    assert(size % 4 == 0);
 
-   if (batch->next + size > batch->end)
-      batch->extend_cb(batch, batch->user_data);
+   if (batch->next + size > batch->end) {
+      VkResult result = batch->extend_cb(batch, batch->user_data);
+      if (result != VK_SUCCESS) {
+         anv_batch_set_error(batch, result);
+         return;
+      }
+   }
 
    assert(batch->next + size <= batch->end);
 
@@ -232,8 +250,12 @@ anv_batch_emit_batch(struct anv_batch *batch, struct anv_batch *other)
    memcpy(batch->next, other->start, size);
 
    offset = batch->next - batch->start;
-   anv_reloc_list_append(batch->relocs, batch->alloc,
-                         other->relocs, offset);
+   VkResult result = anv_reloc_list_append(batch->relocs, batch->alloc,
+                                           other->relocs, offset);
+   if (result != VK_SUCCESS) {
+      anv_batch_set_error(batch, result);
+      return;
+   }
 
    batch->next += size;
 }
@@ -449,6 +471,9 @@ emit_batch_buffer_start(struct anv_cmd_buffer *cmd_buffer,
     * gens.
     */
 
+#define GEN7_MI_BATCH_BUFFER_START_length      2
+#define GEN7_MI_BATCH_BUFFER_START_length_bias      2
+
    const uint32_t gen7_length =
       GEN7_MI_BATCH_BUFFER_START_length - GEN7_MI_BATCH_BUFFER_START_length_bias;
    const uint32_t gen8_length =
@@ -620,7 +645,9 @@ anv_cmd_buffer_alloc_binding_table(struct anv_cmd_buffer *cmd_buffer,
 struct anv_state
 anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer *cmd_buffer)
 {
-   return anv_state_stream_alloc(&cmd_buffer->surface_state_stream, 64, 64);
+   struct isl_device *isl_dev = &cmd_buffer->device->isl_dev;
+   return anv_state_stream_alloc(&cmd_buffer->surface_state_stream,
+                                 isl_dev->ss.size, isl_dev->ss.align);
 }
 
 struct anv_state
@@ -638,8 +665,10 @@ anv_cmd_buffer_new_binding_table_block(struct anv_cmd_buffer *cmd_buffer)
        &cmd_buffer->device->surface_state_block_pool;
 
    int32_t *offset = u_vector_add(&cmd_buffer->bt_blocks);
-   if (offset == NULL)
+   if (offset == NULL) {
+      anv_batch_set_error(&cmd_buffer->batch, VK_ERROR_OUT_OF_HOST_MEMORY);
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
+   }
 
    *offset = anv_block_pool_alloc_back(block_pool);
    cmd_buffer->bt_next = 0;
@@ -692,7 +721,9 @@ anv_cmd_buffer_init_batch_bo_chain(struct anv_cmd_buffer *cmd_buffer)
       goto fail_bt_blocks;
    cmd_buffer->last_ss_pool_center = 0;
 
-   anv_cmd_buffer_new_binding_table_block(cmd_buffer);
+   result = anv_cmd_buffer_new_binding_table_block(cmd_buffer);
+   if (result != VK_SUCCESS)
+      goto fail_bt_blocks;
 
    return VK_SUCCESS;
 
@@ -777,11 +808,11 @@ anv_cmd_buffer_end_batch_buffer(struct anv_cmd_buffer *cmd_buffer)
       cmd_buffer->batch.end += GEN8_MI_BATCH_BUFFER_START_length * 4;
       assert(cmd_buffer->batch.end == batch_bo->bo.map + batch_bo->bo.size);
 
-      anv_batch_emit(&cmd_buffer->batch, GEN7_MI_BATCH_BUFFER_END, bbe);
+      anv_batch_emit(&cmd_buffer->batch, GEN8_MI_BATCH_BUFFER_END, bbe);
 
       /* Round batch up to an even number of dwords. */
       if ((cmd_buffer->batch.next - cmd_buffer->batch.start) & 4)
-         anv_batch_emit(&cmd_buffer->batch, GEN7_MI_NOOP, noop);
+         anv_batch_emit(&cmd_buffer->batch, GEN8_MI_NOOP, noop);
 
       cmd_buffer->exec_mode = ANV_CMD_BUFFER_EXEC_MODE_PRIMARY;
    }
@@ -1059,7 +1090,7 @@ write_reloc(const struct anv_device *device, void *p, uint64_t v, bool flush)
    }
 
    if (flush && !device->info.has_llc)
-      anv_clflush_range(p, reloc_size);
+      anv_flush_range(p, reloc_size);
 }
 
 static void
@@ -1232,8 +1263,11 @@ anv_cmd_buffer_execbuf(struct anv_device *device,
 
    adjust_relocations_from_state_pool(ss_pool, &cmd_buffer->surface_relocs,
                                       cmd_buffer->last_ss_pool_center);
-   anv_execbuf_add_bo(&execbuf, &ss_pool->bo, &cmd_buffer->surface_relocs,
-                      &cmd_buffer->pool->alloc);
+   VkResult result =
+      anv_execbuf_add_bo(&execbuf, &ss_pool->bo, &cmd_buffer->surface_relocs,
+                         &cmd_buffer->pool->alloc);
+   if (result != VK_SUCCESS)
+      return result;
 
    /* First, we walk over all of the bos we've seen and add them and their
     * relocations to the validate list.
@@ -1349,7 +1383,7 @@ anv_cmd_buffer_execbuf(struct anv_device *device,
          cmd_buffer->surface_relocs.relocs[i].presumed_offset = -1;
    }
 
-   VkResult result = anv_device_execbuf(device, &execbuf.execbuf, execbuf.bos);
+   result = anv_device_execbuf(device, &execbuf.execbuf, execbuf.bos);
 
    anv_execbuf_finish(&execbuf, &cmd_buffer->pool->alloc);