Gfx GX Fn GXSetTevSwapMode HW2 - wowjinxy/libPorpoise GitHub Wiki
GXSetTevSwapMode (HW2)
- Category:
Texture Environment
- Matrix Status:
Implemented
- Matrix Notes: Implemented per-stage raster/texture swap selectors with BP-field-width masking (
2-bit each).
- Matrix Link: Gfx-GX-API-Matrix
Official SDK (Reference)
- Manual page:
reference/man/gfx/gx/Tev/GXSetTevSwapMode.html
- SDK source:
reference/ACGC-PC-Port/src/static/dolphin/gx/GXTev.c (GXSetTevSwapMode)
- SDK behavior:
- HW2-only API selecting swap-table entries for raster and texture inputs on one TEV stage.
- Writes
ras_sel and tex_sel as 2-bit fields in TEV stage register.
- SDK debug path checks GX-begin and asserts
stage < 16.
libPorpoise Implementation
- Public API declaration:
include/dolphin/gx/GXTev.h
- Runtime implementation:
src/gx/pc_gx.c (GXSetTevSwapMode)
- Shader consumption:
- Per-stage selectors uploaded via
u_tev_swap[].
- Applied with
u_swap_table[] in src/gx/shaders/default.frag (applySwap path for stage tex/ras colors).
- Behavior:
- Stores per-stage raster/texture swap selectors and marks TEV-stage state dirty.
- Applies
2-bit masking (& 0x3) for each selector to mirror BP field semantics.
- Guards writes with
stage < 16.
SDK vs Porpoise Diff
- Signature parity:
- Signatures match (
GXTevStageID, GXTevSwapSel, GXTevSwapSel).
- Behavioral parity:
- Per-stage raster/texture swap selector behavior is implemented and drives shader swap routing.
- Selector bit-width semantics now match hardware fields.
- Known divergence:
- SDK writes packed BP register state directly; Porpoise stores decoded state and evaluates in shader.
Validation Checklist
Working Notes
- Runtime parity tweak in this pass: 2-bit selector masking added.