pvr: add padding bytes when allocating buffer memory

We need to pad VkBuffers to ensure we don't read beyond a page boundary.

An alternative to this approach would be to allocate an additional virtual
page when binding memory to the buffer, and to map this to the first
physical address, so both the first and last virtual page point to the same
physical location. This would be less expensive in terms of memory usage,
but more complex and invasive, hence the simpler approach has been taken
for now.

Signed-off-by: Luigi Santivetti <luigi.santivetti@imgtec.com>
Reviewed-by: Frank Binns <frank.binns@imgtec.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21101>
This commit is contained in:
Luigi Santivetti 2023-01-20 14:57:47 +00:00 committed by Marge Bot
parent 4e75e1bfec
commit 21f0fc65b2

View file

@ -87,6 +87,11 @@
.name = str_name, .len = sizeof(str_name) - 1 \
}
/* Amount of padding required for VkBuffers to ensure we don't read beyond
* a page boundary.
*/
#define PVR_BUFFER_MEMORY_PADDING_SIZE 4
struct pvr_drm_device_info {
const char *name;
size_t len;
@ -2957,6 +2962,7 @@ void pvr_GetBufferMemoryRequirements2(
{
PVR_FROM_HANDLE(pvr_buffer, buffer, pInfo->buffer);
PVR_FROM_HANDLE(pvr_device, device, _device);
uint64_t size;
/* The Vulkan 1.0.166 spec says:
*
@ -2971,8 +2977,21 @@ void pvr_GetBufferMemoryRequirements2(
(1ul << device->pdevice->memory.memoryTypeCount) - 1;
pMemoryRequirements->memoryRequirements.alignment = buffer->alignment;
size = buffer->vk.size;
if (size % device->ws->page_size == 0 ||
size % device->ws->page_size >
device->ws->page_size - PVR_BUFFER_MEMORY_PADDING_SIZE) {
/* TODO: We can save memory by having one extra virtual page mapped
* in and having the first and last virtual page mapped to the first
* physical address.
*/
size += PVR_BUFFER_MEMORY_PADDING_SIZE;
}
pMemoryRequirements->memoryRequirements.size =
ALIGN_POT(buffer->vk.size, buffer->alignment);
ALIGN_POT(size, buffer->alignment);
}
void pvr_GetImageMemoryRequirements2(VkDevice _device,