diff --git a/scripts/pr_check.py b/scripts/pr_check.py index e70cab9b2..74f2bc87d 100644 --- a/scripts/pr_check.py +++ b/scripts/pr_check.py @@ -43,6 +43,12 @@ def number(s): return int(m.group(1)) if m else None +def lit_percent(s): + """The `lit at end` percentage, or None when the line is missing or `n/a`.""" + m = re.match(r"\s*(\d+(?:\.\d+)?)", s or "") + return float(m.group(1)) if m else None + + def runtime(path): return path.startswith("crates/xcl/src/") and "/tests" not in path and not path.endswith("tests.rs") @@ -104,6 +110,11 @@ def check(body, head, files, is_main_ancestor, *, test_only=False): pc, mc = number(pr.get("peak commit")), number(m.get("peak commit")) if pc and mc and pc > COMMIT_GROWTH * mc: problems.append(f"the PR's run commits much more memory than main's ({pc} MB against {mc} MB)") + # older blocks have no `lit at end` line; n/a means no frame was sampled + pl, ml = lit_percent(pr.get("lit at end")), lit_percent(m.get("lit at end")) + if pl is not None and ml is not None and ml > 50 and pl < 1: + problems.append(f"the PR's last sampled frame is dark ({pr.get('lit at end')}) " + f"while main's is lit ({m.get('lit at end')})") return problems diff --git a/scripts/smoke.ps1 b/scripts/smoke.ps1 index f0738cdb9..53de6bf22 100644 --- a/scripts/smoke.ps1 +++ b/scripts/smoke.ps1 @@ -4,13 +4,16 @@ # # .\scripts\smoke.ps1 -Game 'D:\Games\SomeTitle' [-Seconds 60] [-Xcl .\target\release\xcl.exe] # -# Networking is off (XCL_NETWORK=0). Build first: cargo build --release -p xcl +# Networking is off (XCL_NETWORK=0). One frame in 120 is sampled (XCL_FRAME_DUMP) and the +# block's `lit at end` line is that frame's non-black share (`n/a` if none was sampled). +# Build first: cargo build --release -p xcl param( [Parameter(Mandatory = $true)][string]$Game, [int]$Seconds = 60, [string]$Xcl = (Join-Path $PSScriptRoot '..\target\release\xcl.exe') ) $ErrorActionPreference = 'Stop' +. (Join-Path $PSScriptRoot 'smoke_lit.ps1') if (-not (Test-Path $Xcl)) { throw "no $Xcl - build it first (cargo build --release -p xcl)" } $root = Split-Path $PSScriptRoot -Parent @@ -34,6 +37,8 @@ $p.StartInfo = $psi $env:XCL_NETWORK = '0' $env:XCL_RUN_SECONDS = "$Seconds" $env:XCL_ACTIVITY = '1' +$savedFrameDump = $env:XCL_FRAME_DUMP +$env:XCL_FRAME_DUMP = '120' $null = $p.Start() $stdoutTask = $p.StandardOutput.ReadToEndAsync() $stderrTask = $p.StandardError.ReadToEndAsync() @@ -44,7 +49,8 @@ if (-not $p.WaitForExit(($Seconds + 120) * 1000)) { $p.WaitForExit() $stdout = $stdoutTask.Result $null = $stderrTask.Result -Remove-Item Env:XCL_RUN_SECONDS, Env:XCL_ACTIVITY +Remove-Item Env:XCL_RUN_SECONDS, Env:XCL_ACTIVITY, Env:XCL_FRAME_DUMP +if ($null -ne $savedFrameDump) { $env:XCL_FRAME_DUMP = $savedFrameDump } $logLine = ($stdout -split "`n" | Where-Object { $_ -match '^Log:\s+(.+)$' } | Select-Object -Last 1) if (-not $logLine) { throw "XCL printed no log path; its output:`n$stdout" } @@ -81,5 +87,6 @@ presents per 2 s (last 3): $lastPresents device removals: $removals crashes: $crashes peak commit: $peak MB +lit at end: $(Get-XclSmokeLit $report) `````` "@ diff --git a/scripts/smoke_lit.ps1 b/scripts/smoke_lit.ps1 new file mode 100644 index 000000000..4c6c5a868 --- /dev/null +++ b/scripts/smoke_lit.ps1 @@ -0,0 +1,16 @@ +# Share of the last sampled frame that is not black, from report.json's +# d3d12.last_frame_dump. `n/a` when no frame was sampled or the format was not decoded. +function Get-XclSmokeLit([string]$Report) { + if (-not (Test-Path -LiteralPath $Report)) { return 'n/a' } + try { + $dump = (Get-Content -LiteralPath $Report -Raw -Encoding utf8 | ConvertFrom-Json).d3d12.last_frame_dump + } catch { + return 'n/a' + } + if (-not $dump -or $null -eq $dump.sampled_pixels -or $null -eq $dump.non_dark_samples) { return 'n/a' } + $pixels = [int64]$dump.sampled_pixels + if ($pixels -le 0) { return 'n/a' } + $pct = 100.0 * [int64]$dump.non_dark_samples / $pixels + # A comma decimal would not parse in pr_check.py, so the line is always dotted. + return ([string]::Format([Globalization.CultureInfo]::InvariantCulture, '{0:0.#} %', [double]$pct)) +} diff --git a/scripts/test-smoke-lit.tests.ps1 b/scripts/test-smoke-lit.tests.ps1 new file mode 100644 index 000000000..82673e32e --- /dev/null +++ b/scripts/test-smoke-lit.tests.ps1 @@ -0,0 +1,35 @@ +# Run with powershell.exe. Checks the lit-frame line without starting xcl. +$ErrorActionPreference = 'Stop' +. (Join-Path $PSScriptRoot 'smoke_lit.ps1') + +function Assert-Eq($name, $got, $want) { + if ($got -ne $want) { throw "$name : got '$got' wanted '$want'" } +} + +$dir = Join-Path ([IO.Path]::GetTempPath()) ('xcl-smoke-lit-' + [guid]::NewGuid()) +New-Item -ItemType Directory -Path $dir | Out-Null +try { + $report = Join-Path $dir 'report.json' + function Write-Report($pixels, $lit) { + $litJson = if ($null -eq $lit) { 'null' } else { "$lit" } + @" +{"d3d12":{"last_frame_dump":{"frame":1,"width":8,"height":8,"format":0,"sample_step":4,"sampled_pixels":$pixels,"non_dark_samples":$litJson}}} +"@ | Set-Content -LiteralPath $report -Encoding utf8 + } + Write-Report 1000 1000 + Assert-Eq 'all lit' (Get-XclSmokeLit $report) '100 %' + Write-Report 1000 0 + Assert-Eq 'black' (Get-XclSmokeLit $report) '0 %' + Write-Report 1000 4 + Assert-Eq 'fraction' (Get-XclSmokeLit $report) '0.4 %' + Write-Report 1000 $null + Assert-Eq 'undecoded' (Get-XclSmokeLit $report) 'n/a' + Write-Report 0 0 + Assert-Eq 'no samples' (Get-XclSmokeLit $report) 'n/a' + '{"d3d12":{"last_frame_dump":null}}' | Set-Content -LiteralPath $report -Encoding utf8 + Assert-Eq 'no dump' (Get-XclSmokeLit $report) 'n/a' + Assert-Eq 'missing file' (Get-XclSmokeLit (Join-Path $dir 'nope.json')) 'n/a' +} finally { + Remove-Item -LiteralPath $dir -Recurse -Force +} +Write-Output 'smoke lit tests passed' diff --git a/scripts/test_pr_check.py b/scripts/test_pr_check.py index f93667f53..b0caf4b51 100644 --- a/scripts/test_pr_check.py +++ b/scripts/test_pr_check.py @@ -36,5 +36,48 @@ def test_test_paths_do_not_need_approval(self): self.assertEqual([], check(BODY, HEAD, files, lambda _: False)) +def smoke_body(pr_lit, main_lit, pr_line=True, main_line=True): + def block(commit, lit, include): + line = f"\nlit at end: {lit}" if include else "" + return ( + "```\n" + "xcl-smoke v1\n" + f"commit: {commit}\n" + "gpu: test\n" + "title: game\n" + "seconds: 20\n" + "exit: 0x0\n" + "frames shown: 100 (PresentX 100)\n" + "device removals: 0\n" + "crashes: 0\n" + f"peak commit: 1000 MB{line}\n" + "```\n" + ) + + return BODY + "\n**Regression run**\n" + block("abcdef1234567890", main_lit, main_line) + block(HEAD, pr_lit, pr_line) + + +class LitFrameTests(unittest.TestCase): + def problems(self, body): + return check(body, HEAD, [changed("crates/xcl/src/hle/d3d12x/present.rs")], lambda sha: sha.startswith("abcdef")) + + def test_a_dark_frame_against_a_lit_main_is_refused(self): + problems = self.problems(smoke_body("0 %", "80 %")) + self.assertEqual(1, len(problems)) + self.assertIn("dark", problems[0]) + + def test_a_fraction_under_one_percent_is_dark(self): + problems = self.problems(smoke_body("0.4 %", "60 %")) + self.assertEqual(1, len(problems)) + + def test_a_lit_frame_passes(self): + self.assertEqual([], self.problems(smoke_body("90 %", "80 %"))) + + def test_missing_or_unsampled_lines_are_left_alone(self): + self.assertEqual([], self.problems(smoke_body("0 %", "80 %", pr_line=False))) + self.assertEqual([], self.problems(smoke_body("n/a", "80 %"))) + self.assertEqual([], self.problems(smoke_body("0 %", "40 %"))) + + if __name__ == "__main__": unittest.main()