Skip to content

[BUNDLE] #1296 (texture mip drop) resolved onto the GPU bundles by antikohza, stacked on #1542 - #1617

Closed
MamaLeVrai wants to merge 157 commits into
Marvisak:mainfrom
MamaLeVrai:bundle/texture-mip-drop
Closed

MamaLeVrai wants to merge 157 commits into
Marvisak:mainfrom
MamaLeVrai:bundle/texture-mip-drop

Conversation

@MamaLeVrai

Copy link
Copy Markdown

#1296 (texture mip drop for low-VRAM cards) resolved onto the GPU bundles, by its author. antikohza did the resolution and published it as a branch on top of #1542 (see the comment there); this PR is that branch as it is, so that #1296 can be reviewed and merged on the stack (#1418, #1426, #1439, #1542) instead of conflicting with it. The commits and their authors are not touched.

For reviewers and for anyone verifying with an agent (Claude, Codex, a person): this is a [BUNDLE] PR, stacked on #1542, which is itself on #1418, #1426 and #1439. Until they land, their commits show here too.

What it is

#1296 adds VICTORY_TEXTURE_MIP_DROP (clamped 0..=3), a quality switch that drops the top mips of host textures so a 6-8 GB card does not run out of committed memory while the world streams, plus discrete-GPU selection on hybrid laptops (matching the adapter's LUID) and an automatic default: when the variable is not set, drop = 1 on a GPU with 8.5 GiB or less of dedicated VRAM, 0 otherwise; an explicit setting always wins. Its description has the root cause analysis and the measurements (it fixes #737 and #1226).

That default changes behaviour for owners of 4-8 GB cards (their textures are halved unless they set the variable), which is the point of the PR and worth a maintainer's decision.

What was reconciled onto the stack

From antikohza's comment on #1542 (antikohza/VIctory@0d79788):

Verification

I ran the same checks on the branch (Windows 11, RX 6950 XT, Rust 1.98.1, the pinned toolchain):

Check Result
cargo clippy --workspace --all-targets --locked -- -D warnings clean
cargo clippy --workspace --all-targets --all-features --locked -- -D warnings clean
cargo test --workspace --locked 469 passed, 0 failed, 8 ignored (two runs; #1542 alone: 463 passed, 8 ignored; main: 342 passed, 6 ignored)

antikohza reports the same three checks, plus xtask policy, passing in their fork's CI (run 45473319819). The title was not run. No game data is used or committed.

Re-verify in one go

git fetch https://github.com/MamaLeVrai/VIctory.git bundle/texture-mip-drop
git checkout FETCH_HEAD
cargo clippy --workspace --all-targets --locked -- -D warnings
cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
cargo test --workspace --locked

AI-assisted (Claude Code); no game data.

🤖 Generated with Claude Code

a55uka and others added 30 commits November 24, 2026 00:08
The console's GPU allows uses of some formats that other host GPUs do
not. On an RTX 4070 two 2560x1440 textures failed to create with
E_INVALIDARG (vkd3d-proton: "Requested resource flags Marvisak#5, but no format
in cast list supports it"): format 86 (BGRA8) with unordered access, and
format 115 (B4G4R4A4) as a render target.

When creation fails, try again without unordered access, then without
render-target use, as is already done for depth targets that ask for
unordered access. The views the host cannot make are skipped. A clear
value is only passed while the texture is still a render target or
depth target, since the host refuses it otherwise.

Not checked: whether the title draws to or writes these textures in a
way that now goes missing.

Tested: Linux (Wine 11.21, vkd3d-proton 3.1), i7-12700K, RTX 4070. The
two textures are created and the title runs on.
Co-Authored-By: GPT 6.2 Sol <noreply@openai.com>
Ask Windows for the live allocation type before guarding physical-page views. Keep the existing VirtualQuery fallback for unknown region flags and query failures. This avoids walking a long run of read-only pages solely to learn its memory type.

Validate ordinary mapped files, executable images, private stack memory and free addresses alongside the existing pagefile guard and write-watch tests.
Textures in memory with no write watch (the physical-page views of the
texture pool) were checked with committed() and then read directly,
twice (hash, detile). A title unmapping those pages in between, for
example evicting a texture a big descriptor table still lists, faulted
on the read, and the vectored handler takes only writes. The memory is
now read through copy_mapped (ReadProcessMemory, zeros for unmapped
pages), as the watched path already does, into a per-thread scratch
buffer reused between textures.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
frame::wait marked the tick it waited for as taken (LAST) only after
the sleep, outside the clock's lock, so two threads waiting for one
event kind at once both got the same tick and both returned on it,
against the module's once-per-tick rule (an origin wait then begins two
frames in one interval). next_tick now takes the tick under the clock's
lock when the wait comes within its time-out; a time-out takes none, as
before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace implicit D3D12CreateDevice(None, ...) with explicit DXGI adapter
selection via IDXGIFactory6::EnumAdapterByGpuPreference(HIGH_PERFORMANCE)
(with IDXGIFactory1::EnumAdapters1 fallback), skipping software adapters
by default while preserving diagnostics VICTORY_D3D12_WARP software
validation.

Add optional VICTORY_D3D12_ADAPTER override supporting either a 0-based
hardware adapter index or a case-insensitive description substring match.

Probe and store host D3D12 capabilities on Host in HostCaps (adapter
description, vendor/device IDs, dedicated VRAM, Options 0/1/5/7/9/11,
and highest supported shader model), log a single concise startup summary,
expose capability getters on Host (including supports_wave64,
wave_lane_count_max, supports_atomic_int64_typed, and
resource_binding_tier), and add unit tests covering adapter filter
parsing/matching, capability helpers, and WARP device capability probing.
No graphics object's interface list holds IUnknown, so QueryInterface
for it (and every call that hands out an object by interface id) said
E_NOINTERFACE and returned null. COM code asks for it to compare two
pointers for identity, to keep an object as a plain reference, or to
pass it on to an API that takes any object.

object::is, which all of those go through, now also matches IUnknown.
The DXGI device answers with the D3D12 device, which it already stands
for: one pointer whichever of the object's interfaces is asked.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Two copies into title memory asked the host about the destination before
every copy. copy_mapped's own comment tells what that costs: asking
VirtualQuery about the source took about 2 ms per copy in the title's big
pools, because the query walks the page tables to the end of the region
with the same state, whatever the size of the copy.

- A list's copy into title memory checked that the whole destination was
  committed first, with VirtualQuery. The destinations were private pools
  of about 600 MiB.
- The copy-back of what shaders wrote used WriteProcessMemory, which asks
  for the destination's region before it writes: the same walk for every
  64 KiB piece.

Both now rely on the kernel copy the other copies already use
(ReadProcessMemory on our own process). It fails on a destination page
that is not mapped writable as it does on a source page it cannot read,
without faulting. A title destination is asked for its region only after
its copy has failed, which keeps the page retries (they write their zeros
themselves) off unmapped memory. write_mapped does what it did: mapped
pages are written, unmapped and read-only ones are not.

One difference: a title destination that was not all mapped used to be
left alone, and the bytes before its first unmapped page may now arrive
(the kernel copy stops at that page). No title copy of the run below had
such a destination, and none failed.

Measured in the world (first mission's intro; i7-13650HX, RTX 4060
Laptop, diagnostics build), with the old and the new call timed on the
same copies of one run, 41 frames of about 1.15 s each:

  title copies, 80 per frame (0.45 MB): the check alone 59.5 ms per
  frame; the whole copy now 0.56 ms
  copy-back, 110 pieces per frame (4.9 MB): 38.6 ms per frame; now
  0.55 ms

That is 98 ms of a frame (8.6 %) down to about 1 ms. In stacks of the
submitting thread sampled at 10 Hz, VirtualQuery under these two calls
was 47 of 462 samples before and 0 of 189 after.

Two tests run both copies against reserved memory with a committed block
on each side of a hole (no GPU, no game data).

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

host_shader goes through the shader cache, which translates on a miss
and then writes the entry. When the write failed (a full disk, a file
where the entry's folder goes, a scanner holding the new file during
the rename), the error came back as the shader's: a translation that
had worked was thrown away, the shader was marked as not translating
for the rest of the run, and every draw using it was dropped.

The converter now records that its translation worked; a cache error
after that is logged as such and the shader is translated without the
cache, as when there is none.
A mesh pipeline never loaded from the host pipeline library: LoadPipeline
refused it with E_INVALIDARG (debug layer 972, "does not match the one used
to create the PSO") even with the very stream it was made from, so every
mesh pipeline was compiled again on every run and its store then refused
(970, "already exists"), the 972/970 pair in Marvisak#264.

Measured with synthetic pipelines on an RTX 3060 Ti, Windows 11 26300, with
and without the debug layer: compute, graphics (DXBC and DXIL) and VS/PS
streams load; a mesh stream loads only with a PRIMITIVE_TOPOLOGY subobject
that is not UNDEFINED. The debug layer wants it to match the mesh shader's
output topology (1323), and the translation makes triangle mesh shaders
only (mesh_prologue), so the stream now names TRIANGLE. Mesh pipelines get
a new library name ("mesh triangles"), so entries stored without a
topology are not looked up again.

a_mesh_pipeline_loads_from_the_library makes a mesh pipeline twice through
mesh_pipeline and requires the second to come from the library; it fails
before this change and passes after (skipped without a PC dxc.exe).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An empty slice still has an address, and vkd3d-proton answers E_INVALIDARG to a non-null blob of length 0, so under Wine no pipeline library was ever created and host pipelines were not kept.
The title's descriptor writes and texture releases reach the host at
once, from its own threads, while the host runs a submission for most of
a second in the world. A descriptor slot rewritten then dropped the
resource it held, and a released title texture dropped its host copy,
while the running submission still read them: device-removed data showed
a page fault inside a freed 1024x1024 BC7 texture, about 65 s into the
world (DXGI_ERROR_DEVICE_HUNG, RX 7600).

Those objects now go to a retired list tagged with the submission count
and are dropped when that submission has been waited for (at once if
none is running).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSD61BBk7E79WkryEQA
The world's peak counted 3,630 host textures, 8.9 GB, against a 7 GB
video memory budget on an 8 GB card: the driver moves the excess to
system memory, where it counts against the commit limit. A texture the
title makes and the GPU never uses (no view, target, copy or barrier)
now costs nothing; the creation state and clear value are kept for the
copy made on first use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSCvCZuokASx7f59sAG
The device-removed report printed `[heap N: …]` after every user-data
value, constants included, so a constant 0 next to slot 0's view read as
a draw using slot 0. Each value is now marked `table` or `const`; a table
is followed by `[heap N: …]` as before, a constant by
`[as heap index N: …]`, kept because dynamic resources may index the heap
with one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A root SRV is a bare GPU address: nothing bounds what a shader reads
through it. Vertex fetch reads its stream through a root SRV with no
record limit, and a mesh shader read past the end of the buffer's host
copy into memory the host had already freed (the "inside freed texture"
device removal after the fix for Marvisak#59: the fault lay just past the copy's
end, in the gap where released textures had been).

Each root SRV is now a one-descriptor table holding a raw view of the
host copy from the root address to the copy's end, made once per address
per list in the heap's dynamic slots; reads past the end return zero, as
for any bounded view. A root SRV the title did not set, or one with no
host copy, gets a null raw view (an unset table is undefined). Addresses
not on 16 bytes, which a raw view cannot start at, read zeros and are
logged once. VICTORY_ROOT_SRV_DIRECT=1 restores root descriptors.
…s several

GetWriteWatch refuses a range that spans more than one allocation, and the
runtime reserves title memory allocation by allocation, so a buffer over
several of them was taken as not write-watched and copied whole on every
refresh, even where every part of it is watched.

When the question for the whole range fails, ask it again per allocation.
Parts never committed cannot have been written. If a committed part is not
write-watched, nothing changes: the range falls back as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Of the write-watch questions still refused in the world, almost all were
ranges inside one allocation reserved but not committed at all, copied
whole (as zeros) on every refresh. Nothing can have written there, so
answer them with no writes; once the title commits the memory, the range
is asked about normally.

Also keep the test allocations instead of freeing them: the journal keeps
their pages, and a later test given the same addresses found them written.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A draw whose table starts at a title slot the capped host heap does not
have, and that was not made afresh, got the title's offset as its user
data; the shader then indexed ResourceDescriptorHeap past the heap's end.
On NVIDIA that reads garbage descriptors and the device hangs (Marvisak#71). In
three DRED reports from an RTX 4060 Ti, 13 of 14, 22 of 29 and 20 of 29
of the tables the unfinished draws bound start past slot 1,000,000 (the
title's per-draw tables sit at its heap's top, around 1.2 million).

Such tables are made afresh, but when that fails (no free dynamic slot:
the 65,536 of a capped heap run out seconds into the world; or entries
reaching past the title heap's end) the draw fell back to the title's
offset. The draw or dispatch is dropped instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MamaLeVrai and others added 14 commits November 24, 2026 19:49
…arvisak#1439, verified together

Merges Marvisak#346 Marvisak#431 Marvisak#493 Marvisak#967 Marvisak#1082 Marvisak#1143 Marvisak#1165 Marvisak#1173 Marvisak#1265 Marvisak#1298 on top of the
three GPU bundles (Marvisak#1418, Marvisak#1426, Marvisak#1439, on main ffe310e), each head
unchanged. Marvisak#346, Marvisak#967, Marvisak#1082 and Marvisak#1143 conflict in host.rs (and Marvisak#346 in
indirect.rs) with the PRs of those bundles; those hunks were merged by
keeping both sides, and each PR was kept only if cargo clippy -p
victory-gpu --all-targets --all-features -- -D warnings still passed.

cargo clippy --workspace --all-targets --locked -- -D warnings, with and
without --all-features, is clean and cargo test --workspace --locked passes
(463 passed, 8 ignored; main has 342 passed, 6 ignored).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…d adapter probe

- Adjust ResourceMinLODClamp across all 7 SRV dimensions and avoid duplicate GetDesc() in descriptor/host.rs
- Return (texture, drop) from host_texture() so HostTexture.mip_drop is computed once, and guard BCn 4x4 block alignment for custom MIN_SIZE
- Replace mip-drop mismatch skip in copy_resource() with safe CopyLocation::subresource overlapping-mip copies
- Track per-subresource HostWritten via zero-alloc u128 bitmask (with HashSet fallback) for partial copies and resolves
- Probe D3D_FEATURE_LEVEL_12_0 in best_adapter() with fallback to default adapter in Host::create()
- Add unit tests for out-of-range SRV clamping, ResourceMinLODClamp, BC7 alignment, VRAM threshold, and HostWritten tracking
Copilot AI balanced review requested due to automatic review settings November 24, 2026 19:50

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@Marvisak

Copy link
Copy Markdown
Owner

Automated triage for the maintainers. Closing because this pull request re-packages other open pull requests. Each of those is reviewed on its own, so a bundle cannot be merged.

See #1296.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

@Marvisak Marvisak closed this Nov 25, 2026

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-gpu/src/copystat.rs, crates/victory-gpu/src/descriptor/host.rs, crates/victory-gpu/src/device.rs, crates/victory-gpu/src/draw.rs, crates/victory-gpu/src/host.rs). It will be reviewed once it is rebased onto the current 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.

Patch (fork): add VICTORY_TEXTURE_MIP_DROP quality switch for low-VRAM budgets (75%–93% texture memory savings on 6GB/8GB GPUs)