Mesa (master): v3d: do not emit attribute if has no resource

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Apr 14 11:47:23 UTC 2021


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

Author: Juan A. Suarez Romero <jasuarez at igalia.com>
Date:   Tue Feb  2 13:38:49 2021 +0100

v3d: do not emit attribute if has no resource

When emitting the GL shader state, verify the attribute has a resource
bound; otherwise just skip it

v2 (chema):
 - Move comment
 - Set num_elements_to_emit = 1 if it is 0

Cc: mesa-stable
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/4205
Reviewed-by: Jose Maria Casanova Crespo <jmcasanova at igalia.com>
Signed-off-by: Juan A. Suarez Romero <jasuarez at igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8826>

---

 src/gallium/drivers/v3d/v3dx_draw.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/gallium/drivers/v3d/v3dx_draw.c b/src/gallium/drivers/v3d/v3dx_draw.c
index 0b151b38515..cda31a9517f 100644
--- a/src/gallium/drivers/v3d/v3dx_draw.c
+++ b/src/gallium/drivers/v3d/v3dx_draw.c
@@ -676,8 +676,14 @@ v3d_emit_gl_shader_state(struct v3d_context *v3d,
         }
         job->tmu_dirty_rcl |= v3d->prog.fs->prog_data.fs->base.tmu_dirty_rcl;
 
-        /* See GFXH-930 workaround below */
-        uint32_t num_elements_to_emit = MAX2(vtx->num_elements, 1);
+        uint32_t num_elements_to_emit = 0;
+        for (int i = 0; i < vtx->num_elements; i++) {
+                struct pipe_vertex_element *elem = &vtx->pipe[i];
+                struct pipe_vertex_buffer *vb =
+                        &vertexbuf->vb[elem->vertex_buffer_index];
+                if (vb->buffer.resource)
+                        num_elements_to_emit++;
+        }
 
         uint32_t shader_state_record_length =
                 cl_packet_length(GL_SHADER_STATE_RECORD);
@@ -690,10 +696,11 @@ v3d_emit_gl_shader_state(struct v3d_context *v3d,
         }
 #endif
 
+        /* See GFXH-930 workaround below */
         uint32_t shader_rec_offset =
                     v3d_cl_ensure_space(&job->indirect,
                                     shader_state_record_length +
-                                    num_elements_to_emit *
+                                    MAX2(num_elements_to_emit, 1) *
                                     cl_packet_length(GL_SHADER_STATE_ATTRIBUTE_RECORD),
                                     32);
 
@@ -888,6 +895,9 @@ v3d_emit_gl_shader_state(struct v3d_context *v3d,
                         &vertexbuf->vb[elem->vertex_buffer_index];
                 struct v3d_resource *rsc = v3d_resource(vb->buffer.resource);
 
+                if (!rsc)
+                        continue;
+
                 const uint32_t size =
                         cl_packet_length(GL_SHADER_STATE_ATTRIBUTE_RECORD);
                 cl_emit_with_prepacked(&job->indirect,
@@ -922,7 +932,7 @@ v3d_emit_gl_shader_state(struct v3d_context *v3d,
                 STATIC_ASSERT(sizeof(vtx->attrs) >= V3D_MAX_VS_INPUTS / 4 * size);
         }
 
-        if (vtx->num_elements == 0) {
+        if (num_elements_to_emit == 0) {
                 /* GFXH-930: At least one attribute must be enabled and read
                  * by CS and VS.  If we have no attributes being consumed by
                  * the shader, set up a dummy to be loaded into the VPM.
@@ -938,6 +948,7 @@ v3d_emit_gl_shader_state(struct v3d_context *v3d,
                         attr.number_of_values_read_by_coordinate_shader = 1;
                         attr.number_of_values_read_by_vertex_shader = 1;
                 }
+                num_elements_to_emit = 1;
         }
 
         cl_emit(&job->bcl, VCM_CACHE_SIZE, vcm) {



More information about the mesa-commit mailing list