v3dv: don't allocate MAX_PUSH_CONSTANTS_SIZE bytes for the push constants UBO

We have code in there to allocate various segments of MAX_PUSH_CONSTANTS_SIZE
to handle the case of various draw calls in the same command buffer requiring
different push constants, so we are implicitly expecting it to be larger than
this. In fact, this only works now because when we allocate a BO we are always
at least allocating a full page, so the least we ever allocate is 4096 bytes,
so be explicit about it to avoid confusion.

Also, since we were always mapping MAX_PUSH_CONSTANTS_SIZE and the mapping
always starts at the beginning of the BO, it looks like after the first copy
when the resource offset is not zero, we would be writing outside the mapped
range. Always map the full size of the BO instead to ensure this doesn't
happen.

Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17536>
This commit is contained in:
Iago Toral Quiroga 2022-07-14 08:58:06 +02:00 committed by Marge Bot
parent 51a45f9315
commit 45b8dc667a
1 changed files with 2 additions and 3 deletions

View File

@ -91,8 +91,7 @@ check_push_constants_ubo(struct v3dv_cmd_buffer *cmd_buffer,
if (cmd_buffer->push_constants_resource.bo == NULL) {
cmd_buffer->push_constants_resource.bo =
v3dv_bo_alloc(cmd_buffer->device, MAX_PUSH_CONSTANTS_SIZE,
"push constants", true);
v3dv_bo_alloc(cmd_buffer->device, 4096, "push constants", true);
if (!cmd_buffer->push_constants_resource.bo) {
fprintf(stderr, "Failed to allocate memory for push constants\n");
@ -101,7 +100,7 @@ check_push_constants_ubo(struct v3dv_cmd_buffer *cmd_buffer,
bool ok = v3dv_bo_map(cmd_buffer->device,
cmd_buffer->push_constants_resource.bo,
MAX_PUSH_CONSTANTS_SIZE);
cmd_buffer->push_constants_resource.bo->size);
if (!ok) {
fprintf(stderr, "failed to map push constants buffer\n");
abort();