RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice);
return wsi_common_get_surface_support(&device->wsi_device,
- device->local_fd,
queueFamilyIndex,
surface,
pSupported);
return wsi_common_create_swapchain(&device->physical_device->wsi_device,
radv_device_to_handle(device),
- device->physical_device->local_fd,
pCreateInfo,
alloc,
pSwapchain);
RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice);
return wsi_common_get_present_rectangles(&device->wsi_device,
- device->local_fd,
surface,
pRectCount, pRects);
}
return wsi_get_physical_device_xcb_presentation_support(
&device->wsi_device,
queueFamilyIndex,
- device->local_fd, true,
+ true,
connection, visual_id);
}
return wsi_get_physical_device_xcb_presentation_support(
&device->wsi_device,
queueFamilyIndex,
- device->local_fd, true,
+ true,
XGetXCBConnection(dpy), visualID);
}
ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
return wsi_common_get_surface_support(&device->wsi_device,
- device->local_fd,
queueFamilyIndex,
surface,
pSupported);
else
alloc = &device->alloc;
- return wsi_common_create_swapchain(wsi_device, _device, device->fd,
+ return wsi_common_create_swapchain(wsi_device, _device,
pCreateInfo, alloc, pSwapchain);
}
ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
return wsi_common_get_present_rectangles(&device->wsi_device,
- device->local_fd,
surface,
pRectCount, pRects);
}
return wsi_get_physical_device_xcb_presentation_support(
&device->wsi_device,
queueFamilyIndex,
- device->local_fd, false,
+ false,
connection, visual_id);
}
return wsi_get_physical_device_xcb_presentation_support(
&device->wsi_device,
queueFamilyIndex,
- device->local_fd, false,
+ false,
XGetXCBConnection(dpy), visualID);
}
#include "vk_util.h"
#include <unistd.h>
+#include <xf86drm.h>
VkResult
wsi_device_init(struct wsi_device *wsi,
#define WSI_GET_CB(func) \
PFN_vk##func func = (PFN_vk##func)proc_addr(pdevice, "vk" #func)
+ WSI_GET_CB(GetPhysicalDeviceProperties2);
WSI_GET_CB(GetPhysicalDeviceMemoryProperties);
WSI_GET_CB(GetPhysicalDeviceQueueFamilyProperties);
#undef WSI_GET_CB
+ wsi->pci_bus_info.sType =
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT;
+ VkPhysicalDeviceProperties2 pdp2 = {
+ .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2,
+ .pNext = &wsi->pci_bus_info,
+ };
+ GetPhysicalDeviceProperties2(pdevice, &pdp2);
+
GetPhysicalDeviceMemoryProperties(pdevice, &wsi->memory_props);
GetPhysicalDeviceQueueFamilyProperties(pdevice, &wsi->queue_family_count, NULL);
#endif
}
+bool
+wsi_device_matches_drm_fd(const struct wsi_device *wsi, int drm_fd)
+{
+ drmDevicePtr fd_device;
+ int ret = drmGetDevice(drm_fd, &fd_device);
+ if (ret)
+ return false;
+
+ bool match = false;
+ switch (fd_device->bustype) {
+ case DRM_BUS_PCI:
+ match = wsi->pci_bus_info.pciDomain == fd_device->businfo.pci->domain &&
+ wsi->pci_bus_info.pciBus == fd_device->businfo.pci->bus &&
+ wsi->pci_bus_info.pciDevice == fd_device->businfo.pci->dev &&
+ wsi->pci_bus_info.pciFunction == fd_device->businfo.pci->func;
+ break;
+
+ default:
+ break;
+ }
+
+ drmFreeDevice(&fd_device);
+
+ return match;
+}
+
VkResult
wsi_swapchain_init(const struct wsi_device *wsi,
struct wsi_swapchain *chain,
VkResult
wsi_common_get_surface_support(struct wsi_device *wsi_device,
- int local_fd,
uint32_t queueFamilyIndex,
VkSurfaceKHR _surface,
VkBool32* pSupported)
struct wsi_interface *iface = wsi_device->wsi[surface->platform];
return iface->get_support(surface, wsi_device,
- queueFamilyIndex, local_fd, pSupported);
+ queueFamilyIndex, pSupported);
}
VkResult
VkResult
wsi_common_get_present_rectangles(struct wsi_device *wsi_device,
- int local_fd,
VkSurfaceKHR _surface,
uint32_t* pRectCount,
VkRect2D* pRects)
ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, _surface);
struct wsi_interface *iface = wsi_device->wsi[surface->platform];
- return iface->get_present_rectangles(surface, wsi_device, local_fd,
+ return iface->get_present_rectangles(surface, wsi_device,
pRectCount, pRects);
}
VkResult
wsi_common_create_swapchain(struct wsi_device *wsi,
VkDevice device,
- int fd,
const VkSwapchainCreateInfoKHR *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkSwapchainKHR *pSwapchain)
struct wsi_interface *iface = wsi->wsi[surface->platform];
struct wsi_swapchain *swapchain;
- VkResult result = iface->create_swapchain(surface, device, wsi, fd,
+ VkResult result = iface->create_swapchain(surface, device, wsi,
pCreateInfo, pAllocator,
&swapchain);
if (result != VK_SUCCESS)
VkPhysicalDeviceMemoryProperties memory_props;
uint32_t queue_family_count;
+ VkPhysicalDevicePCIBusInfoPropertiesEXT pci_bus_info;
+
bool supports_modifiers;
uint64_t (*image_get_modifier)(VkImage image);
VkResult
wsi_common_get_surface_support(struct wsi_device *wsi_device,
- int local_fd,
uint32_t queueFamilyIndex,
VkSurfaceKHR surface,
VkBool32* pSupported);
VkResult
wsi_common_get_present_rectangles(struct wsi_device *wsi,
- int local_fd,
VkSurfaceKHR surface,
uint32_t* pRectCount,
VkRect2D* pRects);
VkResult
wsi_common_create_swapchain(struct wsi_device *wsi,
VkDevice device,
- int fd,
const VkSwapchainCreateInfoKHR *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkSwapchainKHR *pSwapchain);
wsi_display_surface_get_support(VkIcdSurfaceBase *surface,
struct wsi_device *wsi_device,
uint32_t queueFamilyIndex,
- int local_fd,
VkBool32* pSupported)
{
*pSupported = VK_TRUE;
return vk_outarray_status(&conn);
}
-static bool
-fds_are_same_gpu(int fd1, int fd2)
-{
- if (fd1 == -1 || fd2 == -1)
- return false;
-
- char *fd1_dev = drmGetRenderDeviceNameFromFd(fd1);
- char *fd2_dev = drmGetRenderDeviceNameFromFd(fd2);
-
- int ret = strcmp(fd1_dev, fd2_dev);
-
- free(fd1_dev);
- free(fd2_dev);
-
- return ret == 0;
-}
-
static VkResult
wsi_display_surface_get_present_rectangles(VkIcdSurfaceBase *surface_base,
struct wsi_device *wsi_device,
- int local_fd,
uint32_t* pRectCount,
VkRect2D* pRects)
{
wsi_display_mode *mode = wsi_display_mode_from_handle(surface->displayMode);
VK_OUTARRAY_MAKE(out, pRects, pRectCount);
- if (fds_are_same_gpu(local_fd, mode->connector->wsi->fd)) {
+ if (wsi_device_matches_drm_fd(wsi_device, mode->connector->wsi->fd)) {
vk_outarray_append(&out, rect) {
*rect = (VkRect2D) {
.offset = { 0, 0 },
VkIcdSurfaceBase *icd_surface,
VkDevice device,
struct wsi_device *wsi_device,
- int local_fd,
const VkSwapchainCreateInfoKHR *create_info,
const VkAllocationCallbacks *allocator,
struct wsi_swapchain **swapchain_out)
const VkPresentRegionKHR *damage);
};
+bool
+wsi_device_matches_drm_fd(const struct wsi_device *wsi, int drm_fd);
+
VkResult
wsi_swapchain_init(const struct wsi_device *wsi,
struct wsi_swapchain *chain,
VkResult (*get_support)(VkIcdSurfaceBase *surface,
struct wsi_device *wsi_device,
uint32_t queueFamilyIndex,
- int local_fd,
VkBool32* pSupported);
VkResult (*get_capabilities2)(VkIcdSurfaceBase *surface,
const void *info_next,
VkPresentModeKHR* pPresentModes);
VkResult (*get_present_rectangles)(VkIcdSurfaceBase *surface,
struct wsi_device *wsi_device,
- int local_fd,
uint32_t* pRectCount,
VkRect2D* pRects);
VkResult (*create_swapchain)(VkIcdSurfaceBase *surface,
VkDevice device,
struct wsi_device *wsi_device,
- int local_fd,
const VkSwapchainCreateInfoKHR* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
struct wsi_swapchain **swapchain);
wsi_wl_surface_get_support(VkIcdSurfaceBase *surface,
struct wsi_device *wsi_device,
uint32_t queueFamilyIndex,
- int local_fd,
VkBool32* pSupported)
{
*pSupported = true;
static VkResult
wsi_wl_surface_get_present_rectangles(VkIcdSurfaceBase *surface,
struct wsi_device *wsi_device,
- int local_fd,
uint32_t* pRectCount,
VkRect2D* pRects)
{
wsi_wl_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
VkDevice device,
struct wsi_device *wsi_device,
- int local_fd,
const VkSwapchainCreateInfoKHR* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
struct wsi_swapchain **swapchain_out)
}
static bool
-wsi_x11_check_dri3_compatible(xcb_connection_t *conn, int local_fd)
+wsi_x11_check_dri3_compatible(const struct wsi_device *wsi_dev,
+ xcb_connection_t *conn)
{
xcb_screen_iterator_t screen_iter =
xcb_setup_roots_iterator(xcb_get_setup(conn));
xcb_screen_t *screen = screen_iter.data;
int dri3_fd = wsi_dri3_open(conn, screen->root, None);
- if (dri3_fd != -1) {
- char *local_dev = drmGetRenderDeviceNameFromFd(local_fd);
- char *dri3_dev = drmGetRenderDeviceNameFromFd(dri3_fd);
- int ret;
-
- close(dri3_fd);
+ if (dri3_fd == -1)
+ return true;
- ret = strcmp(local_dev, dri3_dev);
+ bool match = wsi_device_matches_drm_fd(wsi_dev, dri3_fd);
- free(local_dev);
- free(dri3_dev);
+ close(dri3_fd);
- if (ret != 0)
- return false;
- }
- return true;
+ return match;
}
static struct wsi_x11_connection *
VkBool32 wsi_get_physical_device_xcb_presentation_support(
struct wsi_device *wsi_device,
uint32_t queueFamilyIndex,
- int fd,
bool can_handle_different_gpu,
xcb_connection_t* connection,
xcb_visualid_t visual_id)
return false;
if (!can_handle_different_gpu)
- if (!wsi_x11_check_dri3_compatible(connection, fd))
+ if (!wsi_x11_check_dri3_compatible(wsi_device, connection))
return false;
unsigned visual_depth;
x11_surface_get_support(VkIcdSurfaceBase *icd_surface,
struct wsi_device *wsi_device,
uint32_t queueFamilyIndex,
- int local_fd,
VkBool32* pSupported)
{
xcb_connection_t *conn = x11_surface_get_connection(icd_surface);
static bool
x11_surface_is_local_to_gpu(struct wsi_device *wsi_dev,
- int local_fd,
xcb_connection_t *conn)
{
struct wsi_x11_connection *wsi_conn =
if (!wsi_x11_check_for_dri3(wsi_conn))
return false;
- if (!wsi_x11_check_dri3_compatible(conn, local_fd))
+ if (!wsi_x11_check_dri3_compatible(wsi_dev, conn))
return false;
return true;
static VkResult
x11_surface_get_present_rectangles(VkIcdSurfaceBase *icd_surface,
struct wsi_device *wsi_device,
- int local_fd,
uint32_t* pRectCount,
VkRect2D* pRects)
{
xcb_window_t window = x11_surface_get_window(icd_surface);
VK_OUTARRAY_MAKE(out, pRects, pRectCount);
- if (x11_surface_is_local_to_gpu(wsi_device, local_fd, conn)) {
+ if (x11_surface_is_local_to_gpu(wsi_device, conn)) {
vk_outarray_append(&out, rect) {
xcb_generic_error_t *err = NULL;
xcb_get_geometry_cookie_t geom_cookie = xcb_get_geometry(conn, window);
x11_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
VkDevice device,
struct wsi_device *wsi_device,
- int local_fd,
const VkSwapchainCreateInfoKHR *pCreateInfo,
const VkAllocationCallbacks* pAllocator,
struct wsi_swapchain **swapchain_out)
else
chain->last_present_mode = XCB_PRESENT_COMPLETE_MODE_COPY;
- if (!wsi_x11_check_dri3_compatible(conn, local_fd))
+ if (!wsi_x11_check_dri3_compatible(wsi_device, conn))
chain->base.use_prime_blit = true;
chain->event_id = xcb_generate_id(chain->conn);
VkBool32 wsi_get_physical_device_xcb_presentation_support(
struct wsi_device *wsi_device,
uint32_t queueFamilyIndex,
- int local_fd,
bool can_handle_different_gpu,
xcb_connection_t* connection,
xcb_visualid_t visual_id);