Skip to content

GPU: bound the null sampler staging heap - #83

Open
FIocker wants to merge 1 commit into
Marvisak:mainfrom
FIocker:gpu/null-sampler-staging-heap
Open

FIocker wants to merge 1 commit into
Marvisak:mainfrom
FIocker:gpu/null-sampler-staging-heap

Conversation

@FIocker

@FIocker FIocker commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

The heap initializer uses a CPU-only staging heap to copy null descriptors. It used the view-heap batch size (65,536 descriptors) for samplers too. A host can accept the shader-visible sampler heap and reject that temporary heap, leaving the shader-visible slots undefined.

Use the portable sampler limit to size each sampler batch. If initialization fails, report the error and stop before exposing the heap. This change is independent of the refusal-triggered sampler capacity fallback in #74 and applies to portable-sized heaps as well. Refs #65.

The new synthetic test requires successful initialization of a portable-sized sampler heap when the test has a D3D12 device. It passed on Windows WARP with VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --locked --features diagnostics portable_sampler_null_fill_fits_the_host_limit. The asset policy passed.

@lordon1a

Copy link
Copy Markdown
Contributor

Verified d8f063b04 on Windows 11 (x86_64-pc-windows-gnullvm, rustc 1.100.0, applied cleanly to main@35b054ec0): pass.

  • cargo xtask policy: 150 files ok
  • cargo test -p victory-gpu: 40 passed, 0 failed (including portable_sampler_null_fill_fits_the_host_limit on Intel Iris Xe).

Small edge-case note: in fill_null, if total == 0 (e.g. a zero-slot sampler heap), block_count becomes 0 and CreateDescriptorHeap(NumDescriptors: 0) will fail (E_INVALIDARG), which now causes HostHeap::new to return None due to the added return None; at line 134. Adding if total == 0 { return Ok(()); } at the top of fill_null avoids that edge case.

AI-assisted.

@DaviTostes

Copy link
Copy Markdown

Tested d8f063b under Wine 11.22 + vkd3d-proton 3.1 on Arch Linux x86_64 (AMD RX 9060 XT, RADV 26.3.1), Windows build with cargo xwin ... --target x86_64-pc-windows-msvc: pass, no regression.

No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).

@DaviTostes

Copy link
Copy Markdown

Merged with #86 (a80eb17 + d8f063b): the textual merge succeeds, but the result does not compile — the two PRs disagree on HostHeap::new's return type:

error[E0308]: mismatched types
   --> crates/victory-gpu/src/descriptor/host.rs:178:20
     |     ) -> Self {
     |          ---- expected `HostHeap` because of return type
  178|             return None;
     |                    ^^^^ expected `HostHeap`, found `Option<_>`

So at least one of #83 / #86 / #74 / #100 needs to pick up the chosen HostHeap::new signature before they can coexist; on its own #83 is 37 passed / 3 environment-only failures under Wine (see above). This is the same convergence the #65 family needs anyway.

No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).

r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
…ys inside the heap)

Vaximous's Marvisak#483: every descriptor-heap index the lowering computes is
bounded by the bound heap's guard slot (an index at or above it reads
it), which the host passes in a user-data dword of its own.

Conflict resolutions:
- crates/victory-gpu/src/descriptor/host.rs: this tree's sizing is kept
  (Marvisak#86/Marvisak#83/Marvisak#251, and 2^18 dynamic slots on a capped heap); a view heap
  is made one slot larger, the guard slot, after its dynamic slots and
  outside the pool HostHeap::dynamic hands out (`spare` does not count
  it). On a capped heap that is 737,855 title slots, 262,144 dynamic
  ones and the guard at slot 999,999. Marvisak#483 had the guard at
  `count + DYNAMIC` with the pool sized by a constant; here the pool is
  sized by `spare` (Marvisak#86), so guard_slot() is `count + spare`.
- A sampler heap's guard is its last slot, dynamic ones included
  (`count + spare - 1`), not Marvisak#483's `count - 1`: Marvisak#86 makes sampler
  tables afresh in a capped sampler heap's dynamic slots, which
  `count - 1` would have clamped away.
- crates/victory-shader/src/emit/lower.rs, Lower::new: both fields are
  kept (`dead`, `guard_slots`).
- crates/victory-shader/src/emit/valu_tests.rs: this tree's tests and
  Marvisak#483's new one are both kept.

Changes beyond the PR:
- emit/lower.rs, fetched_index (Marvisak#307's per-lane heap index, which
  Marvisak#483 did not know): it goes through heap_guard too. It is an address
  from a lane's data, as heap_index's.
- emit/image_tests.rs (Marvisak#160's harness): the user data it fills gets the
  guard entries (host::guard).
- descriptor/host.rs: tests the_guard_slot_is_past_every_dynamic_slot,
  and the guard's place in a_capped_view_heap_keeps_its_dynamic_slots.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@mercuryVM mercuryVM 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.

Tested d8f063b on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (228 passed, 0 failed; older base). cargo test -p victory-gpu --features diagnostics --lib portable_sampler passes on the hardware adapter.

  • Capping the CPU staging block at D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE (2048) for samplers, and at total in general, means the temporary heap is never bigger than the heap it fills. The copy loops keep their doubling-then-blocks shape with the new size.
  • Returning None after a failed fill, instead of handing out a heap whose slots are undefined, is the important half. A later null-descriptor read then can't sample garbage.

No issues found.

AI-assisted (Claude Code).

mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 24, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Xeltax pushed a commit to Xeltax/VIcky that referenced this pull request Nov 24, 2026
Xeltax pushed a commit to Xeltax/VIcky that referenced this pull request Nov 24, 2026
…Marvisak#358 Marvisak#89 Marvisak#331 Marvisak#86 Marvisak#83 Marvisak#211 Marvisak#260 Marvisak#275)

Conflict in crates/victory-gpu/src/descriptor/host.rs: gpu-state (Marvisak#251)
moved the dynamic-slot search into free_table(); gpu-draw (Marvisak#86) bounds
the search by the heap's spare slots instead of DYNAMIC. free_table() works
over taken.len(), which is the spare count, so the helper is kept with
gpu-draw's spare-based cursor wrap. Both sides' tests kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-gpu/src/descriptor/host.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants