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@igalia.com>
Signed-off-by: Juan A. Suarez Romero <jasuarez@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8826>
(cherry picked from commit 45ae0e9fb7)
This commit is contained in:
Juan A. Suarez Romero 2021-02-02 13:38:49 +01:00 committed by Dylan Baker
parent df04b749d7
commit c7724ebab1
2 changed files with 16 additions and 5 deletions

View file

@ -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
},

View file

@ -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) {