* IN THE SOFTWARE.
*/
+#include <X11/Xlib-xcb.h>
#include <X11/xshmfence.h>
#include <xcb/xcb.h>
#include <xcb/dri3.h>
#include "anv_wsi.h"
+#include "vk_format_info.h"
#include "util/hash_table.h"
struct wsi_x11_connection {
};
static struct wsi_x11_connection *
-wsi_x11_connection_create(struct anv_instance *instance, xcb_connection_t *conn)
+wsi_x11_connection_create(struct anv_physical_device *device,
+ xcb_connection_t *conn)
{
xcb_query_extension_cookie_t dri3_cookie, pres_cookie;
xcb_query_extension_reply_t *dri3_reply, *pres_reply;
struct wsi_x11_connection *wsi_conn =
- anv_alloc(&instance->alloc, sizeof(*wsi_conn), 8,
+ anv_alloc(&device->instance->alloc, sizeof(*wsi_conn), 8,
VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
if (!wsi_conn)
return NULL;
if (dri3_reply == NULL || pres_reply == NULL) {
free(dri3_reply);
free(pres_reply);
- anv_free(&instance->alloc, wsi_conn);
+ anv_free(&device->instance->alloc, wsi_conn);
return NULL;
}
}
static void
-wsi_x11_connection_destroy(struct anv_instance *instance,
+wsi_x11_connection_destroy(struct anv_physical_device *device,
struct wsi_x11_connection *conn)
{
- anv_free(&instance->alloc, conn);
+ anv_free(&device->instance->alloc, conn);
}
static struct wsi_x11_connection *
-wsi_x11_get_connection(struct anv_instance *instance, xcb_connection_t *conn)
+wsi_x11_get_connection(struct anv_physical_device *device,
+ xcb_connection_t *conn)
{
struct wsi_x11 *wsi =
- (struct wsi_x11 *)instance->wsi[VK_ICD_WSI_PLATFORM_XCB];
+ (struct wsi_x11 *)device->wsi[VK_ICD_WSI_PLATFORM_XCB];
pthread_mutex_lock(&wsi->mutex);
pthread_mutex_unlock(&wsi->mutex);
struct wsi_x11_connection *wsi_conn =
- wsi_x11_connection_create(instance, conn);
+ wsi_x11_connection_create(device, conn);
pthread_mutex_lock(&wsi->mutex);
entry = _mesa_hash_table_search(wsi->connections, conn);
if (entry) {
/* Oops, someone raced us to it */
- wsi_x11_connection_destroy(instance, wsi_conn);
+ wsi_x11_connection_destroy(device, wsi_conn);
} else {
entry = _mesa_hash_table_insert(wsi->connections, conn, wsi_conn);
}
ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
struct wsi_x11_connection *wsi_conn =
- wsi_x11_get_connection(device->instance, connection);
+ wsi_x11_get_connection(device, connection);
if (!wsi_conn->has_dri3) {
fprintf(stderr, "vulkan: No DRI3 support\n");
return true;
}
+VkBool32 anv_GetPhysicalDeviceXlibPresentationSupportKHR(
+ VkPhysicalDevice physicalDevice,
+ uint32_t queueFamilyIndex,
+ Display* dpy,
+ VisualID visualID)
+{
+ return anv_GetPhysicalDeviceXcbPresentationSupportKHR(physicalDevice,
+ queueFamilyIndex,
+ XGetXCBConnection(dpy),
+ visualID);
+}
+
+static xcb_connection_t*
+x11_surface_get_connection(VkIcdSurfaceBase *icd_surface)
+{
+ if (icd_surface->platform == VK_ICD_WSI_PLATFORM_XLIB)
+ return XGetXCBConnection(((VkIcdSurfaceXlib *)icd_surface)->dpy);
+ else
+ return ((VkIcdSurfaceXcb *)icd_surface)->connection;
+}
+
+static xcb_window_t
+x11_surface_get_window(VkIcdSurfaceBase *icd_surface)
+{
+ if (icd_surface->platform == VK_ICD_WSI_PLATFORM_XLIB)
+ return ((VkIcdSurfaceXlib *)icd_surface)->window;
+ else
+ return ((VkIcdSurfaceXcb *)icd_surface)->window;
+}
+
static VkResult
x11_surface_get_support(VkIcdSurfaceBase *icd_surface,
struct anv_physical_device *device,
uint32_t queueFamilyIndex,
VkBool32* pSupported)
{
- VkIcdSurfaceXcb *surface = (VkIcdSurfaceXcb *)icd_surface;
+ xcb_connection_t *conn = x11_surface_get_connection(icd_surface);
+ xcb_window_t window = x11_surface_get_window(icd_surface);
struct wsi_x11_connection *wsi_conn =
- wsi_x11_get_connection(device->instance, surface->connection);
+ wsi_x11_get_connection(device, conn);
if (!wsi_conn)
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
}
unsigned visual_depth;
- if (!get_visualtype_for_window(surface->connection, surface->window,
- &visual_depth)) {
+ if (!get_visualtype_for_window(conn, window, &visual_depth)) {
*pSupported = false;
return VK_SUCCESS;
}
struct anv_physical_device *device,
VkSurfaceCapabilitiesKHR *caps)
{
- VkIcdSurfaceXcb *surface = (VkIcdSurfaceXcb *)icd_surface;
+ xcb_connection_t *conn = x11_surface_get_connection(icd_surface);
+ xcb_window_t window = x11_surface_get_window(icd_surface);
xcb_get_geometry_cookie_t geom_cookie;
xcb_generic_error_t *err;
xcb_get_geometry_reply_t *geom;
unsigned visual_depth;
- geom_cookie = xcb_get_geometry(surface->connection, surface->window);
+ geom_cookie = xcb_get_geometry(conn, window);
/* This does a round-trip. This is why we do get_geometry first and
* wait to read the reply until after we have a visual.
*/
xcb_visualtype_t *visual =
- get_visualtype_for_window(surface->connection, surface->window,
- &visual_depth);
+ get_visualtype_for_window(conn, window, &visual_depth);
- geom = xcb_get_geometry_reply(surface->connection, geom_cookie, &err);
+ geom = xcb_get_geometry_reply(conn, geom_cookie, &err);
if (geom) {
VkExtent2D extent = { geom->width, geom->height };
caps->currentExtent = extent;
return VK_SUCCESS;
}
+VkResult anv_CreateXlibSurfaceKHR(
+ VkInstance _instance,
+ const VkXlibSurfaceCreateInfoKHR* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkSurfaceKHR* pSurface)
+{
+ ANV_FROM_HANDLE(anv_instance, instance, _instance);
+
+ assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR);
+
+ VkIcdSurfaceXlib *surface;
+
+ surface = anv_alloc2(&instance->alloc, pAllocator, sizeof *surface, 8,
+ VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+ if (surface == NULL)
+ return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
+
+ surface->base.platform = VK_ICD_WSI_PLATFORM_XLIB;
+ surface->dpy = pCreateInfo->dpy;
+ surface->window = pCreateInfo->window;
+
+ *pSurface = _VkIcdSurfaceBase_to_handle(&surface->base);
+
+ return VK_SUCCESS;
+}
+
struct x11_image {
struct anv_image * image;
struct anv_device_memory * memory;
.samples = 1,
/* FIXME: Need a way to use X tiling to allow scanout */
.tiling = VK_IMAGE_TILING_OPTIMAL,
- .usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
+ .usage = (pCreateInfo->imageUsage |
+ VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT),
.flags = 0,
}},
NULL,
return result;
image->image = anv_image_from_handle(image_h);
- assert(anv_format_is_color(image->image->format));
+ assert(vk_format_is_color(image->image->vk_format));
VkDeviceMemory memory_h;
result = anv_AllocateMemory(anv_device_to_handle(device),
const VkAllocationCallbacks* pAllocator,
struct anv_swapchain **swapchain_out)
{
- VkIcdSurfaceXcb *surface = (VkIcdSurfaceXcb *)icd_surface;
struct x11_swapchain *chain;
xcb_void_cookie_t cookie;
VkResult result;
chain->base.acquire_next_image = x11_acquire_next_image;
chain->base.queue_present = x11_queue_present;
- chain->conn = surface->connection;
- chain->window = surface->window;
+ chain->conn = x11_surface_get_connection(icd_surface);
+ chain->window = x11_surface_get_window(icd_surface);
chain->extent = pCreateInfo->imageExtent;
chain->image_count = num_images;
}
VkResult
-anv_x11_init_wsi(struct anv_instance *instance)
+anv_x11_init_wsi(struct anv_physical_device *device)
{
struct wsi_x11 *wsi;
VkResult result;
- wsi = anv_alloc(&instance->alloc, sizeof(*wsi), 8,
+ wsi = anv_alloc(&device->instance->alloc, sizeof(*wsi), 8,
VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
if (!wsi) {
result = vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
wsi->base.get_present_modes = x11_surface_get_present_modes;
wsi->base.create_swapchain = x11_surface_create_swapchain;
- instance->wsi[VK_ICD_WSI_PLATFORM_XCB] = &wsi->base;
+ device->wsi[VK_ICD_WSI_PLATFORM_XCB] = &wsi->base;
+ device->wsi[VK_ICD_WSI_PLATFORM_XLIB] = &wsi->base;
return VK_SUCCESS;
fail_mutex:
pthread_mutex_destroy(&wsi->mutex);
fail_alloc:
- anv_free(&instance->alloc, wsi);
+ anv_free(&device->instance->alloc, wsi);
fail:
- instance->wsi[VK_ICD_WSI_PLATFORM_XCB] = NULL;
+ device->wsi[VK_ICD_WSI_PLATFORM_XCB] = NULL;
+ device->wsi[VK_ICD_WSI_PLATFORM_XLIB] = NULL;
return result;
}
void
-anv_x11_finish_wsi(struct anv_instance *instance)
+anv_x11_finish_wsi(struct anv_physical_device *device)
{
struct wsi_x11 *wsi =
- (struct wsi_x11 *)instance->wsi[VK_ICD_WSI_PLATFORM_XCB];
+ (struct wsi_x11 *)device->wsi[VK_ICD_WSI_PLATFORM_XCB];
if (wsi) {
_mesa_hash_table_destroy(wsi->connections, NULL);
pthread_mutex_destroy(&wsi->mutex);
- anv_free(&instance->alloc, wsi);
+ anv_free(&device->instance->alloc, wsi);
}
}