From b0f0c0b45b7009fed42d1217891b6d0a6e21c677 Mon Sep 17 00:00:00 2001 From: aznohonza Date: Tue, 1 Dec 2026 12:19:11 +0100 Subject: [PATCH 1/2] d3d12-gpu: prime a draw's tested depth before its picked textures are 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. --- d3d12/crates/leonida-gpu/src/draw.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/d3d12/crates/leonida-gpu/src/draw.rs b/d3d12/crates/leonida-gpu/src/draw.rs index 812766e082..977fb93b05 100644 --- a/d3d12/crates/leonida-gpu/src/draw.rs +++ b/d3d12/crates/leonida-gpu/src/draw.rs @@ -3081,6 +3081,17 @@ impl State { self.views_untold = false; // (Clears the cache if the switch changed since the last call.) self.cache.sync(); + // The depth target a draw only tests, for the views of it that the + // draw's shaders read (`readable`). Primed before the textures picked + // by index are brought up to date: that pass reads a picked view of + // this target through `readable` too, and the state it leaves has to + // keep `SHADER_RESOURCE` (`State::prepare_for`). + let tested = if !compute && self.depth_state == DEPTH_READ { + self.depth + } else { + 0 + }; + TESTED_DEPTH.set((tested, false)); // Textures picked by index, before anything asks for them. self.early_textures(list, p, compute); if crate::host::walls_trace() { @@ -3137,14 +3148,6 @@ impl State { self.host_roots = [0; 2]; self.cache.heaps_changed(); } - // The depth target a draw only tests, for the views of it that the - // draw's shaders read (`readable`). - let tested = if !compute && self.depth_state == DEPTH_READ { - self.depth - } else { - 0 - }; - TESTED_DEPTH.set((tested, false)); let root = p.root.as_raw() as usize; if self.host_roots[usize::from(compute)] != root { // SAFETY: an open list and a live root signature. From 31e64fcf0da8d2d00cf4a1952b5545dd900148ce Mon Sep 17 00:00:00 2001 From: aznohonza Date: Tue, 1 Dec 2026 17:57:13 +0100 Subject: [PATCH 2/2] d3d12-gpu: the bake pass records the same combined-state barrier too KelboLive's review of #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 --- d3d12/crates/leonida-gpu/src/draw.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/d3d12/crates/leonida-gpu/src/draw.rs b/d3d12/crates/leonida-gpu/src/draw.rs index 977fb93b05..055622e6d0 100644 --- a/d3d12/crates/leonida-gpu/src/draw.rs +++ b/d3d12/crates/leonida-gpu/src/draw.rs @@ -3086,6 +3086,10 @@ impl State { // by index are brought up to date: that pass reads a picked view of // this target through `readable` too, and the state it leaves has to // keep `SHADER_RESOURCE` (`State::prepare_for`). + // The bake list runs that same pass (`early_textures` → `heap_textures` + // on `bake_list`), so it can now record the combined-state barrier for + // this target too: the same state, tracked per list, and the draw's own + // list gets its transition in `prepare_for`. let tested = if !compute && self.depth_state == DEPTH_READ { self.depth } else {