floooh / cimgui-sokol-starterkit

A minimal self-contained Dear ImGui starter project for Windows, Linux and macOS.
MIT License
221 stars 22 forks source link

[macOS] ImGui fails to render in e63a36d31f06de4c71ffed3ff505c8b5b93e51d8 #14

Open fiserj opened 11 months ago

fiserj commented 11 months ago

System Info

Issue

After updating to e63a36d31f06de4c71ffed3ff505c8b5b93e51d8, the UI window doesn't render.

e63a36d31f06de4c71ffed3ff505c8b5b93e51d8

Building from previous commit (16c9bb188713c908240939992e239264ff2018e6) works:

16c9bb188713c908240939992e239264ff2018e6

Steps to Reproduce

Just checkout latest commit (e63a36d31f06de4c71ffed3ff505c8b5b93e51d8) and build with CMake, i.e.:

git clone https://github.com/floooh/cimgui-sokol-starterkit.git
cd cimgui-sokol-starterkit
mkdir build && cd build
cmake ..
cmake --build .
./demo

Note that building via Xcode (i.e., configuring with-G"Xcode") makes no difference.

fiserj commented 11 months ago

I haven't yet had a chance to look into it more, but quick bisecting suggests https://github.com/floooh/sokol/commit/99986cccaaec2ebc21b79e680b543eeb91d60f03 is the culprit. I could compile with the latest ImGui up until that commit.

Edit: Hah, looking at that commit, I don't see why that would be an issue. Will need to take a better look later.

Edit 2: I can confirm that last commit in master that works for me is https://github.com/floooh/sokol/commits/8d5d9929cc559cc6ec087fb621bfbe58c9ccc028. Looking at github's history log, the commit I posted above seems to be going just after this one, but when I check https://github.com/floooh/sokol/commit/99986cccaaec2ebc21b79e680b543eeb91d60f03 history, it's parent is entirely different commit.

image
floooh commented 11 months ago

Are you on an Intel Mac?

I'm on an M1 Mac with macOS 14.0 and everything works here. I can check later on my Intel Mac. Need to deal with another recent regression in GL first.

fiserj commented 11 months ago

Yes, I am.

floooh commented 11 months ago

That last commit that works for you was around the time when the image/sampler split happened, but let me check on my Intel Mac later...

fiserj commented 11 months ago

Thanks! And yes, manually diffing those two commits listed above points to the split you mention.

floooh commented 11 months ago

Bad news, it's working here. But I'm on a different macOS version (latest Big Sur, the last macOS supported on my mid-2014 MBP).

When running in Xcode, do you see any Metal validation layer errors in the bottom right output panel?

I think this scary looking piece of code is also from around that time:

https://github.com/floooh/sokol/blob/227df3a3f9623fda949011d0e88c4f40c1855fbe/sokol_gfx.h#L11458-L11475

...and there was indeed a problem with Intel Macs regarding textures.

Can you try changing the sg_setup call like this and check if it changes anything?

    sg_setup(&(sg_desc){
        .mtl_force_managed_storage_mode = true,
        .context = sapp_sgcontext(),
        .logger.func = slog_func,
    });

(I'll log off for today but will be back tomorrow evening)

Screen Shot 2023-10-26 at 8 25 50 PM
floooh commented 11 months ago

...in general I suspect the culprit might be any of the if (@available( checks in sokol_gfx.h.

IIRC I added those with the image/sampler split to better support optional Metal features on macOS and iOS.

And maybe some of those checks do the wrong thing in the "gap" between Big Sur and Sonoma....

fiserj commented 11 months ago

Hm, indeed, on my older Intel-based Mac that also runs Big Sur, everything renders fine.

I don't see any Metal validation layer error (the settings is on), and the change in sg_setup descriptor also didn't make any change :/ (it looks like _sg.mtl.use_shared_storage_mode has been set false all along).

I'll try to find some more time in the rest of the week to poke around the other API-availability checks.