bigscreen-beyond-vulkan-90hz

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

beyond-90hz-config.c (2552B)


      1 #ifndef _GNU_SOURCE
      2 #define _GNU_SOURCE
      3 #endif
      4 #include <dlfcn.h>
      5 #include <zlib.h>
      6 #include <xcb/randr.h>
      7 #include <stdio.h>
      8 #include <string.h>
      9 #include <stdbool.h>
     10 
     11 /* Local Beyond 90 Hz workaround: no device/firmware writes.
     12  * vrserver: adjust the eye geometry in decompressed device configuration.
     13  * vrcompositor: identify DP connector using the adjusted geometry; actual
     14  * scanout selection uses a real Vulkan 90 Hz mode, not this RandR snapshot.
     15  * Companion headset-gpu-90hz.c filters the Beyond's Vulkan mode list. */
     16 xcb_randr_mode_info_t *xcb_randr_get_screen_resources_modes(
     17         const xcb_randr_get_screen_resources_reply_t *r)
     18 {
     19     static xcb_randr_mode_info_t *(*next)(const xcb_randr_get_screen_resources_reply_t *);
     20     if (!next) next=dlsym(RTLD_NEXT,"xcb_randr_get_screen_resources_modes");
     21     if (!next) return NULL;
     22     xcb_randr_mode_info_t *m=next(r);
     23     for (unsigned i=0; m && i<r->num_modes; ++i)
     24         if (m[i].width==5088 && m[i].height==2544) {
     25             m[i].width=3840; m[i].height=1920;
     26         }
     27     return m;
     28 }
     29 
     30 /* Lighthouse requests DEEPBIND, otherwise bypassing the inflate interposer. */
     31 void *dlopen(const char *path, int flags)
     32 {
     33     static void *(*next)(const char *,int);
     34     if (!next) next=dlsym(RTLD_NEXT,"dlopen");
     35     if (path && strstr(path,"driver_lighthouse.so")) flags &= ~RTLD_DEEPBIND;
     36     return next(path,flags);
     37 }
     38 
     39 static unsigned char *size_value(unsigned char *p, size_t n, const char *key)
     40 {
     41     unsigned char *k=memmem(p,n,key,strlen(key)), *end=p+n;
     42     if (!k) return NULL;
     43     k+=strlen(key);
     44     while (k<end && *k!=':') ++k;
     45     if (k<end) ++k;
     46     while (k<end && (*k==' ' || *k=='\t')) ++k;
     47     return end-k>=4 && !memcmp(k,"2544",4) ? k : NULL;
     48 }
     49 
     50 int inflate(z_streamp s, int flush)
     51 {
     52     static int (*next)(z_streamp,int);
     53     if (!next) next=dlsym(RTLD_NEXT,"inflate");
     54     unsigned char *start=s->next_out;
     55     uInt available=s->avail_out;
     56     int result=next(s,flush);
     57     size_t n=available-s->avail_out;
     58     /* This headset emits both fields in one 135-byte JSON chunk. Only
     59      * substitute the exact native Beyond dimensions; never change length. */
     60     unsigned char *w=size_value(start,n,"\"eye_target_width_in_pixels\"");
     61     unsigned char *h=size_value(start,n,"\"eye_target_height_in_pixels\"");
     62     if (w && h) {
     63         memcpy(w,"1920",4); memcpy(h,"1920",4);
     64         FILE *f=fopen("/tmp/beyond-90hz-config.log","a");
     65         if (f) { fprintf(f,"Adjusted native 2544x2544 eye geometry to 1920x1920 in memory\n"); fclose(f); }
     66     }
     67     return result;
     68 }