Shader translator: Structured buffer stride support incomplete, causes black frames #3366

Open
opened 2026-11-26 20:43:32 +00:00 by github-bot · 1 comment
Owner

@⁠Mdemets on GitHub · 2026-11-26 20:36 UTC · original

Shader translator: Structured buffer stride support incomplete, causes black frames

Summary

Commit 4c52e97 "GPU: Bind the stride of root-selected shader buffers" added support for handling structured buffers with unknown strides, but the implementation was left incomplete. The stride discovery mechanism exists, but the stride values are never populated from the descriptor heap. This causes shaders accessing structured buffers to fail translation with "a structured buffer of unknown stride is not supported", dropping all draws and producing black frames.

Impact

  • GTA6 on RTX A5000: Menu text and 3D geometry render on hardware but appear black in Victory's frame capture
  • Affects any title using compute or pixel shaders that access structured buffers with dynamic strides
  • Fallback: Shader cache doesn't use translate_with_view_strides(), so shaders fail to translate entirely

Root Cause

What commit 4c52e97 added:

  1. ✅ StructuredBinding type to identify buffer bindings
  2. ✅ translate_with_view_strides() function that accepts a stride callback
  3. ✅ Pipeline's find_stride_bindings() to probe shaders and discover which bindings are accessed
  4. ✅ Cache format update (VSH1 → VSH2) to store stride metadata

What was left incomplete:

  1. ❌ Stride population — No code populates Pending::strides with actual stride values from descriptors
  2. ❌ Shader cache integration — shader_cache.rs still uses translate_with_wave32() (line 94) instead of translate_with_view_strides()
  3. ❌ Pipeline specialization — Pending::specialize_shaders() expects strides but Pending::strides is initialized empty and never filled

Code Analysis

In crates/victory-gpu/src/pipeline/make.rs:

Line 72: Strides initialized empty:

strides: Vec::new(),

Line 87-98: Pipeline attempts to make without strides, discovers bindings, but never populates strides:

if self.strides.is_empty() {
    let made = HostPipeline::new(&self.shaders, self.graphics.as_deref(), &[]);
    if made.is_none()
        && let Some(bindings) = self.find_stride_bindings()  // ← Discovers bindings
    {
        let _ = self.bindings.set(bindings);  // ← Stores them, but...
    }
    // ← Never looks up actual stride values from descriptor heap
}

Line 140-148: specialize_shaders() does binary search on strides, but it's empty:

let i = self.strides.binary_search_by_key(&binding, |&(key, _)| key).ok()?;
let stride = self.strides[i].1;  // ← Always fails because strides is empty

In crates/victory-gpu/src/shader_cache.rs:

Line 94: Cache uses basic translator without stride callback:

victory_shader::emit::translate_with_wave32(c, wave32)  // ← Wrong function

Should be:

translate_with_view_strides(c, wave32, &|binding, _required| {
    // Look up actual stride for binding from descriptor heap
})

Solution

Part 1: Populate strides in pipeline

Add Pending::populate_strides_from_descriptors() method:

After line 92, once bindings are discovered:

if made.is_none() && let Some(bindings) = self.find_stride_bindings() {
    let _ = self.bindings.set(bindings.clone());
    if let Some(strides) = self.populate_strides_from_descriptors(&bindings) {
        // Mutate self.strides with discovered values
        // Then retry specialization
    }
}

New method:

fn populate_strides_from_descriptors(&self, bindings: &[StructuredBinding]) -> Option<Vec<(StructuredBinding, u32)>> {
    // For each binding:
    // 1. Access descriptor heap via self.graphics or HLE
    // 2. Read buffer descriptor at (slot, offset_dwords)
    // 3. Extract stride using descriptor::selected_buffer() or equivalent
    // 4. Collect into sorted Vec<(StructuredBinding, u32)>
}

This requires access to the descriptor heap, which should be available via:

  • crate::descriptor::Heap
  • crate::descriptor::selected_buffer()
  • BufferRead::stride field

Part 2: Wire stride support into shader cache

Update shader_cache.rs line 94 to use translate_with_view_strides() with a default or conservative stride assumption. However, this is tricky because:

  • Cache doesn't have access to actual descriptor bindings
  • Hardcoding stride=4 caused game crashes (wrong memory access)
  • Alternative: Skip stride caching entirely and defer to pipeline's specialization

Part 3: Make pipeline always specialize

Ensure the pipeline always calls specialize_shaders() when stride bindings are discovered, rather than giving up after the first attempt.

Testing

Repro steps:

  1. Run GTA6 title with diagnostics binary
  2. Enable VICTORY_CAPTURE and VICTORY_AUDIO_CAPTURE
  3. Currently: Black frames, 37 compute shader drops with "unknown stride" errors
  4. After fix: Should see menu text, 3D geometry, and audio

References

  • Commit 4c52e97: "GPU: Bind the stride of root-selected shader buffers"
  • File: crates/victory-gpu/src/shader_cache.rs (line 94)
  • File: crates/victory-gpu/src/pipeline/make.rs (lines 72, 87-98, 128-154)
  • Related: crates/victory-gpu/src/descriptor/host.rs (BufferRead struct, selected_buffer fn)
  • Related: crates/victory-shader/src/emit/mod.rs (translate_with_view_strides function)
**@⁠Mdemets** on GitHub · 2026-11-26 20:36 UTC · [original](https://github.com/Marvisak/VIctory/issues/3366) # Shader translator: Structured buffer stride support incomplete, causes black frames ## Summary Commit 4c52e97 "GPU: Bind the stride of root-selected shader buffers" added support for handling structured buffers with unknown strides, but the implementation was left incomplete. The stride discovery mechanism exists, but the stride *values* are never populated from the descriptor heap. This causes shaders accessing structured buffers to fail translation with "a structured buffer of unknown stride is not supported", dropping all draws and producing black frames. ## Impact - **GTA6 on RTX A5000**: Menu text and 3D geometry render on hardware but appear black in Victory's frame capture - Affects any title using compute or pixel shaders that access structured buffers with dynamic strides - Fallback: Shader cache doesn't use `translate_with_view_strides()`, so shaders fail to translate entirely ## Root Cause ### What commit 4c52e97 added: 1. ✅ `StructuredBinding` type to identify buffer bindings 2. ✅ `translate_with_view_strides()` function that accepts a stride callback 3. ✅ Pipeline's `find_stride_bindings()` to probe shaders and discover which bindings are accessed 4. ✅ Cache format update (VSH1 → VSH2) to store stride metadata ### What was left incomplete: 1. ❌ **Stride population** — No code populates `Pending::strides` with actual stride values from descriptors 2. ❌ **Shader cache integration** — `shader_cache.rs` still uses `translate_with_wave32()` (line 94) instead of `translate_with_view_strides()` 3. ❌ **Pipeline specialization** — `Pending::specialize_shaders()` expects strides but `Pending::strides` is initialized empty and never filled ## Code Analysis ### In `crates/victory-gpu/src/pipeline/make.rs`: **Line 72**: Strides initialized empty: ```rust strides: Vec::new(), ``` **Line 87-98**: Pipeline attempts to make without strides, discovers bindings, but never populates strides: ```rust if self.strides.is_empty() { let made = HostPipeline::new(&self.shaders, self.graphics.as_deref(), &[]); if made.is_none() && let Some(bindings) = self.find_stride_bindings() // ← Discovers bindings { let _ = self.bindings.set(bindings); // ← Stores them, but... } // ← Never looks up actual stride values from descriptor heap } ``` **Line 140-148**: `specialize_shaders()` does binary search on strides, but it's empty: ```rust let i = self.strides.binary_search_by_key(&binding, |&(key, _)| key).ok()?; let stride = self.strides[i].1; // ← Always fails because strides is empty ``` ### In `crates/victory-gpu/src/shader_cache.rs`: **Line 94**: Cache uses basic translator without stride callback: ```rust victory_shader::emit::translate_with_wave32(c, wave32) // ← Wrong function ``` Should be: ```rust translate_with_view_strides(c, wave32, &|binding, _required| { // Look up actual stride for binding from descriptor heap }) ``` ## Solution ### Part 1: Populate strides in pipeline Add `Pending::populate_strides_from_descriptors()` method: **After line 92**, once bindings are discovered: ```rust if made.is_none() && let Some(bindings) = self.find_stride_bindings() { let _ = self.bindings.set(bindings.clone()); if let Some(strides) = self.populate_strides_from_descriptors(&bindings) { // Mutate self.strides with discovered values // Then retry specialization } } ``` **New method**: ```rust fn populate_strides_from_descriptors(&self, bindings: &[StructuredBinding]) -> Option<Vec<(StructuredBinding, u32)>> { // For each binding: // 1. Access descriptor heap via self.graphics or HLE // 2. Read buffer descriptor at (slot, offset_dwords) // 3. Extract stride using descriptor::selected_buffer() or equivalent // 4. Collect into sorted Vec<(StructuredBinding, u32)> } ``` This requires access to the descriptor heap, which should be available via: - `crate::descriptor::Heap` - `crate::descriptor::selected_buffer()` - BufferRead::stride field ### Part 2: Wire stride support into shader cache Update `shader_cache.rs` line 94 to use `translate_with_view_strides()` with a default or conservative stride assumption. However, this is tricky because: - Cache doesn't have access to actual descriptor bindings - Hardcoding stride=4 caused game crashes (wrong memory access) - **Alternative**: Skip stride caching entirely and defer to pipeline's specialization ### Part 3: Make pipeline always specialize Ensure the pipeline always calls `specialize_shaders()` when stride bindings are discovered, rather than giving up after the first attempt. ## Testing Repro steps: 1. Run GTA6 title with diagnostics binary 2. Enable `VICTORY_CAPTURE` and `VICTORY_AUDIO_CAPTURE` 3. Currently: Black frames, 37 compute shader drops with "unknown stride" errors 4. After fix: Should see menu text, 3D geometry, and audio ## References - Commit 4c52e97: "GPU: Bind the stride of root-selected shader buffers" - File: `crates/victory-gpu/src/shader_cache.rs` (line 94) - File: `crates/victory-gpu/src/pipeline/make.rs` (lines 72, 87-98, 128-154) - Related: `crates/victory-gpu/src/descriptor/host.rs` (BufferRead struct, selected_buffer fn) - Related: `crates/victory-shader/src/emit/mod.rs` (translate_with_view_strides function)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 20:43:32 +00:00
Author
Owner

@⁠Ingenioeren on GitHub · 2026-11-27 00:42 UTC · original

I checked this against upstream main 63bcca4. The cited 4c52e97 commit is on a diverged branch. Commit comparison

On main, the heap-indexed path loads the stride at execution time from the VIEW_STRIDES root SRV. The host records the stride from the descriptor in its heap table and binds that table at draw or dispatch time. The shader cache can therefore keep one translation for this path. Stride lowering · Host metadata · Runtime binding

Two synthetic checks passed. The same compiled compute pipeline read the expected values on all 32 lanes across strides of 12, 20 and 12 bytes on both an RX 6750 XT and Windows WARP. Separately, the production heap metadata writer recorded 12, then 20, then cleared the slot to 0 on WARP.

This establishes the heap-indexed case on upstream. The lowering still rejects some sources whose stride it cannot resolve, including a Source::Phi in this path. Could you share the exact VIctory build commit and the first refused shader's hash, stage and error offset? Those would help tell whether this is a branch difference or an uncovered binding shape. The tests above used no game files.

AI-assisted synthetic verification with OpenAI Codex.

**@⁠Ingenioeren** on GitHub · 2026-11-27 00:42 UTC · [original](https://github.com/Marvisak/VIctory/issues/3366#issuecomment-7206688024) I checked this against upstream main `63bcca4`. The cited `4c52e97` commit is on a diverged branch. [Commit comparison](https://github.com/Marvisak/VIctory/compare/4c52e9774570f4f59e3adc70a9435d5456ef6c46...63bcca43c6a00a758510398fa43096ce7e4f7df0) On main, the heap-indexed path loads the stride at execution time from the `VIEW_STRIDES` root SRV. The host records the stride from the descriptor in its heap table and binds that table at draw or dispatch time. The shader cache can therefore keep one translation for this path. [Stride lowering](https://github.com/Marvisak/VIctory/blob/63bcca43c6a00a758510398fa43096ce7e4f7df0/crates/victory-shader/src/emit/lower.rs#L5244-L5286) · [Host metadata](https://github.com/Marvisak/VIctory/blob/63bcca43c6a00a758510398fa43096ce7e4f7df0/crates/victory-gpu/src/descriptor/host.rs#L494-L514) · [Runtime binding](https://github.com/Marvisak/VIctory/blob/63bcca43c6a00a758510398fa43096ce7e4f7df0/crates/victory-gpu/src/draw.rs#L805-L828) Two synthetic checks passed. The same compiled compute pipeline read the expected values on all 32 lanes across strides of 12, 20 and 12 bytes on both an RX 6750 XT and Windows WARP. Separately, the production heap metadata writer recorded 12, then 20, then cleared the slot to 0 on WARP. This establishes the heap-indexed case on upstream. The lowering still rejects some sources whose stride it cannot resolve, including a `Source::Phi` in this path. Could you share the exact VIctory build commit and the first refused shader's hash, stage and error offset? Those would help tell whether this is a branch difference or an uncovered binding shape. The tests above used no game files. AI-assisted synthetic verification with OpenAI Codex.
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/Marvisak--VIctory#3366
No description provided.