ValveSoftware / gamescope

SteamOS session compositing window manager
Other
3k stars 198 forks source link

Compiling with O3 on Clang causes blurriness on Wayland #1493

Open Exotic0015 opened 2 weeks ago

Exotic0015 commented 2 weeks ago

Compiling a release build or with -O3 using Clang causes output image to be blurry. I've narrowed it down to commit 7fe73df4bcf71579203332baa2f3cf47506bc560, without it everything looks as it should. Below are comparison screenshots, though the difference may be too subtle to notice.

With 7fe73df4bcf71579203332baa2f3cf47506bc560: Screenshot_20240827_212953

Without 7fe73df4bcf71579203332baa2f3cf47506bc560: Screenshot_20240827_212818

Both instances were built using the same compile options.

matte-schwartz commented 2 weeks ago

Nice find, the issue happens on the drm backend as well. Hadn't gotten around to investigating for myself why it happened yet https://github.com/ublue-os/bazzite/issues/1539 but it's also fixed by switching to gcc rather than clang.

Joshua-Ashton commented 2 weeks ago

Screen blurring when composition may be something else? Does it happen if native res..?

Thanks for the report about this one though.

matte-schwartz commented 2 weeks ago

Screen blurring when composition may be something else? Does it happen if native res..?

Thanks for the report about this one though.

You're right, different issue it seems since it only starts to happen with composition. However the fix was the same, switching to GCC, as reported by stereophonick. I'll try to verify on my Deck later.

matte-schwartz commented 2 weeks ago

its two separate issues but both come from the same commit after all.

I also see this specific issue with the Wayland backend, pretty apparent in Dota 2 + Deadlock's settings menus for me:

command: SteamDeck=0 gamescope -f -h 1440 -w 3440 -r 175 --adaptive-sync --force-grab-cursor --mangoapp --composite-debug -- %command%

from git: `SteamDeck=0 gamescope -f -h 1440 -w 3440 -r 175 --adaptive-sync --force-grab-cursor --mangoapp --composite-debug -- %command%`

from git with revert of https://github.com/ValveSoftware/gamescope/commit/7fe73df4bcf71579203332baa2f3cf47506bc560: `SteamDeck=0 gamescope -f -h 1440 -w 3440 -r 175 --adaptive-sync --force-grab-cursor --mangoapp --composite-debug -- %command%`

kind of like going to the eye doctor...

my clang.ini

[binaries]
c = 'clang'
cpp = 'clang++'
ld = 'clang'
ar = 'llvm-ar'
strip = 'llvm-strip'

[properties]
c_args = ['-march=native', '-O3']
cpp_args = ['-march=native', '-O3']
sharkautarch commented 2 weeks ago

@Exotic0015 @matte-schwartz Try adding the meson flag: -Db_sanitize=address,undefined and add these other flags:

CARGS="-fsanitize=float-cast-overflow -fsanitize=integer -fsanitize=float-divide-by-zero -fno-omit-frame-pointer -g -shared-libsan -fsanitize-recover=all"
LINK_ARGS="-fuse-ld=lld -Wl,-rpath=$(echo /usr/lib/clang/*/lib/linux)"
-Dc_args="$CARGS" -Dc_link_args="$CARGS $LINK_ARGS" -Dcpp_args="$CARGS" -Dcpp_link_args="$CARGS $LINK_ARGS"
sharkautarch commented 2 weeks ago

@Joshua-Ashton If this is confirmed to be only happening when:

Then it could be that either a) rare case of scary compiler bug in clang/llvm OR b) gcc is more forgiving w/ -O3 + -ffast-math than clang

I did a mini-test of the ceil behavior for gcc vs clang on godbolt https://godbolt.org/z/vh8TTjzfz and it definitely showed that clang and gcc have very different optimization behavior (tho more similar when targeting native cpu). Though nothing definitive especially when this is without linking & whatnot

might need to reach out to llvm project on github if we can't figure this out...

sharkautarch commented 2 weeks ago

I used https://github.com/GrammaTech/ddisasm for disassembling versions of gamescope with and without commit https://github.com/ValveSoftware/gamescope/commit/7fe73df4bcf71579203332baa2f3cf47506bc560 reverted I diff'd around the two, and didn't see any change outside of CWaylandPlane::Present(FrameInfo_t::Layer_t const*)

Here's the dissaseembly with the commit reverted: https://gist.github.com/sharkautarch/b7545b638f44fb3115a1d929913ae2b6

and without the commit reverted: https://gist.github.com/sharkautarch/c358ab2e12fac442d94684534b994e33

This is making my head hurt... 0_o

matte-schwartz commented 2 weeks ago

did some investigating this evening and the problem seems to be "-vectorize-slp" which gets added in -O2 and -O3 optimization. the window becomes "focused" again if I build with '-fno-slp-vectorize' without reverting anything.