Files
d4r/scripts/windows/build-native-rr-model.ps1
T
ayo 247fe1092d Advance native Windows RR integration, kernel tooling and local packaging
Implement native NGX feature-13 RR through a LUID-matched D3D12/Vulkan
shared-memory and timeline-fence bridge. Add owned parameter snapshots,
GPU resource lifetime handling, inherited/enhanced barriers, optional
guides, sampled input formats and depth-plane support with stencil
preservation. Separate RR initialization from the SR CUDA runtime and
expose explicit backend/model selection through player configuration.

Add synthetic bridge, snapshot and NGX lifecycle harnesses covering
camera/history/reset, parameter mutation, delayed submission, early
release, capability gating and unsupported-input rejection.

Add exact gfx11 D/E model generation, verified caches, versioned local
deployment with configuration backups, and isolated portable model
tools with pinned Python, NumPy and glslang dependencies.

Extend Windows K benchmarking and private native-cache selection.
Fix LLVM 22 emitter/helper compatibility and preserve exact-output
validation for local output-kernel optimization.

Add native FSR RR provider diagnostics, local development package
refresh tooling, installer/checker updates, FidelityFX headers and
Windows parity documentation.

Keep NVIDIA binaries, derived models and private optimized kernels out
of distributable packages. Native RR evidence remains synthetic;
game validation, FSR RR dispatch, installer integration and Linux
performance parity remain incomplete.
2026-10-16 12:53:26 -04:00

74 lines
4.4 KiB
PowerShell

[CmdletBinding()]
param(
[Parameter(Mandatory=$true)][string]$DlssdDll,
[ValidateSet('D','E')][string]$Preset='D',
[string]$OutputDirectory,
[string]$GitBash='C:\Program Files\Git\bin\bash.exe',
[switch]$ReuseCache
)
$ErrorActionPreference='Stop'
$repo=[IO.Path]::GetFullPath((Join-Path $PSScriptRoot '../..'))
$DlssdDll=(Get-Item -LiteralPath $DlssdDll -ErrorAction Stop).FullName
$GitBash=(Get-Item -LiteralPath $GitBash -ErrorAction Stop).FullName
$expectedHash='4bc7ea5fcb2f32cf86bc2cb072e8d2860914a0be511cbdcb2fc206c1d9d83b80'
$hash=(Get-FileHash -LiteralPath $DlssdDll -Algorithm SHA256).Hash.ToLowerInvariant()
if($hash -ne $expectedHash){throw "Unsupported nvngx_dlssd.dll SHA256 $hash; expected NVIDIA DLSS 310.9.1 ($expectedHash)."}
if(!$OutputDirectory){$OutputDirectory=Join-Path $repo ("build/native-rr-$($Preset.ToLower())-windows-gfx1101")}
$OutputDirectory=[IO.Path]::GetFullPath($OutputDirectory)
$buildRoot=[IO.Path]::GetFullPath((Join-Path $repo 'build'))
if(!$OutputDirectory.StartsWith($buildRoot+'\',[StringComparison]::OrdinalIgnoreCase)){
throw "RR model output must stay under the ignored build directory: $OutputDirectory"
}
if((Test-Path -LiteralPath $OutputDirectory) -and !$ReuseCache){throw "Use a new RR model output directory or -ReuseCache: $OutputDirectory"}
$glslang=Join-Path $repo '.tools/glslang-16.6.0/bin'
$pythonHome=Split-Path (Get-Command python.exe -ErrorAction Stop).Source
$pythonShim=Join-Path $repo '.tools/rr-build-bin'
New-Item -ItemType Directory -Force $pythonShim | Out-Null
$python3=Join-Path $pythonShim 'python3.exe'
Copy-Item -LiteralPath (Get-Command python.exe).Source -Destination $python3 -Force
$pythonVendor=Join-Path $repo '.tools/python/vendor'
$cygpath=Join-Path (Split-Path (Split-Path $GitBash -Parent) -Parent) 'usr/bin/cygpath.exe'
if(!(Test-Path -LiteralPath $cygpath)){throw "Git for Windows cygpath missing: $cygpath"}
foreach($tool in @($python3,(Join-Path $glslang 'glslangValidator.exe'))){if(!(Test-Path -LiteralPath $tool)){throw "RR build tool missing: $tool"}}
$unixRepo=(& $cygpath -u $repo).Trim()
$unixDll=(& $cygpath -u $DlssdDll).Trim()
$unixOut=(& $cygpath -u $OutputDirectory).Trim()
if(!$unixRepo -or !$unixDll -or !$unixOut){throw 'Git Bash path conversion failed.'}
$oldPath=$env:PATH
$oldPythonPath=$env:PYTHONPATH
$oldGfx11=$env:D4R_RR_GFX11
$oldRelaxed=$env:D4R_RR_RELAXED
$env:PATH="$pythonShim;$pythonHome;$glslang;$(Split-Path $GitBash -Parent);$oldPath"
$env:PYTHONPATH=$pythonVendor
$env:D4R_RR_GFX11='1'
$env:D4R_RR_RELAXED='0'
$log=Join-Path $buildRoot ("native-rr-$($Preset.ToLower())-windows-build.log")
try{
& $python3 -c 'import numpy; print("numpy", numpy.__version__)'
if($LASTEXITCODE){throw 'Pinned NumPy could not load in the Windows RR build environment.'}
$cacheArguments=@('--model',$OutputDirectory,'--dll',$DlssdDll,'--preset',$Preset,
'--glslang',(Join-Path $glslang 'glslangValidator.exe'),'--bash',$GitBash)
$cacheTool=Join-Path $PSScriptRoot 'rr-model-cache.py'
if(Test-Path -LiteralPath $OutputDirectory){
& $python3 $cacheTool check @cacheArguments
if($LASTEXITCODE){throw 'RR model cache is absent, stale or changed. Use a new output directory.'}
return
}
function Quote-Bash([string]$Value){return "'"+$Value.Replace("'","'\''")+"'"}
$command="cd $(Quote-Bash $unixRepo) && D4R_RR_GFX11=1 D4R_RR_RELAXED=0 bash engine/rr/build_native_model.sh --dll $(Quote-Bash $unixDll) '$Preset' $(Quote-Bash $unixOut)"
$previousPreference=$ErrorActionPreference
try{
$ErrorActionPreference='Continue'
& $GitBash -lc $command *> $log
$bashExit=$LASTEXITCODE
}finally{$ErrorActionPreference=$previousPreference}
if($bashExit){throw "RR model build failed with exit $bashExit; see $log"}
foreach($required in @('rr.txt','model.json','enc0_m.spv','dec0_m.spv','hkpn.spv','enc0.args','hkpn.args')){
if(!(Test-Path -LiteralPath (Join-Path $OutputDirectory $required))){throw "RR build incomplete; missing $required"}
}
& $python3 $cacheTool write @cacheArguments
if($LASTEXITCODE){throw 'RR build completed but cache manifest could not be written.'}
Write-Host "Built local preset $Preset native RR model: $OutputDirectory"
Write-Host "DLL SHA256: $hash. Build log: $log"
}finally{$env:PATH=$oldPath;$env:PYTHONPATH=$oldPythonPath;$env:D4R_RR_GFX11=$oldGfx11;$env:D4R_RR_RELAXED=$oldRelaxed}