Strange behavior after compiling with clang-cl

252 views
Skip to first unread message

sudo

unread,
Mar 8, 2023, 1:38:49 PM3/8/23
to skia-discuss
Hello!

I'm seeing some strange behavior after compiling with clang-cl,
while with msvc, things work as expected.

Skia latest
clang-cl version 14.0.5

Snippet 1:
auto grGl = GrGLMakeNativeInterface();
auto grCtx = GrDirectContext::MakeGL(grGl);
SkASSERT(grCtx); // fail because grCtx is null

Snippet 2:
auto grCtx = GrDirectContext::MakeGL();
SkASSERT(grCtx); // no fail even though it should be the same as snippet 1
...
auto surface = SkSurface::MakeFromBackendRenderTarget(...); // never returns
...
auto surface2 = SkSurface::MakeRenderTarget(...);

Breaking the program shows that it is endlessly looping in SkOnce.h at
SK_POTENTIALLY_BLOCKING_REGION_BEGIN;
while (fState.load(std::memory_order_acquire) != Done) { /*spin*/ }
SK_POTENTIALLY_BLOCKING_REGION_END;

Now, if i remove SkASSERT(grCtx) and run, it does return a valid surface,
but crashes when creating surface2.

> myapp.exe!sk_sp<GrContextThreadSafeProxy>::operator->() Line 304
> myapp.exe!GrContext_Base::caps() Line 35
> myapp.exe!GrBaseContextPriv::caps() Line 28
> myapp.exe!SkSurface::MakeRenderTarget(GrRecordingContext * rContext, skgpu::Budgeted budgeted, const SkImageInfo & info, int sampleCount, GrSurfaceOrigin origin, const SkSurfaceProps * props, bool shouldCreateWithMips) Line 528

Any ideas?

sudo

unread,
Mar 17, 2023, 12:25:49 PM3/17/23
to skia-discuss
I've tried on MacOS as well but without success. Here, the crash in snippet 1 can be traced to the atomic header, and snippet 2 to validate_backend_render_target(). I have not investigated when exactly this started happening, all I know is that branch chrome/m105 works as that is what I upgraded from.

John Stiles

unread,
Mar 20, 2023, 9:33:05 AM3/20/23
to skia-discuss
If you are mixing MSVC and Clang binaries, you might be running into an issue with SK_TRIVIAL_ABI.
Try setting `is_trivial_abi = false` in your GN args and rebuilding everything.
(Context: http://review.skia.org/633089 … if your Skia build predates that change, you will probably need to update.)

sudo

unread,
Mar 20, 2023, 4:30:13 PM3/20/23
to skia-discuss
That works. Thank you very much!
Reply all
Reply to author
Forward
0 new messages