mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-06 02:58:05 +02:00
device-select: clang-format
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com> Reviewed-by: Georg Lehmann <dadschoorse@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36717>
This commit is contained in:
parent
d77b066d52
commit
a392a57778
5 changed files with 269 additions and 222 deletions
4
src/vulkan/device-select-layer/.clang-format
Normal file
4
src/vulkan/device-select-layer/.clang-format
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
BasedOnStyle: InheritParentConfig
|
||||
DisableFormat: false
|
||||
|
||||
ColumnLimit: 100
|
||||
|
|
@ -30,27 +30,35 @@
|
|||
/* We don't use `drmPciDeviceInfo` because it uses 16-bit ids,
|
||||
* instead of Vulkan's 32-bit ones. */
|
||||
struct device_info {
|
||||
uint32_t vendor_id;
|
||||
uint32_t device_id;
|
||||
uint32_t vendor_id;
|
||||
uint32_t device_id;
|
||||
};
|
||||
|
||||
struct device_pci_info {
|
||||
struct device_info dev_info;
|
||||
drmPciBusInfo bus_info;
|
||||
bool has_bus_info;
|
||||
bool cpu_device;
|
||||
struct device_info dev_info;
|
||||
drmPciBusInfo bus_info;
|
||||
bool has_bus_info;
|
||||
bool cpu_device;
|
||||
};
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XCB_KHR
|
||||
int device_select_find_xcb_pci_default(struct device_pci_info *devices, uint32_t device_count);
|
||||
#else
|
||||
static inline int device_select_find_xcb_pci_default(struct device_pci_info *devices, uint32_t device_count) { return -1; }
|
||||
static inline int
|
||||
device_select_find_xcb_pci_default(struct device_pci_info *devices, uint32_t device_count)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
||||
int device_select_find_wayland_pci_default(struct device_pci_info *devices, uint32_t device_count);
|
||||
#else
|
||||
static inline int device_select_find_wayland_pci_default(struct device_pci_info *devices, uint32_t device_count) { return -1; }
|
||||
static inline int
|
||||
device_select_find_wayland_pci_default(struct device_pci_info *devices, uint32_t device_count)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -33,16 +33,16 @@
|
|||
#include <vulkan/vulkan.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "device_select.h"
|
||||
#include "util/hash_table.h"
|
||||
#include "vk_util.h"
|
||||
#include "util/simple_mtx.h"
|
||||
#include "util/u_debug.h"
|
||||
#include "device_select.h"
|
||||
#include "vk_util.h"
|
||||
|
||||
struct instance_info {
|
||||
PFN_vkDestroyInstance DestroyInstance;
|
||||
|
|
@ -65,8 +65,8 @@ device_select_init_instances(void)
|
|||
{
|
||||
simple_mtx_lock(&device_select_mutex);
|
||||
if (!device_select_instance_ht)
|
||||
device_select_instance_ht = _mesa_hash_table_create(NULL, _mesa_hash_pointer,
|
||||
_mesa_key_pointer_equal);
|
||||
device_select_instance_ht =
|
||||
_mesa_hash_table_create(NULL, _mesa_hash_pointer, _mesa_key_pointer_equal);
|
||||
simple_mtx_unlock(&device_select_mutex);
|
||||
}
|
||||
|
||||
|
|
@ -114,27 +114,37 @@ device_select_layer_remove_instance(VkInstance instance)
|
|||
device_select_try_free_ht();
|
||||
}
|
||||
|
||||
static VkResult device_select_CreateInstance(const VkInstanceCreateInfo *pCreateInfo,
|
||||
const VkAllocationCallbacks *pAllocator,
|
||||
VkInstance *pInstance)
|
||||
static VkResult
|
||||
device_select_CreateInstance(const VkInstanceCreateInfo *pCreateInfo,
|
||||
const VkAllocationCallbacks *pAllocator, VkInstance *pInstance)
|
||||
{
|
||||
VkLayerInstanceCreateInfo *chain_info;
|
||||
for(chain_info = (VkLayerInstanceCreateInfo*)pCreateInfo->pNext; chain_info; chain_info = (VkLayerInstanceCreateInfo*)chain_info->pNext)
|
||||
if(chain_info->sType == VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO && chain_info->function == VK_LAYER_LINK_INFO)
|
||||
for (chain_info = (VkLayerInstanceCreateInfo *)pCreateInfo->pNext; chain_info;
|
||||
chain_info = (VkLayerInstanceCreateInfo *)chain_info->pNext)
|
||||
if (chain_info->sType == VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO &&
|
||||
chain_info->function == VK_LAYER_LINK_INFO)
|
||||
break;
|
||||
|
||||
assert(chain_info->u.pLayerInfo);
|
||||
|
||||
PFN_vkGetInstanceProcAddr GetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
|
||||
PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)GetInstanceProcAddr(NULL, "vkCreateInstance");
|
||||
PFN_vkGetInstanceProcAddr GetInstanceProcAddr =
|
||||
chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
|
||||
PFN_vkCreateInstance fpCreateInstance =
|
||||
(PFN_vkCreateInstance)GetInstanceProcAddr(NULL, "vkCreateInstance");
|
||||
if (fpCreateInstance == NULL) {
|
||||
return VK_ERROR_INITIALIZATION_FAILED;
|
||||
}
|
||||
|
||||
chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
|
||||
|
||||
const char *engineName = pCreateInfo->pApplicationInfo && pCreateInfo->pApplicationInfo->pEngineName ? pCreateInfo->pApplicationInfo->pEngineName : "";
|
||||
const char *applicationName = pCreateInfo->pApplicationInfo && pCreateInfo->pApplicationInfo->pApplicationName ? pCreateInfo->pApplicationInfo->pApplicationName : "";
|
||||
const char *engineName =
|
||||
pCreateInfo->pApplicationInfo && pCreateInfo->pApplicationInfo->pEngineName
|
||||
? pCreateInfo->pApplicationInfo->pEngineName
|
||||
: "";
|
||||
const char *applicationName =
|
||||
pCreateInfo->pApplicationInfo && pCreateInfo->pApplicationInfo->pApplicationName
|
||||
? pCreateInfo->pApplicationInfo->pApplicationName
|
||||
: "";
|
||||
VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
|
||||
if (result != VK_SUCCESS) {
|
||||
return result;
|
||||
|
|
@ -151,11 +161,13 @@ static VkResult device_select_CreateInstance(const VkInstanceCreateInfo *pCreate
|
|||
|
||||
for (unsigned i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
|
||||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
||||
if (!strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) && has_wayland)
|
||||
if (!strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) &&
|
||||
has_wayland)
|
||||
info->has_wayland = true;
|
||||
#endif
|
||||
#ifdef VK_USE_PLATFORM_XCB_KHR
|
||||
if (!strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XCB_SURFACE_EXTENSION_NAME) && has_xcb)
|
||||
if (!strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XCB_SURFACE_EXTENSION_NAME) &&
|
||||
has_xcb)
|
||||
info->has_xcb = !info->xserver || !info->zink;
|
||||
#endif
|
||||
}
|
||||
|
|
@ -168,7 +180,8 @@ static VkResult device_select_CreateInstance(const VkInstanceCreateInfo *pCreate
|
|||
info->has_vulkan11 = pCreateInfo->pApplicationInfo &&
|
||||
pCreateInfo->pApplicationInfo->apiVersion >= VK_MAKE_VERSION(1, 1, 0);
|
||||
|
||||
#define DEVSEL_GET_CB(func) info->func = (PFN_vk##func)info->GetInstanceProcAddr(*pInstance, "vk" #func)
|
||||
#define DEVSEL_GET_CB(func) \
|
||||
info->func = (PFN_vk##func)info->GetInstanceProcAddr(*pInstance, "vk" #func)
|
||||
DEVSEL_GET_CB(DestroyInstance);
|
||||
DEVSEL_GET_CB(EnumeratePhysicalDevices);
|
||||
DEVSEL_GET_CB(EnumeratePhysicalDeviceGroups);
|
||||
|
|
@ -183,7 +196,8 @@ static VkResult device_select_CreateInstance(const VkInstanceCreateInfo *pCreate
|
|||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
static void device_select_DestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
|
||||
static void
|
||||
device_select_DestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator)
|
||||
{
|
||||
struct instance_info *info = device_select_layer_get_instance(instance);
|
||||
|
||||
|
|
@ -192,28 +206,33 @@ static void device_select_DestroyInstance(VkInstance instance, const VkAllocatio
|
|||
free(info);
|
||||
}
|
||||
|
||||
static void get_device_properties(const struct instance_info *info, VkPhysicalDevice device, VkPhysicalDeviceProperties2 *properties)
|
||||
static void
|
||||
get_device_properties(const struct instance_info *info, VkPhysicalDevice device,
|
||||
VkPhysicalDeviceProperties2 *properties)
|
||||
{
|
||||
info->GetPhysicalDeviceProperties(device, &properties->properties);
|
||||
info->GetPhysicalDeviceProperties(device, &properties->properties);
|
||||
|
||||
if (info->GetPhysicalDeviceProperties2 && properties->properties.apiVersion >= VK_API_VERSION_1_1)
|
||||
info->GetPhysicalDeviceProperties2(device, properties);
|
||||
if (info->GetPhysicalDeviceProperties2 &&
|
||||
properties->properties.apiVersion >= VK_API_VERSION_1_1)
|
||||
info->GetPhysicalDeviceProperties2(device, properties);
|
||||
}
|
||||
|
||||
static void print_gpu(const struct instance_info *info, unsigned index, VkPhysicalDevice device)
|
||||
static void
|
||||
print_gpu(const struct instance_info *info, unsigned index, VkPhysicalDevice device)
|
||||
{
|
||||
const char *type = "";
|
||||
VkPhysicalDevicePCIBusInfoPropertiesEXT ext_pci_properties = (VkPhysicalDevicePCIBusInfoPropertiesEXT) {
|
||||
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT
|
||||
};
|
||||
VkPhysicalDevicePCIBusInfoPropertiesEXT ext_pci_properties =
|
||||
(VkPhysicalDevicePCIBusInfoPropertiesEXT){
|
||||
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT,
|
||||
};
|
||||
VkPhysicalDeviceProperties2 properties = (VkPhysicalDeviceProperties2){
|
||||
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2
|
||||
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2,
|
||||
};
|
||||
if (info->has_vulkan11 && info->has_pci_bus)
|
||||
properties.pNext = &ext_pci_properties;
|
||||
get_device_properties(info, device, &properties);
|
||||
|
||||
switch(properties.properties.deviceType) {
|
||||
switch (properties.properties.deviceType) {
|
||||
case VK_PHYSICAL_DEVICE_TYPE_OTHER:
|
||||
default:
|
||||
type = "other";
|
||||
|
|
@ -234,23 +253,21 @@ static void print_gpu(const struct instance_info *info, unsigned index, VkPhysic
|
|||
fprintf(stderr, " GPU %d: %x:%x \"%s\" %s", index, properties.properties.vendorID,
|
||||
properties.properties.deviceID, properties.properties.deviceName, type);
|
||||
if (info->has_vulkan11 && info->has_pci_bus)
|
||||
fprintf(stderr, " %04x:%02x:%02x.%x", ext_pci_properties.pciDomain,
|
||||
ext_pci_properties.pciBus, ext_pci_properties.pciDevice,
|
||||
ext_pci_properties.pciFunction);
|
||||
fprintf(stderr, " %04x:%02x:%02x.%x", ext_pci_properties.pciDomain, ext_pci_properties.pciBus,
|
||||
ext_pci_properties.pciDevice, ext_pci_properties.pciFunction);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
static bool fill_drm_device_info(const struct instance_info *info,
|
||||
struct device_pci_info *drm_device,
|
||||
VkPhysicalDevice device)
|
||||
static bool
|
||||
fill_drm_device_info(const struct instance_info *info, struct device_pci_info *drm_device,
|
||||
VkPhysicalDevice device)
|
||||
{
|
||||
VkPhysicalDevicePCIBusInfoPropertiesEXT ext_pci_properties = (VkPhysicalDevicePCIBusInfoPropertiesEXT) {
|
||||
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT
|
||||
};
|
||||
VkPhysicalDevicePCIBusInfoPropertiesEXT ext_pci_properties =
|
||||
(VkPhysicalDevicePCIBusInfoPropertiesEXT){
|
||||
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT};
|
||||
|
||||
VkPhysicalDeviceProperties2 properties = (VkPhysicalDeviceProperties2){
|
||||
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2
|
||||
};
|
||||
VkPhysicalDeviceProperties2 properties =
|
||||
(VkPhysicalDeviceProperties2){.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2};
|
||||
|
||||
if (info->has_vulkan11 && info->has_pci_bus)
|
||||
properties.pNext = &ext_pci_properties;
|
||||
|
|
@ -260,18 +277,18 @@ static bool fill_drm_device_info(const struct instance_info *info,
|
|||
drm_device->dev_info.vendor_id = properties.properties.vendorID;
|
||||
drm_device->dev_info.device_id = properties.properties.deviceID;
|
||||
if (info->has_vulkan11 && info->has_pci_bus) {
|
||||
drm_device->has_bus_info = true;
|
||||
drm_device->bus_info.domain = ext_pci_properties.pciDomain;
|
||||
drm_device->bus_info.bus = ext_pci_properties.pciBus;
|
||||
drm_device->bus_info.dev = ext_pci_properties.pciDevice;
|
||||
drm_device->bus_info.func = ext_pci_properties.pciFunction;
|
||||
drm_device->has_bus_info = true;
|
||||
drm_device->bus_info.domain = ext_pci_properties.pciDomain;
|
||||
drm_device->bus_info.bus = ext_pci_properties.pciBus;
|
||||
drm_device->bus_info.dev = ext_pci_properties.pciDevice;
|
||||
drm_device->bus_info.func = ext_pci_properties.pciFunction;
|
||||
}
|
||||
return drm_device->cpu_device;
|
||||
}
|
||||
|
||||
static int device_select_find_explicit_default(struct device_pci_info *pci_infos,
|
||||
uint32_t device_count,
|
||||
const char *selection)
|
||||
static int
|
||||
device_select_find_explicit_default(struct device_pci_info *pci_infos, uint32_t device_count,
|
||||
const char *selection)
|
||||
{
|
||||
int default_idx = -1;
|
||||
unsigned vendor_id, device_id;
|
||||
|
|
@ -287,9 +304,9 @@ static int device_select_find_explicit_default(struct device_pci_info *pci_infos
|
|||
return default_idx;
|
||||
}
|
||||
|
||||
static int device_select_find_dri_prime_tag_default(struct device_pci_info *pci_infos,
|
||||
uint32_t device_count,
|
||||
const char *dri_prime)
|
||||
static int
|
||||
device_select_find_dri_prime_tag_default(struct device_pci_info *pci_infos, uint32_t device_count,
|
||||
const char *dri_prime)
|
||||
{
|
||||
int default_idx = -1;
|
||||
|
||||
|
|
@ -303,10 +320,8 @@ static int device_select_find_dri_prime_tag_default(struct device_pci_info *pci_
|
|||
|
||||
for (unsigned i = 0; i < device_count; ++i) {
|
||||
char *tag = NULL;
|
||||
if (asprintf(&tag, "pci-%04x_%02x_%02x_%1u",
|
||||
pci_infos[i].bus_info.domain,
|
||||
pci_infos[i].bus_info.bus,
|
||||
pci_infos[i].bus_info.dev,
|
||||
if (asprintf(&tag, "pci-%04x_%02x_%02x_%1u", pci_infos[i].bus_info.domain,
|
||||
pci_infos[i].bus_info.bus, pci_infos[i].bus_info.dev,
|
||||
pci_infos[i].bus_info.func) >= 0) {
|
||||
if (strncmp(dri_prime, tag, n) == 0)
|
||||
default_idx = i;
|
||||
|
|
@ -316,20 +331,20 @@ static int device_select_find_dri_prime_tag_default(struct device_pci_info *pci_
|
|||
return default_idx;
|
||||
}
|
||||
|
||||
static int device_select_find_boot_vga_vid_did(struct device_pci_info *pci_infos,
|
||||
uint32_t device_count)
|
||||
static int
|
||||
device_select_find_boot_vga_vid_did(struct device_pci_info *pci_infos, uint32_t device_count)
|
||||
{
|
||||
char path[1024];
|
||||
int fd;
|
||||
int default_idx = -1;
|
||||
uint8_t boot_vga = 0;
|
||||
ssize_t size_ret;
|
||||
#pragma pack(push, 1)
|
||||
#pragma pack(push, 1)
|
||||
struct id {
|
||||
uint16_t vid;
|
||||
uint16_t did;
|
||||
}id;
|
||||
#pragma pack(pop)
|
||||
} id;
|
||||
#pragma pack(pop)
|
||||
|
||||
for (unsigned i = 0; i < 64; i++) {
|
||||
snprintf(path, 1023, "/sys/class/drm/card%d/device/boot_vga", i);
|
||||
|
|
@ -363,8 +378,7 @@ static int device_select_find_boot_vga_vid_did(struct device_pci_info *pci_infos
|
|||
return default_idx;
|
||||
|
||||
for (unsigned i = 0; i < device_count; ++i) {
|
||||
if (id.vid == pci_infos[i].dev_info.vendor_id &&
|
||||
id.did == pci_infos[i].dev_info.device_id) {
|
||||
if (id.vid == pci_infos[i].dev_info.vendor_id && id.did == pci_infos[i].dev_info.device_id) {
|
||||
default_idx = i;
|
||||
break;
|
||||
}
|
||||
|
|
@ -373,15 +387,16 @@ static int device_select_find_boot_vga_vid_did(struct device_pci_info *pci_infos
|
|||
return default_idx;
|
||||
}
|
||||
|
||||
static int device_select_find_boot_vga_default(struct device_pci_info *pci_infos,
|
||||
uint32_t device_count)
|
||||
static int
|
||||
device_select_find_boot_vga_default(struct device_pci_info *pci_infos, uint32_t device_count)
|
||||
{
|
||||
char boot_vga_path[1024];
|
||||
int default_idx = -1;
|
||||
for (unsigned i = 0; i < device_count; ++i) {
|
||||
/* fallback to probing the pci bus boot_vga device. */
|
||||
snprintf(boot_vga_path, 1023, "/sys/bus/pci/devices/%04x:%02x:%02x.%x/boot_vga", pci_infos[i].bus_info.domain,
|
||||
pci_infos[i].bus_info.bus, pci_infos[i].bus_info.dev, pci_infos[i].bus_info.func);
|
||||
snprintf(boot_vga_path, 1023, "/sys/bus/pci/devices/%04x:%02x:%02x.%x/boot_vga",
|
||||
pci_infos[i].bus_info.domain, pci_infos[i].bus_info.bus, pci_infos[i].bus_info.dev,
|
||||
pci_infos[i].bus_info.func);
|
||||
int fd = open(boot_vga_path, O_RDONLY);
|
||||
if (fd != -1) {
|
||||
uint8_t val;
|
||||
|
|
@ -397,14 +412,14 @@ static int device_select_find_boot_vga_default(struct device_pci_info *pci_infos
|
|||
return default_idx;
|
||||
}
|
||||
|
||||
static int device_select_find_non_cpu(struct device_pci_info *pci_infos,
|
||||
uint32_t device_count)
|
||||
static int
|
||||
device_select_find_non_cpu(struct device_pci_info *pci_infos, uint32_t device_count)
|
||||
{
|
||||
int default_idx = -1;
|
||||
|
||||
/* pick first GPU device */
|
||||
for (unsigned i = 0; i < device_count; ++i) {
|
||||
if (!pci_infos[i].cpu_device){
|
||||
if (!pci_infos[i].cpu_device) {
|
||||
default_idx = i;
|
||||
break;
|
||||
}
|
||||
|
|
@ -412,10 +427,9 @@ static int device_select_find_non_cpu(struct device_pci_info *pci_infos,
|
|||
return default_idx;
|
||||
}
|
||||
|
||||
static int find_non_cpu_skip(struct device_pci_info *pci_infos,
|
||||
uint32_t device_count,
|
||||
int skip_idx,
|
||||
int skip_count)
|
||||
static int
|
||||
find_non_cpu_skip(struct device_pci_info *pci_infos, uint32_t device_count, int skip_idx,
|
||||
int skip_count)
|
||||
{
|
||||
for (unsigned i = 0; i < device_count; ++i) {
|
||||
if (i == skip_idx)
|
||||
|
|
@ -431,21 +445,24 @@ static int find_non_cpu_skip(struct device_pci_info *pci_infos,
|
|||
return -1;
|
||||
}
|
||||
|
||||
static bool should_debug_device_selection() {
|
||||
static bool
|
||||
should_debug_device_selection()
|
||||
{
|
||||
return debug_get_bool_option("MESA_VK_DEVICE_SELECT_DEBUG", false) ||
|
||||
debug_get_bool_option("DRI_PRIME_DEBUG", false);
|
||||
debug_get_bool_option("DRI_PRIME_DEBUG", false);
|
||||
}
|
||||
|
||||
static bool ends_with_exclamation_mark(const char *str) {
|
||||
static bool
|
||||
ends_with_exclamation_mark(const char *str)
|
||||
{
|
||||
size_t n = strlen(str);
|
||||
return n > 1 && str[n - 1] == '!';
|
||||
}
|
||||
|
||||
static uint32_t get_default_device(const struct instance_info *info,
|
||||
const char *selection,
|
||||
uint32_t physical_device_count,
|
||||
VkPhysicalDevice *pPhysicalDevices,
|
||||
bool *expose_only_one_dev)
|
||||
static uint32_t
|
||||
get_default_device(const struct instance_info *info, const char *selection,
|
||||
uint32_t physical_device_count, VkPhysicalDevice *pPhysicalDevices,
|
||||
bool *expose_only_one_dev)
|
||||
{
|
||||
int default_idx = -1;
|
||||
const char *dri_prime = getenv("DRI_PRIME");
|
||||
|
|
@ -460,26 +477,30 @@ static uint32_t get_default_device(const struct instance_info *info,
|
|||
dri_prime_as_int = 0;
|
||||
}
|
||||
|
||||
struct device_pci_info *pci_infos = (struct device_pci_info *)calloc(physical_device_count, sizeof(struct device_pci_info));
|
||||
struct device_pci_info *pci_infos =
|
||||
(struct device_pci_info *)calloc(physical_device_count, sizeof(struct device_pci_info));
|
||||
if (!pci_infos)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
for (unsigned i = 0; i < physical_device_count; ++i) {
|
||||
cpu_count += fill_drm_device_info(info, &pci_infos[i], pPhysicalDevices[i]) ? 1 : 0;
|
||||
}
|
||||
|
||||
if (selection)
|
||||
default_idx = device_select_find_explicit_default(pci_infos, physical_device_count, selection);
|
||||
default_idx =
|
||||
device_select_find_explicit_default(pci_infos, physical_device_count, selection);
|
||||
if (default_idx != -1) {
|
||||
*expose_only_one_dev = ends_with_exclamation_mark(selection);
|
||||
}
|
||||
|
||||
if (default_idx == -1 && dri_prime && dri_prime_as_int == 0) {
|
||||
/* Try DRI_PRIME=vendor_id:device_id */
|
||||
default_idx = device_select_find_explicit_default(pci_infos, physical_device_count, dri_prime);
|
||||
default_idx =
|
||||
device_select_find_explicit_default(pci_infos, physical_device_count, dri_prime);
|
||||
if (default_idx != -1) {
|
||||
if (debug)
|
||||
fprintf(stderr, "device-select: device_select_find_explicit_default selected %i\n", default_idx);
|
||||
fprintf(stderr, "device-select: device_select_find_explicit_default selected %i\n",
|
||||
default_idx);
|
||||
*expose_only_one_dev = ends_with_exclamation_mark(dri_prime);
|
||||
}
|
||||
|
||||
|
|
@ -488,11 +509,14 @@ static uint32_t get_default_device(const struct instance_info *info,
|
|||
if (!info->has_vulkan11 && !info->has_pci_bus)
|
||||
fprintf(stderr, "device-select: cannot correctly use DRI_PRIME tag\n");
|
||||
else
|
||||
default_idx = device_select_find_dri_prime_tag_default(pci_infos, physical_device_count, dri_prime);
|
||||
default_idx = device_select_find_dri_prime_tag_default(pci_infos, physical_device_count,
|
||||
dri_prime);
|
||||
|
||||
if (default_idx != -1) {
|
||||
if (debug)
|
||||
fprintf(stderr, "device-select: device_select_find_dri_prime_tag_default selected %i\n", default_idx);
|
||||
fprintf(stderr,
|
||||
"device-select: device_select_find_dri_prime_tag_default selected %i\n",
|
||||
default_idx);
|
||||
*expose_only_one_dev = ends_with_exclamation_mark(dri_prime);
|
||||
}
|
||||
}
|
||||
|
|
@ -500,12 +524,14 @@ static uint32_t get_default_device(const struct instance_info *info,
|
|||
if (default_idx == -1 && info->has_wayland) {
|
||||
default_idx = device_select_find_wayland_pci_default(pci_infos, physical_device_count);
|
||||
if (debug && default_idx != -1)
|
||||
fprintf(stderr, "device-select: device_select_find_wayland_pci_default selected %i\n", default_idx);
|
||||
fprintf(stderr, "device-select: device_select_find_wayland_pci_default selected %i\n",
|
||||
default_idx);
|
||||
}
|
||||
if (default_idx == -1 && info->has_xcb) {
|
||||
default_idx = device_select_find_xcb_pci_default(pci_infos, physical_device_count);
|
||||
if (debug && default_idx != -1)
|
||||
fprintf(stderr, "device-select: device_select_find_xcb_pci_default selected %i\n", default_idx);
|
||||
fprintf(stderr, "device-select: device_select_find_xcb_pci_default selected %i\n",
|
||||
default_idx);
|
||||
}
|
||||
if (default_idx == -1) {
|
||||
if (info->has_vulkan11 && info->has_pci_bus)
|
||||
|
|
@ -534,10 +560,12 @@ static uint32_t get_default_device(const struct instance_info *info,
|
|||
}
|
||||
/* DRI_PRIME=n handling - pick any other device than default. */
|
||||
if (dri_prime_as_int > 0 && debug)
|
||||
fprintf(stderr, "device-select: DRI_PRIME=%d, default_idx so far: %i\n", dri_prime_as_int, default_idx);
|
||||
fprintf(stderr, "device-select: DRI_PRIME=%d, default_idx so far: %i\n", dri_prime_as_int,
|
||||
default_idx);
|
||||
if (dri_prime_as_int > 0 && physical_device_count > (cpu_count + 1)) {
|
||||
if (default_idx == 0 || default_idx == 1) {
|
||||
default_idx = find_non_cpu_skip(pci_infos, physical_device_count, default_idx, dri_prime_as_int);
|
||||
default_idx =
|
||||
find_non_cpu_skip(pci_infos, physical_device_count, default_idx, dri_prime_as_int);
|
||||
if (default_idx != -1) {
|
||||
if (debug)
|
||||
fprintf(stderr, "device-select: find_non_cpu_skip selected %i\n", default_idx);
|
||||
|
|
@ -549,14 +577,14 @@ static uint32_t get_default_device(const struct instance_info *info,
|
|||
return default_idx == -1 ? 0 : default_idx;
|
||||
}
|
||||
|
||||
static VkResult device_select_EnumeratePhysicalDevices(VkInstance instance,
|
||||
uint32_t* pPhysicalDeviceCount,
|
||||
VkPhysicalDevice *pPhysicalDevices)
|
||||
static VkResult
|
||||
device_select_EnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount,
|
||||
VkPhysicalDevice *pPhysicalDevices)
|
||||
{
|
||||
struct instance_info *info = device_select_layer_get_instance(instance);
|
||||
uint32_t physical_device_count = 0;
|
||||
uint32_t selected_physical_device_count = 0;
|
||||
const char* selection = getenv("MESA_VK_DEVICE_SELECT");
|
||||
const char *selection = getenv("MESA_VK_DEVICE_SELECT");
|
||||
bool expose_only_one_dev = false;
|
||||
if (info->zink && info->xwayland)
|
||||
return info->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
|
||||
|
|
@ -565,9 +593,10 @@ static VkResult device_select_EnumeratePhysicalDevices(VkInstance instance,
|
|||
if (result != VK_SUCCESS)
|
||||
return result;
|
||||
|
||||
VkPhysicalDevice *physical_devices = (VkPhysicalDevice*)calloc(sizeof(VkPhysicalDevice), physical_device_count);
|
||||
VkPhysicalDevice *selected_physical_devices = (VkPhysicalDevice*)calloc(sizeof(VkPhysicalDevice),
|
||||
physical_device_count);
|
||||
VkPhysicalDevice *physical_devices =
|
||||
(VkPhysicalDevice *)calloc(sizeof(VkPhysicalDevice), physical_device_count);
|
||||
VkPhysicalDevice *selected_physical_devices =
|
||||
(VkPhysicalDevice *)calloc(sizeof(VkPhysicalDevice), physical_device_count);
|
||||
|
||||
if (!physical_devices || !selected_physical_devices) {
|
||||
result = VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
|
|
@ -583,7 +612,8 @@ static VkResult device_select_EnumeratePhysicalDevices(VkInstance instance,
|
|||
info->EnumerateDeviceExtensionProperties(physical_devices[i], NULL, &count, NULL);
|
||||
if (count > 0) {
|
||||
VkExtensionProperties *extensions = calloc(count, sizeof(VkExtensionProperties));
|
||||
if (info->EnumerateDeviceExtensionProperties(physical_devices[i], NULL, &count, extensions) == VK_SUCCESS) {
|
||||
if (info->EnumerateDeviceExtensionProperties(physical_devices[i], NULL, &count,
|
||||
extensions) == VK_SUCCESS) {
|
||||
for (unsigned j = 0; j < count; j++) {
|
||||
if (!strcmp(extensions[j].extensionName, VK_EXT_PCI_BUS_INFO_EXTENSION_NAME))
|
||||
info->has_pci_bus = true;
|
||||
|
|
@ -606,7 +636,7 @@ static VkResult device_select_EnumeratePhysicalDevices(VkInstance instance,
|
|||
selected_physical_device_count = physical_device_count;
|
||||
selected_physical_devices[0] = physical_devices[selected_index];
|
||||
for (unsigned i = 0; i < physical_device_count - 1; ++i) {
|
||||
unsigned this_idx = i < selected_index ? i : i + 1;
|
||||
unsigned this_idx = i < selected_index ? i : i + 1;
|
||||
selected_physical_devices[i + 1] = physical_devices[this_idx];
|
||||
}
|
||||
|
||||
|
|
@ -618,41 +648,51 @@ static VkResult device_select_EnumeratePhysicalDevices(VkInstance instance,
|
|||
|
||||
/* do not give multiple device option to app if force default device */
|
||||
const char *force_default_device = getenv("MESA_VK_DEVICE_SELECT_FORCE_DEFAULT_DEVICE");
|
||||
if (force_default_device && !strcmp(force_default_device, "1") && selected_physical_device_count != 0)
|
||||
if (force_default_device && !strcmp(force_default_device, "1") &&
|
||||
selected_physical_device_count != 0)
|
||||
expose_only_one_dev = true;
|
||||
|
||||
if (expose_only_one_dev)
|
||||
selected_physical_device_count = 1;
|
||||
|
||||
for (unsigned i = 0; i < selected_physical_device_count; i++) {
|
||||
vk_outarray_append_typed(VkPhysicalDevice, &out, ent) {
|
||||
vk_outarray_append_typed(VkPhysicalDevice, &out, ent)
|
||||
{
|
||||
*ent = selected_physical_devices[i];
|
||||
}
|
||||
}
|
||||
result = vk_outarray_status(&out);
|
||||
out:
|
||||
out:
|
||||
free(physical_devices);
|
||||
free(selected_physical_devices);
|
||||
return result;
|
||||
}
|
||||
|
||||
static VkResult device_select_EnumeratePhysicalDeviceGroups(VkInstance instance,
|
||||
uint32_t* pPhysicalDeviceGroupCount,
|
||||
VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroups)
|
||||
static VkResult
|
||||
device_select_EnumeratePhysicalDeviceGroups(VkInstance instance,
|
||||
uint32_t *pPhysicalDeviceGroupCount,
|
||||
VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroups)
|
||||
{
|
||||
struct instance_info *info = device_select_layer_get_instance(instance);
|
||||
uint32_t physical_device_group_count = 0;
|
||||
uint32_t selected_physical_device_group_count = 0;
|
||||
if (info->zink && info->xwayland)
|
||||
return info->EnumeratePhysicalDeviceGroups(instance, pPhysicalDeviceGroupCount, pPhysicalDeviceGroups);
|
||||
VkResult result = info->EnumeratePhysicalDeviceGroups(instance, &physical_device_group_count, NULL);
|
||||
VK_OUTARRAY_MAKE_TYPED(VkPhysicalDeviceGroupProperties, out, pPhysicalDeviceGroups, pPhysicalDeviceGroupCount);
|
||||
return info->EnumeratePhysicalDeviceGroups(instance, pPhysicalDeviceGroupCount,
|
||||
pPhysicalDeviceGroups);
|
||||
VkResult result =
|
||||
info->EnumeratePhysicalDeviceGroups(instance, &physical_device_group_count, NULL);
|
||||
VK_OUTARRAY_MAKE_TYPED(VkPhysicalDeviceGroupProperties, out, pPhysicalDeviceGroups,
|
||||
pPhysicalDeviceGroupCount);
|
||||
|
||||
if (result != VK_SUCCESS)
|
||||
return result;
|
||||
|
||||
VkPhysicalDeviceGroupProperties *physical_device_groups = (VkPhysicalDeviceGroupProperties*)calloc(sizeof(VkPhysicalDeviceGroupProperties), physical_device_group_count);
|
||||
VkPhysicalDeviceGroupProperties *selected_physical_device_groups = (VkPhysicalDeviceGroupProperties*)calloc(sizeof(VkPhysicalDeviceGroupProperties), physical_device_group_count);
|
||||
VkPhysicalDeviceGroupProperties *physical_device_groups =
|
||||
(VkPhysicalDeviceGroupProperties *)calloc(sizeof(VkPhysicalDeviceGroupProperties),
|
||||
physical_device_group_count);
|
||||
VkPhysicalDeviceGroupProperties *selected_physical_device_groups =
|
||||
(VkPhysicalDeviceGroupProperties *)calloc(sizeof(VkPhysicalDeviceGroupProperties),
|
||||
physical_device_group_count);
|
||||
|
||||
if (!physical_device_groups || !selected_physical_device_groups) {
|
||||
result = VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
|
|
@ -662,7 +702,8 @@ static VkResult device_select_EnumeratePhysicalDeviceGroups(VkInstance instance,
|
|||
for (unsigned i = 0; i < physical_device_group_count; i++)
|
||||
physical_device_groups[i].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES;
|
||||
|
||||
result = info->EnumeratePhysicalDeviceGroups(instance, &physical_device_group_count, physical_device_groups);
|
||||
result = info->EnumeratePhysicalDeviceGroups(instance, &physical_device_group_count,
|
||||
physical_device_groups);
|
||||
if (result != VK_SUCCESS)
|
||||
goto out;
|
||||
|
||||
|
|
@ -675,14 +716,15 @@ static VkResult device_select_EnumeratePhysicalDeviceGroups(VkInstance instance,
|
|||
for (unsigned j = 0; j < physical_device_groups[i].physicalDeviceCount; j++) {
|
||||
VkPhysicalDevice physical_device = physical_device_groups[i].physicalDevices[j];
|
||||
VkPhysicalDeviceProperties2 properties = (VkPhysicalDeviceProperties2){
|
||||
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2
|
||||
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2,
|
||||
};
|
||||
info->GetPhysicalDeviceProperties(physical_device, &properties.properties);
|
||||
group_has_cpu_device = properties.properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_CPU;
|
||||
}
|
||||
|
||||
if (group_has_cpu_device) {
|
||||
selected_physical_device_groups[physical_device_group_count - num_cpu_groups - 1] = physical_device_groups[i];
|
||||
selected_physical_device_groups[physical_device_group_count - num_cpu_groups - 1] =
|
||||
physical_device_groups[i];
|
||||
num_cpu_groups++;
|
||||
} else {
|
||||
selected_physical_device_groups[num_gpu_groups] = physical_device_groups[i];
|
||||
|
|
@ -693,7 +735,8 @@ static VkResult device_select_EnumeratePhysicalDeviceGroups(VkInstance instance,
|
|||
assert(result == VK_SUCCESS);
|
||||
|
||||
for (unsigned i = 0; i < selected_physical_device_group_count; i++) {
|
||||
vk_outarray_append_typed(VkPhysicalDeviceGroupProperties, &out, ent) {
|
||||
vk_outarray_append_typed(VkPhysicalDeviceGroupProperties, &out, ent)
|
||||
{
|
||||
*ent = selected_physical_device_groups[i];
|
||||
}
|
||||
}
|
||||
|
|
@ -704,24 +747,25 @@ out:
|
|||
return result;
|
||||
}
|
||||
|
||||
static void (*get_instance_proc_addr(VkInstance instance, const char* name))()
|
||||
static void (*get_instance_proc_addr(VkInstance instance, const char *name))()
|
||||
{
|
||||
if (strcmp(name, "vkGetInstanceProcAddr") == 0)
|
||||
return (void(*)())get_instance_proc_addr;
|
||||
return (void (*)())get_instance_proc_addr;
|
||||
if (strcmp(name, "vkCreateInstance") == 0)
|
||||
return (void(*)())device_select_CreateInstance;
|
||||
return (void (*)())device_select_CreateInstance;
|
||||
if (strcmp(name, "vkDestroyInstance") == 0)
|
||||
return (void(*)())device_select_DestroyInstance;
|
||||
return (void (*)())device_select_DestroyInstance;
|
||||
if (strcmp(name, "vkEnumeratePhysicalDevices") == 0)
|
||||
return (void(*)())device_select_EnumeratePhysicalDevices;
|
||||
return (void (*)())device_select_EnumeratePhysicalDevices;
|
||||
if (strcmp(name, "vkEnumeratePhysicalDeviceGroups") == 0)
|
||||
return (void(*)())device_select_EnumeratePhysicalDeviceGroups;
|
||||
return (void (*)())device_select_EnumeratePhysicalDeviceGroups;
|
||||
|
||||
struct instance_info *info = device_select_layer_get_instance(instance);
|
||||
return info->GetInstanceProcAddr(instance, name);
|
||||
}
|
||||
|
||||
PUBLIC VkResult vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct)
|
||||
PUBLIC VkResult
|
||||
vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct)
|
||||
{
|
||||
if (pVersionStruct->loaderLayerInterfaceVersion < 2)
|
||||
return VK_ERROR_INITIALIZATION_FAILED;
|
||||
|
|
|
|||
|
|
@ -25,13 +25,13 @@
|
|||
#ifdef HAVE_BIND_WL_DISPLAY
|
||||
#include "wayland-drm-client-protocol.h"
|
||||
#endif
|
||||
#include "linux-dmabuf-unstable-v1-client-protocol.h"
|
||||
#include "device_select.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <xf86drm.h>
|
||||
#include "device_select.h"
|
||||
#include "linux-dmabuf-unstable-v1-client-protocol.h"
|
||||
|
||||
struct device_select_wayland_info {
|
||||
#ifdef HAVE_BIND_WL_DISPLAY
|
||||
|
|
@ -70,26 +70,24 @@ device_select_drm_handle_authenticated(void *data, struct wl_drm *drm)
|
|||
/* ignore this event */
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
device_select_drm_handle_capabilities(void *data, struct wl_drm *drm, uint32_t value)
|
||||
{
|
||||
/* ignore this event */
|
||||
}
|
||||
|
||||
|
||||
static const struct wl_drm_listener ds_drm_listener = {
|
||||
.device = device_select_drm_handle_device,
|
||||
.format = device_select_drm_handle_format,
|
||||
.authenticated = device_select_drm_handle_authenticated,
|
||||
.capabilities = device_select_drm_handle_capabilities
|
||||
.capabilities = device_select_drm_handle_capabilities,
|
||||
};
|
||||
#endif
|
||||
|
||||
static void
|
||||
default_dmabuf_feedback_format_table(void *data,
|
||||
struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1,
|
||||
int32_t fd, uint32_t size)
|
||||
default_dmabuf_feedback_format_table(
|
||||
void *data, struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1, int32_t fd,
|
||||
uint32_t size)
|
||||
{
|
||||
|
||||
/* ignore this event */
|
||||
|
|
@ -144,8 +142,7 @@ default_dmabuf_feedback_tranche_done(void *data,
|
|||
}
|
||||
|
||||
static void
|
||||
default_dmabuf_feedback_done(void *data,
|
||||
struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback)
|
||||
default_dmabuf_feedback_done(void *data, struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback)
|
||||
{
|
||||
/* ignore this event */
|
||||
}
|
||||
|
|
@ -171,26 +168,23 @@ device_select_registry_global(void *data, struct wl_registry *registry, uint32_t
|
|||
wl_drm_add_listener(info->wl_drm, &ds_drm_listener, data);
|
||||
} else
|
||||
#endif
|
||||
if (strcmp(interface, zwp_linux_dmabuf_v1_interface.name) == 0 &&
|
||||
version >= ZWP_LINUX_DMABUF_V1_GET_DEFAULT_FEEDBACK_SINCE_VERSION) {
|
||||
info->wl_dmabuf =
|
||||
wl_registry_bind(registry, name, &zwp_linux_dmabuf_v1_interface,
|
||||
ZWP_LINUX_DMABUF_V1_GET_DEFAULT_FEEDBACK_SINCE_VERSION);
|
||||
info->wl_dmabuf_feedback =
|
||||
zwp_linux_dmabuf_v1_get_default_feedback(info->wl_dmabuf);
|
||||
zwp_linux_dmabuf_feedback_v1_add_listener(info->wl_dmabuf_feedback,
|
||||
&dmabuf_feedback_listener, data);
|
||||
if (strcmp(interface, zwp_linux_dmabuf_v1_interface.name) == 0 &&
|
||||
version >= ZWP_LINUX_DMABUF_V1_GET_DEFAULT_FEEDBACK_SINCE_VERSION) {
|
||||
info->wl_dmabuf = wl_registry_bind(registry, name, &zwp_linux_dmabuf_v1_interface,
|
||||
ZWP_LINUX_DMABUF_V1_GET_DEFAULT_FEEDBACK_SINCE_VERSION);
|
||||
info->wl_dmabuf_feedback = zwp_linux_dmabuf_v1_get_default_feedback(info->wl_dmabuf);
|
||||
zwp_linux_dmabuf_feedback_v1_add_listener(info->wl_dmabuf_feedback, &dmabuf_feedback_listener,
|
||||
data);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
device_select_registry_global_remove_cb(void *data, struct wl_registry *registry,
|
||||
uint32_t name)
|
||||
device_select_registry_global_remove_cb(void *data, struct wl_registry *registry, uint32_t name)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int device_select_find_wayland_pci_default(struct device_pci_info *devices, uint32_t device_count)
|
||||
int
|
||||
device_select_find_wayland_pci_default(struct device_pci_info *devices, uint32_t device_count)
|
||||
{
|
||||
struct wl_display *display;
|
||||
struct wl_registry *registry = NULL;
|
||||
|
|
@ -207,8 +201,8 @@ int device_select_find_wayland_pci_default(struct device_pci_info *devices, uint
|
|||
return -1;
|
||||
}
|
||||
|
||||
static const struct wl_registry_listener registry_listener =
|
||||
{ device_select_registry_global, device_select_registry_global_remove_cb };
|
||||
static const struct wl_registry_listener registry_listener = {
|
||||
device_select_registry_global, device_select_registry_global_remove_cb};
|
||||
|
||||
wl_registry_add_listener(registry, ®istry_listener, &info);
|
||||
wl_display_dispatch(display);
|
||||
|
|
@ -245,7 +239,7 @@ int device_select_find_wayland_pci_default(struct device_pci_info *devices, uint
|
|||
}
|
||||
}
|
||||
|
||||
done:
|
||||
done:
|
||||
if (info.dmabuf_dev_info != NULL)
|
||||
drmFreeDevice(&info.dmabuf_dev_info);
|
||||
#ifdef HAVE_BIND_WL_DISPLAY
|
||||
|
|
|
|||
|
|
@ -23,26 +23,22 @@
|
|||
|
||||
/* connect to an X server and work out the default device. */
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/dri3.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <xf86drm.h>
|
||||
#include <xcb/dri3.h>
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
#include "device_select.h"
|
||||
static int
|
||||
ds_dri3_open(xcb_connection_t *conn,
|
||||
xcb_window_t root,
|
||||
uint32_t provider)
|
||||
ds_dri3_open(xcb_connection_t *conn, xcb_window_t root, uint32_t provider)
|
||||
{
|
||||
xcb_dri3_open_cookie_t cookie;
|
||||
xcb_dri3_open_reply_t *reply;
|
||||
int fd;
|
||||
xcb_dri3_open_cookie_t cookie;
|
||||
xcb_dri3_open_reply_t *reply;
|
||||
int fd;
|
||||
|
||||
cookie = xcb_dri3_open(conn,
|
||||
root,
|
||||
provider);
|
||||
cookie = xcb_dri3_open(conn, root, provider);
|
||||
|
||||
reply = xcb_dri3_open_reply(conn, cookie, NULL);
|
||||
if (!reply)
|
||||
|
|
@ -60,67 +56,68 @@ ds_dri3_open(xcb_connection_t *conn,
|
|||
return fd;
|
||||
}
|
||||
|
||||
int device_select_find_xcb_pci_default(struct device_pci_info *devices, uint32_t device_count)
|
||||
int
|
||||
device_select_find_xcb_pci_default(struct device_pci_info *devices, uint32_t device_count)
|
||||
{
|
||||
const xcb_setup_t *setup;
|
||||
xcb_screen_iterator_t iter;
|
||||
int scrn;
|
||||
xcb_connection_t *conn;
|
||||
int default_idx = -1;
|
||||
drmDevicePtr xdev = NULL;
|
||||
const xcb_setup_t *setup;
|
||||
xcb_screen_iterator_t iter;
|
||||
int scrn;
|
||||
xcb_connection_t *conn;
|
||||
int default_idx = -1;
|
||||
drmDevicePtr xdev = NULL;
|
||||
|
||||
conn = xcb_connect(NULL, &scrn);
|
||||
if (xcb_connection_has_error(conn)) {
|
||||
xcb_disconnect(conn);
|
||||
return -1;
|
||||
}
|
||||
conn = xcb_connect(NULL, &scrn);
|
||||
if (xcb_connection_has_error(conn)) {
|
||||
xcb_disconnect(conn);
|
||||
return -1;
|
||||
}
|
||||
|
||||
xcb_query_extension_cookie_t dri3_cookie;
|
||||
xcb_query_extension_reply_t *dri3_reply = NULL;
|
||||
xcb_query_extension_cookie_t dri3_cookie;
|
||||
xcb_query_extension_reply_t *dri3_reply = NULL;
|
||||
|
||||
dri3_cookie = xcb_query_extension(conn, 4, "DRI3");
|
||||
dri3_reply = xcb_query_extension_reply(conn, dri3_cookie, NULL);
|
||||
dri3_cookie = xcb_query_extension(conn, 4, "DRI3");
|
||||
dri3_reply = xcb_query_extension_reply(conn, dri3_cookie, NULL);
|
||||
|
||||
if (!dri3_reply)
|
||||
goto out;
|
||||
if (!dri3_reply)
|
||||
goto out;
|
||||
|
||||
if (dri3_reply->present == 0)
|
||||
goto out;
|
||||
if (dri3_reply->present == 0)
|
||||
goto out;
|
||||
|
||||
setup = xcb_get_setup(conn);
|
||||
iter = xcb_setup_roots_iterator(setup);
|
||||
setup = xcb_get_setup(conn);
|
||||
iter = xcb_setup_roots_iterator(setup);
|
||||
|
||||
xcb_screen_t *screen = iter.data;
|
||||
xcb_screen_t *screen = iter.data;
|
||||
|
||||
int dri3_fd = ds_dri3_open(conn, screen->root, 0);
|
||||
if (dri3_fd == -1)
|
||||
goto out;
|
||||
int dri3_fd = ds_dri3_open(conn, screen->root, 0);
|
||||
if (dri3_fd == -1)
|
||||
goto out;
|
||||
|
||||
int ret = drmGetDevice2(dri3_fd, 0, &xdev);
|
||||
close(dri3_fd);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
int ret = drmGetDevice2(dri3_fd, 0, &xdev);
|
||||
close(dri3_fd);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
|
||||
for (unsigned i = 0; i < device_count; i++) {
|
||||
if (devices[i].has_bus_info) {
|
||||
if (xdev->businfo.pci->domain == devices[i].bus_info.domain &&
|
||||
xdev->businfo.pci->bus == devices[i].bus_info.bus &&
|
||||
xdev->businfo.pci->dev == devices[i].bus_info.dev &&
|
||||
xdev->businfo.pci->func == devices[i].bus_info.func) {
|
||||
default_idx = i;
|
||||
for (unsigned i = 0; i < device_count; i++) {
|
||||
if (devices[i].has_bus_info) {
|
||||
if (xdev->businfo.pci->domain == devices[i].bus_info.domain &&
|
||||
xdev->businfo.pci->bus == devices[i].bus_info.bus &&
|
||||
xdev->businfo.pci->dev == devices[i].bus_info.dev &&
|
||||
xdev->businfo.pci->func == devices[i].bus_info.func) {
|
||||
default_idx = i;
|
||||
}
|
||||
} else {
|
||||
if (xdev->deviceinfo.pci->vendor_id == devices[i].dev_info.vendor_id &&
|
||||
xdev->deviceinfo.pci->device_id == devices[i].dev_info.device_id)
|
||||
default_idx = i;
|
||||
}
|
||||
} else {
|
||||
if (xdev->deviceinfo.pci->vendor_id == devices[i].dev_info.vendor_id &&
|
||||
xdev->deviceinfo.pci->device_id == devices[i].dev_info.device_id)
|
||||
default_idx = i;
|
||||
}
|
||||
if (default_idx != -1)
|
||||
break;
|
||||
}
|
||||
if (default_idx != -1)
|
||||
break;
|
||||
}
|
||||
|
||||
out:
|
||||
free(dri3_reply);
|
||||
drmFreeDevice(&xdev); /* Is NULL pointer safe. */
|
||||
xcb_disconnect(conn);
|
||||
return default_idx;
|
||||
free(dri3_reply);
|
||||
drmFreeDevice(&xdev); /* Is NULL pointer safe. */
|
||||
xcb_disconnect(conn);
|
||||
return default_idx;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue