Gfx GX Fn GXSetTexCoordScaleManually - wowjinxy/libPorpoise GitHub Wiki

GXSetTexCoordScaleManually

  • Category: Texture Coordinate Generation
  • Matrix Status: Partial
  • Matrix Notes: Verified and implemented manual texcoord scale override state (enable/ss/ts) and shader application before texture lookup; automatic map-size scaling remains approximate on PC backend.
  • Matrix Link: Gfx-GX-API-Matrix

Official SDK (Reference)

  • Manual page: reference/man/gfx/gx/Texture/GXSetTexCoordScaleManually.html
  • SDK source: reference/gx/GXTexture.c (GXSetTexCoordScaleManually)
  • SDK behavior:
    • Signature: void GXSetTexCoordScaleManually(GXTexCoordID coord, GXBool enable, u16 ss, u16 ts).
    • Tracks per-texcoord manual-scale enable bits.
    • When enable == GX_TRUE, writes SU scale registers using (ss - 1) / (ts - 1).
    • When enable == GX_FALSE, returns texcoord to automatic scaling path (values retained but ignored).

libPorpoise Implementation

  • Public API declaration: include/dolphin/gx/GXTexture.h
  • Runtime implementation: src/gx/pc_gx.c (GXSetTexCoordScaleManually)
  • Shader path: src/gx/shaders/default.frag
  • Internal state: src/gx/pc_gx_internal.h
  • Behavior:
    • API signature matches SDK declaration.
    • Validates coord < GX_MAX_TEXCOORD.
    • Flushes in-progress begin batch and marks texgen state dirty.
    • Stores per-texcoord manual enable bit and ss/ts values (0 is clamped to 1 for safe divide path).
    • Fragment shader applies manual scaling as tc /= vec2(ss, ts) before TEV texture lookup when manual mode is enabled for that texcoord.

SDK vs Porpoise Diff

  • Signature parity:
    • SDK: void GXSetTexCoordScaleManually(GXTexCoordID, GXBool, u16, u16)
    • Porpoise: same
  • Behavioral parity:
    • SDK: per-texcoord manual override over SU auto scaling; disable returns to auto mode.
    • Porpoise: manual override enable/disable and scale values are persisted and honored in shader sampling path.
  • Known divergence:
    • Hardware SU register behavior (including exact interaction with automatic map-size scaling and related SU features like cyl-wrap/bias) is approximated on PC backend.
    • Automatic scaling-by-associated-map path is not yet modeled bit-accurately as discrete SU state.

Validation Checklist

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

Working Notes

  • This function was previously a stub in pc_gx.c and now has runtime + shader behavior.