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

Jonathan jonathan at marek.ca
Wed Jul 20 18:18:21 UTC 2016


I followed your suggestions and changed the prototype, although the implementation only supports basic formats
---
 include/vulkan/vulkan_intel.h | 17 +++++++++++++++
 src/intel/vulkan/anv_intel.c  | 49 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+)

diff --git a/include/vulkan/vulkan_intel.h b/include/vulkan/vulkan_intel.h
index 8ede61b..b483877 100644
--- a/include/vulkan/vulkan_intel.h
+++ b/include/vulkan/vulkan_intel.h
@@ -44,6 +44,17 @@ typedef struct VkDmaBufImageCreateInfo_
 
 typedef VkResult (VKAPI_PTR *PFN_vkCreateDmaBufImageINTEL)(VkDevice device, const VkDmaBufImageCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMem, VkImage* pImage);
 
+typedef struct VkDmaBufINTEL {
+    int fd; /* device fd */
+    uint32_t format;    /* fourcc code */
+    uint32_t handles[4]; /* prime handles (not fd) */
+    uint32_t pitches[4];
+    uint32_t offsets[4];
+    uint64_t modifiers[4]; /* tiling */
+} VkDmaBufINTEL;
+
+typedef VkResult (VKAPI_PTR *PFN_vkGetDmaBufINTEL)(VkDevice device, VkDeviceMemory mem, VkImage image, VkDmaBufINTEL *out);
+
 #ifndef VK_NO_PROTOTYPES
 
 VKAPI_ATTR VkResult VKAPI_CALL vkCreateDmaBufImageINTEL(
@@ -53,6 +64,12 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateDmaBufImageINTEL(
     VkDeviceMemory*                             pMem,
     VkImage*                                    pImage);
 
+VKAPI_ATTR VkResult VKAPI_CALL vkGetDmaBufINTEL(
+    VkDevice                                    _device,
+    VkDeviceMemory                              _mem,
+    VkImage                                     _image,
+    VkDmaBufINTEL*                              out);
+
 #endif
 
 #ifdef __cplusplus
diff --git a/src/intel/vulkan/anv_intel.c b/src/intel/vulkan/anv_intel.c
index d95d9af..d8b95c7 100644
--- a/src/intel/vulkan/anv_intel.c
+++ b/src/intel/vulkan/anv_intel.c
@@ -26,6 +26,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <drm_fourcc.h>
 
 #include "anv_private.h"
 
@@ -98,3 +99,51 @@ VkResult anv_CreateDmaBufImageINTEL(
 
    return result;
 }
+
+static uint64_t isl_tiling_to_modifier(int tiling)
+{
+    switch (tiling) {
+    case ISL_TILING_LINEAR:
+        return 0;
+    case ISL_TILING_X:
+        return I915_FORMAT_MOD_X_TILED;
+    case ISL_TILING_Y0:
+        return I915_FORMAT_MOD_Y_TILED;
+    case ISL_TILING_Yf:
+        return I915_FORMAT_MOD_Yf_TILED;
+    }
+    assert(!"no isl_tiling -> modifier conversion");
+}
+
+static uint32_t isl_format_to_drm_format(int format)
+{
+    switch (format) {
+    case ISL_FORMAT_R8G8B8A8_UNORM:
+        return DRM_FORMAT_RGBA8888;
+    case ISL_FORMAT_B8G8R8A8_UNORM:
+        return DRM_FORMAT_BGRA8888;
+    }
+    assert(!"no isl_format -> drm_format conversion");
+}
+
+VkResult anv_GetDmaBufINTEL(
+    VkDevice                                    _device,
+    VkDeviceMemory                              _mem,
+    VkImage                                     _image,
+    VkDmaBufINTEL*                              out)
+{
+   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;
+
+   memset(out, 0, sizeof(*out));
+   out->fd = device->fd;
+   out->format = isl_format_to_drm_format(surface->isl.format);
+   out->handles[0] = mem->bo.gem_handle;
+   out->pitches[0] = surface->isl.row_pitch;
+   out->modifiers[0] = isl_tiling_to_modifier(surface->isl.tiling);
+
+   return VK_SUCCESS;
+}
-- 
2.8.1



More information about the mesa-dev mailing list