[Mesa-dev] [PATCH] anv: add function to get prime buffer from memory+image

Jonathan jonathan at marek.ca
Tue Jul 19 18:47:15 UTC 2016


counterpart to the CreateDmaBufImageINTEL function, but far more convenient

Signed-off-by: Jonathan <jonathan at marek.ca>
---
 include/vulkan/vulkan_intel.h |  9 +++++++++
 src/intel/vulkan/anv_intel.c  | 30 ++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/include/vulkan/vulkan_intel.h b/include/vulkan/vulkan_intel.h
index 8ede61b..da99a7e 100644
--- a/include/vulkan/vulkan_intel.h
+++ b/include/vulkan/vulkan_intel.h
@@ -44,6 +44,8 @@ typedef struct VkDmaBufImageCreateInfo_
 
 typedef VkResult (VKAPI_PTR *PFN_vkCreateDmaBufImageINTEL)(VkDevice device, const VkDmaBufImageCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMem, VkImage* pImage);
 
+typedef VkResult (VKAPI_PTR *PFN_vkGetDmaBufINTEL)(VkDevice device, VkDeviceMemory mem, VkImage image, int *fd, uint32_t *pitch);
+
 #ifndef VK_NO_PROTOTYPES
 
 VKAPI_ATTR VkResult VKAPI_CALL vkCreateDmaBufImageINTEL(
@@ -53,6 +55,13 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateDmaBufImageINTEL(
     VkDeviceMemory*                             pMem,
     VkImage*                                    pImage);
 
+VKAPI_ATTR VkResult VKAPI_CALL vkGetDmaBufINTEL(
+    VkDevice                                    _device,
+    VkDeviceMemory                              _mem,
+    VkImage                                     _image,
+    int*                                        fd,
+    uint32_t*                                   pitch);
+
 #endif
 
 #ifdef __cplusplus
diff --git a/src/intel/vulkan/anv_intel.c b/src/intel/vulkan/anv_intel.c
index d95d9af..d276754 100644
--- a/src/intel/vulkan/anv_intel.c
+++ b/src/intel/vulkan/anv_intel.c
@@ -98,3 +98,33 @@ VkResult anv_CreateDmaBufImageINTEL(
 
    return result;
 }
+
+VkResult anv_GetDmaBufINTEL(
+    VkDevice                                    _device,
+    VkDeviceMemory                              _mem,
+    VkImage                                     _image,
+    int*                                        fd,
+    uint32_t*                                   pitch)
+{
+   ANV_FROM_HANDLE(anv_device, device, _device);
+   ANV_FROM_HANDLE(anv_device_memory, mem, _mem);
+   ANV_FROM_HANDLE(anv_image, image, _image);
+
+   struct anv_surface *surface = &image->color_surface;
+
+   int tiling = surface->isl.tiling == ISL_TILING_X ? I915_TILING_X :
+                surface->isl.tiling == ISL_TILING_Y0 ? I915_TILING_Y :
+                I915_TILING_NONE;
+   int ret = anv_gem_set_tiling(device, mem->bo.gem_handle,
+                                surface->isl.row_pitch, tiling);
+   if (ret)
+      return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+
+   ret = anv_gem_handle_to_fd(device, mem->bo.gem_handle);
+   if (ret == -1)
+    return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+
+    *fd = ret;
+    *pitch = surface->isl.row_pitch;
+   return VK_SUCCESS;
+}
-- 
2.8.1



More information about the mesa-dev mailing list