From bfe92d50ce0ad48be7ca0d8c028df04a4a9cfaf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ADra=20Canal?= Date: Wed, 18 Mar 2026 17:43:49 -0300 Subject: [PATCH] v3d: sub-allocate sampler view texture state from state uploader MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, each sampler view allocated a dedicated BO for its, TEXTURE_SHADER_STATE packet (~24 bytes), which got rounded up to a full 4KB page. This wastes memory and inflates the per-job BO handle count. Use u_upload_alloc_ref() to sub-allocate texture shader state from the shared state_uploader, matching the pattern already used by image views. Reviewed-by: Iago Toral Quiroga Signed-off-by: MaĆ­ra Canal Part-of: --- src/gallium/drivers/v3d/v3d_context.h | 3 ++- src/gallium/drivers/v3d/v3d_uniforms.c | 4 +++- src/gallium/drivers/v3d/v3dx_state.c | 9 ++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/gallium/drivers/v3d/v3d_context.h b/src/gallium/drivers/v3d/v3d_context.h index a5262f6eb4d..a15320b19f1 100644 --- a/src/gallium/drivers/v3d/v3d_context.h +++ b/src/gallium/drivers/v3d/v3d_context.h @@ -173,7 +173,8 @@ struct v3d_sampler_view { uint8_t texture_shader_state[32]; /* V3D 4.x: Texture state struct. */ - struct v3d_bo *bo; + struct pipe_resource *tex_state; + uint32_t tex_state_offset; enum v3d_sampler_state_variant sampler_variant; diff --git a/src/gallium/drivers/v3d/v3d_uniforms.c b/src/gallium/drivers/v3d/v3d_uniforms.c index 0609a55a7d5..f7e9672f2f4 100644 --- a/src/gallium/drivers/v3d/v3d_uniforms.c +++ b/src/gallium/drivers/v3d/v3d_uniforms.c @@ -151,7 +151,9 @@ write_tmu_p0(struct v3d_job *job, struct v3d_resource *rsc = v3d_resource(sview->texture); - cl_aligned_reloc(&job->indirect, uniforms, sview->bo, + cl_aligned_reloc(&job->indirect, uniforms, + v3d_resource(sview->tex_state)->bo, + sview->tex_state_offset | v3d_unit_data_get_offset(data)); v3d_job_add_bo(job, rsc->bo); } diff --git a/src/gallium/drivers/v3d/v3dx_state.c b/src/gallium/drivers/v3d/v3dx_state.c index a3eb0728c1f..c3db92e75a2 100644 --- a/src/gallium/drivers/v3d/v3dx_state.c +++ b/src/gallium/drivers/v3d/v3dx_state.c @@ -993,10 +993,9 @@ v3dX(create_texture_shader_state_bo)(struct v3d_context *v3d, assert(so->serial_id != rsc->serial_id); - v3d_bo_unreference(&so->bo); - so->bo = v3d_bo_alloc(v3d->screen, - cl_packet_length(TEXTURE_SHADER_STATE), "sampler"); - map = v3d_bo_map(so->bo); + u_upload_alloc_ref(v3d->state_uploader, 0, + cl_packet_length(TEXTURE_SHADER_STATE), 32, + &so->tex_state_offset, &so->tex_state, &map); v3dx_pack(map, TEXTURE_SHADER_STATE, tex) { if (prsc->target != PIPE_BUFFER) { @@ -1194,7 +1193,7 @@ v3d_sampler_view_destroy(struct pipe_context *pctx, { struct v3d_sampler_view *sview = v3d_sampler_view(psview); - v3d_bo_unreference(&sview->bo); + pipe_resource_reference(&sview->tex_state, NULL); pipe_resource_reference(&psview->texture, NULL); pipe_resource_reference(&sview->texture, NULL); free(psview);