Gfx GX Fn GXSetAlphaCompare - wowjinxy/libPorpoise GitHub Wiki
GXSetAlphaCompare
- Category:
Texture Environment
- Matrix Status:
Implemented
- Matrix Notes: Implemented dual compare + logical combine state (
comp0/ref0 op comp1/ref1) with hardware-width field masking for compare/op enums.
- Matrix Link: Gfx-GX-API-Matrix
Official SDK (Reference)
- Manual page:
reference/man/gfx/gx/Tev/GXSetAlphaCompare.html
- SDK source:
reference/ACGC-PC-Port/src/static/dolphin/gx/GXTev.c (GXSetAlphaCompare)
- SDK behavior:
- Programs BP alpha-test register with:
ref0 in bits [7:0]
ref1 in bits [15:8]
comp0 in bits [18:16]
comp1 in bits [21:19]
op in bits [23:22]
- Uses alpha from the last active TEV stage and combines the two comparisons via
GXAlphaOp (AND/OR/XOR/XNOR).
libPorpoise Implementation
- Public API declaration:
include/dolphin/gx/GXTev.h
- Runtime implementation:
src/gx/pc_gx.c (GXSetAlphaCompare)
- Shader path:
src/gx/shaders/default.frag (alphaTest + logical combine in main)
- Behavior:
- Stores both compare functions and refs plus combine op in GX state.
- Masks enum inputs to hardware register widths (
comp* & 0x7, op & 0x3) before storing.
- Shader applies both comparisons and combine op, and discards fragments when alpha test fails.
SDK vs Porpoise Diff
- Signature parity:
- Signatures match (
GXCompare, u8, GXAlphaOp, GXCompare, u8).
- Behavioral parity:
- Dual-compare + logical combine behavior is implemented.
- Bit-width field behavior for compare/op now mirrors BP register packing semantics.
- Known divergence:
- SDK writes packed BP state directly; Porpoise stores decoded state and evaluates in shader.
- Equality/inequality comparison uses a small floating epsilon in shader to approximate 8-bit equality.
Validation Checklist
Working Notes
- Runtime parity tweak in this pass: compare/op field-width masking added.