Files
goldeneye-pc-port/.gitignore
T
James Dansereau 70bc9d65b5 D250: getenv() caching fix -- root cause of the Dam fps drop (plus sysSleep unit fix, GE_D250 probe, perf.ps1) (#75)
* D250: fix sysSleep unit-conversion bug in frame-pacing; add GE_D250 lvlRender probe

port/fast3d/gfx_sdl2.cpp sync_framerate_with_timer() computed the
remaining frame budget in 100ns units (qpc_to_100ns) and passed it
straight into sysSleep(), which takes microseconds -- a real 10x
oversleep whenever that branch fires. Genuine bug, but only active
when target_fps is nonzero (tied to Input/Video FpsCap); confirmed via
live testing that it is NOT the active cause of the user's reported
~45-50fps with FpsCap=0/VSync=0, where this pacing path never runs.

Added GE_D250 (src/boss.c, #ifdef PORT) to isolate lvlRender()'s
DL-building cost (culling/animation/scene traversal) from gfx_run's
already-measured software-RSP interpretation cost. Live test on Dam
shows lvlRender averaging ~0.5-1.5ms -- also not the bottleneck.

Documented in docs/dev/GE-ENV-PROBES.md (GE_D250 row). findings.md
D250 update to follow after rebase.

Claude-Session: https://claude.ai/code/session_016DQUKGLZxFtPy52MkKXXog

* docs(D250): live A/B session -- MSAA/aniso/FOV/resolution/vsync all ruled out

Live session with the user driving the game directly, confirmed the
sim-healthy/render-sagging pattern from earlier idle testing reproduces
under real play on Dam. One-at-a-time A/B via the F10 overlay ruled out
MSAA, anisotropy, FOV, resolution (1280x960 fullscreen vs 640x480
windowed), and VSync (render never exceeds ~60 even uncapped) as the
cause -- the cost is resolution/GPU-setting-independent.

gfx_run (~6-10ms) + lvlRender (~0.5-1.5ms, via the new GE_D250 probe)
together don't account for the real ~20-22ms/frame. Leading remaining
suspect: the emulated N64 thread-handoff/scheduler round-trip
(gesched.c/sched.c) -- real OS context-switch/wake latency standing in
for what was free hardware handoff on N64. Needs a real profiler
(Visual Studio / WPR) attached during a live bad-fps moment to confirm;
ad-hoc per-call timers have now ruled out the two most obvious CPU call
sites without finding the cost.

Claude-Session: https://claude.ai/code/session_016DQUKGLZxFtPy52MkKXXog

* D250: fix uncached getenv() in fast3d hot paths -- root cause of the fps drop

A live WPR/xperf CPU trace (tools_pc/perf.ps1, new sister script to
debug.ps1) with Microsoft public symbols resolved found the dominant
render thread spending only 5.2% of its CPU time in the game's own
code -- 43% was in msvcrt.dll, and getenv()/_getenv_helper_nolock
alone accounted for ~50% of the thread's total CPU time.

Root cause: port/fast3d/gfx_pc.cpp's import_texture() (runs on every
texture bind) and several per-triangle/per-G_SETCOMBINE debug-probe
checks (GE_DTEX, GE_TEXDUMP, GE_TEXRAW, GE_D229 x2, GE_D172 x2, plus
GE_TEXDUMP/GE_PCDUMP in gfx_opengl.cpp) called getenv() uncached on
every call, unlike the safe static-cached pattern already used
elsewhere in this codebase. On a texture-heavy scene that's tens of
thousands of locked, locale-aware Windows CRT environment lookups per
second -- invisible to both of the timers added earlier this session
(gfx_run's own cost measurement and the new GE_D250 lvlRender probe),
since neither isolates CRT/library time from the game's own code.

Fix: cache every getenv() site in gfx_pc.cpp/gfx_opengl.cpp with the
established static-int pattern. Narrow, mechanical, no logic change.

Verified: the exact idle-Dam test that was pinned at 45-50fps before
the fix now holds a rock-steady 60-61fps, zero dips. Also explains why
the earlier MSAA/aniso/FOV/resolution/vsync A/B pass all showed "no
change" -- the getenv() cost was a large per-call constant that
swamped any real, smaller resolution-dependent GPU cost at every
setting tried.

Residual, separate issue found once this was fixed: still runs badly
at 1440p+ (640x480 now holds a clean 60fps) -- likely the real GPU
fill-rate cost the getenv() bug was masking, now exposed on its own.
Not yet investigated.

docs/dev/findings.md D250 updated with the full root-cause writeup.
docs/porting-notes.md gets a new lesson under section E (cache
getenv() in any hot-path probe). tools_pc/perf.ps1 automates the
trace-and-analyze workflow for next time.

Claude-Session: https://claude.ai/code/session_016DQUKGLZxFtPy52MkKXXog

* docs(D250): correct the 1440p+ follow-up -- it was a stale-build false alarm

User re-tested 1440p/4K on the actual getenv-fix build and confirmed
it holds up fine too. The "still runs badly at 1440p+" report was
from before the fix was live, same stale-build class as the DLL-load
false alarm earlier in the session. D250 is fully resolved across all
resolutions tested, not just 640x480.

Claude-Session: https://claude.ai/code/session_016DQUKGLZxFtPy52MkKXXog

* docs: add missing GE_D219RAW row to GE-ENV-PROBES.md (CI validate fix)

Pre-existing gap unrelated to this branch's own changes -- gen_env_probes.py
--check caught it now since it runs on every PR. GE_D219RAW has had live
getenv() sites in src/game/image.c since the D219 investigation but was
never added to the probe doc.
2026-09-13 09:33:36 -04:00

172 lines
3.8 KiB
Plaintext

#Git and VS files
.*~
__pycache__/
.vscode/
.[vV][sS]/
*.rz
*.tmp
*.o
branchdiff.sh
branchdiff_report.txt
*.dump
*.cdata*
/StructLayoutSettings.json
# rom files
*.[zZnN]64
021990.bin
0219D0.bin
# Assets
assets/animationtable_data.bin
assets/animationtable_entries.bin
assets/font/*.bin
assets/ge007.e.118660.jfont_chardata.bin
assets/ge007.j.118660.jfont_chardata.bin
assets/jfont_dl.bin
assets/font_chardataj.bin
assets/font_chardatae.bin
assets/ge007.u.29D160.Globalimagetable.bin
assets/rarewarelogo.bin
assets/ge007.u.2A4D50.usedby7F008DE4.bin
assets/ge007.u.117880.jfont_dl.bin
assets/ge007.u.117940.jfont_chardata.bin
assets/ge007.u.123040.efont_chardata.bin
assets/ge007.u.29E560.Globalimagetable_commandblock.bin
#images
assets/images/split/*.bin*
assets/images/combined/*.bin*
assets/images/out/*
assets/images/split/png/*
#music
assets/music/*.bin
assets/music/*.ctl
assets/music/*.tbl
assets/music/*.sbk
assets/music/*.seq
assets/music/*.aifc
assets/music/*.aiff
#obseg
assets/obseg/bg/*.bin
assets/obseg/bg/e/*.bin
assets/obseg/chr/*/Model.c
assets/obseg/gun/*/Model.c
assets/obseg/ob__ob_end.seg
assets/obseg/prop/*/Model.c
assets/obseg/setup/*.bin
assets/obseg/setup/[eju]/*.bin
assets/obseg/stan/*.bin
assets/obseg/text/*.bin
assets/obseg/text/[eju]/*.bin
assets/obseg/text/[eju]/*.c
assets/ramrom/*.bin
assets/ramrom/[eju]/*.bin
# bin is required, but lets prevent accidental deletion
bin/*
build/*
build-*/*
notes/*
# Local working / planning notes — rolling drafts, not published, not tracked.
# docs/HANDOFF.md and docs/BACKLOG.md are the long-standing pair (also in
# .git/info/exclude); docs/dev/notes/ is the drop for everything else
# (roadmaps, session plans, scratch triage).
docs/HANDOFF.md
docs/BACKLOG.md
docs/dev/notes/
# PC port (see CMakeLists.txt / port/)
build-pc/
tools_pc/*.exe
data/
# release bundles built by tools_pc/bundle-win.sh (repo root only; the
# packaging template lives in tools_pc/dist/ and IS tracked)
/dist/
ge007.ini
!build/test.c
!notes/StyleGuide.md
#tools
# Original SGI IRIX 5.3 IDO toolchain (proprietary SGI binaries) and the SGI
# image viewer are NOT distributed with this repo. They are only needed to
# build the N64 ROM or to regenerate tools/ido5.3_recomp; the PC port does not
# use them. See docs/SetupGuide.md "Recompile IDO" for how to obtain them.
tools/irix/
tools/SGIImageViewer.exe
tools/extractor/*.o
tools/extractor/extractor
tools/aaa_rip/main.o
tools/aaa_rip/aaa_rip
tools/n64cksum
tools/armips
tools/gzipsrc/gzip
tools/gzipsrc/*.o
tools/report/report
tools/report/index.html
tools/report/JPN.htm
tools/gaudio/*
bondtypes_AI.h
acpp_c.c
as1_c.c
cc_c.c
cfe_c.c
copt_c.c
ugen_c.c
ujoin_c.c
uld_c.c
umerge_c.c
uopt_c.c
usplit_c.c
#exclude local user scripts in root folder
/my_*.sh
assets/obseg/em/data/alien8.seg
assets/obseg/em/data/atic.seg
assets/obseg/em/data/cookie.seg
assets/obseg/em/data/gunfright.seg
assets/obseg/em/data/jetman.seg
assets/obseg/em/data/jetpac.seg
assets/obseg/em/data/knightlore.seg
assets/obseg/em/data/pssst.seg
assets/obseg/em/data/sabre.seg
assets/obseg/em/data/spec_rom.seg
assets/obseg/em/data/under.seg
scripts/local/
scripts/make/local/
# PC port debug/session artifacts
_run.log
ge007.crash.log
.pi/
run_out.log
ppm/
screenshots/
# tools_pc/perf.ps1 output (raw ETW traces + CSV analysis, regenerable)
perf_captures/
# local Mupen64 Plus checkout (N64 reference footage); binaries, do not commit
tools_pc/mupen64/
# local N64 emulator checkout (D205 A/B reference)
mupen64/
# PC port run/scratch logs
run_*.log
d6*.log
ge007.crash.log
# agent scratch space + audio probe artifacts (regenerable dumps/traces)
scratchpad/
/audiodump.raw
/audiotrace.log
/mixertrace.log
# Claude Code local state / agent worktrees
.claude/
# saved reference webpage assets (keep the .htm, not the sidecar cruft)
docs/reference/*_files/
nohup.out
gdb.txt
gdb-hang.txt