bigscreen-beyond-vulkan-90hz

shim to get 90hz working on bigscreen beyond 2e in steamvr without monado
Log | Files | Refs

headset-gpu-90hz.c (20344B)


      1 /* Opt-in Vulkan layer: expose only the headset GPU, PCI 0000:07:00.0.
      2  *
      3  * Loader-robustness note: Valve's SteamRuntime loader (1.3.239 fork) hands the
      4  * topmost layer a *trampoline* GIPA as pfnNextGetInstanceProcAddr. Resolving
      5  * intercepted names through that trampoline at call time returns this layer's
      6  * own functions (infinite recursion). Fix: resolve all downward function
      7  * pointers once inside vkCreateInstance, while the child dispatch is still
      8  * intact, and call those pointers directly thereafter.
      9  */
     10 #include <vulkan/vulkan.h>
     11 #include <vulkan/vk_layer.h>
     12 #include <stdatomic.h>
     13 #include <stdbool.h>
     14 #include <stdio.h>
     15 #include <stdlib.h>
     16 #include <string.h>
     17 #include <stdarg.h>
     18 #define _GNU_SOURCE 1
     19 #include <dlfcn.h>
     20 
     21 static void hgpu_log(const char *fmt, ...)
     22 {
     23     FILE *f = fopen("/tmp/headset-gpu.log", "a");
     24     if (!f) return;
     25     va_list ap; va_start(ap, fmt);
     26     vfprintf(f, fmt, ap); va_end(ap);
     27     fclose(f);
     28 }
     29 
     30 static atomic_flag dispatch_lock = ATOMIC_FLAG_INIT;
     31 static void dispatch_acquire(void) { while (atomic_flag_test_and_set_explicit(&dispatch_lock, memory_order_acquire)) { } }
     32 static void dispatch_release(void) { atomic_flag_clear_explicit(&dispatch_lock, memory_order_release); }
     33 
     34 struct physical_device {
     35     VkPhysicalDevice handle;
     36     struct physical_device *next;
     37 };
     38 
     39 struct instance_dispatch {
     40     VkInstance handle;                  /* app-visible handle */
     41     VkInstance child;                   /* handle produced by the node below */
     42     PFN_vkEnumeratePhysicalDevices enumerate;
     43     PFN_vkEnumeratePhysicalDeviceGroups groups;
     44     PFN_vkDestroyInstance destroy;
     45     PFN_vkCreateDevice create_device;
     46     PFN_vkGetDisplayModePropertiesKHR display_modes;
     47     PFN_vkGetPhysicalDeviceDisplayPropertiesKHR displays;
     48     PFN_vkGetPhysicalDeviceProperties2 props2;
     49     PFN_vkGetInstanceProcAddr next_gipa; /* for generic pass-through */
     50     struct physical_device *physical;
     51     struct instance_dispatch *next;
     52 };
     53 
     54 struct device_dispatch {
     55     VkDevice handle;
     56     VkDevice child;
     57     PFN_vkDestroyDevice destroy;
     58     PFN_vkGetDeviceProcAddr gdpa;
     59     struct device_dispatch *next;
     60 };
     61 
     62 static struct instance_dispatch *instances;
     63 static struct device_dispatch *devices;
     64 
     65 static struct instance_dispatch *instance_entry(VkInstance handle)
     66 {
     67     for (struct instance_dispatch *it = instances; it; it = it->next)
     68         if (it->handle == handle)
     69             return it;
     70     return NULL;
     71 }
     72 
     73 static VkResult remember_physical(VkInstance instance, VkPhysicalDevice physical)
     74 {
     75     dispatch_acquire();
     76     for (struct instance_dispatch *it = instances; it; it = it->next) {
     77         if (it->handle != instance)
     78             continue;
     79         for (struct physical_device *p = it->physical; p; p = p->next) {
     80             if (p->handle == physical) {
     81                 dispatch_release();
     82                 return VK_SUCCESS;
     83             }
     84         }
     85         struct physical_device *p = malloc(sizeof(*p));
     86         if (!p) {
     87             dispatch_release();
     88             return VK_ERROR_OUT_OF_HOST_MEMORY;
     89         }
     90         p->handle = physical;
     91         p->next = it->physical;
     92         it->physical = p;
     93         dispatch_release();
     94         return VK_SUCCESS;
     95     }
     96     dispatch_release();
     97     return VK_ERROR_INITIALIZATION_FAILED;
     98 }
     99 
    100 static VkInstance physical_owner(VkPhysicalDevice physical)
    101 {
    102     VkInstance result = VK_NULL_HANDLE;
    103     dispatch_acquire();
    104     for (struct instance_dispatch *it = instances; it; it = it->next)
    105         for (struct physical_device *p = it->physical; p; p = p->next)
    106             if (p->handle == physical) {
    107                 dispatch_release();
    108                 return it->handle;
    109             }
    110     dispatch_release();
    111     return result;
    112 }
    113 
    114 static const char *target_pci = "0000:07:00.0";
    115 
    116 static void load_target(void)
    117 {
    118     const char *env = getenv("STEAMVR_HEADSET_GPU");
    119     if (env && env[0] && strcmp(env, "1"))
    120         target_pci = env;
    121 }
    122 
    123 /* Mesa encodes the DRM PCI address into deviceUUID as
    124  *   [0..3]=domain (LE), [4]=bus, [5]=device<<3|func, [6..7]=0
    125  * on this driver stack, so bus 07 device 00 function 0 gives byte 4 = 0x07
    126  * and bus 03 gives 0x03. Match on that plus driverID == RADV. */
    127 static bool is_target(VkInstance instance, VkPhysicalDevice physical)
    128 {
    129     struct instance_dispatch *entry;
    130     dispatch_acquire();
    131     entry = instance_entry(instance);
    132     dispatch_release();
    133     if (!entry || !entry->props2)
    134         return false;
    135 
    136     VkPhysicalDeviceIDProperties idp = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES };
    137     VkPhysicalDeviceProperties2 props = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2 };
    138     props.pNext = &idp;
    139     entry->props2(physical, &props);
    140 
    141 
    142     unsigned int bus = idp.deviceUUID[4];
    143     char text[32];
    144     snprintf(text, sizeof(text), "0000:%02x:00.0", bus);
    145     static int uuid_budget = 12;
    146     if (uuid_budget > 0) {
    147         hgpu_log("is_target name=%s bus=%u -> %s target=%s\n",
    148                  props.properties.deviceName, bus, text, target_pci);
    149         uuid_budget--;
    150     }
    151     return strcmp(text, target_pci) == 0;
    152 }
    153 
    154 
    155 static VKAPI_ATTR VkResult VKAPI_CALL enumerate_physical(VkInstance instance,
    156         uint32_t *count, VkPhysicalDevice *physicals)
    157 {
    158     static int log_budget = 20;
    159     struct instance_dispatch *entry;
    160     dispatch_acquire();
    161     entry = instance_entry(instance);
    162     dispatch_release();
    163     if (log_budget > 0) { hgpu_log("enumerate_physical instance=%p entry=%p\n", (void *)instance, (void *)entry); log_budget--; }
    164     if (!entry || !entry->enumerate)
    165         return VK_ERROR_INITIALIZATION_FAILED;
    166     uint32_t n = 0;
    167     VkResult result = entry->enumerate(entry->child, &n, NULL);
    168     if (result != VK_SUCCESS && result != VK_INCOMPLETE)
    169         return result;
    170     if (n == 0) {
    171         if (count) *count = 0;
    172         return VK_SUCCESS;
    173     }
    174     VkPhysicalDevice *all = calloc(n, sizeof(*all));
    175     if (!all)
    176         return VK_ERROR_OUT_OF_HOST_MEMORY;
    177     uint32_t cap = n;
    178     result = entry->enumerate(entry->child, &cap, all);
    179     if (result != VK_SUCCESS && result != VK_INCOMPLETE) {
    180         free(all);
    181         return result;
    182     }
    183     n = cap;
    184     uint32_t kept = 0;
    185     for (uint32_t i = 0; i < n; i++) {
    186         if (!is_target(instance, all[i]))
    187             continue;
    188         if (physicals) {
    189             if (kept >= *count) { free(all); return VK_INCOMPLETE; }
    190             physicals[kept] = all[i];
    191         }
    192         if (remember_physical(instance, all[i]) != VK_SUCCESS) {
    193             free(all);
    194             return VK_ERROR_OUT_OF_HOST_MEMORY;
    195         }
    196         kept++;
    197     }
    198     free(all);
    199     *count = kept;
    200     hgpu_log("enumerate_physical kept=%u\n", kept);
    201     return VK_SUCCESS;
    202 }
    203 
    204 static VKAPI_ATTR VkResult VKAPI_CALL enumerate_physical_device_groups(VkInstance instance,
    205         uint32_t *count, VkPhysicalDeviceGroupProperties *groups)
    206 {
    207     struct instance_dispatch *entry;
    208     dispatch_acquire();
    209     entry = instance_entry(instance);
    210     dispatch_release();
    211     if (!entry || !entry->groups)
    212         return VK_ERROR_INITIALIZATION_FAILED;
    213     uint32_t n = 0;
    214     VkResult result = entry->groups(entry->child, &n, NULL);
    215     if (result != VK_SUCCESS && result != VK_INCOMPLETE)
    216         return result;
    217     if (n == 0) {
    218         if (count) *count = 0;
    219         return VK_SUCCESS;
    220     }
    221     VkPhysicalDeviceGroupProperties *all = calloc(n, sizeof(*all));
    222     if (!all)
    223         return VK_ERROR_OUT_OF_HOST_MEMORY;
    224     for (uint32_t i = 0; i < n; i++)
    225         all[i].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES;
    226     uint32_t cap = n;
    227     result = entry->groups(entry->child, &cap, all);
    228     if (result != VK_SUCCESS && result != VK_INCOMPLETE) {
    229         free(all);
    230         return result;
    231     }
    232     n = cap;
    233     uint32_t kept = 0;
    234     for (uint32_t i = 0; i < n; i++) {
    235         if (all[i].physicalDeviceCount == 0 || !is_target(instance, all[i].physicalDevices[0]))
    236             continue;
    237         if (groups) {
    238             if (kept >= *count) { free(all); return VK_INCOMPLETE; }
    239             groups[kept] = all[i];
    240         }
    241         if (remember_physical(instance, all[i].physicalDevices[0]) != VK_SUCCESS) {
    242             free(all);
    243             return VK_ERROR_OUT_OF_HOST_MEMORY;
    244         }
    245         kept++;
    246     }
    247     free(all);
    248     *count = kept;
    249     return VK_SUCCESS;
    250 }
    251 
    252 VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo *info,
    253         const VkAllocationCallbacks *allocator, VkInstance *instance)
    254 {
    255     load_target();
    256     const VkLayerInstanceCreateInfo *chain = info->pNext;
    257     hgpu_log("create_instance ENTER pNext=%p\n", (void *)info->pNext);
    258     while (chain && (chain->sType != VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO ||
    259                      chain->function != VK_LAYER_LINK_INFO))
    260         chain = chain->pNext;
    261     if (!chain || !chain->u.pLayerInfo) {
    262         hgpu_log("create_instance NO LINK INFO\n");
    263         return VK_ERROR_INITIALIZATION_FAILED;
    264     }
    265     PFN_vkGetInstanceProcAddr next = chain->u.pLayerInfo->pfnNextGetInstanceProcAddr;
    266     if (!next)
    267         return VK_ERROR_INITIALIZATION_FAILED;
    268     struct instance_dispatch *entry = calloc(1, sizeof(*entry));
    269     if (!entry)
    270         return VK_ERROR_OUT_OF_HOST_MEMORY;
    271     ((VkLayerInstanceCreateInfo *)chain)->u.pLayerInfo = chain->u.pLayerInfo->pNext;
    272     VkApplicationInfo app = {.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO};
    273     if (info->pApplicationInfo)
    274         app = *info->pApplicationInfo;
    275     uint32_t original = app.apiVersion;
    276     if (app.apiVersion < VK_API_VERSION_1_1)
    277         app.apiVersion = VK_API_VERSION_1_1;
    278     VkInstanceCreateInfo copy = *info;
    279     copy.pApplicationInfo = &app;
    280     PFN_vkCreateInstance fn = (PFN_vkCreateInstance)next(VK_NULL_HANDLE, "vkCreateInstance");
    281     if (!fn) {
    282         free(entry);
    283         return VK_ERROR_INITIALIZATION_FAILED;
    284     }
    285     VkResult result = fn(&copy, allocator, instance);
    286     if (result != VK_SUCCESS) {
    287         free(entry);
    288         return result;
    289     }
    290     hgpu_log("vkCreateInstance API %u.%u -> %u.%u\n",
    291             VK_API_VERSION_MAJOR(original), VK_API_VERSION_MINOR(original),
    292             VK_API_VERSION_MAJOR(app.apiVersion), VK_API_VERSION_MINOR(app.apiVersion));
    293     /* Resolve downward functions NOW, while the child dispatch is intact. */
    294     entry->handle = *instance;
    295     entry->child = *instance;
    296     entry->next_gipa = next;
    297     entry->enumerate = (PFN_vkEnumeratePhysicalDevices)next(*instance, "vkEnumeratePhysicalDevices");
    298     entry->groups = (PFN_vkEnumeratePhysicalDeviceGroups)next(*instance, "vkEnumeratePhysicalDeviceGroups");
    299     entry->destroy = (PFN_vkDestroyInstance)next(*instance, "vkDestroyInstance");
    300     entry->create_device = (PFN_vkCreateDevice)next(*instance, "vkCreateDevice");
    301     entry->display_modes = (PFN_vkGetDisplayModePropertiesKHR)next(*instance, "vkGetDisplayModePropertiesKHR");
    302     entry->displays = (PFN_vkGetPhysicalDeviceDisplayPropertiesKHR)next(*instance, "vkGetPhysicalDeviceDisplayPropertiesKHR");
    303     entry->props2 = (PFN_vkGetPhysicalDeviceProperties2)next(*instance, "vkGetPhysicalDeviceProperties2");
    304     hgpu_log("create_instance handle=%p enumerate=%p groups=%p destroy=%p createdev=%p props2=%p\n",
    305              (void *)entry->handle, (void *)entry->enumerate, (void *)entry->groups,
    306              (void *)entry->destroy, (void *)entry->create_device, (void *)entry->props2);
    307     dispatch_acquire();
    308     entry->next = instances;
    309     instances = entry;
    310     dispatch_release();
    311     return VK_SUCCESS;
    312 }
    313 
    314 static VKAPI_ATTR void VKAPI_CALL destroy_instance(VkInstance instance,
    315         const VkAllocationCallbacks *allocator)
    316 {
    317     if (instance == VK_NULL_HANDLE)
    318         return;
    319     struct instance_dispatch *entry = NULL;
    320     dispatch_acquire();
    321     for (struct instance_dispatch **it = &instances; *it; it = &(*it)->next) {
    322         if ((*it)->handle == instance) {
    323             entry = *it;
    324             *it = entry->next;
    325             break;
    326         }
    327     }
    328     dispatch_release();
    329     if (!entry)
    330         return;
    331     PFN_vkDestroyInstance fn = entry->destroy;
    332     if (fn)
    333         fn(entry->child, allocator);
    334     while (entry->physical) {
    335         struct physical_device *p = entry->physical;
    336         entry->physical = p->next;
    337         free(p);
    338     }
    339     free(entry);
    340 }
    341 
    342 static struct device_dispatch *device_entry(VkDevice handle)
    343 {
    344     for (struct device_dispatch *it = devices; it; it = it->next)
    345         if (it->handle == handle)
    346             return it;
    347     return NULL;
    348 }
    349 
    350 static VKAPI_ATTR VkResult VKAPI_CALL create_device(VkPhysicalDevice physical,
    351         const VkDeviceCreateInfo *info, const VkAllocationCallbacks *allocator, VkDevice *device)
    352 {
    353     const VkLayerDeviceCreateInfo *chain = info->pNext;
    354     while (chain && (chain->sType != VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO ||
    355                      chain->function != VK_LAYER_LINK_INFO))
    356         chain = chain->pNext;
    357     if (!chain || !chain->u.pLayerInfo)
    358         return VK_ERROR_INITIALIZATION_FAILED;
    359     VkInstance instance = physical_owner(physical);
    360     struct instance_dispatch *ientry;
    361     dispatch_acquire();
    362     ientry = instance_entry(instance);
    363     dispatch_release();
    364     if (!ientry || !ientry->create_device)
    365         return VK_ERROR_INITIALIZATION_FAILED;
    366     PFN_vkGetDeviceProcAddr next_gdpa = chain->u.pLayerInfo->pfnNextGetDeviceProcAddr;
    367     if (!next_gdpa)
    368         return VK_ERROR_INITIALIZATION_FAILED;
    369     struct device_dispatch *entry = calloc(1, sizeof(*entry));
    370     if (!entry)
    371         return VK_ERROR_OUT_OF_HOST_MEMORY;
    372     ((VkLayerDeviceCreateInfo *)chain)->u.pLayerInfo = chain->u.pLayerInfo->pNext;
    373     VkResult result = ientry->create_device(physical, info, allocator, device);
    374     if (result != VK_SUCCESS) {
    375         free(entry);
    376         return result;
    377     }
    378     entry->handle = *device;
    379     entry->child = *device;
    380     entry->gdpa = next_gdpa;
    381     entry->destroy = (PFN_vkDestroyDevice)next_gdpa(*device, "vkDestroyDevice");
    382     hgpu_log("create_device handle=%p destroy=%p\n", (void *)entry->handle, (void *)entry->destroy);
    383     dispatch_acquire();
    384     entry->next = devices;
    385     devices = entry;
    386     dispatch_release();
    387     return VK_SUCCESS;
    388 }
    389 
    390 static VKAPI_ATTR void VKAPI_CALL destroy_device(VkDevice device,
    391         const VkAllocationCallbacks *allocator)
    392 {
    393     if (device == VK_NULL_HANDLE)
    394         return;
    395     struct device_dispatch *entry = NULL;
    396     dispatch_acquire();
    397     for (struct device_dispatch **it = &devices; *it; it = &(*it)->next) {
    398         if ((*it)->handle == device) {
    399             entry = *it;
    400             *it = entry->next;
    401             break;
    402         }
    403     }
    404     dispatch_release();
    405     if (!entry)
    406         return;
    407     PFN_vkDestroyDevice fn = entry->destroy;
    408     VkDevice child = entry->child;
    409     free(entry);
    410     if (fn)
    411         fn(child, allocator);
    412 }
    413 
    414 static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL gdpa(VkDevice device, const char *name)
    415 {
    416     if (!strcmp(name, "vkGetDeviceProcAddr"))
    417         return (PFN_vkVoidFunction)gdpa;
    418     if (!strcmp(name, "vkDestroyDevice"))
    419         return (PFN_vkVoidFunction)destroy_device;
    420     struct device_dispatch *entry;
    421     dispatch_acquire();
    422     entry = device_entry(device);
    423     dispatch_release();
    424     return entry && entry->gdpa ? entry->gdpa(device, name) : NULL;
    425 }
    426 
    427 /* Work around SteamVR selecting full-resolution 75 Hz despite requesting 90 Hz.
    428  * Only filter vrcompositor, and only a Beyond display exposing both known modes.
    429  * Disable without rebuilding via /tmp/steamvr-disable-beyond-90hz-filter. */
    430 static VKAPI_ATTR VkResult VKAPI_CALL beyond_display_modes(
    431     VkPhysicalDevice physical, VkDisplayKHR display, uint32_t *count,
    432     VkDisplayModePropertiesKHR *out)
    433 {
    434     VkInstance instance = physical_owner(physical);
    435     struct instance_dispatch *entry;
    436     dispatch_acquire();
    437     entry = instance_entry(instance);
    438     dispatch_release();
    439     PFN_vkGetDisplayModePropertiesKHR fn = entry ? entry->display_modes : NULL;
    440     if (!fn) return VK_ERROR_INITIALIZATION_FAILED;
    441     char comm[64] = {0};
    442     FILE *f = fopen("/proc/self/comm", "r");
    443     if (f) { fgets(comm, sizeof(comm), f); fclose(f); }
    444     f = fopen("/tmp/steamvr-disable-beyond-90hz-filter", "r");
    445     if (f) { fclose(f); return fn(physical, display, count, out); }
    446     if (strncmp(comm, "vrcompositor", 12)) return fn(physical, display, count, out);
    447     uint32_t n = 0;
    448     VkResult r = fn(physical, display, &n, NULL);
    449     if (r != VK_SUCCESS || !n) return fn(physical, display, count, out);
    450     VkDisplayModePropertiesKHR *modes = calloc(n, sizeof(*modes));
    451     if (!modes) return VK_ERROR_OUT_OF_HOST_MEMORY;
    452     r = fn(physical, display, &n, modes);
    453     int selected = -1;
    454     bool beyond = false;
    455     if (r == VK_SUCCESS) for (uint32_t i = 0; i < n; ++i) {
    456         VkDisplayModeParametersKHR p = modes[i].parameters;
    457         if (p.visibleRegion.width == 5088 && p.visibleRegion.height == 2544 &&
    458             p.refreshRate >= 74900 && p.refreshRate <= 75100) beyond = true;
    459         if (p.visibleRegion.width == 3840 && p.visibleRegion.height == 1920 &&
    460             p.refreshRate >= 89900 && p.refreshRate <= 90100) selected = (int)i;
    461     }
    462     if (!beyond || selected < 0) { free(modes); return fn(physical, display, count, out); }
    463     if (!out) { *count = 1; r = VK_SUCCESS; }
    464     else if (*count) { out[0] = modes[selected]; *count = 1; r = VK_SUCCESS; }
    465     else { *count = 0; r = VK_INCOMPLETE; }
    466     hgpu_log("Beyond 90Hz filter: exposing only 3840x1920@%u display=%p\n",
    467               modes[selected].parameters.refreshRate, (void *)display);
    468     free(modes);
    469     return r;
    470 }
    471 
    472 static VKAPI_ATTR VkResult VKAPI_CALL beyond_displays(VkPhysicalDevice physical,
    473         uint32_t *count, VkDisplayPropertiesKHR *out)
    474 {
    475     struct instance_dispatch *entry;
    476     VkInstance owner = physical_owner(physical);
    477     dispatch_acquire(); entry = instance_entry(owner); dispatch_release();
    478     if (!entry || !entry->displays) return VK_ERROR_INITIALIZATION_FAILED;
    479     VkResult r = entry->displays(physical, count, out);
    480     char comm[64] = {0}; FILE *f = fopen("/proc/self/comm", "r");
    481     if (f) { fgets(comm, sizeof(comm), f); fclose(f); }
    482     if (out && (r == VK_SUCCESS || r == VK_INCOMPLETE) && !strncmp(comm,"vrcompositor",12))
    483         for (uint32_t i=0; i<*count; ++i)
    484             if (out[i].physicalResolution.width==5088 && out[i].physicalResolution.height==2544)
    485                 out[i].physicalResolution = (VkExtent2D){3840,1920};
    486     return r;
    487 }
    488 
    489 static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL gipa(VkInstance instance, const char *name)
    490 {
    491     if (!name)
    492         return NULL;
    493     if (!strcmp(name, "vkGetInstanceProcAddr"))
    494         return (PFN_vkVoidFunction)gipa;
    495     if (!strcmp(name, "vkGetDeviceProcAddr"))
    496         return (PFN_vkVoidFunction)gdpa;
    497     if (!strcmp(name, "vkCreateInstance"))
    498         return (PFN_vkVoidFunction)vkCreateInstance;
    499     if (!strcmp(name, "vkDestroyInstance"))
    500         return (PFN_vkVoidFunction)destroy_instance;
    501     if (!strcmp(name, "vkCreateDevice"))
    502         return (PFN_vkVoidFunction)create_device;
    503     if (!strcmp(name, "vkDestroyDevice"))
    504         return (PFN_vkVoidFunction)destroy_device;
    505     if (!strcmp(name, "vkGetPhysicalDeviceDisplayPropertiesKHR"))
    506         return (PFN_vkVoidFunction)beyond_displays;
    507     if (!strcmp(name, "vkGetDisplayModePropertiesKHR"))
    508         return (PFN_vkVoidFunction)beyond_display_modes;
    509     if (!strcmp(name, "vkEnumeratePhysicalDevices"))
    510         return (PFN_vkVoidFunction)enumerate_physical;
    511     if (!strcmp(name, "vkEnumeratePhysicalDeviceGroups") || !strcmp(name, "vkEnumeratePhysicalDeviceGroupsKHR"))
    512         return (PFN_vkVoidFunction)enumerate_physical_device_groups;
    513     if (!instance)
    514         return NULL;
    515     struct instance_dispatch *entry;
    516     dispatch_acquire();
    517     entry = instance_entry(instance);
    518     dispatch_release();
    519     return entry && entry->next_gipa ? entry->next_gipa(instance, name) : NULL;
    520 }
    521 
    522 VKAPI_ATTR VkResult VKAPI_CALL vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *version)
    523 {
    524     hgpu_log("negotiate loaderLayerInterfaceVersion=%u\n", version ? version->loaderLayerInterfaceVersion : 999);
    525     if (!version || version->loaderLayerInterfaceVersion < 2)
    526         return VK_ERROR_INITIALIZATION_FAILED;
    527     version->loaderLayerInterfaceVersion = 2;
    528     version->pfnGetInstanceProcAddr = gipa;
    529     version->pfnGetDeviceProcAddr = gdpa;
    530     version->pfnGetPhysicalDeviceProcAddr = gipa;
    531     return VK_SUCCESS;
    532 }