decaf-emu / decaf-emu

Researching Wii U emulation.
GNU General Public License v3.0
1.25k stars 141 forks source link

SQ_VTX_SEMANTIC endian issues causing shader compilation failures #537

Closed ashquarky closed 5 years ago

ashquarky commented 5 years ago

Heyo! I've been working on an SDL2 port using wut, and it's been acting rather strange. I was hoping decaf might shed some light on the graphics issues, but ran into what looks like an endian handling bug.

Here's a log from running the opentyrian.rpx on my Linux system, freshly compiled Decaf (commit 070e29c977c87ff05cce2fc29007d497a4b7cdcf): https://pastebin.com/Y6vDyXtF - skip to line 1993-ish. I'm using the OpenGL backend here since I can't get the Vulkan one to work right on my (AMD) machine. I've only really looked into the '_fs_out_0 redeclared' error, kinda hoping the pixel shader issue is something similar.

After much gdb-ing, it turns out that sq_vtx_semantic.SEMANTIC_ID() (used here) always comes back as 0. Specifically:

(gdb) s
1134          if (id == 0xff) {
(gdb) p sq_vtx_semantic
$24 = {value = 0x1000000}
(gdb) p sq_vtx_semantic.SEMANTIC_ID()
$25 = 0x0
(gdb) p id
$26 = 0x0

From what I understand, sq_vtx_semantic is supposed to be 0x01 here, so that .SEMANTIC_ID can take the rightmost 8 bits. I tried printing shader->regs.sq_vtx_semantic on a real Wii U and yeah, the 01 is on the right, not the left. This makes me think it's an endian issue! I went and checked places it might be swapped:

It looks to me like there's something awry in the interactions between be2_array, be2_struct and be2_val; though I honestly couldn't follow it well enough to try and debug it. The other place be2_array gets used with vertex shaders is exports, which gives similar-looking issues in other apps (Health and Safety is a good/free example)

Sorry to dump a problem like this on you, hoping it's something fairly simple in the be2_ stuff. Thanks for all the awesome work! Happy to provide sources and other info if needed.

ashquarky commented 5 years ago

Fixed in #544