Skip to content

gpu: a software adapter does not support the depth bounds test, whatever it answers - #2823

Open
fiestorra wants to merge 2 commits into
ProjectLeonida:mainfrom
fiestorra:fix-depth-bounds-software
Open

fiestorra wants to merge 2 commits into
ProjectLeonida:mainfrom
fiestorra:fix-depth-bounds-software

Conversation

@fiestorra

Copy link
Copy Markdown
Contributor

A software adapter answers that it supports the depth bounds test and then does not gate the draw, so depth_bounds() now says no for one. Eleven lines, and the test that guards on it skips where there is no card instead of failing there.

How this was found: #2816's job ran for the first time on windows-latest and failed in five minutes, on a test that passes on a machine with a GPU:

pipeline::host::tests::depth_bounds_pipeline_loads_and_filters_draws
assertion `left == right` failed: depth 0.5 outside [0.6, 1.0] must be culled
  left: 255
  right: 0

And it reproduces here on the software adapter, which is what a runner without a card gets:

LEONIDA_D3D12_WARP=1 cargo test -p leonida-gpu --features diagnostics --lib \
    depth_bounds_pipeline_loads_and_filters_draws
  panicked ... left: 255, right: 0

The query, and why it is not enough (host.rs, depth_bounds): D3D12_OPTIONS2.DepthBoundsTestSupported is true on WARP. OMSetDepthBounds is then accepted and every fragment passes - the draw the test expects to be culled is not - so the feature query is right about the API surface and wrong about what the driver does with it. That is a software rasterizer's prerogative and not something to fix by trusting the query harder.

The change:

    pub(crate) fn depth_bounds(&self) -> bool {
        static BOUNDS: OnceLock<bool> = OnceLock::new();
        // A software adapter answers that it supports the test and then does not gate the draw:
        // `OMSetDepthBounds` is accepted and every fragment passes (measured on WARP, which is
        // what a CI runner without a card gets, and the same frame reads back 255 instead of 0).
        // The query is right about the API surface and wrong about the driver, so the answer is
        // no for a software adapter.
        if crate::indirect::adapter_of(&self.device)
            .is_some_and(|d| d.Flags & DXGI_ADAPTER_FLAG_SOFTWARE.0 as u32 != 0)
        {
            return false;
        }
        *BOUNDS.get_or_init(|| { ... })

adapter_of was already there (indirect.rs, the helper amd() and the NVIDIA check use) and becomes pub(crate); the flag check is the one warp_adapter() and three other call sites already use.

Both arms, measured:

LEONIDA_D3D12_WARP=1 (the CI shape)   ok. 1 passed   "no host depth bounds support; skipped"
the card (RTX 4090)                   ok. 1 passed   (0.88 s, runs)
cargo test -p leonida-gpu --lib      ok. 589 passed; 0 failed; 53 ignored

What this does not do: it does not make the rest of the GPU tests safe on a runner without a card. This one had a guard that happened to ask the wrong question; others may not have a guard at all, and #2816's job will find them one at a time. It does mean the depth bounds test neither hides on a real GPU nor lies on a software one.

AI-assisted: yes - DeepSeek v4.1 (flash), which reproduced it on WARP before changing anything.

Written with an AI assistant.

@fiestorra

Copy link
Copy Markdown
Contributor Author

One clarification I want in the record, because I nearly wrote the wrong justification: this does not change what renders on a software adapter.

depth_bounds() has two production callers, not just the test:

draw.rs:7952            if crate::host::host().is_some_and(|h| h.depth_bounds())
                            && let Ok(l1) = list.list.cast::<ID3D12GraphicsCommandList1>()
                        {
                            unsafe { l1.OMSetDepthBounds(min, max) };
                        }
pipeline/host.rs:866    if host.depth_bounds() { ... }
pipeline/host.rs:1553   the test's guard

So before this change, on WARP, the runtime emitted OMSetDepthBounds and WARP ignored it - every fragment drawn. After, the runtime does not emit it - every fragment drawn. The picture is the same either way, and I am not claiming a rendering fix.

What changes is that depth_bounds() stops being wrong. It was returning "this host supports the test" when what it knew was "the device reports DepthBoundsTestSupported", and on WARP those differ. The test is the place that difference became visible; the two production callers would go on being harmless no-ops.

If a title depended on depth bounds for correctness, it would render wrong on WARP before and after - that is a software adapter's limitation, not something this can fix. What this does is stop the answer lying to anything that asks it next.

AI-assisted: yes - DeepSeek v4.1 (flash), which checked its own claim against the callers before making it.

Written with an AI assistant.

@fiestorra

Copy link
Copy Markdown
Contributor Author

And what the second production caller does now, since that is the one with a message in it:

let depth_bounds = if g.depth_bounds {
    if host.depth_bounds() {
        true
    } else {
        static SEEN: AtomicU64 = ...;
        if SEEN.fetch_add(1, Relaxed) < 4 {
            tracing::warn!("a pipeline enables the depth bounds test, which the host GPU does not support");
        }
        false
    }
} else { false };

On a software adapter this branch now fires: the warning appears up to four times and the pipeline does not claim the state. That is the intended behaviour finally happening - the message has always said "the host GPU does not support", and until now a host that could not run the test answered that it could, so the warning never appeared on the one class of adapter it is about.

So the blast radius of the change, both places:

draw.rs:7952          no OMSetDepthBounds emitted (it was a no-op on WARP anyway)
pipeline/host.rs:866  the "does not support" warning fires, the state is not set
pipeline/host.rs:1553 the test skips instead of failing

Three call sites, one answer, and the two that were silent were the ones that had something to say.

AI-assisted: yes - DeepSeek v4.1 (flash).

Written with an AI assistant.

@fiestorra

Copy link
Copy Markdown
Contributor Author

done: green on every check.

change-scope            SUCCESS
no-game-data            SUCCESS
check                   SUCCESS   (the one that builds the Python tools and rpf9dump)
linux-python-and-viewer SUCCESS
semantic-tests          SUCCESS
MERGEABLE

And what it is worth, measured before the pipeline agreed: the test that failed on a card-less runner now skips there and still runs on the 4090.

LEONIDA_D3D12_WARP=1   ok. 1 passed   "no host depth bounds support; skipped"
the 4090               ok. 1 passed   (0.88 s, runs)
cargo test -p leonida-gpu --lib   ok. 589 passed; 0 failed; 53 ignored

Where this came from, so it is on the record: #2816's job ran for the first time and failed on this test in five minutes, on a machine with a GPU where it passes. A pull request that is not merged found a red that main could not see, and this is the second fix it produced.

The first is #2815 (the asset policy). With both merged, and #2652 (the xbox_present flake), main has no known red in either layer - and #2816 can rebase onto that and its five-minute job is the thing that keeps it that way.

AI-assisted: yes - DeepSeek v4.1 (flash).

Written with an AI assistant.

@KelboLive KelboLive left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified both arms on this machine: with LEONIDA_D3D12_WARP=1 the test skips and passes on the head; on the RTX 4070 Ti SUPER it runs and passes; deleting the early return makes the WARP run fail exactly as reported (left: 255, right: 0, pipeline/host.rs:1793).

The rule is the right level: adapter_of matches the adapter by the device's LUID (indirect.rs:328-336), so the software flag cannot be applied to a hardware adapter, and it covers software adapters beyond WARP (Basic Render Driver). Vendor/device id would miss those; trusting D3D12_OPTIONS2 is the thing that is wrong on WARP. Worth saying in the body that a hardware driver which reports the feature and ignores it is still trusted — only a behavioural probe would catch that, and it is not worth the cost for a CI-only failure.

One real cost to fix before merge: the software check sits outside the OnceLock (host.rs:5772-5777), so every depth_bounds() call does CreateDXGIFactory2 + EnumAdapterByLuid + GetDesc1. I measured ~134 µs per call (~138 µs per warm depth_bounds), and draw::depth_bounds is called on every OMSetDepthBounds and every list replay (draw.rs:2780-2781). Before this PR it was a OnceLock load. Move the check inside BOUNDS.get_or_init, or cache the software flag in its own OnceLock — host() is a process singleton (host.rs:1208-1217), so once per process is safe and matches the existing global cache. On WARP it is never cached at all today, because the early return skips the OnceLock.

Minor: add a direct test of the rule on a software device — right now only the GPU test's skip catches a regression, and only in the shape where WARP is the device.

@fiestorra

Copy link
Copy Markdown
Contributor Author

done: it merges onto today's main and both arms behave - the test skips on a software adapter and still runs on a card.

main 640b0d0df, this branch's one commit cherry-picked (base 90c514437, no conflict), cargo 1.98.1:

tree ae3042486   (main + this branch)

LEONIDA_D3D12_WARP=1 cargo test -p leonida-gpu --features diagnostics --lib \
    depth_bounds_pipeline_loads_and_filters_draws
  exit 0 · ok. 1 passed
  "no host depth bounds support; skipped"

cargo test -p leonida-gpu --lib depth_bounds_pipeline_loads_and_filters_draws
  exit 0 · ok. 1 passed   (0.97 s, the test runs)

So on the merged tree the guard does what the branch claims: a runner without a card skips instead of failing, and a machine with one still exercises the depth bounds path.

Why this matters to the job that found it: #2816's first real run failed on exactly this test (assertion left: 255, right: 0). With this merged, that red is gone from its suite, and the only one it would still see is the policy test - which #2815 fixes, also measured on the merged tree.

The two together are what turns #2816 green: one for the WARP red, one for the policy red, and neither needs the other's file.

AI-assisted: yes - DeepSeek v4.1 (flash), both arms on the merged tree.

Written with an AI assistant.

@MoonEyes

MoonEyes commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

fc96e20b2: the adapter is asked inside get_or_init, so once, not at every OMSetDepthBounds and every replayed list (KelboLive measured about 134 µs a call). On main cd0c52fcf: cargo test -p leonida-gpu --lib 631 passed, 0 failed.

Pushed to your branch by MoonEyes (maintainer, the branch allows it), on top of your head, nothing rewritten. Say so if you would rather have it another way, and I take it out. The earlier verdicts are for the head before this one.

AI-assisted (Claude Code).

fiestorra and others added 2 commits December 1, 2026 19:12
…ver it answers

D3D12_OPTIONS2.DepthBoundsTestSupported is true on WARP, and OMSetDepthBounds is then
accepted with every fragment passing: the same frame reads back 255 where a card culls
and reads 0. The feature query is right about the API surface and wrong about the driver.

So depth_bounds() answers no for an adapter with DXGI_ADAPTER_FLAG_SOFTWARE. The test that
guards on it then skips on a CI runner with no card, instead of failing there and passing
on a GPU, and still runs where there is one.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fiestorra
fiestorra force-pushed the fix-depth-bounds-software branch from fc96e20 to b60a729 Compare December 1, 2026 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants