gamescope icon indicating copy to clipboard operation
gamescope copied to clipboard

Compiling with O3 on Clang causes blurriness on Wayland

Open Exotic0015 opened this issue 1 year ago • 8 comments

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.

Exotic0015 avatar Aug 27 '24 19:08 Exotic0015

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.

matte-schwartz avatar Aug 27 '24 19:08 matte-schwartz

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

Thanks for the report about this one though.

misyltoad avatar Aug 27 '24 19:08 misyltoad

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 avatar Aug 27 '24 19:08 matte-schwartz

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']

matte-schwartz avatar Aug 28 '24 01:08 matte-schwartz

@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 avatar Aug 28 '24 14:08 sharkautarch

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

  • compiling w/ clang And
  • only when building a release build (so need confirmation that the issue isn't present on builds w/ -O0 aka --buildtype=debug)

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 avatar Aug 28 '24 15:08 sharkautarch

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

sharkautarch avatar Aug 29 '24 01:08 sharkautarch

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.

matte-schwartz avatar Aug 29 '24 05:08 matte-schwartz