- struct radv_device *device = radv_device_from_handle(device_h);
- VkResult result = VK_SUCCESS;
- struct radeon_surf *surface;
- VkImage image_h;
- struct radv_image *image;
- bool bret;
- int fd;
-
- result = radv_image_create(device_h,
- &(struct radv_image_create_info) {
- .vk_info =
- &(VkImageCreateInfo) {
- .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
- .imageType = VK_IMAGE_TYPE_2D,
- .format = pCreateInfo->imageFormat,
- .extent = {
- .width = pCreateInfo->imageExtent.width,
- .height = pCreateInfo->imageExtent.height,
- .depth = 1
- },
- .mipLevels = 1,
- .arrayLayers = 1,
- .samples = 1,
- /* FIXME: Need a way to use X tiling to allow scanout */
- .tiling = VK_IMAGE_TILING_OPTIMAL,
- .usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
- .flags = 0,
- },
- .scanout = true},
- NULL,
- &image_h);
- if (result != VK_SUCCESS)
- return result;
-
- image = radv_image_from_handle(image_h);
-
- VkDeviceMemory memory_h;
- struct radv_device_memory *memory;
- result = radv_AllocateMemory(device_h,
- &(VkMemoryAllocateInfo) {
- .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
- .allocationSize = image->size,
- .memoryTypeIndex = 0,
- },
- NULL /* XXX: pAllocator */,
- &memory_h);
- if (result != VK_SUCCESS)
- goto fail_create_image;
-
- memory = radv_device_memory_from_handle(memory_h);
-
- radv_BindImageMemory(VK_NULL_HANDLE, image_h, memory_h, 0);
-
- bret = device->ws->buffer_get_fd(device->ws,
- memory->bo, &fd);
- if (bret == false)
- goto fail_alloc_memory;
-
- {
- struct radeon_bo_metadata metadata;
- radv_init_metadata(device, image, &metadata);
- device->ws->buffer_set_metadata(memory->bo, &metadata);
- }
- surface = &image->surface;
-
- *image_p = image_h;
- *memory_p = memory_h;
- *fd_p = fd;
- *size = image->size;
- *offset = image->offset;
- *row_pitch = surface->level[0].pitch_bytes;
- return VK_SUCCESS;
- fail_alloc_memory:
- radv_FreeMemory(device_h, memory_h, pAllocator);
-
-fail_create_image:
- radv_DestroyImage(device_h, image_h, pAllocator);