#include <sys/mman.h>
#include "drm-uapi/v3d_drm.h"
+#include "util/u_memory.h"
-bool
-v3dv_bo_alloc(struct v3dv_device *device, uint32_t size, struct v3dv_bo *bo)
+struct v3dv_bo *
+v3dv_bo_alloc(struct v3dv_device *device, uint32_t size)
{
+ struct v3dv_bo *bo = vk_alloc(&device->alloc, sizeof(struct v3dv_bo), 8,
+ VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
+ if (!bo)
+ return NULL;
+
const uint32_t page_align = 4096; /* Always allocate full pages */
size = align(size, page_align);
struct drm_v3d_create_bo create = {
int ret = v3dv_ioctl(device->fd, DRM_IOCTL_V3D_CREATE_BO, &create);
if (ret != 0)
- return false;
+ return NULL;
assert(create.offset % page_align == 0);
assert((create.offset & 0xffffffff) == create.offset);
bo->map = NULL;
bo->map_size = 0;
- return true;
+ return bo;
}
bool
if (ret != 0)
fprintf(stderr, "close object %d: %s\n", bo->handle, strerror(errno));
+ vk_free(&device->alloc, bo);
+
return ret == 0;
}
{
/* Our kernel interface is 32-bit */
assert((size & 0xffffffff) == size);
- bool ok = v3dv_bo_alloc(device, size, &mem->bo);
- if (!ok)
+ mem->bo = v3dv_bo_alloc(device, size);
+ if (!mem->bo)
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
return VK_SUCCESS;
}
static void
device_free(struct v3dv_device *device, struct v3dv_device_memory *mem)
{
- v3dv_bo_free(device, &mem->bo);
+ v3dv_bo_free(device, mem->bo);
}
static VkResult
* considered to be currently host mapped. It is an application error to
* call vkMapMemory on a memory object that is already host mapped."
*/
- assert(mem && mem->bo.map == NULL);
+ assert(mem && mem->bo->map == NULL);
- bool ok = v3dv_bo_map(device, &mem->bo, size);
+ bool ok = v3dv_bo_map(device, mem->bo, size);
if (!ok)
return VK_ERROR_MEMORY_MAP_FAILED;
static void
device_unmap(struct v3dv_device *device, struct v3dv_device_memory *mem)
{
- assert(mem && mem->bo.map && mem->bo.map_size > 0);
- v3dv_bo_unmap(device, &mem->bo);
+ assert(mem && mem->bo->map && mem->bo->map_size > 0);
+ v3dv_bo_unmap(device, mem->bo);
}
VkResult
if (mem == NULL)
return;
- if (mem->bo.map)
+ if (mem->bo->map)
v3dv_UnmapMemory(_device, _mem);
device_free(device, mem);
return VK_SUCCESS;
}
- assert(offset < mem->bo.size);
+ assert(offset < mem->bo->size);
/* We always map from the beginning of the region, so if our offset
* is not 0 and we are not mapping the entire region, we need to
* add the offset to the map size.
*/
if (size == VK_WHOLE_SIZE)
- size = mem->bo.size;
+ size = mem->bo->size;
else if (offset > 0)
size += offset;
if (result != VK_SUCCESS)
return vk_error(device->instance, result);
- *ppData = ((uint8_t *) mem->bo.map) + offset;
+ *ppData = ((uint8_t *) mem->bo->map) + offset;
return VK_SUCCESS;
}
* vkGetImageMemoryRequirements with image"
*/
assert(memoryOffset % image->alignment == 0);
- assert(memoryOffset < mem->bo.size);
+ assert(memoryOffset < mem->bo->size);
image->mem = mem;
image->mem_offset = memoryOffset;
* vkGetBufferMemoryRequirements with buffer"
*/
assert(memoryOffset % buffer->alignment == 0);
- assert(memoryOffset < mem->bo.size);
+ assert(memoryOffset < mem->bo->size);
buffer->mem = mem;
buffer->mem_offset = memoryOffset;