PureOne's picture
Add CHRONO-SHEAF III input latency research dataset
987b273 verified
Raw History Blame Contribute Delete
3.54 kB
/* Standalone deterministic host for the add-on's documented x64 call boundary.
Links the actual adapter source as a native object. No Windows loader or game. */
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#define MS __attribute__((ms_abi))
typedef void (MS *before_cb)(void*,void*,const void*,const void*,uint32_t,const void*);
typedef void (MS *after_cb)(void*,void*);
typedef void (MS *destroy_cb)(void*,bool);
extern MS bool AddonInit(void*,void*);
extern MS void AddonUninit(void*,void*);
static before_cb before;
static after_cb after;
static destroy_cb destroy;
static int64_t ticks=100000, pending_us;
static int locks,closes,added,removed,slept,logs;
static unsigned thread=1;
static bool api_supported=true,timers=true;
static MS bool reg(void *a,uint32_t api) { assert(a==(void*)1&&api==20);added++;return api_supported; }
static MS void unreg(void *a) {assert(a==(void*)1);removed++;}
static MS void evt(uint32_t code,void *ptr) {
if(code==74) before=(before_cb)ptr;
else if(code==100) after=(after_cb)ptr;
else {assert(code==8);destroy=(destroy_cb)ptr;}
}
static MS void logger(void *a,int level,const char *text) {assert(a==(void*)1&&level==3&&text);logs++;}
MS void *GetProcAddress(void *host,const char *n) {
assert(host==(void*)2);
if(!strcmp(n,"ReShadeRegisterAddon"))return (void*)reg;
if(!strcmp(n,"ReShadeUnregisterAddon"))return (void*)unreg;
if(!strcmp(n,"ReShadeRegisterEvent"))return (void*)evt;
if(!strcmp(n,"ReShadeLogMessage"))return (void*)logger;
return NULL;
}
MS int QueryPerformanceCounter(int64_t *q){*q=ticks;return 1;}
MS int QueryPerformanceFrequency(int64_t *q){*q=1000000;return 1;}
MS uint32_t GetCurrentThreadId(void){return thread;}
MS unsigned char TryAcquireSRWLockExclusive(void *l){(void)l;if(locks)return 0;locks=1;return 1;}
MS void AcquireSRWLockExclusive(void *l){assert(TryAcquireSRWLockExclusive(l));}
MS void ReleaseSRWLockExclusive(void *l){(void)l;assert(locks);locks=0;}
MS void *CreateWaitableTimerExW(void *a,void *n,uint32_t f,uint32_t rights) {
assert(!a&&!n&&f==2&&rights==0x100002);return timers?(void*)3:NULL;
}
MS int SetWaitableTimer(void *t,const int64_t *due,int32_t period,void *cb,void*b,int wake) {
assert(t==(void*)3&&*due<0&&!period&&!cb&&!b&&!wake);pending_us=-*due/10;return 1;
}
MS uint32_t WaitForSingleObject(void *t,uint32_t timeout){
assert(t==(void*)3 && timeout>0&&pending_us>0);ticks+=pending_us;pending_us=0;slept++;return 0;
}
MS int CloseHandle(void *t){assert(t==(void*)3);closes++;return 1;}
int main(void) {
void *a=(void*)1,*host=(void*)2,*chain=(void*)45;
assert(!AddonInit(NULL,host));timers=false;assert(!AddonInit(a,host));timers=true;
api_supported=false;assert(!AddonInit(a,host)&&closes==1);api_supported=true;
assert(AddonInit(a,host)&&before&&after&&destroy);
int64_t underlying=ticks;
for(int i=0;i<90;i++){
ticks+=2000;before(NULL,chain,NULL,NULL,0,NULL);underlying+=10000;ticks=underlying;after(NULL,chain);
}
assert(slept>40 && logs>=2);
int count=slept;destroy(chain,true);ticks+=2000;before(NULL,chain,NULL,NULL,0,NULL);
thread=2;ticks+=8000;after(NULL,chain);assert(slept==count);
before(NULL,chain,NULL,NULL,0,NULL);ticks+=1000;after(NULL,chain);assert(slept==count);
AddonUninit(a,host);assert(!locks&&closes==2&&removed==1&&added==2);
printf("MS-x64 ABI fixture passed. Registration, timing, resize, thread changes, teardown and %d timer waits verified.\n",slept);
}