vk: Do relocations in surface states when they are created
authorJason Ekstrand <jason.ekstrand@intel.com>
Thu, 21 May 2015 22:55:27 +0000 (15:55 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Thu, 21 May 2015 22:55:29 +0000 (15:55 -0700)
Previously, we waited until later and did a pass through the used surfaces
and did the relocations then.  This lead to doing double-relocations which
was causing us to get bogus surface offsets.

src/vulkan/device.c
src/vulkan/meta.c
src/vulkan/private.h

index 745e5dd7090c79f4940f99d886cdd8145f886dec..3381729680ad185121ba6fb4f2ade02571f300e0 100644 (file)
@@ -2466,9 +2466,13 @@ void anv_CmdBindDescriptorSets(
                anv_cmd_buffer_alloc_surface_state(cmd_buffer, 64, 64);
             memcpy(state.map, view->surface_state.map, 64);
 
+            /* The address goes in dwords 8 and 9 of the SURFACE_STATE */
+            *(uint64_t *)(state.map + 8 * 4) =
+               anv_reloc_list_add(&cmd_buffer->surface_relocs,
+                                  state.offset + 8 * 4,
+                                  view->bo, view->offset);
+
             bindings->descriptors[s].surfaces[start + b] = state.offset;
-            bindings->descriptors[s].relocs[start + b].bo = view->bo;
-            bindings->descriptors[s].relocs[start + b].offset = view->offset;
          }
 
          start = layout->set[firstSet + i].sampler_start[s];
@@ -2553,34 +2557,12 @@ flush_descriptor_sets(struct anv_cmd_buffer *cmd_buffer)
 
       if (layers + surface_count > 0) {
          struct anv_state state;
-         uint32_t offset;
-         uint32_t *address;
          uint32_t size;
 
          size = (bias + surface_count) * sizeof(uint32_t);
          state = anv_cmd_buffer_alloc_surface_state(cmd_buffer, size, 32);
          memcpy(state.map, bindings->descriptors[s].surfaces, size);
 
-         for (uint32_t i = 0; i < layers; i++) {
-            offset = bindings->descriptors[s].surfaces[i] + 8 * sizeof(int32_t);
-            address = cmd_buffer->surface_bo.map + offset;
-
-            *address =
-               anv_reloc_list_add(&cmd_buffer->surface_relocs, offset,
-                                  bindings->descriptors[s].relocs[i].bo,
-                                  bindings->descriptors[s].relocs[i].offset);
-         }
-
-         for (uint32_t i = 0; i < surface_count; i++) {
-            offset = bindings->descriptors[s].surfaces[i] + 8 * sizeof(int32_t);
-            address = cmd_buffer->surface_bo.map + offset;
-
-            *address =
-               anv_reloc_list_add(&cmd_buffer->surface_relocs, offset,
-                                  bindings->descriptors[s].relocs[bias + i].bo,
-                                  bindings->descriptors[s].relocs[bias + i].offset);
-         }
-
          static const uint32_t binding_table_opcodes[] = {
             [VK_SHADER_STAGE_VERTEX] = 38,
             [VK_SHADER_STAGE_TESS_CONTROL] = 39,
@@ -3172,9 +3154,13 @@ anv_cmd_buffer_fill_render_targets(struct anv_cmd_buffer *cmd_buffer)
          anv_cmd_buffer_alloc_surface_state(cmd_buffer, 64, 64);
       memcpy(state.map, view->surface_state.map, 64);
 
+      /* The address goes in dwords 8 and 9 of the SURFACE_STATE */
+      *(uint64_t *)(state.map + 8 * 4) =
+         anv_reloc_list_add(&cmd_buffer->surface_relocs,
+                            state.offset + 8 * 4,
+                            view->bo, view->offset);
+
       bindings->descriptors[VK_SHADER_STAGE_FRAGMENT].surfaces[i] = state.offset;
-      bindings->descriptors[VK_SHADER_STAGE_FRAGMENT].relocs[i].bo = view->bo;
-      bindings->descriptors[VK_SHADER_STAGE_FRAGMENT].relocs[i].offset = view->offset;
    }
    cmd_buffer->dirty |= ANV_CMD_BUFFER_DESCRIPTOR_SET_DIRTY;
 }
index cd4fbaf87f3215c18fdb51fab27ab16c297a42b8..c4d245614ce0c913ded248593a12de2da560419d 100644 (file)
@@ -185,11 +185,6 @@ anv_cmd_buffer_copy_render_targets(struct anv_cmd_buffer *cmd_buffer,
    for (uint32_t i = 0; i < fb->color_attachment_count; i++) {
       bindings->descriptors[VK_SHADER_STAGE_FRAGMENT].surfaces[i] =
          old_bindings->descriptors[VK_SHADER_STAGE_FRAGMENT].surfaces[i];
-
-      bindings->descriptors[VK_SHADER_STAGE_FRAGMENT].relocs[i].bo =
-         old_bindings->descriptors[VK_SHADER_STAGE_FRAGMENT].relocs[i].bo;
-      bindings->descriptors[VK_SHADER_STAGE_FRAGMENT].relocs[i].offset =
-         old_bindings->descriptors[VK_SHADER_STAGE_FRAGMENT].relocs[i].offset;
    }
 
    cmd_buffer->dirty |= ANV_CMD_BUFFER_DESCRIPTOR_SET_DIRTY;
index f15856387d8b0225fc0dcd63a1405e29e013362a..e1d306f780e89c80ef59cc7a8a35bfbaa4de2b46 100644 (file)
@@ -530,10 +530,6 @@ struct anv_bindings {
 
    struct {
       uint32_t                                  surfaces[256];
-      struct {
-         struct anv_bo *bo;
-         uint32_t offset;
-      }                                         relocs[256];
       struct { uint32_t dwords[4]; }            samplers[16];
    }                                            descriptors[VK_NUM_SHADER_STAGE];
 };