Gfx GX Fn GXBegin - wowjinxy/libPorpoise GitHub Wiki

GXBegin

  • Category: Geometry and Vertex
  • Matrix Status: Implemented
  • Matrix Notes: SDK parity pass done: typed signature, primitive/vtxfmt guards, and documented max-count handling (nverts==0 -> 65536).
  • Matrix Link: Gfx-GX-API-Matrix

Official SDK (Reference)

  • Manual page: E:/GPT5/Porpoise_SDK/libPorpoise/reference/man/gfx/gx/Geometry/GXBegin.html
  • Related page: E:/GPT5/Porpoise_SDK/libPorpoise/reference/man/gfx/gx/Geometry/GXEnd.html
  • SDK source parity check area: E:/GPT5/ACGC-PC-Port-Debug-Stuff/src/static/dolphin/gx
  • Notes:
    • Signature/prototype is void GXBegin(GXPrimitive type, GXVtxFmt vtxfmt, u16 nverts).
    • Manual requires vertex stream between GXBegin/GXEnd to match configured descriptors/formats.
    • Manual states the submitted vertex count must match nverts and documents a maximum of 65536 vertices.
    • Manual notes clockwise primitive order is front-facing.

libPorpoise Implementation

  • Runtime implementation area: E:/GPT5/Porpoise_SDK/libPorpoise/src/gx/pc_gx.c
  • Public API surface: E:/GPT5/Porpoise_SDK/libPorpoise/include/dolphin/gx/GXGeometry.h
  • Notes:
    • Runtime signature now matches SDK types (GXPrimitive, GXVtxFmt, u16).
    • Begin-state reset remains intact (current_primitive, current_vtxfmt, vertex counters, default color, current matrix index).
    • PC backend now applies explicit primitive whitelist + vtxfmt bounds guard (fail-soft fallback).
    • nverts==0 is treated as 65536 to match documented max-count semantics for the 16-bit field.

SDK vs Porpoise Diff

  • Signature parity:
    • SDK: void GXBegin(GXPrimitive, GXVtxFmt, u16)
    • Porpoise: matches in pc_gx.c and public header
  • Behavioral parity:
    • SDK: primitive begin packet with typed primitive/vtxfmt and 16-bit vertex count
    • Porpoise: mirrors begin-state setup and expected-count tracking, with soft guards for invalid input
  • Known divergence:
    • SDK uses assert/debug checks for invalid input; PC backend fails soft (fallback to GX_TRIANGLES / GX_VTXFMT0).
    • PC backend auto-flushes previous pending batch when a new GXBegin starts if GXEnd was omitted.

Validation Checklist

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

Working Notes

  • Implementation location: GXBegin in E:/GPT5/Porpoise_SDK/libPorpoise/src/gx/pc_gx.c near the vertex-submission section.