Batched indirect clamp serves records clamped before the title's culling rewrote them: vehicle bodies vanish or go black at some camera angles (RX 9070 XT) #523

Open
opened 2026-12-04 21:47:33 +00:00 by github-bot · 1 comment
Owner

@⁠abomalocaris on GitHub · 2026-12-04 21:45 UTC · original

What is seen

On main at 2d7cb69 (also with #342 merged), RX 9070 XT 16 GB, Series X profile, 2560x1440 output with FSR 4 quality, ray tracing on or off:

  • A parked vehicle loses its body at some camera angles and gets it back when the camera turns away. Wheels and interior stay. The wall behind shows through.
  • At other angles the body stays as a solid black silhouette: every G-buffer target is zero under it while depth has it.
  • It is stable while the camera is still, and it is the same from run to run at the same place and angle.

It is not ray tracing (VICTORY_BVH_BUILDER=0 shows it too), and indirect mesh dispatches: ... 0.00 indirect records a frame ran empty for want of their list's budget.

What I checked first, and ruled out

Captures (VICTORY_CAPTURE + VICTORY_DUMP_TARGETS, with a local addition that dumps every level of R32F textures as raw floats):

  • Every level of the 512x256 depth pyramid is the exact minimum of the level below it.
  • The 128x72 occluder picture the title rasterises on the CPU and ec68a4e805ecba26 merges into the pyramid is the same in the host copy and in title memory, and its occluders lie behind the real geometry.

So the inputs to the title's occlusion test are right.

Cause

One command list of the title holds several groups of draws, each preceded by its own culling:

K C c K C c K  m m m m m m m      <- 7 mesh draws
C c K          m m ... (18)
C c K          m m ... (7)
C c K          m m ... (16)       <- same argument addresses as the first group

C = instance culling (3b471c122be79b3e / fc5e66f8f873d3bb / 764ca63daec9c616), c = meshlet culling (9f017d9011377efa / 0452fc2d2e2fc4c3 / 87bf9e3f2bf2f052), K = 9146291b38ea9ce1, m = indirect kind 10 max 1. All of C, c, K write the 32768-byte argument buffer the following draws read.

State::batched() returns the place of a record from the open batch whenever the table can place it. State::buffers_written() only sets batch.wrote; the batch is dropped in State::synced(), which runs at the title's barrier() / sync() / groups_asked(). When no such call falls between K and the draws, the draws of a later group are served by the batch opened for an earlier group, whose clamp pass ran before this group's C c K. A count of zero there is a body that is not drawn in that pass: missing from the G-buffer pass only gives the black silhouette, missing from both gives the see-through one.

What fixes it here

Four local variants of one switch, checked by eye at a place where it reproduces every time, and timed on a scripted walk (same save, 30 fps cap):

variant vehicles fps
unchanged vanish / black 29.4
drop the batch at every buffers_written() fixed about 21
new batch only when a record already in the table is asked for again after a write not fixed 29.4
new batch for any draw record (kinds 0, 1, 10) asked for after a compute write fixed 29.4
the same, with a UAV barrier in front of the reopened batch fixed, wheel rims steadier 29.3 to 29.7

Two things follow from the table:

  • The second row's cost is all in indirect dispatches after compute writes. With VICTORY_BVH_BUILDER=0 the first variant runs at full speed (29.7), so it is the ray-tracing dispatches that are expensive to re-batch.
  • The third row failing says a record first placed after a write is stale too, not only one placed before it.

Also covering the meshlet culling's own indirect dispatches made rims and manhole covers flicker much more, until the barrier was added in front of the reopened batch. I read that as the clamp pass running before the stores of the shader just before it are visible, but I have not shown it directly.

Patch

The last row, as an opt-in switch. In State::batched() (crates/victory-gpu/src/draw.rs), before the open batch is asked for the record's place:

let wrote_before = self.batch.as_ref().is_some_and(|b| b.wrote & crate::waits::COMPUTE != 0);
// A draw record asked for after a compute shader that writes buffers was
// recorded is not the one the open batch clamped: a new batch, after it.
if on && kind != 2 && wrote_before {
    self.batch = None;
}
if let Some(b) = &mut self.batch
    && let Some(at) = b.table.place(id, offset, kind)
{
    return Some((b.scratch.clone(), at));
}
// The new batch's pass reads what those shaders wrote: they finish first.
if on && wrote_before && self.batch.is_none() {
    unsafe { list.list.barriers(&[crate::indirect::uav_barrier()]) };
}
self.batch = None;
let (mut table, scratch) = crate::indirect::open_batch(list, (id, &args.buffer), &argument_copies(args))?;

(on is the switch; kind != 2 leaves indirect dispatches as they are.) It is a workaround at the place the symptom shows. The exact condition is probably "a shader whose unordered views overlap a source of the open batch was recorded", which would cover dispatches as well without the cost; I have not written that.

Not fixed by this

Shadows and bushes still pop along a walk. A frame-by-frame pop count over twelve recorded replays of one walk gave 5.8 (unchanged), 5.5 and 6.0 big pops per 1000 frames for the variants: no difference. That is a separate fault.

Side note

The title's depth-pyramid sampler is CLAMP_BORDER with a transparent-black border (words 438, 0xc00000, 0x18500000, 0), so on the console a test rectangle that reaches past the screen reads 0 (farthest) there. lower.rs's gather-with-level emulation clamps coordinates to the edge instead. I tried border semantics behind a switch; it did not turn out to be the cause of the above, and I have no case where it changes a picture.

**@⁠abomalocaris** on GitHub · 2026-12-04 21:45 UTC · [original](https://github.com/lobomfz/VIctory-xmem/issues/523) ## What is seen On `main` at `2d7cb69` (also with #342 merged), RX 9070 XT 16 GB, Series X profile, 2560x1440 output with FSR 4 quality, ray tracing on or off: - A parked vehicle loses its body at some camera angles and gets it back when the camera turns away. Wheels and interior stay. The wall behind shows through. - At other angles the body stays as a solid black silhouette: every G-buffer target is zero under it while depth has it. - It is stable while the camera is still, and it is the same from run to run at the same place and angle. It is not ray tracing (`VICTORY_BVH_BUILDER=0` shows it too), and `indirect mesh dispatches: ... 0.00 indirect records a frame ran empty for want of their list's budget`. ## What I checked first, and ruled out Captures (`VICTORY_CAPTURE` + `VICTORY_DUMP_TARGETS`, with a local addition that dumps every level of R32F textures as raw floats): - Every level of the 512x256 depth pyramid is the exact minimum of the level below it. - The 128x72 occluder picture the title rasterises on the CPU and `ec68a4e805ecba26` merges into the pyramid is the same in the host copy and in title memory, and its occluders lie behind the real geometry. So the inputs to the title's occlusion test are right. ## Cause One command list of the title holds several groups of draws, each preceded by its own culling: ``` K C c K C c K m m m m m m m <- 7 mesh draws C c K m m ... (18) C c K m m ... (7) C c K m m ... (16) <- same argument addresses as the first group ``` `C` = instance culling (`3b471c122be79b3e` / `fc5e66f8f873d3bb` / `764ca63daec9c616`), `c` = meshlet culling (`9f017d9011377efa` / `0452fc2d2e2fc4c3` / `87bf9e3f2bf2f052`), `K` = `9146291b38ea9ce1`, `m` = `indirect kind 10 max 1`. All of `C`, `c`, `K` write the 32768-byte argument buffer the following draws read. `State::batched()` returns the place of a record from the open batch whenever the table can place it. `State::buffers_written()` only sets `batch.wrote`; the batch is dropped in `State::synced()`, which runs at the title's `barrier()` / `sync()` / `groups_asked()`. When no such call falls between `K` and the draws, the draws of a later group are served by the batch opened for an earlier group, whose clamp pass ran before this group's `C c K`. A count of zero there is a body that is not drawn in that pass: missing from the G-buffer pass only gives the black silhouette, missing from both gives the see-through one. ## What fixes it here Four local variants of one switch, checked by eye at a place where it reproduces every time, and timed on a scripted walk (same save, 30 fps cap): | variant | vehicles | fps | |---|---|---| | unchanged | vanish / black | 29.4 | | drop the batch at every `buffers_written()` | fixed | about 21 | | new batch only when a record already in the table is asked for again after a write | **not fixed** | 29.4 | | new batch for any draw record (kinds 0, 1, 10) asked for after a compute write | fixed | 29.4 | | the same, with a UAV barrier in front of the reopened batch | fixed, wheel rims steadier | 29.3 to 29.7 | Two things follow from the table: - The second row's cost is all in indirect *dispatches* after compute writes. With `VICTORY_BVH_BUILDER=0` the first variant runs at full speed (29.7), so it is the ray-tracing dispatches that are expensive to re-batch. - The third row failing says a record first placed after a write is stale too, not only one placed before it. Also covering the meshlet culling's own indirect dispatches made rims and manhole covers flicker much more, until the barrier was added in front of the reopened batch. I read that as the clamp pass running before the stores of the shader just before it are visible, but I have not shown it directly. ## Patch The last row, as an opt-in switch. In `State::batched()` (`crates/victory-gpu/src/draw.rs`), before the open batch is asked for the record's place: ```rust let wrote_before = self.batch.as_ref().is_some_and(|b| b.wrote & crate::waits::COMPUTE != 0); // A draw record asked for after a compute shader that writes buffers was // recorded is not the one the open batch clamped: a new batch, after it. if on && kind != 2 && wrote_before { self.batch = None; } if let Some(b) = &mut self.batch && let Some(at) = b.table.place(id, offset, kind) { return Some((b.scratch.clone(), at)); } // The new batch's pass reads what those shaders wrote: they finish first. if on && wrote_before && self.batch.is_none() { unsafe { list.list.barriers(&[crate::indirect::uav_barrier()]) }; } self.batch = None; let (mut table, scratch) = crate::indirect::open_batch(list, (id, &args.buffer), &argument_copies(args))?; ``` (`on` is the switch; `kind != 2` leaves indirect dispatches as they are.) It is a workaround at the place the symptom shows. The exact condition is probably "a shader whose unordered views overlap a source of the open batch was recorded", which would cover dispatches as well without the cost; I have not written that. ## Not fixed by this Shadows and bushes still pop along a walk. A frame-by-frame pop count over twelve recorded replays of one walk gave 5.8 (unchanged), 5.5 and 6.0 big pops per 1000 frames for the variants: no difference. That is a separate fault. ## Side note The title's depth-pyramid sampler is `CLAMP_BORDER` with a transparent-black border (words 438, 0xc00000, 0x18500000, 0), so on the console a test rectangle that reaches past the screen reads 0 (farthest) there. `lower.rs`'s gather-with-level emulation clamps coordinates to the edge instead. I tried border semantics behind a switch; it did not turn out to be the cause of the above, and I have no case where it changes a picture.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-04 21:47:33 +00:00
Author
Owner

@⁠tommiehansen on GitHub · 2026-12-05 15:58 UTC · original

There's now a PR for this in #597, based on your findings. The reported fix looks promising and doesn't seem to cost much FPS. It's still waiting for review/merge. :)

**@⁠tommiehansen** on GitHub · 2026-12-05 15:58 UTC · [original](https://github.com/lobomfz/VIctory-xmem/issues/523#issuecomment-7440894302) There's now a PR for this in #597, based on your findings. The reported fix looks promising and doesn't seem to cost much FPS. It's still waiting for review/merge. :)
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/lobomfz--VIctory-xmem#523
No description provided.