Gfx GX Fn GXSetNumIndStages - wowjinxy/libPorpoise GitHub Wiki

GXSetNumIndStages

  • Category: Indirect Texturing
  • Matrix Status: Implemented
  • Matrix Notes: Parity-checked vs SDK stage-count semantics (0..GX_MAX_INDTEXSTAGE) with fail-soft clamp in PC backend.
  • Matrix Link: Gfx-GX-API-Matrix

Official SDK (Reference)

  • Manual page: reference/man/gfx/gx/Indirect/GXSetNumIndStages.html
  • SDK source: reference/gx/GXBump.c (GXSetNumIndStages, around lines 352+)
  • Verified SDK behavior:
    • Accepts indirect stage count in range 0..GX_MAX_INDTEXSTAGE (max 4).
    • Writes indirect-stage count into GEN_MODE (NBMP field).
    • SDK uses debug assert for out-of-range values.

libPorpoise Implementation

  • Runtime implementation area: src/gx
  • Public API surface: include/dolphin/gx
  • Current implementation:
    • src/gx/pc_gx.c: GXSetNumIndStages now flushes pending begin state, marks indirect state dirty, and clamps to GX_MAX_INDTEXSTAGE.
    • Runtime/shader use u_num_ind_stages as loop gate for indirect sampling state.

SDK vs Porpoise Diff

  • Signature parity:
    • SDK: void GXSetNumIndStages(u8 nIndStages)
    • Porpoise: same
  • Behavioral parity:
    • SDK: range assert (<= GX_MAX_INDTEXSTAGE) + GEN_MODE update.
    • Porpoise: equivalent range semantics via clamp + indirect runtime state update.
  • Known divergence:
    • Out-of-range handling is fail-soft clamp instead of SDK debug assert.

Validation Checklist

  • GX demo coverage checked (state-only change; regression-safe)
  • Pikmin usage path checked (indirect loop gate path in shader/runtime)
  • Matrix status updated if needed
  • Notes updated with concrete file/function references

Working Notes

  • Build sanity target after update: pikmin_demo (Win32 Debug).