From c7724ebab19c908ea09f23fccc0232126bd3fc58 Mon Sep 17 00:00:00 2001 From: "Juan A. Suarez Romero" Date: Tue, 2 Feb 2021 13:38:49 +0100 Subject: [PATCH] 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 Signed-off-by: Juan A. Suarez Romero Part-of: (cherry picked from commit 45ae0e9fb7c079f61fa74df850063af9c627e66e) --- .pick_status.json | 2 +- src/gallium/drivers/v3d/v3dx_draw.c | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 4c0f2e99442..dc4ba84fbcd 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -310,7 +310,7 @@ "description": "v3d: do not emit attribute if has no resource", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "master_sha": null, "because_sha": null }, diff --git a/src/gallium/drivers/v3d/v3dx_draw.c b/src/gallium/drivers/v3d/v3dx_draw.c index 0b63b1b43c8..07d13a864d6 100644 --- a/src/gallium/drivers/v3d/v3dx_draw.c +++ b/src/gallium/drivers/v3d/v3dx_draw.c @@ -675,8 +675,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); @@ -689,10 +695,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); @@ -887,6 +894,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, @@ -921,7 +931,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. @@ -937,6 +947,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) {