Skip to content

GPU: make placed-texture heap slots that shaders actually read - #1962

Open
antocorvo3000 wants to merge 1 commit into
Marvisak:mainfrom
antocorvo3000:pr-heap-usage
Open

antocorvo3000 wants to merge 1 commit into
Marvisak:mainfrom
antocorvo3000:pr-heap-usage

Conversation

@antocorvo3000

@antocorvo3000 antocorvo3000 commented Nov 25, 2026 •

Copy link
Copy Markdown

Shaders that take descriptors from the resource heap itself (bindless
materials) read placed-texture slots that the heap mirror leaves null
until a draw reads them through a table (the shortcut that keeps ~20,000
host textures from being made at once). In Grand Theft Auto VI most
world materials sample that way, so their G-buffer albedo came out
black and the lit scene stayed dark.

Translated shaders now mark each heap slot they take a shader resource
view from in a bitmap (u1 in the memory space, an atomic OR per lane),
bound per list like the written-pages bitmap. After the list ran, each
marked slot still holding a placed texture left for later is made, so it
reads from the next list on. Only the textures in use are made.

VICTORY_HEAP_USAGE=0 turns the marks off (shaders as before). The frame
line reports slots marked, views made, and why marked slots were not
made. Unit tests leave the marks off (the hardware harness binds only
the parameters each test names).

Measured in the world: albedo coverage from ~20% to 99% of the screen;
about 10-20 views made per 5 s once streamed in; no view failed to make.

Testing

  • cargo test --release -p victory-shader -p victory-gpu --lib: 246 + 141 passed.
  • In game (Grand Theft Auto VI, Series X mode): world albedo went from ~20% to 99% of the screen; no placed-texture view failed to make.

Shaders that take descriptors from the resource heap itself (bindless
materials) read placed-texture slots that the heap mirror leaves null
until a draw reads them through a table (the shortcut that keeps ~20,000
host textures from being made at once). In Grand Theft Auto VI most
world materials sample that way, so their G-buffer albedo came out
black and the lit scene stayed dark.

Translated shaders now mark each heap slot they take a shader resource
view from in a bitmap (u1 in the memory space, an atomic OR per lane),
bound per list like the written-pages bitmap. After the list ran, each
marked slot still holding a placed texture left for later is made, so it
reads from the next list on. Only the textures in use are made.

VICTORY_HEAP_USAGE=0 turns the marks off (shaders as before). The frame
line reports slots marked, views made, and why marked slots were not
made. Unit tests leave the marks off (the hardware harness binds only
the parameters each test names).

Measured in the world: albedo coverage from ~20% to 99% of the screen;
about 10-20 views made per 5 s once streamed in; no view failed to make.
@DesertGamer

Copy link
Copy Markdown

VIctory V2: community PRs, merged and tested

Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch.

Where it stands today: launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1).

⚠️ Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk.

Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help:
https://DesertGamer/VIctory-V2

Unofficial community fork of Marvisak/VIctory, GPL-3.0.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

This pull request does not merge cleanly into main. Conflicting files: crates/victory-gpu/src/shader_cache.rs, crates/victory-shader/src/emit/host.rs, crates/victory-shader/src/emit/shader.rs.

It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

@ryotdev

ryotdev commented Nov 25, 2026

Copy link
Copy Markdown

On Windows I reproduced a warm-cache issue at 3c18447. Start with VICTORY_HEAP_USAGE=0, translate a shader that reads a bindless texture, then start a fresh process with the same cache and VICTORY_HEAP_USAGE=1. The second process reports a cache hit and the returned shader still has heap_usage=false. Starting with the modes reversed also reuses the first translation. This can hide the effect of the setting in an A/B test.

Fix and regression assertion. The cache now keys on the same effective boolean that controls emission and feedback consumption. With that commit, the first run in each mode missed, repeat runs in both modes hit with matching flags, and the default shared the enabled cache. I tested both toggle orders in separate Windows processes and ran the GPU crate suite with diagnostics on WARP (144 passed, 2 ignored). AI-assisted.

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge conflict with current main (940d32f) — git merge origin/main fails on the PR head; rebase needed. GPU: make placed-texture heap slots that shaders actually read — the shader-visible side of placed textures; relates to #1730's root views (merged) and #1971's descriptor metadata. Will re-test after rebase.

@r4tedx

r4tedx commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

@antocorvo3000, this PR conflicts with main 940d32f, so I rebased it there, keeping your authorship. You're welcome to take the branch for this PR: r4tedx/VIctory@rebase/1962-on-main (015274f4).

  • 0c791faa: your change, where it applied cleanly.
  • 3a4d6a8e: the conflict resolution. main now uses u1 and shader-cache flag bit 5 for its buffer-write marks (cd94d35), so the heap-read marks move to u2 and bit 6. That way both run side by side.
  • 015274f4: a fix for @ryotdev's warm-cache report. VICTORY_HEAP_USAGE=0 changes the DXIL but was in neither the shader-cache key nor the pipeline pre-build tag. Now both include it. With marks on (the default), nothing is added to either, and a synthetic test (heap_usage_changes_the_key_only_when_disabled) checks both.

Tested on WARP only (the software adapter), each revision with its own build:

main 940d32f rebased 015274f4
victory-gpu --lib --features diagnostics 146 passed, 0 failed, 2 ignored 147 passed, 0 failed, 2 ignored
victory-shader --lib (every-adapter tests skipped) 244 passed, 2 failed 244 passed, 2 failed (the same two, same values: gathers_at_a_level_match_the_hardware, permutes_read_the_lane_named_and_zero_from_lanes_left_out)
clippy -D warnings, both crates, with and without diagnostics clean clean

Not verified: the shader test harness runs with heap marks off, so placed-texture feedback end to end, hardware rendering and a warm cache across processes are untested. The title was not used in these tests.

AI-assisted

@Slay326

Slay326 commented Nov 25, 2026

Copy link
Copy Markdown

Hardware test on an RTX 3070 (8 GB VRAM, 32-lane waves), Windows 11, Series X mode. I merged the PR onto our local test branch: main plus #1890, #1906, #1779, #1763, #1762, #1883, and a page-mark guard like #2167.

The image: the merge works. Before, world albedo covered ~1.3 % of the screen in a target dump (the G-buffer albedo target, 2560x1440). After the merge, materials show in the world and in cutscenes: prison clothes, shirt prints, hair, buttons.

Merge conflict: on current main (940d32f), u1 in the memory space is already taken by the buffer views' written-pages bitmap (VIEW_WRITES). The heap-usage bitmap needs its own register. I used u3; r4tedx's rebase (015274f) uses u2. Either works, since VIEW_MARKS is t2, an SRV. The shader-cache flag goes to bit 6.

Performance (the main problem on this card): the bitmap comes from shared_buffer, which is system memory. Every texture read does an unconditional atomicBinOp OR into it, and with a uniform index all lanes of a wave hit the same dword.

Run (480 s, BVH builder skipped) GPU ms/frame in the world Result
without the PR ~190 ~2.2 fps
with the PR, bitmap in system memory 3,000-6,900 (0.1-0.2 fps) device removed (hung, 0x887A0006) after ~450 s
with the PR, bitmap in GPU memory 130-1,400 still 0.3-0.8 fps, device removed after ~167 s
  • The atomics: the same pattern (system-memory bitmap, all lanes on one dword) cost us 560 us per 64-thread group in a synthetic test on the written-pages bitmap. A load first, and the atomic only where the bit is clear, brought that to 0.1 us (Shaders: guard memory_dirty atomics with test-before-or and coalesce page-table loads (FIND-12) #2167 does the same).
  • Bitmap in GPU memory: in my patch the bitmap lives in GPU memory, one per list, kept across resets. It is zeroed by a copy at the first bind of each recording and copied to a read-back buffer as the list closes. Patch/branch available if useful. This removes the multi-second GPU stalls.
  • What remains on 8 GB: the PR then makes 300-580 placed-texture views per 5 s. Process commit grows past 34 GB, then come page-fault storms (313k against 8k per interval without the PR) and many 0x8007000E "no host texture / no upload buffer" errors. The device is then removed after ~167 s.
  • Suggestions: a budget for the textures made per frame, or releasing views that are no longer marked, would probably be needed for 8 GB cards. A shader-side test-before-or guard would also help, but GPU: make placed-texture heap slots that shaders actually read #1962 notes that a branch there broke dominance. Callers keep emitting into the block they started in, so the guard would have to hand the new block back to them.

AI-assisted.

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.

7 participants