<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Feb 15, 2018 at 7:57 AM, Daniel Stone <span dir="ltr"><<a href="mailto:daniels@collabora.com" target="_blank">daniels@collabora.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">zwp_linux_dmabuf_v1 lets us use multi-planar images and buffer<br>
modifiers.<br>
<br>
Signed-off-by: Daniel Stone <<a href="mailto:daniels@collabora.com">daniels@collabora.com</a>><br>
---<br>
src/vulkan/Makefile.am | 10 +++<br>
src/vulkan/Makefile.sources | 4 +-<br>
src/vulkan/wsi/meson.build | 2 +<br>
src/vulkan/wsi/wsi_common_<wbr>wayland.c | 138 ++++++++++++++++++++++++++++++<wbr>++----<br>
4 files changed, 139 insertions(+), 15 deletions(-)<br>
<br>
diff --git a/src/vulkan/Makefile.am b/src/vulkan/Makefile.am<br>
index 4fdaedf38c1..c7813ce05e3 100644<br>
--- a/src/vulkan/Makefile.am<br>
+++ b/src/vulkan/Makefile.am<br>
@@ -71,6 +71,16 @@ wsi/wayland-drm-client-<wbr>protocol.h : $(WL_DRM_XML)<br>
$(MKDIR_GEN)<br>
$(AM_V_GEN)$(WAYLAND_SCANNER) client-header < $< > $@<br>
<br>
+WL_DMABUF_XML = $(WAYLAND_PROTOCOLS_DATADIR)/<wbr>unstable/linux-dmabuf/linux-<wbr>dmabuf-unstable-v1.xml<br>
+<br>
+wsi/linux-dmabuf-unstable-v1-<wbr>protocol.c : $(WL_DMABUF_XML)<br>
+ $(MKDIR_GEN)<br>
+ $(AM_V_GEN)$(WAYLAND_SCANNER) code < $< > $@<br>
+<br>
+wsi/linux-dmabuf-unstable-v1-<wbr>client-protocol.h : $(WL_DMABUF_XML)<br>
+ $(MKDIR_GEN)<br>
+ $(AM_V_GEN)$(WAYLAND_SCANNER) client-header < $< > $@<br>
+<br>
if HAVE_PLATFORM_WAYLAND<br>
AM_CPPFLAGS += \<br>
-I$(top_builddir)/src/vulkan/<wbr>wsi \<br>
diff --git a/src/vulkan/Makefile.sources b/src/vulkan/Makefile.sources<br>
index a0a24ce7de8..101a94349c6 100644<br>
--- a/src/vulkan/Makefile.sources<br>
+++ b/src/vulkan/Makefile.sources<br>
@@ -11,7 +11,9 @@ VULKAN_WSI_WAYLAND_FILES := \<br>
<br>
VULKAN_WSI_WAYLAND_GENERATED_<wbr>FILES := \<br>
wsi/wayland-drm-protocol.c \<br>
- wsi/wayland-drm-client-<wbr>protocol.h<br>
+ wsi/wayland-drm-client-<wbr>protocol.h \<br>
+ wsi/linux-dmabuf-unstable-v1-<wbr>protocol.c \<br>
+ wsi/linux-dmabuf-unstable-v1-<wbr>client-protocol.h<br>
<br>
VULKAN_WSI_X11_FILES := \<br>
wsi/wsi_common_x11.c \<br>
diff --git a/src/vulkan/wsi/meson.build b/src/vulkan/wsi/meson.build<br>
index 66ccc8316ec..223c8ca357e 100644<br>
--- a/src/vulkan/wsi/meson.build<br>
+++ b/src/vulkan/wsi/meson.build<br>
@@ -54,6 +54,8 @@ if with_platform_wayland<br>
files_vulkan_wsi += [<br>
wayland_drm_client_protocol_h,<br>
wayland_drm_protocol_c,<br>
+ linux_dmabuf_unstable_v1_<wbr>client_protocol_h,<br>
+ linux_dmabuf_unstable_v1_<wbr>protocol_c,<br>
]<br>
endif<br>
<br>
diff --git a/src/vulkan/wsi/wsi_common_<wbr>wayland.c b/src/vulkan/wsi/wsi_common_<wbr>wayland.c<br>
index 1162b92c35f..26acde194d6 100644<br>
--- a/src/vulkan/wsi/wsi_common_<wbr>wayland.c<br>
+++ b/src/vulkan/wsi/wsi_common_<wbr>wayland.c<br>
@@ -31,10 +31,13 @@<br>
#include <string.h><br>
#include <pthread.h><br>
<br>
+#include <drm_fourcc.h><br>
+<br>
#include "vk_util.h"<br>
#include "wsi_common_private.h"<br>
#include "wsi_common_wayland.h"<br>
#include "wayland-drm-client-protocol.<wbr>h"<br>
+#include "linux-dmabuf-unstable-v1-<wbr>client-protocol.h"<br>
<br>
#include <util/hash_table.h><br>
#include <util/u_vector.h><br>
@@ -53,11 +56,17 @@ struct wsi_wl_display {<br>
struct wl_display * wl_display_wrapper;<br>
struct wl_event_queue * queue;<br>
struct wl_drm * drm;<br>
+ struct zwp_linux_dmabuf_v1 * dmabuf;<br>
<br>
struct wsi_wayland *wsi_wl;<br>
/* Vector of VkFormats supported */<br>
struct u_vector formats;<br>
<br>
+ struct {<br>
+ struct u_vector argb8888;<br>
+ struct u_vector xrgb8888;<br>
+ } modifiers;<br>
+<br>
uint32_t capabilities;<br>
<br>
/* Only used for displays created by wsi_wl_display_create */<br>
@@ -223,6 +232,53 @@ static const struct wl_drm_listener drm_listener = {<br>
drm_handle_capabilities,<br>
};<br>
<br>
+static void<br>
+dmabuf_handle_format(void *data, struct zwp_linux_dmabuf_v1 *dmabuf,<br>
+ uint32_t format)<br>
+{<br>
+ /* Formats are implicitly advertised by the modifier event, so we ignore<br>
+ * them here. */<br>
+}<br>
+<br>
+static void<br>
+dmabuf_handle_modifier(void *data, struct zwp_linux_dmabuf_v1 *dmabuf,<br>
+ uint32_t format, uint32_t modifier_hi,<br>
+ uint32_t modifier_lo)<br>
+{<br>
+ struct wsi_wl_display *display = data;<br>
+ uint64_t *mod = NULL;<br>
+<br>
+ /* If we're not fetching formats, don't fetch modifiers either. */<br>
+ if (display->formats.element_size == 0)<br>
+ return;<br>
+<br>
+ if (modifier_hi == (DRM_FORMAT_MOD_INVALID >> 32) &&<br>
+ modifier_lo == (DRM_FORMAT_MOD_INVALID & 0xffffffff))<br>
+ return;<br>
+<br>
+ switch (format) {<br>
+ case WL_DRM_FORMAT_ARGB8888:<br>
+ mod = u_vector_add(&display-><wbr>modifiers.argb8888);<br>
+ break;<br>
+ case WL_DRM_FORMAT_XRGB8888:<br>
+ mod = u_vector_add(&display-><wbr>modifiers.xrgb8888);<br>
+ break;<br>
+ default:<br>
+ break;<br>
+ }<br>
+<br>
+ if (!mod)<br>
+ return;<br>
+<br>
+ *mod = (uint64_t) modifier_hi << 32;<br>
+ *mod |= (uint64_t) (modifier_lo & 0xffffffff);<br>
+}<br>
+<br>
+static const struct zwp_linux_dmabuf_v1_listener dmabuf_listener = {<br>
+ dmabuf_handle_format,<br>
+ dmabuf_handle_modifier,<br>
+};<br>
+<br>
static void<br>
registry_handle_global(void *data, struct wl_registry *registry,<br>
uint32_t name, const char *interface, uint32_t version)<br>
@@ -237,6 +293,11 @@ registry_handle_global(void *data, struct wl_registry *registry,<br>
<br>
if (display->drm)<br>
wl_drm_add_listener(display-><wbr>drm, &drm_listener, display);<br>
+ } else if (strcmp(interface, "zwp_linux_dmabuf_v1") == 0 && version >= 3) {<br>
+ display->dmabuf =<br>
+ wl_registry_bind(registry, name, &zwp_linux_dmabuf_v1_<wbr>interface, 3);<br>
+ zwp_linux_dmabuf_v1_add_<wbr>listener(display->dmabuf, &dmabuf_listener,<br>
+ display);<br>
}<br>
}<br>
<br>
@@ -277,7 +338,9 @@ wsi_wl_display_init(struct wsi_wayland *wsi_wl,<br>
display->wl_display = wl_display;<br>
<br>
if (get_format_list) {<br>
- if (!u_vector_init(&display-><wbr>formats, sizeof(VkFormat), 8)) {<br>
+ if (!u_vector_init(&display-><wbr>formats, sizeof(VkFormat), 8) ||<br>
+ !u_vector_init(&display-><wbr>modifiers.argb8888, sizeof(uint64_t), 32) ||<br>
+ !u_vector_init(&display-><wbr>modifiers.xrgb8888, sizeof(uint64_t), 32)) {<br>
result = VK_ERROR_OUT_OF_HOST_MEMORY;<br>
goto fail;<br>
}<br>
@@ -706,25 +769,72 @@ wsi_wl_image_init(struct wsi_wl_swapchain *chain,<br>
const VkSwapchainCreateInfoKHR *pCreateInfo,<br>
const VkAllocationCallbacks* pAllocator)<br>
{<br>
+ struct wsi_wl_display *display = chain->display;<br>
+ const uint64_t *modifiers = NULL;<br>
+ uint32_t num_modifiers = 0;<br>
VkResult result;<br>
<br>
+ if (display->dmabuf && chain->base.wsi->supports_<wbr>modifiers) {<br>
+ switch (chain->drm_format) {<br>
+ case WL_DRM_FORMAT_ARGB8888:<br>
+ modifiers = u_vector_tail(&display-><wbr>modifiers.argb8888);<br>
+ num_modifiers = u_vector_length(&display-><wbr>modifiers.argb8888);<br>
+ break;<br>
+ case WL_DRM_FORMAT_XRGB8888:<br>
+ modifiers = u_vector_tail(&display-><wbr>modifiers.xrgb8888);<br>
+ num_modifiers = u_vector_length(&display-><wbr>modifiers.xrgb8888);<br>
+ break;<br>
+ default:<br>
+ break;<br>
+ }<br>
+ }<br>
+<br>
result = wsi_create_native_image(&<wbr>chain->base, pCreateInfo,<br>
- 0, NULL, NULL, &image->base);<br>
+ num_modifiers > 0 ? 1 : 0,<br>
+ &num_modifiers, &modifiers,<br>
+ &image->base);<br>
+<br>
if (result != VK_SUCCESS)<br>
return result;<br>
<br>
- /* Without passing modifiers, we can't have multi-plane RGB images. */<br>
- assert(image->base.num_planes == 1);<br>
-<br>
- image->buffer = wl_drm_create_prime_buffer(<wbr>chain->drm_wrapper,<br>
- image->base.fds[0], /* name */<br>
- chain->extent.width,<br>
- chain->extent.height,<br>
- chain->drm_format,<br>
- image->base.offsets[0],<br>
- image->base.row_pitches[0],<br>
- 0, 0, 0, 0 /* unused */);<br>
- close(image->base.fds[0]);<br>
+ if (display->dmabuf && image->base.drm_modifier != DRM_FORMAT_MOD_INVALID) {<br></blockquote><div><br></div><div>You don't need the "display->dmabuf" here. modifier != INVALID implies dmabuf. Feel free to make it an assert though.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ struct zwp_linux_buffer_params_v1 *params =<br>
+ zwp_linux_dmabuf_v1_create_<wbr>params(display->dmabuf);<br>
+ wl_proxy_set_queue((struct wl_proxy *) params, chain->display->queue);<br>
+<br>
+ for (int i = 0; i < image->base.num_planes; i++) {<br>
+ zwp_linux_buffer_params_v1_<wbr>add(params,<br>
+ image->base.fds[i],<br>
+ i,<br>
+ image->base.offsets[i],<br>
+ image->base.row_pitches[i],<br>
+ image->base.drm_modifier >> 32,<br>
+ image->base.drm_modifier & 0xffffffff);<br>
+ close(image->base.fds[i]);<br>
+ }<br>
+<br>
+ image->buffer =<br>
+ zwp_linux_buffer_params_v1_<wbr>create_immed(params,<br>
+ chain->extent.width,<br>
+ chain->extent.height,<br>
+ chain->drm_format,<br>
+ 0);<br>
+ zwp_linux_buffer_params_v1_<wbr>destroy(params);<br>
+ } else {<br>
+ /* Without passing modifiers, we can't have multi-plane RGB images. */<br>
+ assert(image->base.num_planes == 1);<br>
+<br>
+ image->buffer =<br>
+ wl_drm_create_prime_buffer(<wbr>chain->drm_wrapper,<br>
+ image->base.fds[0], /* name */<br>
+ chain->extent.width,<br>
+ chain->extent.height,<br>
+ chain->drm_format,<br>
+ image->base.offsets[0],<br>
+ image->base.row_pitches[0],<br>
+ 0, 0, 0, 0 /* unused */);<br>
+ close(image->base.fds[0]);<br>
+ }<br>
<br>
if (!image->buffer)<br>
goto fail_image;<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.14.3<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>