Repository navigation
wineopenxr: Account for QPC to CLOCK_MONOTONIC offset in time conversion - #9372
PhialsBasement wants to merge 2 commits into
Conversation
96c3905 to
e4967d2
Compare
gofman
left a comment
There was a problem hiding this comment.
Looks good to me in general, apart from the cosmetic edits I suggested.
| #define NANOSECONDS_IN_A_SECOND 1000000000 | ||
| #define TICKSPERSEC 10000000 | ||
|
|
||
| static LONGLONG get_qpc_to_monotonic_offset(void) |
There was a problem hiding this comment.
Let's call it just qpc_to_monotonic_offset().
| XrTime *time) { | ||
| wine_XrInstance *wine_instance = wine_instance_from_handle(instance); | ||
| struct timespec ts; | ||
| LONGLONG monotonic_qpc, offset; |
There was a problem hiding this comment.
Let's remove 'offset' variable and just use qpc_to_monotonic_offset() inline, that is going to appear in one place in a function anyway.
| /* Convert QPC ticks to timespec (Wine QPC is 10MHz = 100ns ticks). */ | ||
| ts.tv_sec = performanceCounter->QuadPart / TICKSPERSEC; | ||
| ts.tv_nsec = (performanceCounter->QuadPart % TICKSPERSEC) * (NANOSECONDS_IN_A_SECOND / TICKSPERSEC); | ||
| /* Get offset between QPC and CLOCK_MONOTONIC, then convert to monotonic time. */ |
There was a problem hiding this comment.
I think the comment is excessive, it says almost exactly what the simple code does anyway, let's remove it.
| ts.tv_nsec = (performanceCounter->QuadPart % TICKSPERSEC) * (NANOSECONDS_IN_A_SECOND / TICKSPERSEC); | ||
| /* Get offset between QPC and CLOCK_MONOTONIC, then convert to monotonic time. */ | ||
| offset = get_qpc_to_monotonic_offset(); | ||
| monotonic_qpc = performanceCounter->QuadPart - offset; |
There was a problem hiding this comment.
As mentioned above, just inline qpc_to_monotonic_offset() without extra variable.
| LARGE_INTEGER *performanceCounter) { | ||
| wine_XrInstance *wine_instance = wine_instance_from_handle(instance); | ||
| struct timespec ts; | ||
| LONGLONG monotonic_qpc, offset; |
There was a problem hiding this comment.
Same here, let's get rid of offset variable.
|
|
||
| performanceCounter->QuadPart = (ULONGLONG)ts.tv_sec * TICKSPERSEC + | ||
| ts.tv_nsec / (NANOSECONDS_IN_A_SECOND / TICKSPERSEC); | ||
| /* Convert timespec to monotonic QPC, then apply offset to get Windows QPC. */ |
|
All feedback has been addressed, renamed the function, removed the intermediate variable and comments, and inlined the function calls. |
The QPC value from Windows applications needs adjustment before converting to/from XrTime, as there's an offset between Windows QPC (which starts from system boot) and CLOCK_MONOTONIC. Compute the offset at each conversion call by comparing the current QPC value with CLOCK_MONOTONIC, then apply it to the conversion.
|
Accidentally added some outside files not related to the commit, fixed that now. |
…ion. Link: #9372 CW-Bug-Id: #26405
|
Thanks! This is now in Proton Experimental (bleeding-edge branch): https://github.com/ValveSoftware/Proton/commits/experimental-bleeding-edge-10.0-291487-20260107-pbf7abd-wa21b86f-df76b0e-v9ca0b9/ I pulled that before the last update but I only pulled the related patch and not submodules bump, that had only wineopenxr changes. |
Thanks! Happy to help with more VR stuff if anything comes up. |
…ion. Link: ValveSoftware#9372 CW-Bug-Id: #26405
…ion. Link: #9372 CW-Bug-Id: #26405
Follow-up to #9347. Addresses the QPC to CLOCK_MONOTONIC clock mismatch by computing the offset at each conversion call as suggested by gofman.
get_qpc_to_monotonic_offset()helper that callsNtQueryPerformanceCounterandclock_gettime(CLOCK_MONOTONIC)to compute the current offsetwine_xrConvertWin32PerformanceCounterToTimeKHRandwine_xrConvertTimeToWin32PerformanceCounterKHRBuilt and tested, works as expected.
@gofman Ready for review when you have time.