From e22c83f4cec4b3f70815ffc780ffa22b6d91818c Mon Sep 17 00:00:00 2001 From: kd-11 Date: Sat, 21 Feb 2026 14:03:04 +0300 Subject: [PATCH] rsx: Improve comments/documentation around border color SEXT convert --- rpcs3/Emu/RSX/RSXTexture.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/rpcs3/Emu/RSX/RSXTexture.cpp b/rpcs3/Emu/RSX/RSXTexture.cpp index b3f9dc1962..e6483b51d7 100644 --- a/rpcs3/Emu/RSX/RSXTexture.cpp +++ b/rpcs3/Emu/RSX/RSXTexture.cpp @@ -315,6 +315,7 @@ namespace rsx // Border color is broken on PS3. The SNORM behavior is completely broken and behaves like BIASED renormalization instead. // To solve the mismatch, we need to first do a bit expansion on the value then store it as sign extended. The second part is a natural part of numbers on a binary system, so we only need to do the former. + // Note that the input color is in BE order (BGRA) so we reverse the mask to match. static constexpr u32 expand4_lut[16] = { 0x00000000u, // 0000 @@ -335,7 +336,7 @@ namespace rsx 0xFFFFFFFFu // 1111 }; - // Bit pattern expand and reverse BE -> LE using LUT + // Bit pattern expand const u32 mask = expand4_lut[sext]; // Now we perform the compensation operation @@ -344,16 +345,14 @@ namespace rsx // Load const __m128i _0 = _mm_setzero_si128(); const __m128i _128 = _mm_set1_epi32(128); - const __m128i _127 = _mm_set1_epi32(127); - const __m128i _255 = _mm_set1_epi32(255); - const auto be_raw = be_t(raw); - __m128i v = _mm_cvtsi32_si128(static_cast(be_raw)); + // Explode the bytes. + __m128i v = _mm_cvtsi32_si128(raw); v = _mm_unpacklo_epi8(v, _0); - v = _mm_unpacklo_epi16(v, _0); // [ 0, 64, 255, 128 ] + v = _mm_unpacklo_epi16(v, _0); // Conversion: x = (y - 128) - v = _mm_sub_epi32(v, _128); // [ -128, -64, 127, 0 ] + v = _mm_sub_epi32(v, _128); // Convert to signed encoding (reverse sext) v = _mm_slli_epi32(v, 24);