TASEmulators / desmume

DeSmuME is a Nintendo DS emulator
http://desmume.org
GNU General Public License v2.0
2.99k stars 547 forks source link

softrasterizer bug, mac only, 0.9.13 ? #659

Closed zeromus closed 1 year ago

zeromus commented 1 year ago

http://forums.desmume.org/viewtopic.php?id=12307&p=2 see here. This guy doesn't seem totally crazy

rogerman commented 1 year ago

As background, the user is running a MacBook Air 13" 2015/2017, which has an Intel Broadwell CPU. Therefore, the user is running the AVX2 binary of the Mac version.

I have confirmed this issue on AVX2, and have found that this is just your classic off-by-one texture sampling error that can be solved by using "Enable TXT Hack" on Windows, or "Enable Fragment Sampling Hack" on macOS. (The two options are identical, in which they simply set the CommonSettings.GFX3D_TXTHack Flag.) In the v0.9.13 release, just use that option when running Fire Emblem 12, and this graphical glitch goes away.

However, when CommonSettings.GFX3D_TXTHack is false, then results become inconsistent. Here are the results of my testing, with all 3D rendering done at the native resolution:

Based on these tests, we can assume that different compiler/ISA combinations have an effect on the release builds, where SSE2/SSE3/SSSE3/SSE4.1/NEON-A64 code seems to avoid the off-by-one sampling bug, while only the AVX2 code exhibits the bug. This can also be shown in how a debug build of 0.9.13 may exhibit or avoid the bug through the use of different compiler optimizations.

The last several rounds of commits pertaining to GFX3D and SoftRasterizer have been my attempt at fixing the off-by-one sampling bug once and for all. Commit bf344e9 is the latest step in doing so, but Fire Emblem 12 seems to be a bit stubborn with this bug. But there is some good news out of this -- as of commit bf344e9, the off-by-one sampling bug seems to exhibit itself consistently across all the compiler/ISA combinations that I've tried, and so I'm hoping that we've finally moved past being at the mercy of any compiler or hardware magic that can occur when dealing with floating-point calculations.

To conclude, we can safely close this ticket for the following reasons:

  1. This is a duplicate ticket of a notoriously well-known bug in DeSmuME.
  2. The user has a workaround in using "Enable Fragment Sampling Hack" in the v0.9.13 Mac release.
  3. I wouldn't call this issue a Mac-specific problem -- just one that only the Mac version can reveal. This is due to the fact that the Windows version supports only a single binary (x64-SSE2), while the Mac version supports 6 binaries (ppc32 / i386-SSE3 / SSSE3 / SSE4.1 / AVX2 / NEON-A64), and the user coincidentally struck on the one binary that exhibited the bug. I'm pretty sure that this bug would also exhibit itself in Windows or Linux if one were to make an AVX2 build with Clang while running -Ofast optimizations.

We'll just have to note Fire Emblem 12 as yet another test case for this bug.