mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-19 04:19:57 -04:00
Land the shader and pipeline stutter pass, and the fixes it needed.
Large compute shaders that no cache holds are built on one background thread after the boot prebuild, smallest first, so their first dispatch no longer compiles them on the replay thread. NX2NAVI_BIG_BUILD_MAX_MB stops that builder once the process has grown by that much: on a 31 GB machine one of these shaders took the process up by 12.8 GB and the game stuttered while Windows paged. The builder takes the queue under its lock and copies each entry out before compiling it, so a shader queued meanwhile cannot free the arrays under it. The same change reports what pipeline-cache.bin gives back, and starts over when the file grows past NX2NAVI_PIPELINE_CACHE_MAX_MB. A tensor-core program is now tested before its shader is asked for, in both dispatch paths. It runs the stand-in while NX2NAVI_NATIVE_TENSOR is off, and translating it anyway recorded four AI-upscaler shaders of 0.87 to 4.4 million SPIR-V words that this game never dispatches natively. Process memory went from 29.3 GB to 24 GB and the multi-gigabyte builds during play are gone. The frame-time summary says which part a slow frame went to, and with NX2NAVI_REPLAY_TIME how the replay splits between draws, binds and transfers; NX2NAVI_SVC_SLOW_MS logs the kernel services that block, with the thread they blocked on. prof_report.py reads the map this build writes and adds the image base to a runtime Rip, so a profile resolves to function names instead of question marks. build_xlate.py applies the patches with GIT_CEILING_DIRECTORIES set to the build folder's parent. Inside a checkout git read 0021-prmt-byte-permute.patch's paths from the repository's top, skipped every file of it and still exited 0, so PRMT was missing from locally built translators and every byte permute was a no-op. A Skipped patch line now fails the build. The note in AmpereLowering.cs that said the translator emits nothing for PRMT is corrected.
This commit is contained in:
@@ -101,14 +101,21 @@ def prepare_sources() -> Path:
|
||||
patches = sorted((XLATE / "patches").glob("*.patch"))
|
||||
if len(patches) != 35:
|
||||
sys.exit(f"expected 35 patches, found {len(patches)}")
|
||||
# build/xlate is inside this checkout, and git inside a repository reads a "diff --git" patch's paths from the
|
||||
# repository's top: those hunks fall outside the directory handed to --directory, git skips every file of the patch
|
||||
# and still exits 0. 0021-prmt-byte-permute.patch is the only one written in that form, so it used to be skipped in
|
||||
# silence and every byte permute stayed a no-op. GIT_CEILING_DIRECTORIES stops git from walking up to the checkout,
|
||||
# so it reads the patch as it would outside a repository, and a "Skipped patch" line fails the build.
|
||||
env = dict(os.environ, GIT_CEILING_DIRECTORIES=str(BUILD.parent), LC_ALL="C")
|
||||
for patch in patches:
|
||||
# git apply works outside a repository when given a directory; --check first so a failure names the patch.
|
||||
for extra in (["--check"], []):
|
||||
r = subprocess.run(
|
||||
["git", "apply", *extra, "--whitespace=nowarn", "--directory", str(src.relative_to(BUILD)), str(patch)],
|
||||
cwd=BUILD, capture_output=True, text=True,
|
||||
["git", "apply", *extra, "--verbose", "--whitespace=nowarn",
|
||||
"--directory", str(src.relative_to(BUILD)), str(patch)],
|
||||
cwd=BUILD, capture_output=True, text=True, env=env,
|
||||
)
|
||||
if r.returncode != 0:
|
||||
skipped = "Skipped patch" in r.stdout or "Skipped patch" in r.stderr
|
||||
if r.returncode != 0 or skipped:
|
||||
sys.exit(f"patch does not apply: {patch.name}\n{r.stdout}{r.stderr}")
|
||||
print(f"applied {patch.name}")
|
||||
return src
|
||||
|
||||
@@ -18,13 +18,15 @@ import sys
|
||||
from pathlib import Path
|
||||
|
||||
SYM = re.compile(r'^([0-9a-f]{8}) +[0-9a-f]{8} +\d+ {2,}(\S+)$') # In column empty: object lines have a path:(section) there
|
||||
SYM_LD = re.compile(r'^\s*0x([0-9a-f]{8,16})\s+(\S+)\s*$') # a GNU ld map: the address, then the name, no size
|
||||
|
||||
|
||||
def load_map(path):
|
||||
syms = {}
|
||||
with open(path, encoding='utf-8', errors='replace') as f:
|
||||
for line in f:
|
||||
m = SYM.match(line.rstrip('\n'))
|
||||
line = line.rstrip('\n')
|
||||
m = SYM.match(line) or SYM_LD.match(line)
|
||||
if m and '(' not in m.group(2):
|
||||
syms.setdefault(int(m.group(1), 16), m.group(2))
|
||||
addrs = sorted(syms)
|
||||
@@ -96,16 +98,23 @@ def main():
|
||||
prof = load_profile(a.profile)
|
||||
addrs, names = load_map(a.map)
|
||||
base = prof['base']
|
||||
# The map's addresses include the image base (0x140000000 for an x64 exe); a runtime Rip is an offset from wherever
|
||||
# the loader put the image. The lowest map address aligned down to 64 KiB recovers that base, so a Rip becomes a map
|
||||
# address by adding it back.
|
||||
img_base = addrs[0] & ~0xFFFFF if addrs else 0
|
||||
exe = next((m for m in prof['modules'] if m[0] == base), None)
|
||||
exe_end = base + exe[1] if exe else base
|
||||
|
||||
def in_exe(rip):
|
||||
return base <= rip < exe_end
|
||||
|
||||
def sym_at(rip):
|
||||
i = bisect.bisect_right(addrs, img_base + (rip - base)) - 1
|
||||
return names[i] if i >= 0 else '?'
|
||||
|
||||
def name_of(rip):
|
||||
if in_exe(rip):
|
||||
i = bisect.bisect_right(addrs, rip - base) - 1
|
||||
return names[i] if i >= 0 else '?'
|
||||
return sym_at(rip)
|
||||
m = next((m for m in prof['modules'] if m[0] <= rip < m[0] + m[1]), None)
|
||||
return f'{Path(m[2]).name}!+{rip - m[0]:#x}' if m else 'unknown'
|
||||
total = sum(n for _, n in prof['rips']) or 1
|
||||
|
||||
@@ -1594,8 +1594,9 @@ static class AmpereLowering
|
||||
// HFMA2.RELU (79) clamps each lane at zero where the predicate in bits 87-90 holds; only PT is lowered. Measured
|
||||
// on an NVIDIA GPU (tests/tensor_lowering_check.py): a negative result or -0 becomes +0, +inf stays, -inf
|
||||
// becomes 0, a NaN result stays NaN (0x7fff). The sum goes to TexOut and integer operations build the mask of
|
||||
// the half lanes to clear. Maxwell PRMT would be the obvious tool, but the translator emits nothing for it
|
||||
// (Instructions/InstEmit.cs: PrmtR only logs "not implemented").
|
||||
// the half lanes to clear. Maxwell PRMT would do that in one instruction and the translator implements it
|
||||
// (xlate/patches/0021-prmt-byte-permute.patch, Instructions/InstEmitPermute.cs PrmtR); this keeps the integer
|
||||
// form, which is what was measured.
|
||||
// F32 results (78), the H0_NH1 source (86) and absolute values where Maxwell has none are not lowered. HADD2's
|
||||
// second operand is B, or C for forms 2/3.
|
||||
void Half(ulong maxwell)
|
||||
|
||||
Reference in New Issue
Block a user