Gfx GX Fn GXSetTevOrder - wowjinxy/libPorpoise GitHub Wiki

GXSetTevOrder

  • Category: Texture Environment
  • Matrix Status: Implemented
  • Matrix Notes: Parity-checked vs SDK GXTev.c map/coord normalization and texture-enable semantics.
  • Matrix Link: Gfx-GX-API-Matrix

Official SDK (Reference)

  • Manual page: reference/man/gfx/gx/Tev/GXSetTevOrder.html
  • SDK source: reference/gx/GXTev.c (GXSetTevOrder, around lines 1115+)
  • Verified SDK behavior:
    • Stores raw stage map ID (gx->texmapId[stage] = map) and programs normalized BP values.
    • Normalizes map as (map & ~GX_TEX_DISABLE) and falls back to GX_TEXMAP0 if out of range.
    • Normalizes coord to GX_TEXCOORD0 when coord is NULL/invalid.
    • Enables texture lookup only when map != GX_TEXMAP_NULL and GX_TEX_DISABLE is not set.
    • Maps GX_COLOR_NULL to zero raster channel selector (RAS1_CC_Z path in SDK source).

libPorpoise Implementation

  • Runtime implementation area: src/gx
  • Public API surface: include/dolphin/gx
  • Current implementation:
    • src/gx/pc_gx.c (GXSetTevOrder) now mirrors SDK map/coord normalization behavior.
    • Added per-stage tex_lookup_enable state (src/gx/pc_gx_internal.h) so lookup enable is derived from map NULL/disable flags, not only map index range checks.
    • Sampler binding path uses tex_lookup_enable (src/gx/pc_gx.c, texture upload/bind block near u_use_texture updates).
    • Preserved existing GX_COLOR_NULL + PASSCLR compatibility safeguard used by demos.

SDK vs Porpoise Diff

  • Signature parity:
    • SDK: void GXSetTevOrder(GXTevStageID, GXTexCoordID, GXTexMapID, GXChannelID)
    • Porpoise: same
  • Behavioral parity:
    • SDK: map/coord normalization + separate lookup-enable semantics from NULL/disable bits.
    • Porpoise: now matches those semantics in runtime state and sampler bind decision.
  • Known divergence:
    • SDK/HW texture-coordinate scaling interactions tied to SU setup are still approximated by the PC backend’s normalized GL sampling path.
    • Raster channel GX_ALPHA_BUMP/GX_ALPHA_BUMPN behavior remains shader-approximated (not full HW-accurate EMBM channel semantics yet).

Validation Checklist

  • GX demo coverage checked (regression-safe update; no new demo break reported in this step)
  • Pikmin usage path checked (build sanity target: pikmin_demo)
  • Matrix status updated if needed
  • Notes updated with concrete file/function references

Working Notes

  • Build sanity: cmake --build build_pikmin_win32 --config Debug --target pikmin_demo passed after the update.