Gfx GX Fn GXSetTevSwapModeTable HW2 - wowjinxy/libPorpoise GitHub Wiki

GXSetTevSwapModeTable (HW2)

  • Category: Texture Environment
  • Matrix Status: Implemented
  • Matrix Notes: Implemented swap-table channel routing for all four swap tables with BP-field-width masking (2-bit per channel select).
  • Matrix Link: Gfx-GX-API-Matrix

Official SDK (Reference)

  • Manual page: reference/man/gfx/gx/Tev/GXSetTevSwapModeTable.html
  • SDK source: reference/ACGC-PC-Port/src/static/dolphin/gx/GXTev.c (GXSetTevSwapModeTable)
  • SDK behavior:
    • HW2-only API that programs one of four swap-table entries.
    • Each output channel route (red/green/blue/alpha) is written as a 2-bit field.
    • SDK debug path checks GX-begin and asserts table < 4.

libPorpoise Implementation

  • Public API declaration: include/dolphin/gx/GXTev.h
  • Runtime implementation: src/gx/pc_gx.c (GXSetTevSwapModeTable)
  • Shader consumption:
    • Uploaded through u_swap_table[4].
    • Used by applySwap in src/gx/shaders/default.frag for stage raster/texture component routing.
  • Behavior:
    • Stores per-table channel routes and marks swap-table state dirty.
    • Applies 2-bit masks (& 0x3) for each route to match BP field semantics.
    • Uses fail-soft guard table < 4.

SDK vs Porpoise Diff

  • Signature parity:
    • Signatures match (GXTevSwapSel, GXTevColorChan, GXTevColorChan, GXTevColorChan, GXTevColorChan).
  • Behavioral parity:
    • Swap-table routing behavior is implemented for all 4 table entries and consumed by TEV shader path.
    • Channel selector field-width behavior now matches hardware register packing.
  • Known divergence:
    • SDK writes packed BP registers; Porpoise stores decoded swap table state and applies it in shader.

Validation Checklist

  • GX demo coverage checked
  • Pikmin usage path checked
  • Matrix status updated if needed
  • Notes updated with concrete file/function references

Working Notes

  • Runtime parity tweak in this pass: 2-bit mask on all channel routes.