flyinghead / flycast

Flycast is a multiplatform Sega Dreamcast, Naomi, Naomi 2 and Atomiswave emulator
GNU General Public License v2.0
1.28k stars 161 forks source link

Polygon "with two volumes" incorrect color palette selection #1528

Open buhman opened 1 month ago

buhman commented 1 month ago

Platform / OS / Hardware: Linux / Dreamcast

Github hash: e85fa82101813ba803a071cfa6d6f8983f0a1f5c

Hardware: AMD Ryzen 5 4500U with Radeon Graphics / Hitachi SH-4 SH7091 with Holly Graphics

Description of the Issue

Flycast appears to ignore the palette selector from the second texture control word for a "with two volumes" polygon, and instead uses the palette selector from the first texture control word for both textures. Minimal testcase attached.

Debugging Steps Tested

sierpinski.elf.zip

Flycast, running sierpinski.elf, produces this image (incorrect result):

Screenshot from 2024-05-25 17-14-27

Real hardware, running sierpinski.bin, produces this image (expected result):

mpv-shot0020

Specifically, the color/palette of the strawberry texture in the Flycast screenshot is incorrect.

Logs Gathered

Global parameter: polygon type 3 Vertex parameter: polygon type 11

  const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
                                        | para_control::list_type::opaque
                                        | obj_control::col_type::packed_color
                                        | obj_control::shadow
                                        | obj_control::volume::polygon::with_two_volumes
                                        | obj_control::texture;

  const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater
                                          | isp_tsp_instruction_word::culling_mode::no_culling;

  const uint32_t tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one
                                      | tsp_instruction_word::dst_alpha_instr::zero
                                      | tsp_instruction_word::fog_control::no_fog
                                      | tsp_instruction_word::texture_u_size::from_int(1024)
                                      | tsp_instruction_word::texture_v_size::from_int(1024);

  const uint32_t texture_address_0 = texture_memory_alloc::texture.start + 1024 * 1024 * 0;
  const uint32_t texture_control_word_0 = texture_control_word::pixel_format::_8bpp_palette
                                        | texture_control_word::scan_order::twiddled
                                        | texture_control_word::texture_address(texture_address_0 / 8)
                                        | texture_control_word::palette_selector8(0);

  const uint32_t texture_address_1 = texture_memory_alloc::texture.start + 1024 * 1024 * 1;
  const uint32_t texture_control_word_1 = texture_control_word::pixel_format::_8bpp_palette
                                        | texture_control_word::scan_order::twiddled
                                        | texture_control_word::texture_address(texture_address_1 / 8)
                                        | texture_control_word::palette_selector8(1);

Screenshots

(screenshots relocated to description section)