if (dma_buf < 0)
return VK_ERROR_INVALID_EXTERNAL_HANDLE;
+ uint64_t alloc_size = 0;
mem->bo = device->ws->buffer_from_fd(device->ws, dma_buf,
- priority);
+ priority, &alloc_size);
if (!mem->bo)
return VK_ERROR_OUT_OF_HOST_MEMORY;
mem->bo = NULL;
return result;
}
+
+ if (alloc_size < mem->image->size) {
+ device->ws->buffer_destroy(mem->bo);
+ mem->bo = NULL;
+ return VK_ERROR_INVALID_EXTERNAL_HANDLE;
+ }
+ } else if (mem->buffer) {
+ if (alloc_size < mem->buffer->size) {
+ device->ws->buffer_destroy(mem->bo);
+ mem->bo = NULL;
+ return VK_ERROR_INVALID_EXTERNAL_HANDLE;
+ }
}
/* "If the vkAllocateMemory command succeeds, the implementation must
import_info->handleType ==
VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT);
mem->bo = device->ws->buffer_from_fd(device->ws, import_info->fd,
- priority);
+ priority, NULL);
if (!mem->bo) {
result = VK_ERROR_INVALID_EXTERNAL_HANDLE;
goto fail;
struct radeon_winsys_bo *(*buffer_from_fd)(struct radeon_winsys *ws,
int fd,
- unsigned priority);
+ unsigned priority,
+ uint64_t *alloc_size);
bool (*buffer_get_fd)(struct radeon_winsys *ws,
struct radeon_winsys_bo *bo,
static struct radeon_winsys_bo *
radv_amdgpu_winsys_bo_from_fd(struct radeon_winsys *_ws,
- int fd, unsigned priority)
+ int fd, unsigned priority,
+ uint64_t *alloc_size)
{
struct radv_amdgpu_winsys *ws = radv_amdgpu_winsys(_ws);
struct radv_amdgpu_winsys_bo *bo;
if (r)
goto error_query;
+ if (alloc_size) {
+ *alloc_size = info.alloc_size;
+ }
+
r = amdgpu_va_range_alloc(ws->dev, amdgpu_gpu_va_range_general,
result.alloc_size, 1 << 20, 0, &va, &va_handle,
AMDGPU_VA_RANGE_HIGH);