From 917049e7d65ab6ebd2418339b4c6b4faf1325eb0 Mon Sep 17 00:00:00 2001 From: Iago Toral Quiroga Date: Thu, 15 Apr 2021 12:00:40 +0200 Subject: [PATCH] v3dv: fix array sizes when tracking BOs during uniform setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The resource indices we get point to descriptor map entries that include all shader stages, so we need to size the arrays to account for more than just one stage. For now we only support up to 2 stages in a pipeline, so we use that. Fixes: 002304482ce ('v3dv: avoid redundant BO job additions for UBO/SSBO') Fixes: fa170dab4c5 ('v3dv: avoid redundant BO job additions for textures and samplers') Reviewed-by: Alejandro PiƱeiro Part-of: --- src/broadcom/vulkan/v3dv_uniforms.c | 32 +++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/broadcom/vulkan/v3dv_uniforms.c b/src/broadcom/vulkan/v3dv_uniforms.c index 1be6c579192..adbaaa7861d 100644 --- a/src/broadcom/vulkan/v3dv_uniforms.c +++ b/src/broadcom/vulkan/v3dv_uniforms.c @@ -28,18 +28,32 @@ #include "v3dv_private.h" #include "vk_format_info.h" +/* Our Vulkan resource indices represent indices in descriptor maps which + * include all shader stages, so we need to size the arrays below + * accordingly. For now we only support a maximum of 2 stages for VS and + * FS. + */ +#define MAX_STAGES 2 + +#define MAX_TOTAL_TEXTURE_SAMPLERS (V3D_MAX_TEXTURE_SAMPLERS * MAX_STAGES) struct texture_bo_list { - struct v3dv_bo *tex[V3D_MAX_TEXTURE_SAMPLERS]; + struct v3dv_bo *tex[MAX_TOTAL_TEXTURE_SAMPLERS]; }; +/* This tracks state BOs forboth textures and samplers, so we + * multiply by 2. + */ +#define MAX_TOTAL_STATES (2 * V3D_MAX_TEXTURE_SAMPLERS * MAX_STAGES) struct state_bo_list { uint32_t count; - struct v3dv_bo *states[2 * V3D_MAX_TEXTURE_SAMPLERS]; + struct v3dv_bo *states[MAX_TOTAL_STATES]; }; +#define MAX_TOTAL_UNIFORM_BUFFERS (1 + MAX_UNIFORM_BUFFERS * MAX_STAGES) +#define MAX_TOTAL_STORAGE_BUFFERS (MAX_STORAGE_BUFFERS * MAX_STAGES) struct buffer_bo_list { - struct v3dv_bo *ubo[MAX_UNIFORM_BUFFERS]; - struct v3dv_bo *ssbo[MAX_STORAGE_BUFFERS]; + struct v3dv_bo *ubo[MAX_TOTAL_UNIFORM_BUFFERS]; + struct v3dv_bo *ssbo[MAX_TOTAL_STORAGE_BUFFERS]; }; static bool @@ -265,10 +279,10 @@ write_ubo_ssbo_uniforms(struct v3dv_cmd_buffer *cmd_buffer, offset + dynamic_offset); if (content == QUNIFORM_UBO_ADDR) { - assert(index < MAX_UNIFORM_BUFFERS); + assert(index + 1 < MAX_TOTAL_UNIFORM_BUFFERS); buffer_bos->ubo[index + 1] = descriptor->buffer->mem->bo; } else { - assert(index < MAX_STORAGE_BUFFERS); + assert(index < MAX_TOTAL_STORAGE_BUFFERS); buffer_bos->ssbo[index] = descriptor->buffer->mem->bo; } } @@ -485,7 +499,7 @@ v3dv_write_uniforms_wg_offsets(struct v3dv_cmd_buffer *cmd_buffer, cl_end(&job->indirect, uniforms); - for (int i = 0; i < V3D_MAX_TEXTURE_SAMPLERS; i++) { + for (int i = 0; i < MAX_TOTAL_TEXTURE_SAMPLERS; i++) { if (tex_bos.tex[i]) v3dv_job_add_bo(job, tex_bos.tex[i]); } @@ -493,12 +507,12 @@ v3dv_write_uniforms_wg_offsets(struct v3dv_cmd_buffer *cmd_buffer, for (int i = 0; i < state_bos.count; i++) v3dv_job_add_bo(job, state_bos.states[i]); - for (int i = 0; i < MAX_UNIFORM_BUFFERS; i++) { + for (int i = 0; i < MAX_TOTAL_UNIFORM_BUFFERS; i++) { if (buffer_bos.ubo[i]) v3dv_job_add_bo(job, buffer_bos.ubo[i]); } - for (int i = 0; i < MAX_STORAGE_BUFFERS; i++) { + for (int i = 0; i < MAX_TOTAL_STORAGE_BUFFERS; i++) { if (buffer_bos.ssbo[i]) v3dv_job_add_bo(job, buffer_bos.ssbo[i]); }