shader: record a diagnostic draw while translation is missing #3220

Manually merged
github merged 1 commit from github-bot/gh-3218 into gh-pr/3218/base 2026-11-27 22:23:46 +00:00 AGit
Owner

@⁠Leyukaka on GitHub · 2026-11-27 22:14 UTC · original
Leyukaka:shader/missing-draw-fallback → main · +198 −19 · 7 files · 1 commits · merged 2026-11-27 22:21 UTC

Add an opt-in D3D12 fallback for direct, non-indexed triangle-list draws while the translation manifest is absent. Enable it with X2W_DRAW_MISSING_SHADER=1.

The fallback uses the bound single-sample attachment formats and clips all geometry. It records the draw without writing colour, depth or UAV data. It has its own render counter and keeps the normal translation request and manifest polling active. Downstream passes still need the original shader's outputs.

The WARP fixture checks three IA vertices and unchanged colour and depth readbacks with fallback enabled. The disabled control checks zero IA vertices. Both verify that a shader request was published, then publish a source-built translation and check that the same guest pipeline renders red.

Tested at 1d011315 on Windows build 26300 with WARP (Microsoft Basic Render Driver 10.0.26100.9818). The D3D12 debug layer was unavailable. All five selected tests passed, including three existing indirect draw regressions.

cmake --build --preset dev --target startup_indirect_draw_indexed
ctest --preset dev --no-tests=error -R '^(startup_missing_shader_fallback.*|startup_indirect_translated_targets|startup_indirect_translated_draw|startup_indirect_translated_refusal_census)_warp$' --output-on-failure
python -B tests/docs_links_check.py
**@⁠Leyukaka** on GitHub · 2026-11-27 22:14 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3218) `Leyukaka:shader/missing-draw-fallback` → `main` · +198 −19 · 7 files · 1 commits · merged 2026-11-27 22:21 UTC Add an opt-in D3D12 fallback for direct, non-indexed triangle-list draws while the translation manifest is absent. Enable it with `X2W_DRAW_MISSING_SHADER=1`. The fallback uses the bound single-sample attachment formats and clips all geometry. It records the draw without writing colour, depth or UAV data. It has its own render counter and keeps the normal translation request and manifest polling active. Downstream passes still need the original shader's outputs. The WARP fixture checks three IA vertices and unchanged colour and depth readbacks with fallback enabled. The disabled control checks zero IA vertices. Both verify that a shader request was published, then publish a source-built translation and check that the same guest pipeline renders red. Tested at `1d011315` on Windows build 26300 with WARP (Microsoft Basic Render Driver 10.0.26100.9818). The D3D12 debug layer was unavailable. All five selected tests passed, including three existing indirect draw regressions. ```powershell cmake --build --preset dev --target startup_indirect_draw_indexed ctest --preset dev --no-tests=error -R '^(startup_missing_shader_fallback.*|startup_indirect_translated_targets|startup_indirect_translated_draw|startup_indirect_translated_refusal_census)_warp$' --output-on-failure python -B tests/docs_links_check.py ```
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 22:16:49 +00:00
github-bot changed target branch from main to gh-pr/3218/base 2026-11-27 22:23:44 +00:00
github manually merged commit 1d0113158b into gh-pr/3218/base 2026-11-27 22:23:46 +00:00
Author
Owner

@⁠pigalot on GitHub · 2026-11-27 22:21 UTC · original · approved these changes

I reviewed 1d011315 merged over main e582a9a4. The merge is clean (tree 1c9afeb5) and git diff --cached --check is clean.

What I traced.

  • When it applies: the fallback is reached only from list_draw (slot 12, non-indexed) through draw_startup_direct. It applies only when a translation exists and its manifest retry is pending. It also needs:

    • X2W_DRAW_MISSING_SHADER to be exactly 1;
    • a direct list and a triangle-list topology;
    • single-sample targets;
    • a guest viewport and scissor.

    Indexed and indirect draws keep their existing paths.

  • The PSO: it takes the bound RTV and DSV formats, with blend, depth and stencil left at zero. So there are no colour writes and depth and stencil are off. The vertex shader puts every vertex at the same point outside the clip volume, and the pixel shader discards. So nothing can reach the attachments, and nothing reads a guest buffer or binds a heap.

  • The cache: the cached root signature holds a reference to the guest root, so a pointer key cannot be reused while the entry lives. The map is only touched under draw_lock.

  • State afterwards: the translated path calls SetPipelineState and SetGraphicsRootSignature itself, so a fallback draw does not leak its PSO into a later translated draw in the same list. The guest root is reused when there is one, so its bindings are kept. The native topology is the guest's (slot 20 forwards it).

  • Counters: a fallback draw counts in its own counter and in neither translated draws nor not drawn, as documented.

What I ran. I built startup_indirect_draw_indexed startup_indirect_dispatch startup_stream_consumer in dev and release, then ran

ctest --test-dir out/build/<preset> --no-tests=error -j 4 -R '^(startup_missing_shader_fallback(_off)?_warp|startup_indirect[a-z_]*_warp(_dual)?)$'
  • Results: 33/33 pass in Debug and Release /O2. That covers the two new cases and the existing indirect fixtures on WARP, with no skips. tests/docs_links_check.py also passes.
  • Negative control: on main, the two new tests are not registered. Mutant 1 below is main's behaviour for this draw, and it fails the enabled case.

Mutants in src/startup_stubs/d3d12_draw.inl. For each, I rebuilt in dev and ran both new tests:

Mutant Result
fallback never used killed (missing translation: IA vertices 0, expected 3)
env switch ignored (always on) killed (off control: IA vertices 3, expected 0)
fallback also used after the manifest is published killed (published translation (rtv0) pixel (0,0): got 0xff000000, expected 0xff0000ff)

Restored and rebuilt afterwards; git diff --quiet is clean.

Non-blocking.

  • Overlapping guards: the constant vertex position makes every triangle degenerate, so clip(-1), the off-screen position and the zero write mask each guard the attachments on their own. The fixture can't tell them apart, which is fine for a no-write draw.
  • Counter: missing shader fallback draws is not checked by the fixture. A one-line assert on the render totals would pin it.
  • Debug layer: the debug-layer message check in the fixture is vacuous when the layer is unavailable, as it was here and in the PR body.

Verdict: approve on 1d011315.

Environment: WARP (Microsoft Basic Render Driver) on Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Windows SDK 10.0.28000.0, Python 3.12.10, debug layer off.
CI: Build and test on Windows passes on 1d011315.

This reply was AI-assisted.

**@⁠pigalot** on GitHub · 2026-11-27 22:21 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3218#pullrequestreview-6093906441) · **approved these changes** I reviewed `1d011315` merged over `main` `e582a9a4`. The merge is clean (tree `1c9afeb5`) and `git diff --cached --check` is clean. **What I traced.** - **When it applies:** the fallback is reached only from `list_draw` (slot 12, non-indexed) through `draw_startup_direct`. It applies only when a translation exists and its manifest retry is pending. It also needs: - `X2W_DRAW_MISSING_SHADER` to be exactly `1`; - a direct list and a triangle-list topology; - single-sample targets; - a guest viewport and scissor. Indexed and indirect draws keep their existing paths. - **The PSO:** it takes the bound RTV and DSV formats, with blend, depth and stencil left at zero. So there are no colour writes and depth and stencil are off. The vertex shader puts every vertex at the same point outside the clip volume, and the pixel shader discards. So nothing can reach the attachments, and nothing reads a guest buffer or binds a heap. - **The cache:** the cached root signature holds a reference to the guest root, so a pointer key cannot be reused while the entry lives. The map is only touched under `draw_lock`. - **State afterwards:** the translated path calls `SetPipelineState` and `SetGraphicsRootSignature` itself, so a fallback draw does not leak its PSO into a later translated draw in the same list. The guest root is reused when there is one, so its bindings are kept. The native topology is the guest's (slot 20 forwards it). - **Counters:** a fallback draw counts in its own counter and in neither `translated draws` nor `not drawn`, as documented. **What I ran.** I built `startup_indirect_draw_indexed startup_indirect_dispatch startup_stream_consumer` in `dev` and `release`, then ran ```powershell ctest --test-dir out/build/<preset> --no-tests=error -j 4 -R '^(startup_missing_shader_fallback(_off)?_warp|startup_indirect[a-z_]*_warp(_dual)?)$' ``` - **Results:** 33/33 pass in Debug and Release `/O2`. That covers the two new cases and the existing indirect fixtures on WARP, with no skips. `tests/docs_links_check.py` also passes. - **Negative control:** on `main`, the two new tests are not registered. Mutant 1 below is `main`'s behaviour for this draw, and it fails the enabled case. **Mutants** in `src/startup_stubs/d3d12_draw.inl`. For each, I rebuilt in `dev` and ran both new tests: | Mutant | Result | |---|---| | fallback never used | killed (`missing translation: IA vertices 0, expected 3`) | | env switch ignored (always on) | killed (off control: `IA vertices 3, expected 0`) | | fallback also used after the manifest is published | killed (`published translation (rtv0) pixel (0,0): got 0xff000000, expected 0xff0000ff`) | Restored and rebuilt afterwards; `git diff --quiet` is clean. **Non-blocking.** - **Overlapping guards:** the constant vertex position makes every triangle degenerate, so `clip(-1)`, the off-screen position and the zero write mask each guard the attachments on their own. The fixture can't tell them apart, which is fine for a no-write draw. - **Counter:** `missing shader fallback draws` is not checked by the fixture. A one-line assert on the render totals would pin it. - **Debug layer:** the debug-layer message check in the fixture is vacuous when the layer is unavailable, as it was here and in the PR body. **Verdict:** approve on `1d011315`. Environment: WARP (Microsoft Basic Render Driver) on Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Windows SDK 10.0.28000.0, Python 3.12.10, debug layer off. CI: `Build and test on Windows` passes on `1d011315`. This reply was AI-assisted.
This discussion has been locked. Commenting is limited to contributors.
No description provided.