[Mesa-dev] [RFC v4 12/23] radv/wsi: Move image allocation into helper function
Louis-Francis Ratté-Boulianne
lfrb at collabora.com
Mon Oct 16 07:04:22 UTC 2017
From: Daniel Stone <daniels at collabora.com>
Create a new helper function which handles the actual image/memory
allocations for a swapchain image, removing the bulk of
radv_wsi_image_create. This will make it easier to move linear handling
into radv in the next patch.
Signed-off-by: Daniel Stone <daniels at collabora.com>
---
src/amd/vulkan/radv_wsi.c | 76 +++++++++++++++++++++++++++++------------------
1 file changed, 47 insertions(+), 29 deletions(-)
diff --git a/src/amd/vulkan/radv_wsi.c b/src/amd/vulkan/radv_wsi.c
index 135808461f..cd2b36a57f 100644
--- a/src/amd/vulkan/radv_wsi.c
+++ b/src/amd/vulkan/radv_wsi.c
@@ -139,19 +139,15 @@ VkResult radv_GetPhysicalDeviceSurfacePresentModesKHR(
}
static VkResult
-radv_wsi_image_create(VkDevice device_h,
- const VkSwapchainCreateInfoKHR *pCreateInfo,
- const VkAllocationCallbacks* pAllocator,
- bool should_export,
- bool linear,
- struct wsi_image_base *wsi_image)
+radv_wsi_image_alloc(VkDevice device_h,
+ const VkSwapchainCreateInfoKHR *pCreateInfo,
+ const VkAllocationCallbacks *pAllocator,
+ bool linear,
+ VkImage *image_h_p,
+ VkDeviceMemory *memory_h_p)
{
- VkResult result = VK_SUCCESS;
- struct radeon_surf *surface;
VkImage image_h;
- struct radv_image *image;
- int fd;
- RADV_FROM_HANDLE(radv_device, device, device_h);
+ VkResult result;
result = radv_image_create(device_h,
&(struct radv_image_create_info) {
@@ -168,7 +164,6 @@ radv_wsi_image_create(VkDevice device_h,
.mipLevels = 1,
.arrayLayers = 1,
.samples = 1,
- /* FIXME: Need a way to use X tiling to allow scanout */
.tiling = linear ? VK_IMAGE_TILING_LINEAR : VK_IMAGE_TILING_OPTIMAL,
.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
.flags = 0,
@@ -179,10 +174,6 @@ radv_wsi_image_create(VkDevice device_h,
if (result != VK_SUCCESS)
return result;
- image = radv_image_from_handle(image_h);
-
- VkDeviceMemory memory_h;
-
const VkMemoryDedicatedAllocateInfoKHR ded_alloc = {
.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR,
.pNext = NULL,
@@ -190,6 +181,8 @@ radv_wsi_image_create(VkDevice device_h,
.image = image_h
};
+ struct radv_image *image = radv_image_from_handle(image_h);
+ VkDeviceMemory memory_h;
result = radv_AllocateMemory(device_h,
&(VkMemoryAllocateInfo) {
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
@@ -204,21 +197,48 @@ radv_wsi_image_create(VkDevice device_h,
radv_BindImageMemory(device_h, image_h, memory_h, 0);
- /*
- * return the fd for the image in the no copy mode,
- * or the fd for the linear image if a copy is required.
- */
+ *image_h_p = image_h;
+ *memory_h_p = memory_h;
+
+ return VK_SUCCESS;
+
+fail_create_image:
+ radv_DestroyImage(device_h, image_h, pAllocator);
+ return result;
+}
+
+
+static VkResult
+radv_wsi_image_create(VkDevice device_h,
+ const VkSwapchainCreateInfoKHR *pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ bool should_export,
+ bool linear,
+ struct wsi_image_base *wsi_image)
+{
+ VkResult result = VK_SUCCESS;
+ struct radeon_surf *surface;
+ VkImage image_h;
+ VkDeviceMemory memory_h;
+ struct radv_image *image;
+
+ result = radv_wsi_image_alloc(device_h, pCreateInfo, pAllocator,
+ linear, &image_h, &memory_h);
+ if (result != VK_SUCCESS)
+ return result;
+
+ image = radv_image_from_handle(image_h);
+ surface = &image->surface;
+
if (should_export) {
+ RADV_FROM_HANDLE(radv_device, device, device_h);
RADV_FROM_HANDLE(radv_device_memory, memory, memory_h);
- if (!radv_get_memory_fd(device, memory, &fd))
- goto fail_alloc_memory;
- wsi_image->fds[0] = fd;
+ if (!radv_get_memory_fd(device, memory, &wsi_image->fds[0]))
+ goto fail_alloc;
} else {
wsi_image->fds[0] = -1;
}
- surface = &image->surface;
-
wsi_image->image = image_h;
wsi_image->memory = memory_h;
wsi_image->num_planes = 1;
@@ -232,12 +252,10 @@ radv_wsi_image_create(VkDevice device_h,
surface->u.legacy.level[0].nblk_x * surface->bpe;
return VK_SUCCESS;
- fail_alloc_memory:
- radv_FreeMemory(device_h, memory_h, pAllocator);
-fail_create_image:
+ fail_alloc:
+ radv_FreeMemory(device_h, memory_h, pAllocator);
radv_DestroyImage(device_h, image_h, pAllocator);
-
return result;
}
--
2.13.0
More information about the mesa-dev
mailing list