engine/rr: opt-in D4R_RR2_UNGUARDED, the translated code without its exactness guards

The parts of preset F that are NVIDIA's PTX translated by ptx2rr.py (encoder
0's and decoder 0's per-pixel code around the native blocks, the output
passes) keep NVIDIA's arithmetic bit for bit with three kinds of guard:
every register precise, an opaque zero OR-ed into binary16 stores and
conversions (SUST_Z), and the NoContraction pass spv_exact_convert.py on
their modules. At level 3 the native stages already run this GPU's own
arithmetic, so D4R_RR2_UNGUARDED=1 drops the guards there too:
ptx2rr.py --unguarded (no precise, SUST_Z 0) and no spv_exact_convert.py on
those modules. compile_rr2.py refuses it below level 3. Off by default: the
default model's files are byte-identical to the previous ones.

Presented image against the default, RGB, peak 1: 1280x720 -> 1440p 56.0 dB
on the reset frame, then 43.0 - 45.6 dB; 1114x626 -> 1080p 48.5, then 43.4
- 44.1; the moderate stress input 52.7, then 25 - 30. The exact build
(level 0) is as far from the default (43.0 - 44.4; 43.2 - 44.3; 23.8 -
24.3) as from this build (43.0 - 44.4; 43.4 - 44.3; 23.8 - 24.3). Builds
with D4R_RR2_SPLIT=1 too.

RX 9070 XT, d4r-rr 720p -> 1440p, interleaved: frame 3.526 -> 3.501 ms
(output 649 -> 624 us, dec0_1 446 -> 442).

Signed-off-by: itchyfeetleech <[email protected]>
This commit is contained in:
itchyfeetleech committed 2026-10-19 21:03:21 +13:00
1 parent e94c4018e7
commit 44433c320a
2 files changed
+23 -7

No files matched your search

+15 -6
View File
@@ -84,6 +84,13 @@ SPLIT = os.environ.get('D4R_RR2_SPLIT', '0' if RELAXED >= 3 and 'enc0' in ONE_WA
# differently: identical at 3x and 2x scaling, 44 - 51 dB on temporal frames at 1.5x (capFQ, 2026-10-13)
POOLED = os.environ.get('D4R_RR2_POOLED', 'rgba32f')
SURFACES = {'dec0_1': {176: 'rgba8_snorm', 184: 'rgba8', 192: 'rgba8'}, 'post': {120: POOLED}, 'pooled': {8: POOLED}}
# D4R_RR2_UNGUARDED=1 (opt-in, D4R_RR_RELAXED=3 only): the translated code (encoder 0's and decoder 0's per-pixel parts,
# the output passes) without its exactness guards: no `precise` registers, no opaque zero OR-ed into binary16 stores and
# conversions (ptx2rr.py --unguarded) and no NoContraction pass (spv_exact_convert.py) on those modules, so the driver may
# contract, fold and fuse there as it does in the relaxed native stages (engine/rr/README.md)
UNGUARDED = os.environ.get('D4R_RR2_UNGUARDED') == '1'
if UNGUARDED and RELAXED < 3:
raise SystemExit('D4R_RR2_UNGUARDED=1 is for D4R_RR_RELAXED=3')
def find_module(ptx_dir, kernel):
@@ -170,8 +177,8 @@ def main():
cmd += [f'--surface={off}={fmt}' for off, fmt in SURFACES.get(stage, {}).items()]
# the hybrid stages' and the output passes' modules go through spv_exact_convert.py, so their conversions need
# only the lighter guard (ptx2rr.py --exact-convert)
exact = (bool(a.native) and stage in HYBRID) or not network
cmd += ['--exact-convert'] if exact else []
exact = ((bool(a.native) and stage in HYBRID) or not network) and not UNGUARDED
cmd += ['--exact-convert'] if exact else ['--unguarded'] if UNGUARDED else []
subprocess.run(cmd, check=True, stderr=subprocess.DEVNULL)
info = json.loads(generated.with_suffix('.json').read_text())
weights = '-'
@@ -195,8 +202,9 @@ def main():
subprocess.run(capped + ['glslangValidator', '-V', '--target-env', 'vulkan1.3', *defs, f'-I{work}',
f'-I{HERE / "rr"}', str(work / 'enc0_g.comp'), '-o', str(out / 'enc0g.spv')],
check=True, stdout=subprocess.DEVNULL)
subprocess.run([sys.executable, str(HERE / 'rr' / 'spv_exact_convert.py'), str(out / 'enc0g.spv')],
check=True, stdout=subprocess.DEVNULL)
if not UNGUARDED:
subprocess.run([sys.executable, str(HERE / 'rr' / 'spv_exact_convert.py'), str(out / 'enc0g.spv')],
check=True, stdout=subprocess.DEVNULL)
record = int((work / 'enc0_g.record').read_text())
if RELAXED >= 3 and stage in ONE_WAVE and (split or GROUP == 1):
how = how + ['--one-wave']
@@ -206,8 +214,9 @@ def main():
subprocess.run(capped + ['glslangValidator', '-V', '--target-env', 'vulkan1.3', *defs, f'-I{work}',
f'-I{HERE / "rr"}', str(work / f'{stage}_m.comp'), '-o', str(out / f'{stage}.spv')],
check=True, stdout=subprocess.DEVNULL)
subprocess.run([sys.executable, str(HERE / 'rr' / 'spv_exact_convert.py'), str(out / f'{stage}.spv')],
check=True, stdout=subprocess.DEVNULL)
if not UNGUARDED:
subprocess.run([sys.executable, str(HERE / 'rr' / 'spv_exact_convert.py'), str(out / f'{stage}.spv')],
check=True, stdout=subprocess.DEVNULL)
else:
subprocess.run(capped + ['glslangValidator', '-V', '--target-env', 'vulkan1.3', str(generated), '-o',
str(out / f'{stage}.spv')], check=True, stdout=subprocess.DEVNULL)