Snapshot: fog implementation + fidelity tooling baseline (pre bilinear-clamp fix)

Per-vertex GS fog end-to-end (gs_stub emit incl. persp_emit5, gs_prim_list_feeder
XYZ2->XYZF2 on PRIM.FGE, gs_make_sh3_scheduler_fixture.py F/FGE packing), new fog
TBs, fidelity attribution tooling. Functional baseline before removing the dead
bilinear lerp8 clamps (Codex: 161-node comb loop -> -0.042ns setup fail).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-20 19:56:46 -04:00
parent ec82764bef
commit ba74bbd5aa
476 changed files with 696247 additions and 130119 deletions
+172 -7
View File
@@ -129,8 +129,159 @@ $(mac "FEEDER_STG_INIT_FILE=\\\"$MEMDIR/feeder_sh3_persp.mem\\\"")"
$(mac GS_LPDDR_TEX=1)
$(mac "FEEDER_STG_INIT_FILE=\\\"$MEMDIR/feeder_sh3_real.mem\\\"")"
;;
sh3_lpddr_fb)
# Ch353 — the SH3 real draw on an LPDDR-ONLY direct PSMCT32 framebuffer (the FULL 256x334 bounding box, NOT
# the Ch352 256x120 BRAM crop). Same feeder-driven SH3 config as sh3_real_draw (LPDDR texture cache @0x200000
# + real CSM1 CLUT + Ch351 widened perspective), but the bram-top runs with FB_LPDDR_ONLY (the PSMCT32 writer
# commits the frame to LPDDR @ base 0 instead of the BRAM mirror) and FEEDER_AUTOSTART=0 (no boot render). The
# line-buffer scanout serves the LPDDR FB, HARD-gated on the ordered frame_drained ack (no timeout). VRAM stays
# 128 KiB / CBP=480 (Codex option A). The static QSF EMIF/GS_LPDDR4B_FB/USE_QSYS_TOP already provide the EMIF +
# writer + line-buffer scanout. Proven end-to-end by tb_top_psmct32_sh3_lpddr_fb_seq (the mandatory fit gate).
# BOARD ORDER (Codex host sequence): (1) wait setup/CLUT + feeder ready (0x0D8[0]); (2) HPS PRECLEAR the LPDDR
# FB 0x000000..0x0537FF via the write-probe; (3) upload the 512x512 PSMT8 texture to LPDDR @0x200000; (4) fill +
# checksum-verify the texture cache (0x054/0x070=fbdeaa32); (5) set FB base 0 (0x01C=0), canary off, ARM the
# writer (0x018[0]); (6) pulse feeder GO (0x0E8); (7) confirm drain (poll LPDDR_STATUS 0x02C[0] idle + LPDDR_BYTES
# 0x030 != 0); (8) scanout auto-enables from frame_drained — raise video_src (0x018[2]=1); scanout_lb is forced.
# Fixtures SH3-derived -> LOCAL/gitignored: run `python3 tools/gs_make_sh3_real_draw_fixture.py --full-frame` FIRST.
FIXTURE="$(fix bios_sh3_full payload_sh3_full)"
SCENE="$(mac GS_SH3_LPDDR_FB=1)
$(mac GS_LPDDR_TEX=1)
$(mac "FEEDER_STG_INIT_FILE=\\\"$MEMDIR/feeder_sh3_full.mem\\\"")"
;;
sh3_lpddr_fb_multi)
# Ch354 Brick 1 — MULTI-DRAW: 3 authentic SH3 draws (idx89548/89761/89974) that SHARE one texture/CLUT,
# composited into ONE LPDDR PSMCT32 framebuffer (256x338, the union bbox). Same LPDDR-FB path as sh3_lpddr_fb
# (FEEDER_AUTOSTART=0 + render-epoch EOF + frame_drained hard gate + line-buffer scanout) but GS_SH3_LPDDR_FB_MULTI
# raises FEEDER_STG_WORDS 768->2048 (204-tri combined list) and SCANOUT_LB_NROWS 334->338. Accumulation is
# bit-exact (combined RTL == RTL-composed singles, 0/86528 px); per-draw <=1-texel fidelity is draw-dependent
# (97.5/95.6/93.2%, the existing perspective-sampling limit, NOT an acceptance gate). Proven by
# tb_top_psmct32_sh3_multidraw. GS_SH3_LPDDR_FB + GS_LPDDR4B_FB + GS_LPDDR_TEX all apply (the profile sets them).
# BOARD ORDER: identical to sh3_lpddr_fb, but preclear the LARGER FB range:
# sudo ./ps2_sh3_tex_upload sh3_real_tex_lpddr.mem --lpddr-fb --fb-rows 338 (preclears 0..0x54800).
# Fixtures SH3-derived -> LOCAL/gitignored: run `python3 tools/gs_make_sh3_multidraw_fixture.py <dump>
# --draw-list 89548,89761,89974 --tag multi --emit` FIRST.
FIXTURE="$(fix bios_sh3_multi payload_sh3_multi)"
SCENE="$(mac GS_SH3_LPDDR_FB=1)
$(mac GS_SH3_LPDDR_FB_MULTI=1)
$(mac GS_LPDDR_TEX=1)
$(mac "FEEDER_STG_INIT_FILE=\\\"$MEMDIR/feeder_sh3_multi.mem\\\"")"
;;
sh3_lpddr_fb_multitex)
# Ch355 Brick 1 — MULTI-TEXTURE: 2 SH3 draws with DIFFERENT textures/CLUTs (A=idx19562 tbp=11264/CBP_A,
# B=idx89761 tbp=9216/CBP_B) composited into ONE 320x381 LPDDR FB (FBW=5, stride 1280, 0x77100, 15240 beats/frame)
# via SCENE-LEVEL texture rebind + RUNTIME staged-list retriggering. GS_SH3_LPDDR_FB_MULTITEX raises
# FEEDER_STG_WORDS->2048 + SCANOUT_LB to 320x381. The bootlet (bios/payload_sh3_mt) uploads BOTH relocated CLUTs
# (CBP_A=480, CBP_B=484); the HOST streams each list at runtime (NO FEEDER_STG_INIT_FILE — feeder starts empty).
# Accumulation bit-exact + Q-canonicalized (feeder canonicalizes homogeneous coords to positive Q; NOT native
# signed-Q). Proven by tb_top_psmct32_sh3_multitex.
# BOARD RUN (runtime two-group flow, host streams the lists + rebinds the cache):
# sudo ./ps2_sh3_multitex sh3_mtA_tex_lpddr.mem sh3_mtB_tex_lpddr.mem feeder_sh3_mtA.mem feeder_sh3_mtB.mem
# Fixtures SH3-derived -> LOCAL/gitignored: run `python3 tools/gs_make_sh3_multitex_fixture.py <dump> --emit` FIRST.
FIXTURE="$(fix bios_sh3_mt payload_sh3_mt)"
SCENE="$(mac GS_SH3_LPDDR_FB=1)
$(mac GS_SH3_LPDDR_FB_MULTITEX=1)
$(mac GS_LPDDR_TEX=1)"
;;
sh3_lpddr_fb_sched)
# Ch356 — N-TEXTURE SCHEDULER: N (default 3) authentic SH3 draws with DIFFERENT textures/CLUTs
# (E0=idx11671 tbp=10240/CBP480, E1=idx19562 tbp=11264/CBP484, E2=idx89761 tbp=9216/CBP488) composited into ONE
# 384x381 LPDDR FB (FBW=6, stride 1536, 0x8ee00, 18288 beats/frame) via a DATA-DRIVEN scheduler over epoch
# descriptors (scene-level texture rebind + runtime staged-list retriggering). GS_SH3_LPDDR_FB_SCHED raises
# FEEDER_STG_WORDS->2048 + SCANOUT_LB to 384x381. The bootlet (bios/payload_sh3_sched) preloads ALL N relocated
# CLUTs; the HOST streams each list at runtime (NO FEEDER_STG_INIT_FILE). Accumulation proven 100% BIT-FOR-BIT
# (compose_sched.py) + Q-canonicalized; tb_top_psmct32_sh3_sched (+ _compose gate).
# BOARD RUN (data-driven; host reads the descriptor table + streams each list, rebinds the cache per epoch):
# sudo ./ps2_sh3_sched sh3_sched_epochs.txt (all fixtures in the cwd)
# Fixtures SH3-derived -> LOCAL/gitignored: run `python3 tools/gs_make_sh3_scheduler_fixture.py <dump> --emit` FIRST.
FIXTURE="$(fix bios_sh3_sched payload_sh3_sched)"
SCENE="$(mac GS_SH3_LPDDR_FB=1)
$(mac GS_SH3_LPDDR_FB_SCHED=1)
$(mac GS_LPDDR_TEX=1)"
;;
sh3_lpddr_fb_640)
# Ch357 — NATIVE 640x480 LPDDR framebuffer: the Ch356 N-texture scheduler on a full-frame 640x480 FB
# (FBW=10, stride 2560, size 0x12C000, 80 beats/row, 38400 beats/frame). Draws land at their AUTHENTIC screen
# coordinates (NO union-origin translation). Scheduler/host UNCHANGED from Ch356; only the FB geometry differs.
# GS_SH3_LPDDR_FB_640 sets SCANOUT_LB 640x480 + FEEDER_STG_WORDS=2048. Bootlet (bios/payload_sh3_s640) preloads
# all N relocated CLUTs; the HOST streams each list at runtime (NO FEEDER_STG_INIT_FILE). FB[0..0x12C000) disjoint
# from texture region [0x200000..). Composition proven 100% BIT-FOR-BIT (compose_sched.py); tb_top_psmct32_sh3_sched640.
# BOARD RUN (same data-driven host, different descriptor table):
# sudo ./ps2_sh3_sched sh3_s640_epochs.txt
# Fixtures SH3-derived -> LOCAL/gitignored: run `python3 tools/gs_make_sh3_scheduler_fixture.py <dump> --fb640 --emit` FIRST.
FIXTURE="$(fix bios_sh3_s640 payload_sh3_s640)"
SCENE="$(mac GS_SH3_LPDDR_FB=1)
$(mac GS_SH3_LPDDR_FB_640=1)
$(mac GS_LPDDR_TEX=1)"
;;
sh3_lpddr_fb_z)
# Ch357 — PERSISTENT AUTHENTIC Z: the N-texture scheduler with a REAL per-fragment PSMZ16S depth test on an
# LPDDR-persistent Z buffer. The plain color writer is replaced by gs_lpddr_zc_emit: per fragment it clamp16-reads
# /GEQUAL-compares/updates a packed-16b Z line in LPDDR (Z base 0x140000) and emits color ONLY on Z-pass. Z PERSISTS
# across the 3 scheduler epochs (precleared exactly once by clear_start at ARM; texture rebind does NOT clear it).
# The three AXI streams share the LPDDR through the existing arbiters (color->wr_arb s0, Z-write->wr_arb s2,
# Z-read->rd_arb s3). Strong-reject acceptance fixture (256x210, 18.31% reject: far-late fragments MUST be depth-
# rejected). GS_SH3_LPDDR_FB_Z sets SCANOUT_LB 256x210 (6720 beats/frame). Bootlet (bios/payload_sh3_zsched) preloads
# all 3 relocated CLUTs; the HOST streams each list at runtime (NO FEEDER_STG_INIT_FILE). ROP + arbitration + REAL-
# RASTER integration all sim-proven: tb_top_psmct32_sh3_zrop (ROP golden), tb_top_psmct32_sh3_zarb (arbitration),
# tb_top_psmct32_sh3_zint (real raster, ZERO fragment drops, Z+color bit-exact vs the clamp16 scoreboard).
# BOARD ORDER (Codex host sequence): (1) wait setup/CLUT + feeder ready; (2) HPS PRECLEAR color 0x000000..0x0347FF
# AND Z 0x140000..0x15A3FF via the write-probe; (3) per epoch upload the 512x512 PSMT8 texture @0x200000 + fill/verify
# the cache; (4) ARM the writer (0x018[0]) -> clear_start preclears the Z buffer; WAIT clear_done before the first GO;
# (5) per epoch stream the list + pulse GO (0x0E8) + confirm a FRESH frame_drained; Z persists across epochs; (6) after
# the LAST drain raise video_src (0x018[2]=1) — scanout_lb (256x210) is forced. Read zc_g_drops (must be 0).
# Fixtures SH3-derived -> LOCAL/gitignored: run `python3 tools/gs_make_sh3_scheduler_fixture.py <dump> --authz
# --tag zsched --emit` FIRST (strong-reject draw list, authentic per-vertex Z).
FIXTURE="$(fix bios_sh3_zsched payload_sh3_zsched)"
SCENE="$(mac GS_SH3_LPDDR_FB=1)
$(mac GS_SH3_LPDDR_FB_Z=1)
$(mac GS_LPDDR_TEX=1)"
;;
sh3_lpddr_fb_z640)
# Ch358 — PERSISTENT AUTHENTIC Z at NATIVE 640x480: the SAME strong-reject persistent-Z scene as sh3_lpddr_fb_z
# (draws 8634/12757/145742, gs_lpddr_zc_emit, clamp16/GEQUAL, Z persists across epochs) but on the full-frame
# native FB at AUTHENTIC screen coordinates (FBW=10, stride 2560, size 0x12C000, 38400 beats/frame; draws land at
# x[407..619] y[97..306]). GS_SH3_LPDDR_FB_Z + GS_SH3_LPDDR_FB_640 together select SCANOUT_LB 640x480 AND
# ZFB_PXW/H=640x480 (Z clear = 19200 beats). Map (gs_lpddr_map_pkg, disjoint by construction): color 0x0..0x12C000,
# Z 0x140000..0x1D6000, tex 0x200000. Bootlet (bios/payload_sh3_zs640) preloads all 3 relocated CLUTs; the HOST
# streams each list at runtime (NO FEEDER_STG_INIT_FILE). Sim gates: tb_top_psmct32_sh3_zs640_cap (capture +
# fidelity oracle) and tb_top_psmct32_sh3_zint640 (real raster -> zc_emit -> REAL arbiters -> shared LPDDR,
# ZERO drops, Z+color scoreboard-exact). Board proof = make -C sim sh3_zs640_board_compare (byte-for-byte vs
# zint640 + replay-color 100%).
# BOARD RUN (host unchanged — geometry comes from the epochs META):
# sudo ./ps2_sh3_sched --zbuf sh3_zs640_epochs.txt --dump-fb sh3_zs640_board_fb.mem
# Fixtures SH3-derived -> LOCAL/gitignored: run `make -C sim sh3_zs640_fixture` FIRST.
FIXTURE="$(fix bios_sh3_zs640 payload_sh3_zs640)"
SCENE="$(mac GS_SH3_LPDDR_FB=1)
$(mac GS_SH3_LPDDR_FB_Z=1)
$(mac GS_SH3_LPDDR_FB_640=1)
$(mac GS_LPDDR_TEX=1)"
;;
sh3_lpddr_fb_z640c6)
# Ch359 — shared-texture residency scene: six authentic SH3 draws grouped into two
# 204-triangle epochs at native 640x480 persistent Z. The bootlet preloads the C6
# relocated CLUT at CBP=13888; the host uploads/fills the shared texture once, then
# verifies it remains resident for the reuse epoch.
FIXTURE="$(fix bios_sh3_zs640c6 payload_sh3_zs640c6)"
SCENE="$(mac GS_SH3_LPDDR_FB=1)
$(mac GS_SH3_LPDDR_FB_Z=1)
$(mac GS_SH3_LPDDR_FB_640=1)
$(mac GS_LPDDR_TEX=1)"
;;
sh3_lpddr_fb_z640_runtime_clut)
# Ch367 -- runtime palette residency proof. Same native 640x480
# persistent-Z geometry as Ch358. Keep the proven nonempty C6 setup
# bootlet as a synthesis-retention anchor; the runtime test lists use
# TEX0.CLD=0 and the HPS stages/checks every palette before each GO.
# A zero-transfer bootlet lets Quartus prune the otherwise runtime-fed
# texture/raster RAMs, so it is not a valid hardware proof vehicle.
FIXTURE="$(fix bios_sh3_zs640c6 payload_sh3_zs640c6)"
SCENE="$(mac GS_SH3_LPDDR_FB=1)
$(mac GS_SH3_LPDDR_FB_Z=1)
$(mac GS_SH3_LPDDR_FB_640=1)
$(mac GS_LPDDR_TEX=1)"
;;
--list|"")
echo "Profiles: lpddr_tex (Ch322 texture) lpddr128_scanout (Ch321 scanout) tile_spill (Ch323 spill/reload) feeder (Ch330 command-list) feeder_persp (Ch342 perspective) feeder_cube (Ch343 authentic cube) texalpha (Ch344 textured-alpha sprite) feeder_sprite (Ch345a runtime sprite) sh3_clut (Ch347 authentic SH3 PSMT8+CLUT) sh3_persp (Ch348 SH3 PSMT8+CLUT perspective) sh3_real_draw (Ch350/351/352 SH3 real-draw crop, LPDDR tex + CSM1 + widened persp)"
echo "Profiles: lpddr_tex (Ch322 texture) lpddr128_scanout (Ch321 scanout) tile_spill (Ch323 spill/reload) feeder (Ch330 command-list) feeder_persp (Ch342 perspective) feeder_cube (Ch343 authentic cube) texalpha (Ch344 textured-alpha sprite) feeder_sprite (Ch345a runtime sprite) sh3_clut (Ch347 authentic SH3 PSMT8+CLUT) sh3_persp (Ch348 SH3 PSMT8+CLUT perspective) sh3_real_draw (Ch350/351/352 SH3 real-draw crop, LPDDR tex + CSM1 + widened persp) sh3_lpddr_fb (Ch353 SH3 full 256x334 on an LPDDR-only PSMCT32 FB + line-buffer scanout, frame_drained-gated) sh3_lpddr_fb_multi (Ch354 3 SH3 draws -> 256x338) sh3_lpddr_fb_multitex (Ch355 2 DIFFERENT-texture draws -> 320x381, runtime-staged) sh3_lpddr_fb_sched (Ch356 N-texture data-driven scheduler -> 384x381) sh3_lpddr_fb_640 (Ch357 native 640x480 full-frame) sh3_lpddr_fb_z (Ch357 PERSISTENT PSMZ16S Z, 256x210 strong-reject) sh3_lpddr_fb_z640 (Ch358 PERSISTENT Z at NATIVE 640x480) sh3_lpddr_fb_z640c6 (Ch359 shared-texture residency) sh3_lpddr_fb_z640_runtime_clut (Ch367 runtime palette residency)"
echo "Active profile:"
sed -n '/DE25_PROFILE_SCENE/,/DE25_PROFILE_SCENE/p' "$QSF" | grep VERILOG_MACRO || echo " (no scene macros)"
sed -n '/DE25_PROFILE_FIXTURE/,/DE25_PROFILE_FIXTURE/p' "$QSF" | grep IMAGE_FILE
@@ -139,24 +290,38 @@ $(mac "FEEDER_STG_INIT_FILE=\\\"$MEMDIR/feeder_sh3_real.mem\\\"")"
*) echo "unknown profile: $PROFILE (try --list)"; exit 2 ;;
esac
# Replace the content between each marker pair (awk: print markers, swap the body).
swap_block() { # $1=tag $2=replacement-text (reads stdin QSF, writes stdout)
awk -v tag="$1" -v repl="$2" '
$0 ~ (">>> " tag " ") { print; print repl; inblk=1; next }
# Replace the content between each marker pair. Read the replacement from a file
# rather than `awk -v`: awk consumes backslash-escaped quotes in Verilog macros.
swap_block() { # $1=tag $2=replacement-file (reads stdin QSF, writes stdout)
awk -v tag="$1" -v repl_file="$2" '
$0 ~ (">>> " tag " ") {
print
while ((getline line < repl_file) > 0) print line
close(repl_file)
inblk=1
next
}
$0 ~ ("<<< " tag " <<<") { inblk=0 }
!inblk { print }
'
}
fixture_tmp="$(mktemp)"
scene_tmp="$(mktemp)"
tmp="$(mktemp)"
swap_block DE25_PROFILE_FIXTURE "$FIXTURE" < "$QSF" \
| swap_block DE25_PROFILE_SCENE "$SCENE" > "$tmp"
trap 'rm -f "$fixture_tmp" "$scene_tmp" "$tmp"' EXIT HUP INT TERM
printf '%s\n' "$FIXTURE" > "$fixture_tmp"
printf '%s\n' "$SCENE" > "$scene_tmp"
swap_block DE25_PROFILE_FIXTURE "$fixture_tmp" < "$QSF" \
| swap_block DE25_PROFILE_SCENE "$scene_tmp" > "$tmp"
# sanity: both marker pairs must still be present (don't clobber the QSF on a bad run)
for tag in DE25_PROFILE_FIXTURE DE25_PROFILE_SCENE; do
[ "$(grep -c "$tag" "$tmp")" -eq 2 ] || { echo "ERROR: marker '$tag' missing after edit — QSF unchanged"; rm -f "$tmp"; exit 1; }
done
mv "$tmp" "$QSF"
trap - EXIT HUP INT TERM
rm -f "$fixture_tmp" "$scene_tmp"
echo "Selected profile: $PROFILE"
echo " fixture: $(echo "$FIXTURE" | grep -o '[a-z0-9_]*\.mem' | tr '\n' ' ')"
echo " scene : $(echo "$SCENE" | grep -o 'GS_[A-Z0-9_]*=1' | tr '\n' ' ')"