Files
mandy/scripts/build_runtime.ps1
Kam471 9015a62748 Runtime: Xbox-ABI device proxy (slots 9/10/62/76)
- Wrap the PC ID3D12Device in a copied-vtable proxy: per-slot thunks swap `this` to the PC device, with IUnknown refcounting/QueryInterface, per-slot hit counters and XS_TRACE=1 first-call logging.
- Override Xbox slot 62 to the PC CreateComputePipelineState (PC slot 62 is CreateStateObject) and Xbox slot 76 to CreateCommittedResource (PC slot 27). The 56-byte description prefix is copied and its 0x101/0x1 layout word replaced by ROW_MAJOR for buffers and UNKNOWN for textures.
- Slot 14 wraps the created descriptor heap. On the measured PC runtime the heap getters take the hidden return pointer in RDX, while the Xbox ABI expects the 8-byte handle in RAX; heap slots 9/10 convert between them. Device slots 9/10 stay CreateCommandAllocator/CreateGraphicsPipelineState, because the measured handle getters are ID3D12DescriptorHeap methods.
- Heap slot 7 GetDevice returns the device proxy, not the raw PC device. The heap holds a device-proxy reference, so GetDevice cannot dangle; the device proxy does not reference heap proxies, so there is no cycle.
- Add device_proxy_test (WARP, no game executable): shim-created proxy, QI/refcount, slot 14 heap, heap GetDevice/refcount, raw RAX handles vs the PC hidden-pointer result, slot 9/16/30/43 forwarding, slot 76 buffer and texture, slot 62 compute PSO, and counter checks. Register it with ctest.
- Wire both CMake and scripts/build_runtime.ps1.

Verified against Windows SDK 10.0.26100 d3d12.h (slot counts through ID3D12Device14; no Device15/16 exists there) and a live WARP device. Still unknown: PresentX, queue/fence/command-list extensions, Xbox vtable order beyond the measured slots, and struct returns other than the heap handles.

Clean-room: implemented from the measured ABI-facts spec; no americas-recomp or AnyPS5 source was read or copied.
2026-11-21 18:26:19 +00:00

50 lines
3.1 KiB
PowerShell

# Builds runtime\build\gta6rt.exe with MSVC at BelowNormal priority, on half the cores.
# Uses VS's CMake + Ninja when the "C++ CMake tools" component is installed, otherwise calls cl.exe directly.
param([switch]$Debug)
$ErrorActionPreference = "Stop"
$root = Split-Path $PSScriptRoot -Parent
$installer = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer"
$vs = & "$installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
if (-not $vs) { throw "Visual Studio with the C++ x64 tools wasn't found." }
$vcvars = Join-Path $vs "VC\Auxiliary\Build\vcvars64.bat"
$jobs = [Math]::Max(1, [int]([Environment]::ProcessorCount / 2))
$src = Join-Path $root "runtime"
$out = Join-Path $src "build"
New-Item -ItemType Directory -Force $out | Out-Null
$cmakeDir = Join-Path $vs "Common7\IDE\CommonExtensions\Microsoft\CMake"
$cmake = Join-Path $cmakeDir "CMake\bin\cmake.exe"
$ninja = Join-Path $cmakeDir "Ninja\ninja.exe"
$cfg = if ($Debug) { "Debug" } else { "RelWithDebInfo" }
if ((Test-Path $cmake) -and (Test-Path $ninja)) {
$body = @"
"$cmake" -S "$src" -B "$out" -G Ninja "-DCMAKE_MAKE_PROGRAM=$ninja" -DCMAKE_BUILD_TYPE=$cfg || exit /b 1
"$cmake" --build "$out" -j $jobs || exit /b 1
"@
} else {
# Keep this list in step with runtime\CMakeLists.txt.
$files = "src\main.cpp", "src\pe_loader.cpp", "shims\registry.cpp", "shims\xmem.cpp", "shims\d3d12_xs.cpp", "shims\d3d12_xs_device.cpp", "shims\d3d12_xs_rootsig.cpp" | ForEach-Object { "`"$src\$_`"" }
$opt = if ($Debug) { "/Od /MDd" } else { "/O2 /MD" }
$body = @"
cd /d "$out" || exit /b 1
cl /nologo /std:c++20 /EHsc /W4 /permissive- /utf-8 /Zi $opt /MP$jobs /DWIN32_LEAN_AND_MEAN /DNOMINMAX /DUNICODE /D_UNICODE $($files -join ' ') /Fe:gta6rt.exe /link /OPT:NOREF psapi.lib || exit /b 1
cl /nologo /std:c++20 /EHsc /W4 /permissive- /utf-8 /O2 /DWIN32_LEAN_AND_MEAN /DNOMINMAX /I "$src\shims" "$src\shims\d3d12_xs_rootsig.cpp" "$src\shims\registry.cpp" "$src\shims\d3d12_xs.cpp" "$src\shims\d3d12_xs_device.cpp" "$src\test\root_sig_test.cpp" /Fe:root_sig_test.exe /link d3d12.lib || exit /b 1
cl /nologo /std:c++20 /EHsc /W4 /permissive- /utf-8 /O2 /DWIN32_LEAN_AND_MEAN /DNOMINMAX /I "$src\shims" "$src\shims\d3d12_xs_rootsig.cpp" "$src\shims\registry.cpp" "$src\shims\d3d12_xs.cpp" "$src\shims\d3d12_xs_device.cpp" "$src\test\device_proxy_test.cpp" /Fe:device_proxy_test.exe /link d3d12.lib dxgi.lib || exit /b 1
if defined VULKAN_SDK cl /nologo /std:c++20 /EHsc /O2 /DWIN32_LEAN_AND_MEAN /DNOMINMAX /I "%VULKAN_SDK%\Include" "$src\test\vk_pipeline_check.cpp" /Fe:vk_pipeline_check.exe || exit /b 1
"@
}
# A .cmd file avoids cmd.exe's quote stripping on paths with spaces.
$bat = Join-Path $out "_build.cmd"
"@echo off`r`nset `"PATH=$installer;%PATH%`"`r`ncall `"$vcvars`" >nul || exit /b 1`r`n$body" | Set-Content -Encoding ascii $bat
$p = Start-Process cmd.exe -ArgumentList "/c", "`"$bat`"" -NoNewWindow -PassThru
$null = $p.Handle # keeps the exit code readable after WaitForExit
try { $p.PriorityClass = "BelowNormal" } catch {}
$p.WaitForExit()
if ($p.ExitCode -ne 0) { throw "build failed ($($p.ExitCode))" }
Write-Host "built $out\gta6rt.exe"