Repository navigation
Conversation
… read A read-only depth target that a draw's shaders read through a heap-indexed view could be left in DEPTH_READ without SHADER_RESOURCE. The textures picked by index are brought up to date at the start of `State::bind`, before `TESTED_DEPTH` was set for the draw; their views go through `readable`, which marks the depth read (and keeps SHADER_RESOURCE in the state) only when the target it holds is this draw's. It held the previous draw's, so the read was not marked, and `State::prepare_for` then moved the target to DEPTH_READ alone. Set the draw's tested depth before `early_textures`, so the pass reads it with the draw it belongs to. The state decision in `prepare_for` and the states `readable` picks are unchanged.
|
Independent check of The Windows GPU crate built with this PR, #2834 and #2831. Three existing draw tests passed on AMD Raphael (RADV 26.3.1) and RTX 4070 SUPER (NVIDIA 620.73.4) under Wine and vkd3d-proton 3.1.0. The isolated test checks state transitions. A complete offscreen draw and pixel comparison remain open. AI-assisted with OpenAI Codex. |
|
Thanks — that matches the intent exactly: the early pass now reads the picked views with the draw they belong to, so The full offscreen draw and pixel comparison needs the title's own draw; no D3D12 device here, so the state transition is as far as this side goes. Nothing further from us on this one. AI-assisted. |
KelboLive
left a comment
There was a problem hiding this comment.
The diagnosis and the move are right. readable() decides SHADER_RESOURCE at upload time while prepare_for decides the DSV state later, and they only agree if TESTED_DEPTH already names this draw — so priming it at the top of State::bind, before early_textures, is the minimal fix. The guard is the right condition too: read-only DSV (D3D12_DSV_FLAG_READ_ONLY_DEPTH/..._STENCIL, draw.rs:7376-7397), not "DepthEnable", because a draw that writes depth cannot share the target with an SRV anyway and goes through twin_use. No ordering hole: the value is reset per bind (compute → 0), the table caches hash the tested address, and nothing reads it outside that bind.
Two things before merge:
- There is no test, and the mutation proves it: reverting the reorder leaves the whole lib suite green (627 passed, 0 failed).
AGENTS.mdasks that such a change come with a test — at minimum say in the body that the mechanism is GPU-only and that the verification was a run, and ideally add a seam that records whatearly_texturessees inTESTED_DEPTHwhen a picked view is a read of the draw's tested depth. - The bake path also runs the pass:
early_texturesrunsheap_textureson a separatebake_list(draw.rs:3882-3907), so with the prime in place that upload list can now also record the combined-state barrier for the depth target. Harmless — same state, per-list tracking, and the draw's own list gets its own transition viaprepare_for— but one sentence in the comment would save the next reader the question.
Also worth noting: texture::alias_cast_tests::committed_and_placed_r32_uint_textures_cast_to_r9g9b9e5_under_legacy_barriers failed once in a mutated run at texture.rs:5664 (pool::fresh) and passes alone and in both unmutated runs — a pre-existing parallel-execution flake, unrelated to this change, but you may want it on the silent/flaky list.
VERIFY-2866 — Linux, Rust 1.98.1 (the pinned toolchain), no GPU device, no game filesVerdict: PASS. The ordering change is necessary, and the pull request's explanation of why is accurate: the value it moves is a "which depth target does this draw test" marker that a reader compares against the texture being read, and in Head 1. What the marker is
thread_local! {
/// While a draw is prepared (`State::bind`, then its targets' states):
/// the depth target the draw only tests (0: none, or one it writes),
/// and whether a view its shaders read is of that same texture.
static TESTED_DEPTH: std::cell::Cell<(usize, bool)> =
const { std::cell::Cell::new((0, false)) };The first component is the depth texture the draw only tests; the second says whether a view the draw's shaders read turned out to be of that same texture. The reader is (View::Shader(resource, _), ResourceType::Srv) => {
if let Some((held_source, _)) = crate::resource::cast_alias_of(*resource as This) {
let source = held_source.get();
let (tested, _) = TESTED_DEPTH.get();
let state = if tested != 0 && tested == source as usize {
TESTED_DEPTH.set((tested, true));
DEPTH_READ | SHADER_RESOURCE
} else {
SHADER_RESOURCE
};
crate::list::ensure_state(list, source, state);
return true;
}So the comparison The other end of the flag is let state = if self.depth_state == DEPTH_READ {
let (tested, read) = TESTED_DEPTH.get();
if read && tested == self.depth { DEPTH_READ | SHADER_RESOURCE } else { DEPTH_READ }
} else {
DEPTH_WRITE
};
crate::list::ensure_state(list, self.depth as This, state);
2. Where the stale value came from
and So the chain the pull request names is real: 3. The order in
|
|
Thanks for the PASS and for walking the chain. One nuance on the ordering: the targets' states are not the next draw's — The rest matches: the early pass is the only |
KelboLive's review of ProjectLeonida#2866: with the prime in place, `early_textures` runs `heap_textures` on the separate `bake_list`, so that upload list can also record the combined-state barrier for the depth target. It is harmless (same state, tracked per list; the draw's own list gets its transition in `prepare_for`), but the comment now says so. AI-assisted: yes
|
Both points, on
If you want the seam anyway, the shape I would give it is: have Re-ran |
State::bindbrings the textures picked by index up to date at its start, and those views go throughreadable(heap_textures, andflush_for_bakebefore it).readableis what notes that a draw reads a view of the depth target it only tests: it setsTESTED_DEPTH's read bit, and a read-only depth target then keepsSHADER_RESOURCEin the stateState::prepare_forgives it (DEPTH_READ | SHADER_RESOURCE).TESTED_DEPTHwas primed for the draw after that pass, so during it the cell still held the previous draw's target. A heap-indexed read of this draw's own depth target was therefore not marked, the pass left the target inSHADER_RESOURCEalone, andprepare_forthen moved it toDEPTH_READalone while the shader samples it.This moves the priming before
early_textures; the state decision inprepare_forand the statesreadablepicks are unchanged. Reads found by the table walk later inbindwere already covered, since that walk is after the priming.Reported in #2570 by @zmasi (
finding: read-only depth plus a heap-indexed read gets DEPTH_READ without SHADER_RESOURCE, pointing at this call).Verification:
cargo xwin check --target x86_64-pc-windows-msvc --workspace --all-targets --lockedpasses. There is no D3D12 device on this Linux host, so the pass itself could only be read-verified here; thed3d12CI job builds and runs the workspace's tests. No game data, no new switches.AI-assisted.