From 6f138819f44f2a392163569be4b6cd2519ecd93a Mon Sep 17 00:00:00 2001 From: Jose Maria Casanova Crespo Date: Wed, 17 Jan 2024 12:38:15 +0100 Subject: [PATCH] v3d: Only flush jobs that write texture from different job submission. Avoids flushing jobs that write a texture that is read by a job in the same job submission. Now we need to handle the case where a texture is written by the graphics pipeline and it is read by a compute pipeline. Before this patch, glTextureBarrier() could be implemented as a NOP in v3d. So the driver was doing more flushing than needed when glTextureBarrier was not used. v2: Use V3D_FLUSH_ALWAYS for resources written by graphics pipeline and read by compute insead of V3D_FLUSH_DEFAULT. (Iago Toral) Reviewed-by: Iago Toral Quiroga Part-of: --- src/broadcom/ci/traces-broadcom.yml | 2 +- src/gallium/drivers/v3d/v3d_job.c | 9 ++++++--- src/gallium/drivers/v3d/v3d_resource.c | 1 + src/gallium/drivers/v3d/v3d_resource.h | 5 +++++ src/gallium/drivers/v3d/v3dx_draw.c | 6 +++++- src/gallium/drivers/v3d/v3dx_rcl.c | 1 + 6 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/broadcom/ci/traces-broadcom.yml b/src/broadcom/ci/traces-broadcom.yml index 0b1fa9a9628..8443a6e40f2 100644 --- a/src/broadcom/ci/traces-broadcom.yml +++ b/src/broadcom/ci/traces-broadcom.yml @@ -121,7 +121,7 @@ traces: supertuxkart/supertuxkart-mansion-egl-gles-v2.trace: broadcom-rpi4: - checksum: b24708141d2642bbdd05274a2104b0d4 + checksum: 93fe17a18ab10d862b5a42b4ea05a658 valve/counterstrike-source-v2.trace: broadcom-rpi4: diff --git a/src/gallium/drivers/v3d/v3d_job.c b/src/gallium/drivers/v3d/v3d_job.c index a929ab6e05c..37c2827f222 100644 --- a/src/gallium/drivers/v3d/v3d_job.c +++ b/src/gallium/drivers/v3d/v3d_job.c @@ -195,14 +195,17 @@ v3d_flush_jobs_writing_resource(struct v3d_context *v3d, struct v3d_resource *rsc = v3d_resource(prsc); /* We need to sync if graphics pipeline reads a resource written - * by the compute pipeline. The same would be needed for the case of - * graphics-compute dependency but nowadays all compute jobs - * are serialized with the previous submitted job. + * by the compute pipeline. The same is needed for the case of + * graphics-compute dependency but flushing the job. */ if (!is_compute_pipeline && rsc->bo != NULL && rsc->compute_written) { v3d->sync_on_last_compute_job = true; rsc->compute_written = false; } + if (is_compute_pipeline && rsc->bo != NULL && rsc->graphics_written) { + flush_cond = V3D_FLUSH_ALWAYS; + rsc->graphics_written = false; + } if (!entry) return; diff --git a/src/gallium/drivers/v3d/v3d_resource.c b/src/gallium/drivers/v3d/v3d_resource.c index 77fa2f638af..1b806dfb089 100644 --- a/src/gallium/drivers/v3d/v3d_resource.c +++ b/src/gallium/drivers/v3d/v3d_resource.c @@ -236,6 +236,7 @@ v3d_map_usage_prep(struct pipe_context *pctx, if (usage & PIPE_MAP_WRITE) { rsc->writes++; + rsc->graphics_written = true; rsc->initialized_buffers = ~0; } } diff --git a/src/gallium/drivers/v3d/v3d_resource.h b/src/gallium/drivers/v3d/v3d_resource.h index a1f74fbbdc6..751933a2475 100644 --- a/src/gallium/drivers/v3d/v3d_resource.h +++ b/src/gallium/drivers/v3d/v3d_resource.h @@ -100,6 +100,11 @@ struct v3d_resource { */ bool compute_written; + /** + * Indicates if the Graphics pipeline has written the resource + */ + bool graphics_written; + /** * Number of times the resource has been written to. * diff --git a/src/gallium/drivers/v3d/v3dx_draw.c b/src/gallium/drivers/v3d/v3dx_draw.c index eec3b0b6df8..b8029efbde9 100644 --- a/src/gallium/drivers/v3d/v3dx_draw.c +++ b/src/gallium/drivers/v3d/v3dx_draw.c @@ -174,7 +174,7 @@ v3d_predraw_check_stage_inputs(struct pipe_context *pctx, v3d_update_shadow_texture(pctx, &view->base); v3d_flush_jobs_writing_resource(v3d, view->texture, - V3D_FLUSH_DEFAULT, + V3D_FLUSH_NOT_CURRENT_JOB, s == PIPE_SHADER_COMPUTE); } @@ -1026,12 +1026,16 @@ v3d_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info, u_foreach_bit(i, v3d->ssbo[s].enabled_mask) { v3d_job_add_write_resource(job, v3d->ssbo[s].sb[i].buffer); + struct v3d_resource *rsc= v3d_resource(v3d->ssbo[s].sb[i].buffer); + rsc->graphics_written = true; job->tmu_dirty_rcl = true; } u_foreach_bit(i, v3d->shaderimg[s].enabled_mask) { v3d_job_add_write_resource(job, v3d->shaderimg[s].si[i].base.resource); + struct v3d_resource *rsc= v3d_resource(v3d->shaderimg[s].si[i].base.resource); + rsc->graphics_written = true; job->tmu_dirty_rcl = true; } } diff --git a/src/gallium/drivers/v3d/v3dx_rcl.c b/src/gallium/drivers/v3d/v3dx_rcl.c index 2efe70b7b42..f11b6fc27a1 100644 --- a/src/gallium/drivers/v3d/v3dx_rcl.c +++ b/src/gallium/drivers/v3d/v3dx_rcl.c @@ -102,6 +102,7 @@ store_general(struct v3d_job *job, struct v3d_resource *rsc = v3d_resource(psurf->texture); rsc->writes++; + rsc->graphics_written = true; uint32_t layer_offset = v3d_layer_offset(&rsc->base, psurf->u.tex.level,