diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..f0b50c8 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,65 @@ +# Working on Bathyal + +Bathyal is a fork of XCL (https://github.com/ivall/xcl). Read `README.md` (what works, how to run) and +`HANDOFF.md` (measurements and open work) before changing anything. This file adds the rules for this fork. + +## Rules + +1. **No game material in the repository, ever:** no executables, archives, shaders in any form (binary, + disassembly, HLSL, DXIL), textures, audio, carved files, or logs that quote them. Tests synthesize their inputs + or read local files through the `XCL_SAMPLE_*` variables. Do not name commercial titles in code, docs or + commit messages: write "a newer retail title". +2. **No keys, decryption or DRM workarounds** in code or docs. The project runs unpacked files the user owns. +3. **Nothing online in the code:** no HTTP clients, no telemetry, no downloads at start. Networking APIs a title + calls stay offline stand-ins (`hle/netoff.rs`). +4. **Keep XCL's license and credit:** `LICENSE`, `NOTICE.md`, `THIRD_PARTY.md` and the upstream history stay. + New files are GPL-2.0 too. +5. **Commits under the project identity** (`T-Crypt `), with no personal + names or addresses and no AI attribution lines. +6. **Agents never push to `main`.** Work on a branch and open a pull request. + +## Untrusted executables + +A title's executable is untrusted code until it has proven itself. Before its first run: + +1. Check its SHA-256 against a source you trust. +2. Keep it out of the read-only package folder; build a game folder with `scripts\setup-game-folder.ps1`. +3. Block its egress: `scripts\block-egress.ps1` (outbound block on `xcl.exe`; the title runs inside it). +4. Run on a machine with no personal accounts or sensitive data when you can. + +## Build, test, run (Windows) + +```powershell +cargo build --release --workspace # target\release\xcl.exe +.\scripts\test.ps1 # cargo build + cargo test --workspace +.\scripts\run-title.ps1 -Game D:\games\title # precompiles caches once, then runs; logs in %LOCALAPPDATA%\bathyal\runs +``` + +## Following XCL + +```powershell +git remote add xcl https://github.com/ivall/xcl.git # once +git fetch xcl +git merge xcl/main # on a branch; keep our README header and NOTICE.md +``` + +Binary, crate and `XCL_*` names stay XCL's so these merges stay clean. + +## Notes carried over from Leonida + +Leonida (a C++ port engine for the same console, D3D12.X on Vulkan) met these issues on a newer retail title. +XCL already covers most of them: AMD-only CPU instructions such as CLZERO, B5G5R5A1 UAVs, A8 targets, +AcpHal's negative-HRESULT asserts, XErrorReport, the TLS index 0 handover and wave64 lane-mask SGPR pairs. +Still worth checking here: + +- **R9G9B9E5_SHAREDEXP UAV textures.** PC drivers give that format no typed storage. Leonida stores such a + texture as a mutable R32_UINT image and lets shaders write the packed bits; SRVs and RTVs keep the shared + exponent format. B5G5R5A1 is handled the same way, as R16_UINT. +- **sRGB UAV textures.** The title asks for UAVs on sRGB textures (2048x2048 seen), which PC D3D12 refuses. + Leonida drops the UAV flag from the console description when the format has no UAV support, and gives + UAV views the matching UNORM format. +- **GetResourceAllocationInfo with unsupported formats.** The title asks for layouts of formats the PC rejects; + an error there ended in an int3 in Leonida. Answer with the layout of a same-size stand-in format. +- **NVIDIA (32-lane subgroups).** Measured on an RTX 4090: wave64 cross-half operations (readlane, permlane, + DPP or shuffles across lanes 31/32, wave-wide reductions) are the known fidelity gap in vertex and pixel + shaders. See `docs/wave64-on-wave32.md`. diff --git a/scripts/block-egress.ps1 b/scripts/block-egress.ps1 new file mode 100644 index 0000000..1854f3e --- /dev/null +++ b/scripts/block-egress.ps1 @@ -0,0 +1,21 @@ +# Adds a Windows Firewall rule that blocks all outbound traffic of one program (default: the release xcl.exe). +# A title's network calls go straight to the host's network stack, so a first run of an untrusted executable +# should have no egress. Needs an elevated shell. Running it again keeps the existing rule. +# +# powershell -ExecutionPolicy Bypass -File scripts\block-egress.ps1 +# powershell -ExecutionPolicy Bypass -File scripts\block-egress.ps1 -Program D:\other\xcl.exe +param( + [string]$Program = (Join-Path (Split-Path -Parent $PSScriptRoot) 'target\release\xcl.exe'), + [string]$Name = '' +) +$ErrorActionPreference = 'Stop' +$Program = [System.IO.Path]::GetFullPath($Program) +if (-not $Name) { $Name = "bathyal egress block: $Program" } + +$existing = Get-NetFirewallRule -DisplayName $Name -ErrorAction SilentlyContinue +if (-not $existing) { + New-NetFirewallRule -DisplayName $Name -Direction Outbound -Action Block -Program $Program -Profile Any | Out-Null +} +$rule = Get-NetFirewallRule -DisplayName $Name +$app = $rule | Get-NetFirewallApplicationFilter +"$($rule.DisplayName): Enabled=$($rule.Enabled) Direction=$($rule.Direction) Action=$($rule.Action) Program=$($app.Program)" diff --git a/scripts/run-title.ps1 b/scripts/run-title.ps1 new file mode 100644 index 0000000..7c16b5e --- /dev/null +++ b/scripts/run-title.ps1 @@ -0,0 +1,38 @@ +# Runs a title with the release build in a visible window and keeps a log of each run. +# Before the first run it fills XCL's shader caches, as HANDOFF.md advises for large titles: compute programs +# first (`--precompile --only cs`), then the compute pipelines (`--precompile --pipelines`). A marker file in the +# log folder records that this was done for this xcl.exe; -Precompile forces it again. +# +# powershell -ExecutionPolicy Bypass -File scripts\run-title.ps1 -Game D:\games\title +# powershell -ExecutionPolicy Bypass -File scripts\run-title.ps1 -Game D:\games\title -Seconds 120 +param( + [Parameter(Mandatory = $true)][string]$Game, + [string]$Xcl = (Join-Path (Split-Path -Parent $PSScriptRoot) 'target\release\xcl.exe'), + [string]$Logs = (Join-Path $env:LOCALAPPDATA 'bathyal\runs'), + [int]$Seconds = 0, + [switch]$Precompile +) +$ErrorActionPreference = 'Stop' +if (-not (Test-Path -LiteralPath $Xcl)) { throw "xcl.exe not found: $Xcl (cargo build --release --workspace)" } +$shaders = Get-ChildItem -LiteralPath $Game -Filter 'shaders.rpf' -Recurse -Depth 2 -ErrorAction SilentlyContinue | + Select-Object -First 1 +New-Item -ItemType Directory -Force -Path $Logs | Out-Null + +$stamp = (Get-FileHash -LiteralPath $Xcl -Algorithm SHA256).Hash.Substring(0, 16) +$marker = Join-Path $Logs "precompiled-$stamp.txt" +if ($shaders -and ($Precompile -or -not (Test-Path -LiteralPath $marker))) { + "precompiling $($shaders.FullName) (compute programs, then pipelines); this can take a long time once" + & $Xcl shaders $shaders.FullName --precompile --only cs + if ($LASTEXITCODE -ne 0) { throw "precompile --only cs exited $LASTEXITCODE" } + & $Xcl shaders $shaders.FullName --precompile --pipelines + if ($LASTEXITCODE -ne 0) { throw "precompile --pipelines exited $LASTEXITCODE" } + Get-Date -Format o | Out-File -LiteralPath $marker -Encoding utf8 +} + +$log = Join-Path $Logs ("run-{0}.log" -f (Get-Date -Format 'yyyyMMdd-HHmmss')) +if ($Seconds -gt 0) { $env:XCL_RUN_SECONDS = "$Seconds" } +"running $Game; log $log" +& $Xcl run $Game 2>&1 | Tee-Object -FilePath $log +$code = $LASTEXITCODE +"xcl exited with code $code; the run's report.json is written as XCL describes in README.md" +exit $code diff --git a/scripts/setup-game-folder.ps1 b/scripts/setup-game-folder.ps1 new file mode 100644 index 0000000..471ae59 --- /dev/null +++ b/scripts/setup-game-folder.ps1 @@ -0,0 +1,58 @@ +# Builds a local game folder for `xcl run` without copying the game's content. +# +# A packaged title often arrives as a read-only folder (a NAS share, an unpacked package) with the executable +# stored somewhere else. `xcl run` canonicalizes the executable and takes the folder that holds +# MicrosoftGame.Config as the game root, so the executable and the config have to be real files side by side. +# This script makes -Dest hold: +# - a copy of the executable (-Exe), +# - copies of the small top-level metadata files (MicrosoftGame.Config, microsoft_gameconfig.bin, +# appxmanifest.xml) when the source has them, +# - one symbolic link per other top-level entry of -Source, so archives stay where they are. +# Nothing is written into -Source. XCL sends the title's writes to its overlay, not to the game folder. +# +# Symbolic links need Developer Mode or an elevated shell. +# +# powershell -ExecutionPolicy Bypass -File scripts\setup-game-folder.ps1 -Source \\nas\games\Title ` +# -Exe D:\quarantine\verified\title.exe -Dest D:\games\title +param( + [Parameter(Mandatory = $true)][string]$Source, + [Parameter(Mandatory = $true)][string]$Exe, + [Parameter(Mandatory = $true)][string]$Dest +) +$ErrorActionPreference = 'Stop' + +if (-not (Test-Path -LiteralPath $Source -PathType Container)) { throw "Source folder not found: $Source" } +if (-not (Test-Path -LiteralPath $Exe -PathType Leaf)) { throw "Executable not found: $Exe" } +$config = Join-Path $Source 'MicrosoftGame.Config' +if (-not (Test-Path -LiteralPath $config)) { throw "No MicrosoftGame.Config in $Source" } + +# The executable's name must be the one MicrosoftGame.Config names, or `xcl run` starts nothing. +$text = Get-Content -LiteralPath $config -Raw +$named = [regex]::Matches($text, '