dzn: Ensure buffer offsets are aligned

If the app passes us unaligned buffer offsets, we need to align them
down to the nearest aligned offset, and then put the difference into
the descriptor set buffer.

Fixes: 8bd5fbf8 ("dzn: Bind buffers for bindless descriptor sets")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22225>
This commit is contained in:
Jesse Natalie
2023-03-30 13:38:37 -07:00
committed by Marge Bot
parent eaa8c8097c
commit c914d53d13
2 changed files with 15 additions and 3 deletions
+3 -1
View File
@@ -3216,8 +3216,10 @@ dzn_cmd_buffer_update_heaps(struct dzn_cmd_buffer *cmdbuf, uint32_t bindpoint)
const struct dzn_buffer_desc *bdesc = &set->dynamic_buffers[o];
struct dxil_spirv_bindless_entry *map_entry = &map[pipeline->sets[s].dynamic_buffer_heap_offsets[o].primary];
if (*bdesc->bindless_descriptor_slot >= 0) {
uint32_t embedded_offset = (bdesc->offset / D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT) * D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT;
uint32_t additional_offset = bdesc->offset - embedded_offset;
map_entry->buffer_idx = *bdesc->bindless_descriptor_slot;
map_entry->buffer_offset = desc_state->sets[s].dynamic_offsets[o];
map_entry->buffer_offset = additional_offset + desc_state->sets[s].dynamic_offsets[o];
} else {
map_entry->buffer_idx = bdesc->type == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC ?
bdesc->buffer->uav_bindless_slot : bdesc->buffer->cbv_bindless_slot;
+12 -2
View File
@@ -1182,10 +1182,16 @@ dzn_bindless_descriptor_set_write_buffer_desc(struct dzn_device *device,
if (*info->bindless_descriptor_slot < 0)
*info->bindless_descriptor_slot =
dzn_device_descriptor_heap_alloc_slot(device, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
uint32_t offset = (info->offset / D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT) * D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT;
struct dzn_buffer_desc local_info = *info;
local_info.offset = offset;
info = &local_info;
dzn_descriptor_heap_write_buffer_desc(device, &device->device_heaps[D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV].heap,
*info->bindless_descriptor_slot, info->type == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, info);
map[desc_offset].buffer_idx = *info->bindless_descriptor_slot;
map[desc_offset].buffer_offset = 0;
map[desc_offset].buffer_offset = info->offset - offset;
}
}
@@ -1372,8 +1378,12 @@ dzn_descriptor_set_write_dynamic_buffer_desc(struct dzn_device *device,
if (*info->bindless_descriptor_slot < 0)
*info->bindless_descriptor_slot =
dzn_device_descriptor_heap_alloc_slot(device, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
uint32_t offset = (info->offset / D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT) * D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT;
struct dzn_buffer_desc local_info = *info;
local_info.offset = offset;
dzn_descriptor_heap_write_buffer_desc(device, &device->device_heaps[D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV].heap,
*info->bindless_descriptor_slot, info->type == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, info);
*info->bindless_descriptor_slot, info->type == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, &local_info);
}
}