summaryrefslogtreecommitdiff
path: root/src/vulkan
diff options
context:
space:
mode:
authorDaniel Stone <daniels@collabora.com>2018-02-09 15:43:30 -0800
committerDaniel Stone <daniels@collabora.com>2018-02-21 22:37:10 +0000
commitbfa22266cd4d268e52d2535b41ef972421e66f71 (patch)
tree7bb57ca0aa38d23c324672d69eddc72d326d475b /src/vulkan
parentc757fd2852849a5c8db92032ff66b6bbe5073f1c (diff)
vulkan/wsi/wayland: Add support for zwp_dmabuf
zwp_linux_dmabuf_v1 lets us use multi-planar images and buffer modifiers. Signed-off-by: Daniel Stone <daniels@collabora.com> Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Diffstat (limited to 'src/vulkan')
-rw-r--r--src/vulkan/Makefile.am10
-rw-r--r--src/vulkan/Makefile.sources4
-rw-r--r--src/vulkan/wsi/meson.build2
-rw-r--r--src/vulkan/wsi/wsi_common_wayland.c141
4 files changed, 142 insertions, 15 deletions
diff --git a/src/vulkan/Makefile.am b/src/vulkan/Makefile.am
index 4fdaedf38c..c7813ce05e 100644
--- a/src/vulkan/Makefile.am
+++ b/src/vulkan/Makefile.am
@@ -71,6 +71,16 @@ wsi/wayland-drm-client-protocol.h : $(WL_DRM_XML)
$(MKDIR_GEN)
$(AM_V_GEN)$(WAYLAND_SCANNER) client-header < $< > $@
+WL_DMABUF_XML = $(WAYLAND_PROTOCOLS_DATADIR)/unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml
+
+wsi/linux-dmabuf-unstable-v1-protocol.c : $(WL_DMABUF_XML)
+ $(MKDIR_GEN)
+ $(AM_V_GEN)$(WAYLAND_SCANNER) code < $< > $@
+
+wsi/linux-dmabuf-unstable-v1-client-protocol.h : $(WL_DMABUF_XML)
+ $(MKDIR_GEN)
+ $(AM_V_GEN)$(WAYLAND_SCANNER) client-header < $< > $@
+
if HAVE_PLATFORM_WAYLAND
AM_CPPFLAGS += \
-I$(top_builddir)/src/vulkan/wsi \
diff --git a/src/vulkan/Makefile.sources b/src/vulkan/Makefile.sources
index a0a24ce7de..101a94349c 100644
--- a/src/vulkan/Makefile.sources
+++ b/src/vulkan/Makefile.sources
@@ -11,7 +11,9 @@ VULKAN_WSI_WAYLAND_FILES := \
VULKAN_WSI_WAYLAND_GENERATED_FILES := \
wsi/wayland-drm-protocol.c \
- wsi/wayland-drm-client-protocol.h
+ wsi/wayland-drm-client-protocol.h \
+ wsi/linux-dmabuf-unstable-v1-protocol.c \
+ wsi/linux-dmabuf-unstable-v1-client-protocol.h
VULKAN_WSI_X11_FILES := \
wsi/wsi_common_x11.c \
diff --git a/src/vulkan/wsi/meson.build b/src/vulkan/wsi/meson.build
index 66ccc8316e..223c8ca357 100644
--- a/src/vulkan/wsi/meson.build
+++ b/src/vulkan/wsi/meson.build
@@ -54,6 +54,8 @@ if with_platform_wayland
files_vulkan_wsi += [
wayland_drm_client_protocol_h,
wayland_drm_protocol_c,
+ linux_dmabuf_unstable_v1_client_protocol_h,
+ linux_dmabuf_unstable_v1_protocol_c,
]
endif
diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c
index 1162b92c35..d36947bc29 100644
--- a/src/vulkan/wsi/wsi_common_wayland.c
+++ b/src/vulkan/wsi/wsi_common_wayland.c
@@ -31,10 +31,13 @@
#include <string.h>
#include <pthread.h>
+#include <drm_fourcc.h>
+
#include "vk_util.h"
#include "wsi_common_private.h"
#include "wsi_common_wayland.h"
#include "wayland-drm-client-protocol.h"
+#include "linux-dmabuf-unstable-v1-client-protocol.h"
#include <util/hash_table.h>
#include <util/u_vector.h>
@@ -53,11 +56,17 @@ struct wsi_wl_display {
struct wl_display * wl_display_wrapper;
struct wl_event_queue * queue;
struct wl_drm * drm;
+ struct zwp_linux_dmabuf_v1 * dmabuf;
struct wsi_wayland *wsi_wl;
/* Vector of VkFormats supported */
struct u_vector formats;
+ struct {
+ struct u_vector argb8888;
+ struct u_vector xrgb8888;
+ } modifiers;
+
uint32_t capabilities;
/* Only used for displays created by wsi_wl_display_create */
@@ -224,6 +233,53 @@ static const struct wl_drm_listener drm_listener = {
};
static void
+dmabuf_handle_format(void *data, struct zwp_linux_dmabuf_v1 *dmabuf,
+ uint32_t format)
+{
+ /* Formats are implicitly advertised by the modifier event, so we ignore
+ * them here. */
+}
+
+static void
+dmabuf_handle_modifier(void *data, struct zwp_linux_dmabuf_v1 *dmabuf,
+ uint32_t format, uint32_t modifier_hi,
+ uint32_t modifier_lo)
+{
+ struct wsi_wl_display *display = data;
+ uint64_t *mod = NULL;
+
+ /* If we're not fetching formats, don't fetch modifiers either. */
+ if (display->formats.element_size == 0)
+ return;
+
+ if (modifier_hi == (DRM_FORMAT_MOD_INVALID >> 32) &&
+ modifier_lo == (DRM_FORMAT_MOD_INVALID & 0xffffffff))
+ return;
+
+ switch (format) {
+ case WL_DRM_FORMAT_ARGB8888:
+ mod = u_vector_add(&display->modifiers.argb8888);
+ break;
+ case WL_DRM_FORMAT_XRGB8888:
+ mod = u_vector_add(&display->modifiers.xrgb8888);
+ break;
+ default:
+ break;
+ }
+
+ if (!mod)
+ return;
+
+ *mod = (uint64_t) modifier_hi << 32;
+ *mod |= (uint64_t) (modifier_lo & 0xffffffff);
+}
+
+static const struct zwp_linux_dmabuf_v1_listener dmabuf_listener = {
+ dmabuf_handle_format,
+ dmabuf_handle_modifier,
+};
+
+static void
registry_handle_global(void *data, struct wl_registry *registry,
uint32_t name, const char *interface, uint32_t version)
{
@@ -237,6 +293,11 @@ registry_handle_global(void *data, struct wl_registry *registry,
if (display->drm)
wl_drm_add_listener(display->drm, &drm_listener, display);
+ } else if (strcmp(interface, "zwp_linux_dmabuf_v1") == 0 && version >= 3) {
+ display->dmabuf =
+ wl_registry_bind(registry, name, &zwp_linux_dmabuf_v1_interface, 3);
+ zwp_linux_dmabuf_v1_add_listener(display->dmabuf, &dmabuf_listener,
+ display);
}
}
@@ -277,7 +338,9 @@ wsi_wl_display_init(struct wsi_wayland *wsi_wl,
display->wl_display = wl_display;
if (get_format_list) {
- if (!u_vector_init(&display->formats, sizeof(VkFormat), 8)) {
+ if (!u_vector_init(&display->formats, sizeof(VkFormat), 8) ||
+ !u_vector_init(&display->modifiers.argb8888, sizeof(uint64_t), 32) ||
+ !u_vector_init(&display->modifiers.xrgb8888, sizeof(uint64_t), 32)) {
result = VK_ERROR_OUT_OF_HOST_MEMORY;
goto fail;
}
@@ -706,25 +769,75 @@ wsi_wl_image_init(struct wsi_wl_swapchain *chain,
const VkSwapchainCreateInfoKHR *pCreateInfo,
const VkAllocationCallbacks* pAllocator)
{
+ struct wsi_wl_display *display = chain->display;
+ const uint64_t *modifiers = NULL;
+ uint32_t num_modifiers = 0;
VkResult result;
+ if (display->dmabuf && chain->base.wsi->supports_modifiers) {
+ switch (chain->drm_format) {
+ case WL_DRM_FORMAT_ARGB8888:
+ modifiers = u_vector_tail(&display->modifiers.argb8888);
+ num_modifiers = u_vector_length(&display->modifiers.argb8888);
+ break;
+ case WL_DRM_FORMAT_XRGB8888:
+ modifiers = u_vector_tail(&display->modifiers.xrgb8888);
+ num_modifiers = u_vector_length(&display->modifiers.xrgb8888);
+ break;
+ default:
+ break;
+ }
+ }
+
result = wsi_create_native_image(&chain->base, pCreateInfo,
- 0, NULL, NULL, &image->base);
+ num_modifiers > 0 ? 1 : 0,
+ &num_modifiers, &modifiers,
+ &image->base);
+
if (result != VK_SUCCESS)
return result;
- /* Without passing modifiers, we can't have multi-plane RGB images. */
- assert(image->base.num_planes == 1);
-
- image->buffer = wl_drm_create_prime_buffer(chain->drm_wrapper,
- image->base.fds[0], /* name */
- chain->extent.width,
- chain->extent.height,
- chain->drm_format,
- image->base.offsets[0],
- image->base.row_pitches[0],
- 0, 0, 0, 0 /* unused */);
- close(image->base.fds[0]);
+ if (image->base.drm_modifier != DRM_FORMAT_MOD_INVALID) {
+ /* Only request modifiers if we have dmabuf, else it must be implicit. */
+ assert(display->dmabuf);
+
+ struct zwp_linux_buffer_params_v1 *params =
+ zwp_linux_dmabuf_v1_create_params(display->dmabuf);
+ wl_proxy_set_queue((struct wl_proxy *) params, chain->display->queue);
+
+ for (int i = 0; i < image->base.num_planes; i++) {
+ zwp_linux_buffer_params_v1_add(params,
+ image->base.fds[i],
+ i,
+ image->base.offsets[i],
+ image->base.row_pitches[i],
+ image->base.drm_modifier >> 32,
+ image->base.drm_modifier & 0xffffffff);
+ close(image->base.fds[i]);
+ }
+
+ image->buffer =
+ zwp_linux_buffer_params_v1_create_immed(params,
+ chain->extent.width,
+ chain->extent.height,
+ chain->drm_format,
+ 0);
+ zwp_linux_buffer_params_v1_destroy(params);
+ } else {
+ /* Without passing modifiers, we can't have multi-plane RGB images. */
+ assert(image->base.num_planes == 1);
+
+ image->buffer =
+ wl_drm_create_prime_buffer(chain->drm_wrapper,
+ image->base.fds[0], /* name */
+ chain->extent.width,
+ chain->extent.height,
+ chain->drm_format,
+ image->base.offsets[0],
+ image->base.row_pitches[0],
+ 0, 0, 0, 0 /* unused */);
+ close(image->base.fds[0]);
+ }
if (!image->buffer)
goto fail_image;