apitrace / apitrace

Tools for tracing OpenGL, Direct3D, and other graphics APIs

Home Page:https://apitrace.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Another playing-a-MacOS-trace-on-Windows issue

AnyOldName3 opened this issue · comments

The trace linked here https://gitlab.com/OpenMW/openmw/-/issues/7052#note_1260607763 won't play for me on Windows with a non-specific Process exited with non zero exit code message. If I remember and get time, I might have a look in a debugger to give some more specific information.

This issue is that the application is binding the same GL context/drawable to multiple threads (the thread is the @NN number ):

[...]
175 @1 CGLSetCurrentContext(ctx = 0x11d0e1c00) = kCGLNoError
176 @0 CGLGetCurrentContext() = NULL
177 @0 CGLLockContext(ctx = 0x11d0e1c00) = kCGLNoError
178 @0 CGLUnlockContext(ctx = 0x11d0e1c00) = kCGLNoError
179 @0 CGLSetCurrentContext(ctx = 0x11d0e1c00) = kCGLNoError
[...]

This is allowed by CGL, but not by WGL/GLX/etc. CGL is unique in this regard -- it allows same context be used on different threads, provided one only thread uses it at any single instant.

Apitrace can't make miracles happen -- there's no reasonable way to emulate this. (Though I have a vague memory some EGL extension might allow this.)

Therefore, one needs a mac to replay this trace, or the application needs to be updated to not use same context from multiple threads.

That said, I tried replaying this on macOS 13, and this also creates troubles:

$ ./glretrace ~/openmw.trace 
/Applications/OpenMW.app/Contents/MacOS/openmw
GL_RENDERER: Intel(R) HD Graphics 630
GL_VENDOR: Intel Inc.
error: drawable failed to resize: expected 1920x1152, got 3840x2304
423 @1 CGLQueryRendererInfo(display_mask = 4294967295, rend = &0x10df0cd50, nrend = &2) = kCGLNoError
423: warning: unsupported CGLQueryRendererInfo call
427 @1 CGLDestroyRendererInfo(rend = 0x10df0cd50) = kCGLNoError
427: warning: unsupported CGLDestroyRendererInfo call
428 @1 CGLChoosePixelFormat(attribs = {kCGLPFANoRecovery, kCGLPFAAllowOfflineRenderers, 1262, kCGLPFASingleRenderer, kCGLPFARendererID, 16940800, 0}, pix = &0x600000e8b4c0, npix = &1) = kCGLNoError
428: warning: unexpected attribute 1262
2023-02-02 11:26:59.889 glretrace[70608:1636360] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!'
*** First throw call stack:
(
        0   CoreFoundation                      0x00007ff8098383eb __exceptionPreprocess + 242
        1   libobjc.A.dylib                     0x00007ff809384e25 objc_exception_throw + 48
        2   CoreFoundation                      0x00007ff809860596 _CFBundleGetValueForInfoKey + 0
        3   AppKit                              0x00007ff80c935167 -[NSWindow(NSWindow_Theme) _postWindowNeedsToResetDragMarginsUnlessPostingDisabled] + 307
        4   AppKit                              0x00007ff80c9216b3 -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 1247
        5   AppKit                              0x00007ff80c9211cd -[NSWindow initWithContentRect:styleMask:backing:defer:] + 42
        6   glretrace                           0x00000001077f03d6 _ZN4glws13CocoaDrawableC2EPKNS_6VisualEiiPKNS_12pbuffer_infoE + 294
        7   glretrace                           0x00000001077ef571 _ZN4glws13CocoaDrawableC1EPKNS_6VisualEiiPKNS_12pbuffer_infoE + 49
        8   glretrace                           0x00000001077ef509 _ZN4glws14createDrawableEPKNS_6VisualEiiPKNS_12pbuffer_infoE + 73
        9   glretrace                           0x00000001079bdd4a _ZN9glretraceL20createDrawableHelperEN10glfeatures7ProfileEiiPKN4glws12pbuffer_infoE + 58
        10  glretrace                           0x00000001079bdd04 _ZN9glretrace14createDrawableEN10glfeatures7ProfileE + 36
        11  glretrace                           0x0000000107996eea _ZL28retrace_CGLSetCurrentContextRN5trace4CallE + 138
        12  glretrace                           0x00000001077f44c5 _ZN7retrace8Retracer7retraceERN5trace4CallE + 565
        13  glretrace                           0x00000001077fdebf _ZN7retraceL11retraceCallEPN5trace4CallE + 95
        14  glretrace                           0x00000001077fdcaf _ZN7retrace11RelayRunner6runLegEPN5trace4CallE + 159
        15  glretrace                           0x00000001077f7d86 _ZN7retrace11RelayRunner7runRaceEv + 246
        16  glretrace                           0x00000001077f7c85 _ZN7retrace11RelayRunner12runnerThreadEPS0_ + 21
        17  glretrace                           0x00000001077fffe0 _ZNSt3__1L8__invokeIPFvPN7retrace11RelayRunnerEEJS3_EEEDTclscT_fp_spscT0_fp0_EEOS6_DpOS7_ + 32
        18  glretrace                           0x00000001077fffae _ZNSt3__1L16__thread_executeINS_10unique_ptrINS_15__thread_structENS_14default_deleteIS2_EEEEPFvPN7retrace11RelayRunnerEEJS8_EJLm2EEEEvRNS_5tupleIJT_T0_DpT1_EEENS_15__tuple
_indicesIJXspT2_EEEE + 62
        19  glretrace                           0x00000001077ffbd8 _ZNSt3__1L14__thread_proxyINS_5tupleIJNS_10unique_ptrINS_15__thread_structENS_14default_deleteIS3_EEEEPFvPN7retrace11RelayRunnerEES9_EEEEEPvSD_ + 88
        20  libsystem_pthread.dylib             0x00007ff8096e4259 _pthread_start + 125
        21  libsystem_pthread.dylib             0x00007ff8096dfc7b thread_start + 15
)
libc++abi: terminating with uncaught exception of type NSException
apitrace: warning: caught signal 6
433: error: caught an unhandled exception
apitrace: info: taking default action for signal 6
Abort trap: 6

Cocoa is a pain to deal with, and I don't have have the time/interest/expertise to chase this.

So I strongly recommend seeing if you can update OpenMW so it doesn't bind the same GL context to multiple threads, as that would make this much easier to handle.

FWIW, if one trims one some calls, one can play

$apitrace trim --calls=0-175,181-999999999 -o openmw-trimmed.trace openmw.trace
$glretrace   openmw.trace

But unfortunately it doesn't seem to draw anything. I think it's because it's rendering everything to an IOSurface.

I hope this helps.

We're not knowingly or intentionally making the context current on multiple threads, so that's a surprise. Annoyingly, replaying the trace single-threaded doesn't work as a workaround because it gets unbound from thread zero after it's bound to thread one.