Mesa (main): radv: adjust num_records when offset>stride

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Jul 6 13:15:46 UTC 2021


Module: Mesa
Branch: main
Commit: a2ac660eb7ab27326e7ad8cf35b14e2f5e05f011
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=a2ac660eb7ab27326e7ad8cf35b14e2f5e05f011

Author: Rhys Perry <pendingchaos02 at gmail.com>
Date:   Tue Jun 29 16:30:00 2021 +0100

radv: adjust num_records when offset>stride

If an attribute's offset is larger than the stride, the compiler will
increase the vertex index and use offset%stride instead as the offset.

Signed-off-by: Rhys Perry <pendingchaos02 at gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/5007
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11642>

---

 src/amd/vulkan/radv_cmd_buffer.c | 12 +++++++++---
 src/amd/vulkan/radv_pipeline.c   |  3 +++
 src/amd/vulkan/radv_private.h    |  1 +
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/amd/vulkan/radv_cmd_buffer.c b/src/amd/vulkan/radv_cmd_buffer.c
index b73116accc5..ec7e11e20cd 100644
--- a/src/amd/vulkan/radv_cmd_buffer.c
+++ b/src/amd/vulkan/radv_cmd_buffer.c
@@ -2904,12 +2904,18 @@ radv_flush_vertex_descriptors(struct radv_cmd_buffer *cmd_buffer, bool pipeline_
          if (pipeline->use_per_attribute_vb_descs) {
             uint32_t attrib_end = pipeline->attrib_ends[i];
 
-            if (num_records < attrib_end)
+            if (num_records < attrib_end) {
                num_records = 0; /* not enough space for one vertex */
-            else if (stride == 0)
+            } else if (stride == 0) {
                num_records = 1; /* only one vertex */
-            else
+            } else {
                num_records = (num_records - attrib_end) / stride + 1;
+               /* If attrib_offset>stride, then the compiler will increase the vertex index by
+                * attrib_offset/stride and decrease the offset by attrib_offset%stride. This is
+                * only allowed with static strides.
+                */
+               num_records += pipeline->attrib_index_offset[i];
+            }
 
             /* GFX10 uses OOB_SELECT_RAW if stride==0, so convert num_records from elements into
              * into bytes in that case. GFX8 always uses bytes.
diff --git a/src/amd/vulkan/radv_pipeline.c b/src/amd/vulkan/radv_pipeline.c
index fb1d95e63cf..5de27eeb85f 100644
--- a/src/amd/vulkan/radv_pipeline.c
+++ b/src/amd/vulkan/radv_pipeline.c
@@ -5316,6 +5316,9 @@ radv_pipeline_init_vertex_input_state(struct radv_pipeline *pipeline,
 
       uint32_t end = desc->offset + vk_format_get_blocksize(desc->format);
       pipeline->attrib_ends[desc->location] = end;
+      if (pipeline->binding_stride[desc->binding])
+         pipeline->attrib_index_offset[desc->location] =
+            desc->offset / pipeline->binding_stride[desc->binding];
       pipeline->attrib_bindings[desc->location] = desc->binding;
    }
 
diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h
index 39ab7b50322..7c8eee3de92 100644
--- a/src/amd/vulkan/radv_private.h
+++ b/src/amd/vulkan/radv_private.h
@@ -1730,6 +1730,7 @@ struct radv_pipeline {
 
    uint8_t attrib_bindings[MAX_VERTEX_ATTRIBS];
    uint32_t attrib_ends[MAX_VERTEX_ATTRIBS];
+   uint32_t attrib_index_offset[MAX_VERTEX_ATTRIBS];
 
    bool use_per_attribute_vb_descs;
    uint32_t vb_desc_usage_mask;



More information about the mesa-commit mailing list