Mesa (master): v3dv: fix array sizes when tracking BOs during uniform setup

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Apr 15 11:38:49 UTC 2021


Module: Mesa
Branch: master
Commit: 917049e7d65ab6ebd2418339b4c6b4faf1325eb0
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=917049e7d65ab6ebd2418339b4c6b4faf1325eb0

Author: Iago Toral Quiroga <itoral at igalia.com>
Date:   Thu Apr 15 12:00:40 2021 +0200

v3dv: fix array sizes when tracking BOs during uniform setup

The resource indices we get point to descriptor map entries that include
all shader stages, so we need to size the arrays to account for more than
just one stage.

For now we only support up to 2 stages in a pipeline, so we use that.

Fixes: 002304482ce ('v3dv: avoid redundant BO job additions for UBO/SSBO')
Fixes: fa170dab4c5 ('v3dv: avoid redundant BO job additions for textures and samplers')
Reviewed-by: Alejandro Piñeiro <apinheiro at igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10252>

---

 src/broadcom/vulkan/v3dv_uniforms.c | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/src/broadcom/vulkan/v3dv_uniforms.c b/src/broadcom/vulkan/v3dv_uniforms.c
index 1be6c579192..adbaaa7861d 100644
--- a/src/broadcom/vulkan/v3dv_uniforms.c
+++ b/src/broadcom/vulkan/v3dv_uniforms.c
@@ -28,18 +28,32 @@
 #include "v3dv_private.h"
 #include "vk_format_info.h"
 
+/* Our Vulkan resource indices represent indices in descriptor maps which
+ * include all shader stages, so we need to size the arrays below
+ * accordingly. For now we only support a maximum of 2 stages for VS and
+ * FS.
+ */
+#define MAX_STAGES 2
+
+#define MAX_TOTAL_TEXTURE_SAMPLERS (V3D_MAX_TEXTURE_SAMPLERS * MAX_STAGES)
 struct texture_bo_list {
-   struct v3dv_bo *tex[V3D_MAX_TEXTURE_SAMPLERS];
+   struct v3dv_bo *tex[MAX_TOTAL_TEXTURE_SAMPLERS];
 };
 
+/* This tracks state BOs forboth textures and samplers, so we
+ * multiply by 2.
+ */
+#define MAX_TOTAL_STATES (2 * V3D_MAX_TEXTURE_SAMPLERS * MAX_STAGES)
 struct state_bo_list {
    uint32_t count;
-   struct v3dv_bo *states[2 * V3D_MAX_TEXTURE_SAMPLERS];
+   struct v3dv_bo *states[MAX_TOTAL_STATES];
 };
 
+#define MAX_TOTAL_UNIFORM_BUFFERS (1 + MAX_UNIFORM_BUFFERS * MAX_STAGES)
+#define MAX_TOTAL_STORAGE_BUFFERS (MAX_STORAGE_BUFFERS * MAX_STAGES)
 struct buffer_bo_list {
-   struct v3dv_bo *ubo[MAX_UNIFORM_BUFFERS];
-   struct v3dv_bo *ssbo[MAX_STORAGE_BUFFERS];
+   struct v3dv_bo *ubo[MAX_TOTAL_UNIFORM_BUFFERS];
+   struct v3dv_bo *ssbo[MAX_TOTAL_STORAGE_BUFFERS];
 };
 
 static bool
@@ -265,10 +279,10 @@ write_ubo_ssbo_uniforms(struct v3dv_cmd_buffer *cmd_buffer,
                                   offset + dynamic_offset);
 
          if (content == QUNIFORM_UBO_ADDR) {
-            assert(index < MAX_UNIFORM_BUFFERS);
+            assert(index + 1 < MAX_TOTAL_UNIFORM_BUFFERS);
             buffer_bos->ubo[index + 1] = descriptor->buffer->mem->bo;
          } else {
-            assert(index < MAX_STORAGE_BUFFERS);
+            assert(index < MAX_TOTAL_STORAGE_BUFFERS);
             buffer_bos->ssbo[index] = descriptor->buffer->mem->bo;
          }
       }
@@ -485,7 +499,7 @@ v3dv_write_uniforms_wg_offsets(struct v3dv_cmd_buffer *cmd_buffer,
 
    cl_end(&job->indirect, uniforms);
 
-   for (int i = 0; i < V3D_MAX_TEXTURE_SAMPLERS; i++) {
+   for (int i = 0; i < MAX_TOTAL_TEXTURE_SAMPLERS; i++) {
       if (tex_bos.tex[i])
          v3dv_job_add_bo(job, tex_bos.tex[i]);
    }
@@ -493,12 +507,12 @@ v3dv_write_uniforms_wg_offsets(struct v3dv_cmd_buffer *cmd_buffer,
    for (int i = 0; i < state_bos.count; i++)
       v3dv_job_add_bo(job, state_bos.states[i]);
 
-   for (int i = 0; i < MAX_UNIFORM_BUFFERS; i++) {
+   for (int i = 0; i < MAX_TOTAL_UNIFORM_BUFFERS; i++) {
       if (buffer_bos.ubo[i])
          v3dv_job_add_bo(job, buffer_bos.ubo[i]);
    }
 
-   for (int i = 0; i < MAX_STORAGE_BUFFERS; i++) {
+   for (int i = 0; i < MAX_TOTAL_STORAGE_BUFFERS; i++) {
       if (buffer_bos.ssbo[i])
          v3dv_job_add_bo(job, buffer_bos.ssbo[i]);
    }



More information about the mesa-commit mailing list