Engine: native presets K and M in the D3D12 shim, wider game coverage
A standalone Vulkan inference engine (engine/) for DLSS presets K and M that runs from weights extracted from the user's own nvngx_dlss.dll, with d4r's own input, network and reconstruction shaders or the native HIP network layers, recorded into the game's command list by the shim. Opt-in ([Engine] Enabled / D4R_ENGINE=1); anything uncovered falls back to the CUDA/ZLUDA path with the reason logged. Byte-identical to NGX's CUDA backend under the phase-capable reference (1706x960 -> 2560x1440, native HIP network, eleven frames, RX 9070 XT): - K render- and display-resolution motion vectors, HDR and LDR - K game-supplied exposure and automatic exposure with any pre-exposure and exposure scale (one residual: effective exposure exactly 2 or 4) - K and M with the DLSS indicator's inverted-axis parameters - M with any exposure settings (NGX ignores them for M) K packages need the current compile_k.py (marker D4RO0003). Also: HIP shared buffers are pooled across feature recreation (ROCm leaks destroyed imports), hipnet.bin must match the preset, M-only games do not load the K model, install_d4r_runtime.sh stages k, k-ldr, m, m-ldr with hip/, the activation table has a generator (gen_activation_m.py), and package_release.sh can bundle the engine's shaders (never its weights). Signed-off-by: woutermans <[email protected]>
This commit is contained in:
1 parent
16cfc1f063
commit
e0d1549a21
82 files changed
+13335
-96
No files matched your search
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Condense a ptx2glsl.py translation for reading: drops declarations, prints float constants as decimals and
|
||||
substitutes registers that are assigned once and used once into their use. The result is not meant to compile.
|
||||
|
||||
usage: condense.py KERNEL.comp > KERNEL.txt
|
||||
"""
|
||||
import re, struct, sys
|
||||
src = open(sys.argv[1]).read().split('\n')
|
||||
start = next(i for i, l in enumerate(src) if l.startswith('void main'))
|
||||
body = [l for l in src[start:] if not re.match(r'\s*(precise )?(uint|float|bool|uint64_t|float16_t|f16vec2|int) [a-z0-9_]+ = [^;]*(, [a-z0-9_]+ = [^;,]*)*;\s*$', l) or '(' in l.split('=', 1)[1][:3]]
|
||||
def fl(m):
|
||||
v = struct.unpack('<f', struct.pack('<I', int(m.group(1), 16)))[0]
|
||||
return repr(round(v, 7)) if abs(v) < 1e7 and (abs(v) > 1e-5 or v == 0) else f'{v:.6g}'
|
||||
body = [re.sub(r'uintBitsToFloat\(0x([0-9A-Fa-f]{8})u\)', fl, l) for l in body]
|
||||
body = [re.sub(r'\b(\d+)u\b', r'\1', l) for l in body]
|
||||
body = [re.sub(r' \((\d+) & 31\)', r' \1', l) for l in body]
|
||||
tok = re.compile(r'\b(?:r|f|rs|rd|p)\d+\b')
|
||||
for _ in range(12):
|
||||
assigns, uses = {}, {}
|
||||
for i, l in enumerate(body):
|
||||
m = re.match(r'(\s*)((?:r|f|rs|rd|p)\d+) = (.*);\s*$', l)
|
||||
rhs = l
|
||||
if m:
|
||||
assigns.setdefault(m.group(2), []).append(i); rhs = m.group(3)
|
||||
for t in tok.findall(rhs): uses.setdefault(t, []).append(i)
|
||||
changed = False
|
||||
for name, at in assigns.items():
|
||||
u = uses.get(name, [])
|
||||
if len(at) != 1 or len(u) != 1 or u[0] <= at[0]: continue
|
||||
a, b = at[0], u[0]
|
||||
if body[a] is None or body[b] is None: continue
|
||||
ind = lambda s: len(s) - len(s.lstrip())
|
||||
# only within straight-line code at the same nesting, and short enough to stay readable
|
||||
if any(body[k] is not None and ('{' in body[k] or '}' in body[k]) for k in range(a, b)): continue
|
||||
m = re.match(r'(\s*)((?:r|f|rs|rd|p)\d+) = (.*);\s*$', body[a])
|
||||
expr = m.group(3)
|
||||
if len(expr) > 90: continue
|
||||
# the expression's inputs must not be reassigned in between
|
||||
ins = set(tok.findall(expr))
|
||||
if any(body[k] is not None and re.match(r'\s*(%s) = ' % '|'.join(map(re.escape, ins)) if ins else r'$^', body[k]) for k in range(a + 1, b)): continue
|
||||
simple = re.fullmatch(r'[\w.]+|\w+\([^()]*\)', expr)
|
||||
body[b] = re.sub(r'\b%s\b' % name, expr if simple else f'({expr})', body[b], count=1)
|
||||
body[a] = None; changed = True
|
||||
body = [l for l in body if l is not None]
|
||||
if not changed: break
|
||||
for a, b in ((r'uint\(uint\(([^()]*)\)\)', r'\1'), (r'\buint\(((?:r|rs)\d+)\)', r'\1'), (r'uint64_t\((rd\d+)\)', r'\1')):
|
||||
body = [re.sub(a, b, l) for l in body]
|
||||
# scripts/check_redistributable.py refuses files carrying this line: the input was NVIDIA's code.
|
||||
print(f'// Generated by vulkan/condense.py from NVIDIA PTX ({sys.argv[1]}); do not commit or redistribute.')
|
||||
print('\n'.join(l.rstrip() for l in body if l.strip()))
|
||||
Reference in new issue
Block a user