[Mesa-dev] [PATCH 32/47] anv/cmd_buffer: Add a padding to the vertex buffer

Alejandro PiƱeiro apinheiro at igalia.com
Thu Aug 24 13:54:47 UTC 2017


As we are using 32-bit surface formats with 16-bit elements we can be
on a situation where a vertex element can poke over the buffer by 2
bytes. To avoid that we add a padding when flushing the state.

This is similar to what the i965 drivers prior to Haswell do, as they
use 4-component formats to fake 3-component formats, and add a padding
there too. See commit:
   7c8dfa78b98a12c1c5f74d11433c8554d4c90657
---
 src/intel/vulkan/genX_cmd_buffer.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/intel/vulkan/genX_cmd_buffer.c b/src/intel/vulkan/genX_cmd_buffer.c
index c5735b27e02..f0cedca62e5 100644
--- a/src/intel/vulkan/genX_cmd_buffer.c
+++ b/src/intel/vulkan/genX_cmd_buffer.c
@@ -1903,6 +1903,11 @@ genX(cmd_buffer_flush_state)(struct anv_cmd_buffer *cmd_buffer)
 {
    struct anv_pipeline *pipeline = cmd_buffer->state.pipeline;
    uint32_t *p;
+#if GEN_GEN >= 8
+   const struct brw_vs_prog_data *vs_prog_data = get_vs_prog_data(pipeline);
+   const uint64_t half_inputs_read = vs_prog_data->half_inputs_read;
+   const uint32_t elements_half = half_inputs_read >> VERT_ATTRIB_GENERIC0;
+#endif
 
    uint32_t vb_emit = cmd_buffer->state.vb_dirty & pipeline->vb_used;
 
@@ -1915,6 +1920,17 @@ genX(cmd_buffer_flush_state)(struct anv_cmd_buffer *cmd_buffer)
    if (vb_emit) {
       const uint32_t num_buffers = __builtin_popcount(vb_emit);
       const uint32_t num_dwords = 1 + num_buffers * 4;
+      /* ISL 16-bit formats do a 16-bit to 32-bit float conversion, so we need
+       * to use ISL 32-bit formats to avoid such conversion in order to support
+       * properly 16-bit formats. This means that the vertex element may poke
+       * over the end of the buffer by 2 bytes.
+       */
+      const unsigned padding =
+#if GEN_GEN >= 8
+         (elements_half > 0) * 2;
+#else
+      0;
+#endif
 
       p = anv_batch_emitn(&cmd_buffer->batch, num_dwords,
                           GENX(3DSTATE_VERTEX_BUFFERS));
@@ -1944,9 +1960,9 @@ genX(cmd_buffer_flush_state)(struct anv_cmd_buffer *cmd_buffer)
             .BufferStartingAddress = { buffer->bo, buffer->offset + offset },
 
 #if GEN_GEN >= 8
-            .BufferSize = buffer->size - offset
+            .BufferSize = buffer->size - offset + padding,
 #else
-            .EndAddress = { buffer->bo, buffer->offset + buffer->size - 1},
+            .EndAddress = { buffer->bo, buffer->offset + buffer->size + padding - 1},
 #endif
          };
 
-- 
2.11.0



More information about the mesa-dev mailing list