gpu: reject invalid adapter selectors in the wave startup fixture #3685

Manually merged
github merged 1 commit from github-bot/gh-3683 into main 2026-12-01 03:13:03 +00:00 AGit
Owner

@⁠timbot103 on GitHub · 2026-12-01 01:27 UTC · original
timbot103:gpu-wave-startup-invalid-selector → main · +81 −33 · 4 files · 1 commits · merged 2026-12-01 03:12 UTC

Wave startup now reports an unmatched or overlong XBOX2WINDOWS_ADAPTER on stdout and exits 1. CTest previously treated both selections as capability skips. If device creation fails on every matching hardware adapter, the fixture prints the requested selector and exits 77.

The fixture shares selector parsing and diagnostic text with AdapterNameFilter and keeps its Win32 stdout writer. The new wave_startup_adapter_filter check lives in tests/cmake/wave_startup_adapter_filter.cmake and validates both input errors before device creation or shader dispatch.

Refs #1161.

Verification

Run from the repository root in PowerShell. Set up the Python environment and load the developer shell.

py -3.14 -m venv out\pe-env
.\out\pe-env\Scripts\python.exe -m pip install -r requirements-dev.txt
.\tools\dev.ps1

Red on a3bfd019

Start at this PR’s revision so the Python check and CMake fragment are in place. The commands temporarily substitute only the base C++ fixture, then restore the original bytes.

$source = (Resolve-Path -LiteralPath 'tests/wave_startup_exe.cpp').Path
$saved = [IO.File]::ReadAllBytes($source)
try {
    .\out\pe-env\Scripts\python.exe -B -c "from pathlib import Path; from subprocess import check_output; Path('tests/wave_startup_exe.cpp').write_bytes(check_output(['git', 'show', 'a3bfd019:tests/wave_startup_exe.cpp']))"
    if ($LASTEXITCODE) { throw 'Could not extract the base fixture' }
    foreach ($preset in @('dev', 'release')) {
        Write-Output "BASE preset=$preset"
        cmake --preset $preset
        if ($LASTEXITCODE) { throw 'Configure failed' }
        ctest --preset $preset -N -R wave_startup_adapter_filter
        if ($LASTEXITCODE) { throw 'CTest listing failed' }
        cmake --build --preset $preset --target wave_startup_0_hardware
        if ($LASTEXITCODE) { throw 'Base build failed' }
        $exe = ".\out\build\$preset\wave_startup_0_hardware.exe"
        foreach ($selector in @('x2w-no-such-hardware-adapter', ('x' * 128))) {
            $env:XBOX2WINDOWS_ADAPTER = $selector
            & $exe
            Write-Output "fixture exit=$LASTEXITCODE"
            if ($LASTEXITCODE -ne 77) { throw 'Expected the base fixture to return 77' }
        }
        ctest --preset $preset --no-tests=error -j 1 -R '^wave_startup_adapter_filter$' -V
        Write-Output "red CTest exit=$LASTEXITCODE"
        if ($LASTEXITCODE -ne 8) { throw 'Expected the regression to fail on the base' }
    }
} finally {
    [IO.File]::WriteAllBytes($source, $saved)
}

Both presets listed wave_startup_adapter_filter. Both invalid selectors returned 77 on the base. The check failed in each preset with CTest exit 8 because the overlong case expected exit 1.

Green

$targets = @('wave_startup_0_hardware', 'wave_startup_4_hardware', 'wave_startup_32_hardware',
             'wave_startup_0_warp', 'wave_startup_4_warp', 'wave_startup_32_warp',
             'startup_indirect_dispatch', 'startup_stream_rasterizer')
foreach ($preset in @('dev', 'release')) {
    Write-Output "FIXED preset=$preset"
    cmake --preset $preset
    if ($LASTEXITCODE) { throw 'Configure failed' }
    cmake --build --preset $preset --target $targets
    if ($LASTEXITCODE) { throw 'Fixed build failed' }
    $exe = ".\out\build\$preset\wave_startup_0_hardware.exe"
    foreach ($selector in @('x2w-no-such-hardware-adapter', ('x' * 128))) {
        $env:XBOX2WINDOWS_ADAPTER = $selector
        & $exe
        Write-Output "fixture exit=$LASTEXITCODE"
        if ($LASTEXITCODE -ne 1) { throw 'Expected the fixed fixture to return 1' }
    }
    $env:XBOX2WINDOWS_ADAPTER = 'Radeon'
    ctest --preset $preset --no-tests=error -j 1 -R 'wave_startup|adapter_filter' -V
    if ($LASTEXITCODE) { throw 'Radeon/WARP matrix failed' }
    $env:XBOX2WINDOWS_ADAPTER = 'RTX 5080'
    ctest --preset $preset --no-tests=error -j 1 -R '^wave_startup_(0|4|32)_hardware$' -V
    if ($LASTEXITCODE) { throw 'RTX matrix failed' }
}
foreach ($adapter in @('hardware', 'warp')) {
    foreach ($width in @(0, 4, 32)) {
        dumpbin /dependents ('out/build/release/wave_startup_{0}_{1}.exe' -f $width, $adapter)
        if ($LASTEXITCODE) { throw 'Could not inspect Release binary imports' }
    }
}

Both invalid selectors returned 1 in Debug and Release. The unmatched selector printed No D3D12 hardware adapter matches XBOX2WINDOWS_ADAPTER=x2w-no-such-hardware-adapter. The overlong selector printed XBOX2WINDOWS_ADAPTER is longer than 127 characters.

In each preset, the Radeon and WARP matrix had seven passes and two skips. This includes passes for wave_startup_adapter_filter, startup_indirect_dispatch_adapter_filter, and startup_stream_adapter_filter. The RTX 5080 matrix had two passes and one skip. Radeon and RTX 5080 passed widths 0 and 32 with a 32-lane readback across 64 invocations, and skipped width 4 with exit 77 after E_INVALIDARG. WARP passed widths 0 and 4 with a 4-lane readback, and skipped width 32 with exit 77 after E_INVALIDARG.

An earlier revision of this branch was also built (the six wave targets and two neighbors) in Debug and /O2 Release, and passed the neighboring adapter-filter tests in both presets. Both rounds of dumpbin /dependents showed only KERNEL32.dll, d3d12.dll and dxgi.dll in all six Release wave binaries. The wave binaries link with /ENTRY:fixture_entry /NODEFAULTLIB.

Mutation and device-creation failure

At tests/wave_startup_exe.cpp:214, replace if (!name_matched) return exit_fail; with if (!name_matched) return exit_skip;. Rebuild the same eight targets and rerun the locked matrix in both presets.

foreach ($preset in @('dev', 'release')) {
    cmake --preset $preset
    cmake --build --preset $preset --target $targets
    $env:XBOX2WINDOWS_ADAPTER = 'Radeon'
    ctest --preset $preset --no-tests=error -j 1 -R 'wave_startup|adapter_filter' -V
}

Both mutants linked and both matrices returned CTest exit 8. Only wave_startup_adapter_filter failed because the unmatched selector returned 77. Restoring the line, rebuilding and repeating the locked matrix gave exit 0 in both presets.

There is no existing fault-injection hook for the fixture’s direct D3D12CreateDevice call. A name match followed by device-creation failure remains a gap in automated coverage. On an earlier revision of this branch, replacing name_matched = true; with (void)name_matched; passed the conventional Release matrix. A manual control forced the hardware device-creation condition to if (SUCCEEDED(E_FAIL)) {, rebuilt wave_startup_0_hardware, and ran it with Radeon. It returned 77 with the old generic diagnostic. Also removing the assignment changed the result to exit 1 with the unmatched diagnostic.

Repeating that manual Release control at tests/wave_startup_exe.cpp:202 returned 77 with No D3D12-capable hardware adapter matches XBOX2WINDOWS_ADAPTER=Radeon. With the selector unset it returned 77 with No D3D12-capable hardware adapter visible. The paired assignment mutant at line 201 returned 1 with No D3D12 hardware adapter matches XBOX2WINDOWS_ADAPTER=Radeon. Both temporary edits were restored.

The GPU-less hosted-runner path was reviewed in source and remains unverified on a hosted runner. The unmatched case handles empty or software-only enumeration through DXGI. The overlong case returns before enumeration.

Environment

  • Windows 11 25H2 build 26200.9974, x64 MSVC 19.44.35230.0, Windows SDK 10.0.26100.0, DXC 1.9.2602.17 and Python 3.14.7.
  • AMD Radeon(TM) Graphics (1002:13c0), driver 32.0.21030.2001, reported lane range 32–64.
  • NVIDIA GeForce RTX 5080 (10de:2c02), driver 32.0.16.2140 (621.40), reported lane range 32–32.
  • Microsoft Basic Render Driver, version 10.0.26100.9818, reported lane range 4–4.
  • The D3D12 debug layer was unavailable on this host (0x887a002d). Both physical adapters created devices during the regular matrix.

Prepared with AI assistance; all commands above were run locally.

**@⁠timbot103** on GitHub · 2026-12-01 01:27 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3683) `timbot103:gpu-wave-startup-invalid-selector` → `main` · +81 −33 · 4 files · 1 commits · merged 2026-12-01 03:12 UTC Wave startup now reports an unmatched or overlong `XBOX2WINDOWS_ADAPTER` on stdout and exits 1. CTest previously treated both selections as capability skips. If device creation fails on every matching hardware adapter, the fixture prints the requested selector and exits 77. The fixture shares selector parsing and diagnostic text with `AdapterNameFilter` and keeps its Win32 stdout writer. The new `wave_startup_adapter_filter` check lives in `tests/cmake/wave_startup_adapter_filter.cmake` and validates both input errors before device creation or shader dispatch. Refs #1161. ## Verification Run from the repository root in PowerShell. Set up the Python environment and load the developer shell. ```powershell py -3.14 -m venv out\pe-env .\out\pe-env\Scripts\python.exe -m pip install -r requirements-dev.txt .\tools\dev.ps1 ``` ### Red on `a3bfd019` Start at this PR’s revision so the Python check and CMake fragment are in place. The commands temporarily substitute only the base C++ fixture, then restore the original bytes. ```powershell $source = (Resolve-Path -LiteralPath 'tests/wave_startup_exe.cpp').Path $saved = [IO.File]::ReadAllBytes($source) try { .\out\pe-env\Scripts\python.exe -B -c "from pathlib import Path; from subprocess import check_output; Path('tests/wave_startup_exe.cpp').write_bytes(check_output(['git', 'show', 'a3bfd019:tests/wave_startup_exe.cpp']))" if ($LASTEXITCODE) { throw 'Could not extract the base fixture' } foreach ($preset in @('dev', 'release')) { Write-Output "BASE preset=$preset" cmake --preset $preset if ($LASTEXITCODE) { throw 'Configure failed' } ctest --preset $preset -N -R wave_startup_adapter_filter if ($LASTEXITCODE) { throw 'CTest listing failed' } cmake --build --preset $preset --target wave_startup_0_hardware if ($LASTEXITCODE) { throw 'Base build failed' } $exe = ".\out\build\$preset\wave_startup_0_hardware.exe" foreach ($selector in @('x2w-no-such-hardware-adapter', ('x' * 128))) { $env:XBOX2WINDOWS_ADAPTER = $selector & $exe Write-Output "fixture exit=$LASTEXITCODE" if ($LASTEXITCODE -ne 77) { throw 'Expected the base fixture to return 77' } } ctest --preset $preset --no-tests=error -j 1 -R '^wave_startup_adapter_filter$' -V Write-Output "red CTest exit=$LASTEXITCODE" if ($LASTEXITCODE -ne 8) { throw 'Expected the regression to fail on the base' } } } finally { [IO.File]::WriteAllBytes($source, $saved) } ``` Both presets listed `wave_startup_adapter_filter`. Both invalid selectors returned 77 on the base. The check failed in each preset with CTest exit 8 because the overlong case expected exit 1. ### Green ```powershell $targets = @('wave_startup_0_hardware', 'wave_startup_4_hardware', 'wave_startup_32_hardware', 'wave_startup_0_warp', 'wave_startup_4_warp', 'wave_startup_32_warp', 'startup_indirect_dispatch', 'startup_stream_rasterizer') foreach ($preset in @('dev', 'release')) { Write-Output "FIXED preset=$preset" cmake --preset $preset if ($LASTEXITCODE) { throw 'Configure failed' } cmake --build --preset $preset --target $targets if ($LASTEXITCODE) { throw 'Fixed build failed' } $exe = ".\out\build\$preset\wave_startup_0_hardware.exe" foreach ($selector in @('x2w-no-such-hardware-adapter', ('x' * 128))) { $env:XBOX2WINDOWS_ADAPTER = $selector & $exe Write-Output "fixture exit=$LASTEXITCODE" if ($LASTEXITCODE -ne 1) { throw 'Expected the fixed fixture to return 1' } } $env:XBOX2WINDOWS_ADAPTER = 'Radeon' ctest --preset $preset --no-tests=error -j 1 -R 'wave_startup|adapter_filter' -V if ($LASTEXITCODE) { throw 'Radeon/WARP matrix failed' } $env:XBOX2WINDOWS_ADAPTER = 'RTX 5080' ctest --preset $preset --no-tests=error -j 1 -R '^wave_startup_(0|4|32)_hardware$' -V if ($LASTEXITCODE) { throw 'RTX matrix failed' } } foreach ($adapter in @('hardware', 'warp')) { foreach ($width in @(0, 4, 32)) { dumpbin /dependents ('out/build/release/wave_startup_{0}_{1}.exe' -f $width, $adapter) if ($LASTEXITCODE) { throw 'Could not inspect Release binary imports' } } } ``` Both invalid selectors returned 1 in Debug and Release. The unmatched selector printed `No D3D12 hardware adapter matches XBOX2WINDOWS_ADAPTER=x2w-no-such-hardware-adapter`. The overlong selector printed `XBOX2WINDOWS_ADAPTER is longer than 127 characters`. In each preset, the Radeon and WARP matrix had seven passes and two skips. This includes passes for `wave_startup_adapter_filter`, `startup_indirect_dispatch_adapter_filter`, and `startup_stream_adapter_filter`. The RTX 5080 matrix had two passes and one skip. Radeon and RTX 5080 passed widths 0 and 32 with a 32-lane readback across 64 invocations, and skipped width 4 with exit 77 after `E_INVALIDARG`. WARP passed widths 0 and 4 with a 4-lane readback, and skipped width 32 with exit 77 after `E_INVALIDARG`. An earlier revision of this branch was also built (the six wave targets and two neighbors) in Debug and `/O2` Release, and passed the neighboring adapter-filter tests in both presets. Both rounds of `dumpbin /dependents` showed only `KERNEL32.dll`, `d3d12.dll` and `dxgi.dll` in all six Release wave binaries. The wave binaries link with `/ENTRY:fixture_entry /NODEFAULTLIB`. ### Mutation and device-creation failure At `tests/wave_startup_exe.cpp:214`, replace `if (!name_matched) return exit_fail;` with `if (!name_matched) return exit_skip;`. Rebuild the same eight targets and rerun the locked matrix in both presets. ```powershell foreach ($preset in @('dev', 'release')) { cmake --preset $preset cmake --build --preset $preset --target $targets $env:XBOX2WINDOWS_ADAPTER = 'Radeon' ctest --preset $preset --no-tests=error -j 1 -R 'wave_startup|adapter_filter' -V } ``` Both mutants linked and both matrices returned CTest exit 8. Only `wave_startup_adapter_filter` failed because the unmatched selector returned 77. Restoring the line, rebuilding and repeating the locked matrix gave exit 0 in both presets. There is no existing fault-injection hook for the fixture’s direct `D3D12CreateDevice` call. A name match followed by device-creation failure remains a gap in automated coverage. On an earlier revision of this branch, replacing `name_matched = true;` with `(void)name_matched;` passed the conventional Release matrix. A manual control forced the hardware device-creation condition to `if (SUCCEEDED(E_FAIL)) {`, rebuilt `wave_startup_0_hardware`, and ran it with `Radeon`. It returned 77 with the old generic diagnostic. Also removing the assignment changed the result to exit 1 with the unmatched diagnostic. Repeating that manual Release control at `tests/wave_startup_exe.cpp:202` returned 77 with `No D3D12-capable hardware adapter matches XBOX2WINDOWS_ADAPTER=Radeon`. With the selector unset it returned 77 with `No D3D12-capable hardware adapter visible`. The paired assignment mutant at line 201 returned 1 with `No D3D12 hardware adapter matches XBOX2WINDOWS_ADAPTER=Radeon`. Both temporary edits were restored. The GPU-less hosted-runner path was reviewed in source and remains unverified on a hosted runner. The unmatched case handles empty or software-only enumeration through DXGI. The overlong case returns before enumeration. ### Environment - Windows 11 25H2 build 26200.9974, x64 MSVC 19.44.35230.0, Windows SDK 10.0.26100.0, DXC 1.9.2602.17 and Python 3.14.7. - AMD Radeon(TM) Graphics (1002:13c0), driver 32.0.21030.2001, reported lane range 32–64. - NVIDIA GeForce RTX 5080 (10de:2c02), driver 32.0.16.2140 (621.40), reported lane range 32–32. - Microsoft Basic Render Driver, version 10.0.26100.9818, reported lane range 4–4. - The D3D12 debug layer was unavailable on this host (`0x887a002d`). Both physical adapters created devices during the regular matrix. Prepared with AI assistance; all commands above were run locally.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 01:31:52 +00:00
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-12-01 02:03 UTC · original · approved these changes

Reviewed 6b53cef2 by reading the diff; not built or run.

Verdict: approve. A bad selector now fails instead of skipping, and real skips (no hardware adapter, or device creation failing on every matching adapter) still return 77. No MUST, no SHOULD.

  • NIT The wave fixture still matches with its own ASCII-only contains_ignoring_case (wave_startup_exe.cpp:111), while AdapterNameFilter::matches uses _wcsnicmp. For a description with non-ASCII letters, the same selector could match in one fixture and not the other. A comment saying the matching is deliberately ASCII here would keep the "shares selector parsing" claim exact.
  • Checked, no finding:
    • select_adapter returns exit_pass (0) only after setting *selected and the device, so if (const int result = ...) in run() is correct, and the early return releases factory and debug.
    • With no selector, a hardware adapter whose device creation fails sets name_matched, but the !*wanted branch still prints "visible" and returns 77, as before.
    • On a GPU-less host the unmatched case only sees software adapters, so it returns 1 before creating any device. That makes the new test meaningful on hosted runners.
    • adapter_name_filter.h adds only constexpr arrays and two inline accessors. Its fprintf/_wcsnicmp members are never used by the /NODEFAULTLIB fixture, so they are not emitted, which agrees with the reported dumpbin imports.
    • The existing callers of hardware_adapter_filter_check.py are unchanged: startup_indirect_dispatch_adapter_filter passes <exe> hardware count, which REMAINDER keeps whole, and startup_stream_rasterizer_check.py imports check() with the old defaults (exit 4, stderr).

Tests: wave_startup_adapter_filter proves both selector errors exit 1 with their stdout text on the hardware build, and the body's mutant (exit_fail → exit_skip) shows it catches the old skip. Match-then-create-failure remains manual only, as stated. CI built the targets but did not run the new test: it is not in the pr preset filter.

**@⁠lukaslw-lab** on GitHub · 2026-12-01 02:03 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3683#pullrequestreview-6123878206) · **approved these changes** Reviewed `6b53cef2` by reading the diff; not built or run. **Verdict: approve.** A bad selector now fails instead of skipping, and real skips (no hardware adapter, or device creation failing on every matching adapter) still return 77. No MUST, no SHOULD. - **NIT** The wave fixture still matches with its own ASCII-only `contains_ignoring_case` (`wave_startup_exe.cpp:111`), while `AdapterNameFilter::matches` uses `_wcsnicmp`. For a description with non-ASCII letters, the same selector could match in one fixture and not the other. A comment saying the matching is deliberately ASCII here would keep the "shares selector parsing" claim exact. - Checked, no finding: - `select_adapter` returns `exit_pass` (0) only after setting `*selected` and the device, so `if (const int result = ...)` in `run()` is correct, and the early return releases `factory` and `debug`. - With no selector, a hardware adapter whose device creation fails sets `name_matched`, but the `!*wanted` branch still prints "visible" and returns 77, as before. - On a GPU-less host the unmatched case only sees software adapters, so it returns 1 before creating any device. That makes the new test meaningful on hosted runners. - `adapter_name_filter.h` adds only `constexpr` arrays and two inline accessors. Its `fprintf`/`_wcsnicmp` members are never used by the `/NODEFAULTLIB` fixture, so they are not emitted, which agrees with the reported `dumpbin` imports. - The existing callers of `hardware_adapter_filter_check.py` are unchanged: `startup_indirect_dispatch_adapter_filter` passes `<exe> hardware count`, which `REMAINDER` keeps whole, and `startup_stream_rasterizer_check.py` imports `check()` with the old defaults (exit 4, stderr). Tests: `wave_startup_adapter_filter` proves both selector errors exit 1 with their stdout text on the hardware build, and the body's mutant (`exit_fail` → `exit_skip`) shows it catches the old skip. Match-then-create-failure remains manual only, as stated. CI built the targets but did not run the new test: it is not in the `pr` preset filter.
github manually merged commit d18069e474 into main 2026-12-01 03:13:03 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.