Skip to content

GS/HW: Refactor texture shuffle detection and quad conversion.#14259

Merged
lightningterror merged 2 commits intoPCSX2:masterfrom
TJnotJT:gs-texshuf-refactor
Apr 11, 2026
Merged

GS/HW: Refactor texture shuffle detection and quad conversion.#14259
lightningterror merged 2 commits intoPCSX2:masterfrom
TJnotJT:gs-texshuf-refactor

Conversation

@TJnotJT
Copy link
Copy Markdown
Contributor

@TJnotJT TJnotJT commented Apr 4, 2026

Description of Changes

Refactor/cleanup texture shuffle detection and quad conversion:

  • Contain texture shuffle heuristics in two functions (described below).
  • Convert texture shuffle draws to a single quad.
  • Add internal state to track the type of texture shuffle.

Committed on top on #14240, though they could perhaps be considered a single PR instead.

Rationale behind Changes

  • Make code more maintainable.
  • Make heuristics/hacks more explicit.
  • Keep code/state related to texture shuffles together.

Details

Adds the function DetectTextureShuffle(), which does initial detection based on context/vertices. Classifies texture shuffles into the following subclasses:

  • Copy: No offsetting between X and U so results in channel copies.
  • Offset: Offsetting between X and U so results in channel swaps.
  • RegionRepeat8: Uses region repeat to set/clear bit 3 to do channel swaps.
  • RegionRepeat16: Uses region repeats to set/clear bit 4 to do channel swaps.
  • Reverse: Reverses X and U order to do channel swaps.
  • Swizzle: Swizzles at the same time as shuffling.
  • SwizzleTex32: Swizzles at the same time as shuffling with a 32 bit source texture. Only known to be used for B -> A shuffles in e.g. The Godfather and 007 From Russia With Love.
  • TwoPixel: Two pixel shuffle only seen in Powerdrome.
  • GappedSwizzle: Swizzle shuffle with strange gaps between quads and base address offsetting over multiple draws. Only seen in NFS Undercover and skipped with a CRC hack.
  • HackShuffle: We use the texture shuffle path in certain cases where the source/RT are 32 bit being reinterpreted as 16 bit, although it's not really a shuffle. It appears to be used to preserve the correct size of the RT/DS.

Adds function DetectTextureShuffleSecondPass() that does the second pass detection after RT and source have been looked up.

Changes ConvertSpriteTextureShuffle() to output a single quad per draw, since this is sufficient to emulate texture shuffles.

Adds a function FixSplitTextureShuffleState() that contains the code to continue a split texture shuffle. Mainly a cut/paste of the current code from GSRenderer::Draw().

Suggested Testing Steps

Testing any game with HW renderers would be helpful.

So far tested with dumps runs. The following dumps show up as false positives:

  • Need_for_Speed_-_Undercover_SLUS-21801_20231222095536.gs.xz: tiny difference in color in the borders of some shapes. Happens because master incorrectly samples U = [0, 648] in a texture shuffle while PR correctly samples U = [0, 640].
  • Raw Danger_20181103133127.gs.xz, rawdanger.gs.xz, greenglow.gs.xz, Blockus_depth2.gs.xz, pachipara13.gs.xz, steambot_screffhue.gs.xz, Blokus_depth1.gs.xz: Broken shuffle on both PR/master and may need a separate fix. Some pixels in the top left corner are different.

Did you use AI to help find, test, or implement this issue or feature?

No.

@TJnotJT TJnotJT changed the title GS: Refactor texture shuffle detection and quad conversion. GS/HW: Refactor texture shuffle detection and quad conversion. Apr 4, 2026
@Mrlinkwii Mrlinkwii added this to the Release 2.8 milestone Apr 4, 2026
@lightningterror
Copy link
Copy Markdown
Contributor

Needs rebase.

@TJnotJT TJnotJT force-pushed the gs-texshuf-refactor branch from bf94a9b to 3bd6dab Compare April 8, 2026 11:03
@TJnotJT
Copy link
Copy Markdown
Contributor Author

TJnotJT commented Apr 8, 2026

Rebased

@Mrlinkwii
Copy link
Copy Markdown
Contributor

smoke test was fine on linux on HW renderers

Copy link
Copy Markdown
Contributor

@lightningterror lightningterror left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dump run clear, differences show as mentioned.

@lightningterror lightningterror merged commit 06616ec into PCSX2:master Apr 11, 2026
14 checks passed
Hancock33 added a commit to Hancock33/batocera.piboy that referenced this pull request Apr 11, 2026
--------------------------------------------------------------------------------------------------------
batocera-emulationstation.mk db9a2bcc95fac0e13a65e3ebb0af0b1142345f96 # Version: Commits on Apr 11, 2026
--------------------------------------------------------------------------------------------------------
Merge pull request #2110 from Raketemensch/fix_hotkey_assignment

[InputConfig] Fix hotkey assignment being skipped when holding a button,

------------------------------------------------------------------------------------------------
batocera-es-piboy.mk db9a2bcc95fac0e13a65e3ebb0af0b1142345f96 # Version: Commits on Apr 11, 2026
------------------------------------------------------------------------------------------------
Merge pull request #2110 from Raketemensch/fix_hotkey_assignment

[InputConfig] Fix hotkey assignment being skipped when holding a button,

-----------------------------------------------------------------------------------
cemu.mk 391478b307a22f5e337cceb5a6eac5b71e8d7558 # Version: Commits on Apr 10, 2026
-----------------------------------------------------------------------------------
vulkan: Improve the Breath of the Wild RADV/LLVM workaround (#1862),

------------------------------------------------------------------------------------------
duckstation.mk 5e7be496a2d0480aaabbe9746a1a4576b469d301 # Version: Commits on Apr 10, 2026
------------------------------------------------------------------------------------------
Util: Add missing includes to compress_helpers.h,

-----------------------------------------------------------------------------------
eden.mk abb616c3570f88133e8717d80c48fc5cffe7c8e4 # Version: Commits on Apr 11, 2026
-----------------------------------------------------------------------------------
[vk,swapchain] vsync: Changed Immediate fallback from (FIFO) to (Mailbox, then FIFO) (#3746)

--------------------------------------------------------------------------------------
flycast.mk ed41f982c1bfed65f43c7f5a56d155ea3b7f3adb # Version: Commits on Apr 10, 2026
--------------------------------------------------------------------------------------
Fetch translations & Recreate libretro_core_options_intl.h,

--------------------------------------------------------------------------------------
melonds.mk 94f9bf534cdd1e8f89232607241aef6ca9f23882 # Version: Commits on Apr 10, 2026
--------------------------------------------------------------------------------------
CI: Fix FreeBSD hang (#2624)

Although it did work at some point, I think that FreeBSD's locking

over NFS is a bit unreliable, so we end up with Qt's automoc/autorcc

just hanging indefinitely. (some sort of deadlock?)

Fix this by building in /tmp inside the VM, and then copying it back

to the NFS-synced workspace when we are done.,

----------------------------------------------------
pcsx2.mk v2.7.246 # Version: Commits on Apr 11, 2026
----------------------------------------------------
- [GS/HW: Refactor texture shuffle detection and quad conversion.](PCSX2/pcsx2#14259)

,

------------------------------------------------------------------------------------
rpcs3.mk 110c786d802c4c17850de1d6945dc4df08ac393a # Version: Commits on Apr 02, 2026
------------------------------------------------------------------------------------
Add support to encrypted ISO

fix compile errors and suppress minor warnings

strip minor bug fixes and cleanup

minor cleanup

minor cleanup

Fixed crash at boot parsing an ISO with a empty directory entry at file head

applied suggested changes

added missing break in switch

Update rpcs3/Loader/ISO.cpp

Co-authored-by: Megamouse <studienricky89@googlemail.com>

use hex_to_bytes() instead of self made functions

minor cleanup

rewrite nested if()

add explicit support to .key

minor cleanup

optimize partial sector read

minor optimization

fix conflict,

-------------------------------------------------------------------------------------------
moonlight-qt.mk c685021f2167d3d43125c143daa0de14a5311f27 # Version: Commits on Apr 11, 2026
-------------------------------------------------------------------------------------------
Update SDL3, dav1d, FFmpeg, and OpenSSL

SDL3 -> 3.4.4 (Windows only)

dav1d -> 1.5.3

FFmpeg -> 8.1

OpenSSL -> 3.6.2

Fixes #1394,

---------------------------------------------------------------
ruffle.mk nightly-2026-04-11 # Version: Commits on Apr 11, 2026
---------------------------------------------------------------
## What's Changed

* tests: Add audio amplitude assertions to test framework by @kjarosh in ruffle-rs/ruffle#23397

* chore: Bump axios from 1.13.6 to 1.15.0 in /web by @dependabot[bot] in ruffle-rs/ruffle#23430

* chore: Bump basic-ftp from 5.2.1 to 5.2.2 in /web by @dependabot[bot] in ruffle-rs/ruffle#23433

**Full Changelog**: ruffle-rs/ruffle@nightly-2026-04-09...nightly-2026-04-11,

------------------------------------------------------------------------------------------
devilutionx.mk 3afccc256d8d89d5dbe7407a9a9b351f3ab4e157 # Version: Commits on Apr 11, 2026
------------------------------------------------------------------------------------------
Add Lua towner API and dynamic dialog options (prework for multi-town PR) (#8539)

* Add Lua towner API and dynamic dialog options

Expose TownerShortNames to Lua (devilutionx.towners), per-towner position

helpers, and RegisterTownerDialogOption for mod-driven store dialog lines.

Includes stores integration and tests.,

---------------------------------------------------
nblood.mk r14333 # Version: Commits on Apr 10, 2026
---------------------------------------------------
,

----------------------------------------------------------------------------------------
openjkdf2.mk af67a3c8e999e564e6b336f77b72c630fe203e0e # Version: Commits on Apr 10, 2026
----------------------------------------------------------------------------------------
Clean up sithWeapon_FireProjectile

- Replace goto/label pattern with else/else if blocks

- Replace fireOffset position addition with rdVector_Add3Acc inline site

- Rename all locals and parameters to descriptive names with proper p prefix for pointers

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>,

------------------------------------------------------------------------------------------------
libretro-mame-src.mk 00a4ac9348b17086a3bf7302b2983ea3dcad97b3 # Version: Commits on Apr 11, 2026
------------------------------------------------------------------------------------------------
Merge remote-tracking branch 'upstream/master',

----------------------------------------------------
flatpak.mk 1.17.6 # Version: Commits on Apr 10, 2026
----------------------------------------------------
1.17.6,

---------------------------------------------------------------------------------------
mangohud.mk 272dafc1ae3ec5889b6c383b27e792545b10c11c # Version: Commits on Apr 10, 2026
---------------------------------------------------------------------------------------
amdgpu: gpu_metrics better size checks,

-------------------------------------------------------------------------------------------------
shadps4-qtlauncher.mk 410281877b4a844d009108490b7133e12863bb59 # Version: Commits on Apr 11, 2026
-------------------------------------------------------------------------------------------------
[ci skip] Qt GUI: Update Translation. (#300)

Co-authored-by: georgemoralis <4313123+georgemoralis@users.noreply.github.com>,

----------------------------------------------------------------------------------------------------
sdl2-gamecontrollerdb.mk bd4ef5de42d50480c5be6bd54de164140a62f384 # Version: Commits on Apr 10, 2026
----------------------------------------------------------------------------------------------------
Adds Trust 850F

c/o pob,

--------------------------------------------------------------------------------------
xpadneo.mk 45f39820edc2c3fc5605bfe4daea471263678ed1 # Version: Commits on Apr 11, 2026
--------------------------------------------------------------------------------------
xpadneo, power: Explain review nit

Signed-off-by: Kai Krakow <kai@kaishome.de>,

----------------------------------------------------------------------------------------
retroarch.mk b6c29daa3f03d74a133805bcf5e4ec7f5c5aa0d6 # Version: Commits on Apr 11, 2026
----------------------------------------------------------------------------------------
Fetch translations from Crowdin,

--------------------------------------------------------------------------------------------
vpinball-next.mk 217ddf05cc388d96b982c47820e9a025419c1838 # Version: Commits on Apr 11, 2026
--------------------------------------------------------------------------------------------
remove IRenderable from PartGroup and Timer,

----------------------------------------------------------------------------------------
doomretro.mk dd3f9daeb1621361de95e0c0d53ed53e35b5a794 # Version: Commits on Apr 11, 2026
----------------------------------------------------------------------------------------
Handle empty string assignments in `DEHACKED` lumps properly,

---------------------------------------------------------------------------------------------
libretro-fbneo.mk cab26a10477d4034f05f8992c34d9bb3c5966e0e # Version: Commits on Apr 10, 2026
---------------------------------------------------------------------------------------------
(libretro) update files,

-----------------------------------------------------------------------------------------------
libretro-flycast.mk ed41f982c1bfed65f43c7f5a56d155ea3b7f3adb # Version: Commits on Apr 10, 2026
-----------------------------------------------------------------------------------------------
Fetch translations & Recreate libretro_core_options_intl.h,

-------------------------------------------------------------------------------------------------
libretro-geargrafx.mk fd218707ec725eb2dbf1eae3024084a4d2bd6205 # Version: Commits on Apr 10, 2026
-------------------------------------------------------------------------------------------------
Fix input timing for non-vblank polling games. Fix #114,

----------------------------------------------------------------------------------------------
libretro-stella.mk d082e6a50f98e178896619c75397b1033f7dade1 # Version: Commits on Apr 11, 2026
----------------------------------------------------------------------------------------------
Oops, forgot one in the last commit.,

---------------------------------------------------------------------------------------------
common-shaders.mk ba58d81561544ace09ed338f5c19a17d737c53a2 # Version: Commits on Apr 10, 2026
---------------------------------------------------------------------------------------------
avoid removing *.inc file that's needed for pretty much everything,

--------------------------------------------------------------------------------------------
slang-shaders.mk 3e8578d3341c08647470542010b2daf8e7218fa9 # Version: Commits on Apr 10, 2026
--------------------------------------------------------------------------------------------
Add experimental interlace option (#890)

* Allow auto up-scale by half a multiple

* Change threshold for auto phase to be more tolerant to exotic  resolutions

* Optimize mix_master function

* Allow down-scale only by whole multiple

* Improve halation with high diffusion

* Fix auto phase

* Halved scanlines offset amount

* Fix auto phase once more for manual orientation

* Add experimental interlace option

* Correct relation of brightness and compensation,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants