From eeb831e863096305fb2c2cefb18bf21965450ddd Mon Sep 17 00:00:00 2001 From: notaz Date: Sat, 10 Jan 2026 00:53:32 +0200 Subject: [PATCH] gpu_unai: can't do some optimizations with dithering notaz/pcsx_rearmed#401 --- plugins/gpu_unai/gpulib_if.cpp | 49 +++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/plugins/gpu_unai/gpulib_if.cpp b/plugins/gpu_unai/gpulib_if.cpp index 2a8ae75e..05f5fbf3 100644 --- a/plugins/gpu_unai/gpulib_if.cpp +++ b/plugins/gpu_unai/gpulib_if.cpp @@ -321,9 +321,11 @@ int renderer_do_cmd_list(u32 *list_, int list_len, uint32_t *ex_regs, case 0x2D: case 0x2E: case 0x2F: { // Textured 4-pt poly + u32 dithering = Dithering; u32 simplified_count; gpuSetTexture(le32_to_u32(gpu_unai.PacketBuffer.U4[4]) >> 16); - if ((simplified_count = prim_try_simplify_quad_t(gpu_unai.PacketBuffer.U4, + if (!dithering && + (simplified_count = prim_try_simplify_quad_t(gpu_unai.PacketBuffer.U4, gpu_unai.PacketBuffer.U4))) { for (i = 0;; ) { @@ -337,7 +339,7 @@ int renderer_do_cmd_list(u32 *list_, int list_len, uint32_t *ex_regs, gpuSetCLUT(le32_to_u32(gpu_unai.PacketBuffer.U4[2]) >> 16); u32 driver_idx = - Dithering | + dithering | Blending_Mode | gpu_unai.TEXT_MODE | gpu_unai.Masking | Blending | gpu_unai.PixelMSB; @@ -357,18 +359,21 @@ int renderer_do_cmd_list(u32 *list_, int list_len, uint32_t *ex_regs, case 0x31: case 0x32: case 0x33: { // Gouraud-shaded 3-pt poly + u32 dithering = Dithering; //NOTE: The '129' here is CF_GOURAUD | CF_LIGHT, however // this is an untextured poly, so CF_LIGHT (texture blend) // shouldn't apply. Until the original array of template // instantiation ptrs is fixed, we're stuck with this. (TODO) u8 gouraud = 129; - u32 xor_ = 0, rgb0 = le32_raw(gpu_unai.PacketBuffer.U4[0]); - for (i = 1; i < 3; i++) - xor_ |= rgb0 ^ le32_raw(gpu_unai.PacketBuffer.U4[i * 2]); - if ((xor_ & HTOLE32(0xf8f8f8)) == 0) - gouraud = 0; + if (!dithering) { + u32 xor_ = 0, rgb0 = le32_raw(gpu_unai.PacketBuffer.U4[0]); + for (i = 1; i < 3; i++) + xor_ |= rgb0 ^ le32_raw(gpu_unai.PacketBuffer.U4[i * 2]); + if ((xor_ & HTOLE32(0xf8f8f8)) == 0) + gouraud = 0; + } PP driver = gpuPolySpanDrivers[ - Dithering | + dithering | Blending_Mode | gpu_unai.Masking | Blending | gouraud | gpu_unai.PixelMSB ]; @@ -385,6 +390,7 @@ int renderer_do_cmd_list(u32 *list_, int list_len, uint32_t *ex_regs, case 0x37: { // Gouraud-shaded, textured 3-pt poly gpuSetCLUT (le32_to_u32(gpu_unai.PacketBuffer.U4[2]) >> 16); gpuSetTexture (le32_to_u32(gpu_unai.PacketBuffer.U4[5]) >> 16); + u32 dithering = Dithering; u8 lighting = Lighting; u8 gouraud = lighting ? (1<<7) : 0; if (lighting) { @@ -393,12 +399,12 @@ int renderer_do_cmd_list(u32 *list_, int list_len, uint32_t *ex_regs, xor_ |= rgb0 ^ le32_raw(gpu_unai.PacketBuffer.U4[i * 3]); if ((xor_ & HTOLE32(0xf8f8f8)) == 0) { gouraud = 0; - if (!need_lighting(rgb0)) + if (!dithering && !need_lighting(rgb0)) lighting = 0; } } PP driver = gpuPolySpanDrivers[ - Dithering | + dithering | Blending_Mode | gpu_unai.TEXT_MODE | gpu_unai.Masking | Blending | gouraud | lighting | gpu_unai.PixelMSB ]; @@ -413,15 +419,18 @@ int renderer_do_cmd_list(u32 *list_, int list_len, uint32_t *ex_regs, case 0x39: case 0x3A: case 0x3B: { // Gouraud-shaded 4-pt poly + u32 dithering = Dithering; // See notes regarding '129' for 0x30..0x33 further above -senquack u8 gouraud = 129; - u32 xor_ = 0, rgb0 = le32_raw(gpu_unai.PacketBuffer.U4[0]); - for (i = 1; i < 4; i++) - xor_ |= rgb0 ^ le32_raw(gpu_unai.PacketBuffer.U4[i * 2]); - if ((xor_ & HTOLE32(0xf8f8f8)) == 0) - gouraud = 0; + if (!dithering) { + u32 xor_ = 0, rgb0 = le32_raw(gpu_unai.PacketBuffer.U4[0]); + for (i = 1; i < 4; i++) + xor_ |= rgb0 ^ le32_raw(gpu_unai.PacketBuffer.U4[i * 2]); + if ((xor_ & HTOLE32(0xf8f8f8)) == 0) + gouraud = 0; + } PP driver = gpuPolySpanDrivers[ - Dithering | + dithering | Blending_Mode | gpu_unai.Masking | Blending | gouraud | gpu_unai.PixelMSB ]; @@ -436,9 +445,11 @@ int renderer_do_cmd_list(u32 *list_, int list_len, uint32_t *ex_regs, case 0x3D: case 0x3E: case 0x3F: { // Gouraud-shaded, textured 4-pt poly + u32 dithering = Dithering; u32 simplified_count; gpuSetTexture(le32_to_u32(gpu_unai.PacketBuffer.U4[5]) >> 16); - if ((simplified_count = prim_try_simplify_quad_gt(gpu_unai.PacketBuffer.U4, + if (!dithering && + (simplified_count = prim_try_simplify_quad_gt(gpu_unai.PacketBuffer.U4, gpu_unai.PacketBuffer.U4))) { for (i = 0;; ) { @@ -458,12 +469,12 @@ int renderer_do_cmd_list(u32 *list_, int list_len, uint32_t *ex_regs, xor_ |= rgb0 ^ le32_raw(gpu_unai.PacketBuffer.U4[i * 3]); if ((xor_ & HTOLE32(0xf8f8f8)) == 0) { gouraud = 0; - if (!need_lighting(rgb0)) + if (!dithering && !need_lighting(rgb0)) lighting = 0; } } PP driver = gpuPolySpanDrivers[ - Dithering | + dithering | Blending_Mode | gpu_unai.TEXT_MODE | gpu_unai.Masking | Blending | gouraud | lighting | gpu_unai.PixelMSB ]; -- 2.47.3