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

Closed
github-bot wants to merge 157 commits from gh-pr/1617/head into gh-pr/1617/base
Owner

@⁠MamaLeVrai on GitHub · 2026-11-24 19:50 UTC · original
MamaLeVrai:bundle/texture-mip-drop → main · +10186 −485 · 33 files · 157 commits · closed without merging

#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):

  • list.rs and descriptor.rs: merged without conflict.
  • host.rs: #967's adapter::open() and #1426's device creation kept, a redundant best_adapter() dropped, the LUID-matched DEVICE_MEMORY kept.
  • resource.rs: (texture, drop) = host_texture(...) wired into #431's lazy OnceLock initializer (Resource::host), so the lazy first-use allocation and the retirement after submission combine with the mip drop.
  • texture.rs: #1418's five-argument detile_plane() kept for the existing tests, and a detile_plane_with_drop(..., self.mip_drop, ...) added for dropped-mip staging.

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

**@⁠MamaLeVrai** on GitHub · 2026-11-24 19:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/1617) `MamaLeVrai:bundle/texture-mip-drop` → `main` · +10186 −485 · 33 files · 157 commits · closed without merging **#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](https://git.gtahub.st/github/Marvisak--VIctory/pulls/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`): - `list.rs` and `descriptor.rs`: merged without conflict. - `host.rs`: #967's `adapter::open()` and #1426's device creation kept, a redundant `best_adapter()` dropped, the LUID-matched `DEVICE_MEMORY` kept. - `resource.rs`: `(texture, drop) = host_texture(...)` wired into #431's lazy `OnceLock` initializer (`Resource::host`), so the lazy first-use allocation and the retirement after submission combine with the mip drop. - `texture.rs`: #1418's five-argument `detile_plane()` kept for the existing tests, and a `detile_plane_with_drop(..., self.mip_drop, ...)` added for dropped-mip staging. ## 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 ```powershell 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](https://claude.com/claude-code)
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 #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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 #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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 #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.
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 <[email protected]>
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 <[email protected]>
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 (#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 <[email protected]>
by_allocation asks allocation by allocation with WRITE_WATCH_FLAG_RESET.
When a later allocation in the range is committed but not write-watched,
it returned None and dropped the pages the earlier allocations had
reported, although the kernel had cleared them. The caller then copied
its own range whole, but the journal never learned of those writes, so
another host copy over the same pages would not copy them again.

Hand those pages back and record them in the journal before falling back.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The tuple's `kind` shadowed the function's `kind: String` parameter
(review on #427).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
DispatchMeshX with an indirect address used to be dropped. It now runs as
indirect execution of one mesh dispatch (stride 12), through the same
State::execute_indirect, argument clamp and VICTORY_INDIRECT switch as the
title's ExecuteIndirect; when it does not run it is counted with the other
indirect work dropped. The argument layout is inferred: those of a PC
indirect mesh dispatch, three 32-bit group counts.

A direct mesh dispatch with an empty y or z dimension now runs nothing
instead of its x groups, and y * z no longer overflows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The previous commit dropped the tick next_tick returns, but the
diagnostics build's tracing::debug! still names it (E0425). Bind it
again; it is unused without the feature, so that lint is allowed there.
Reported by Sunkiller-qc and r4tedx. cargo check -p victory-gpu passes
with and without --features diagnostics.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A raw buffer view on the host must start on a multiple of 16 bytes; the
console needs only 4. buffer_srv and buffer_uav move a view's first
element by where its memory sits in the host copy, so a title's raw view
could land on 4, 8 or 12 bytes past a 16-byte boundary. The host then
refuses CreateShaderResourceView (or CreateUnorderedAccessView), and the
device is removed (0x887A0001). A user report from the world:

  CreateShaderResourceView: When creating a RAW Shader Resource View, the
  offset of the first element from the start of the buffer must be a
  multiple of 16 bytes. Thus, FirstElement (42261210) must be a multiple
  of 4 since each element is 4 bytes.

Such a view is now refused like one that is not on an element: the slot
gets a null view of its kind (reads zeros) and a warning is logged once.
Starting the view 16 bytes lower would need the shader to add the
difference.

Type-checked and clippy-clean for x86_64-pc-windows-msvc (cross-checked
from Linux with -Zbuild-std); not run against the title.
As the reviews of this change asked: raw_views_start_on_16_bytes checks
which starts the check lets through (elements 0, 4, 8...) and refuses
(4, 8 and 12 bytes past a boundary, the user report's FirstElement
42261210 included); raw_views_that_fit_are_accepted_by_the_device makes
every start the check lets through below 64 as a raw SRV and UAV of a
real buffer and checks the device stays alive.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Indirect draws with the console's rectangle-list topology (17) were
refused by State::execute_indirect: rectangles are expanded on the CPU
(primitive::expand_rects) and an indirect draw's vertex count is only
known on the GPU. A world frame drops about 250 of them (#255); the
title draws its full-screen passes as rectangles.

Non-indexed ones now run. After the argument clamp, two compute passes
of ours (HLSL compiled at run time, as the clamp is) record before
ExecuteIndirect:

- rect_rewrite reads each live record (the title's count respected),
  checks its source vertices lie inside every per-vertex vertex buffer,
  allocates rects * 6 vertices from a per-list 8 MiB scratch with an
  atomic counter, and writes a rewritten copy of the record into a
  list-owned arguments buffer. The title's arguments are not changed
  beyond the clamp.
- rect_expand writes (v0, v1, v2, v0, v2, v3) per rectangle for each
  per-vertex slot, with v3 = v0 + v2 - v1 computed exactly as
  expand_rects does (same formats, same conversions and rounding).

ExecuteIndirect then reads the rewritten arguments and the expanded
vertices. Records that do not fit or reach past their buffers draw
nothing; if the passes are unavailable the draw is dropped as before,
with its own diagnostics reason. Indexed rectangles stay unsupported, as
for direct draws.

Tests: the element table, scratch layout, source bounds and dispatch
grid are unit-tested; both shaders must compile; and on a host device a
test runs both passes on synthetic vertices (F32, F16, UNORM16, UNORM8,
an unknown format, an element past the stride, a count buffer and an
out-of-bounds record) and compares the result byte for byte with
expand_rects.

Co-Authored-By: Gemini 4 Neon <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
scratch_layout took 16 bytes of alignment slack per extra slot off the
capacity before counting vertices, so a layout that fits exactly (two
slots of 8 and 12 bytes in 120, no padding needed) was refused, and in
8 MiB a few rectangles of room were lost. It now starts from the
unpadded vertex count and steps down a rectangle at a time until the
padded regions fit. Reported by DarX-Oren on #346.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The rewrite pass read the title's records after the clamp and relied on
the clamp having written its bounds back in place. It now applies the
same bounds itself (2^24 vertices, 2^26 vertex instances), so a clamp
that writes elsewhere (#242) cannot bring back unbounded counts.

f32_to_half in the expand shader or-ed the rounded mantissa into the
exponent, losing a rounding carry when the exponent is odd (1.99995
became 1.0); it now adds it, as #260 does for primitive.rs.

The module notes also say that, with vertex inputs, the vertex id is
the expanded one, from an allocated start whose order between records
may change from run to run.

Reported by marquezinii on #346.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The rewrite pass already writes records at or past the title's count as
empty draws, so ExecuteIndirect does not need the count: it now runs all
records from the list's own arguments buffer, with no count buffer. The
rectangle path then changes the state of no title buffer: the count's
host copy was moved to INDIRECT_ARGUMENT and back around the draw, which
a buffer-state tracker such as #458 or #334 may have moved elsewhere,
and which the draw's own shaders may need in another state (reported by
claude-GTA6 on #346: a device removal with #458 stacked).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
#418 made primitive::f32_to_half write half subnormals, rounded to even,
where it flushed them to zero; the expand shader's copy of it still
flushed, so a fourth corner below 2^-14 differed between the CPU and GPU
paths. The shader now rounds them the same way. The byte-for-byte GPU
test gets a rectangle whose half fourth corner is 2^-16 (a subnormal);
with the old flush the test fails.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
f32_to_half added 0x1000 before dropping the low 13 mantissa bits, so a
value exactly halfway between two halves always rounded up: 1 + 2^-11
packed as 0x3c01 instead of 0x3c00. fuzeofficlal measured it in native
draws of the direct path on RTX 5090 and WARP (10 of 16 reference pixels
before, 16 of 16 after) and wrote the fix (c256b97 on their fork): the
retained bit decides halfway cases. Applied to primitive.rs and to the
expand shader's copy, so the direct and indirect paths keep agreeing.

primitive.rs gets a test of both midpoints; the byte-for-byte GPU test
gets a fourth corner of 1 + 2^-11, and fails with the old rounding in
the shader.

Co-Authored-By: fuzeofficlal <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Under Wine and Proton, D3DCompile is vkd3d-shader, which has no Load on
RWByteAddressBuffer (E5005) and ignores the RootSignature attribute, so
the expander did not compile there and indirect rectangles stayed
dropped (reported by Exorion1er on #346, with GE-Proton11-12).

The two passes now read and write buffers as 32-bit words through
(RW)StructuredBuffer<uint>, and their root signatures (eight root
constants, then root descriptors) are serialized in code instead of
coming from the shader. The bindings and the arithmetic are unchanged.
Checked with vkd3d-compiler 2.1 (the vkd3d-shader GE-Proton11-12 ships):
the old shaders fail with the reported E5005 at 25:25; the new ones
compile, and with their bytecode the byte-for-byte GPU test passes on
vkd3d-proton.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: GPT 6.2 Sol <[email protected]>
Rename the thread-local SCRATCH buffer in crates/victory-gpu/src/texture.rs to UNWATCHED_SCRATCH so PR #143 composes cleanly with PR #472's static SCRATCH mutex without an E0428 duplicate-definition error (flagged by @mercuryVM).
# Conflicts:
#	crates/victory-gpu/src/draw.rs
The pipeline workers held the library's lock while a pipeline loaded. A
load is not always a lookup: an AMD driver's library holds about 140 bytes
per pipeline, and what the driver's own cache lacks is compiled inside the
load, for up to seconds. All eight workers then waited for the one that
held the lock.

The library is documented as thread-safe but for loads of one pipeline on
several threads (ID3D12Device1::CreatePipelineLibrary, "Thread Safety"),
so only those exclude each other now: a name is held by one thread at a
time, and loads run without the library's lock. Stores and serialising
keep it.

Measured on an RX 6800 and a Ryzen 9 5900X (sampled stacks, diagnostics
build, the same start from a kept pipeline library):
- worker CPU while a backlog is made: 1.05 cores -> 7.8; samples blocked on
  the lock: 481 -> 0
- in the world, two runs each: pipelines still being made 1219-1315 -> 43-54,
  draws run per frame 3-20 -> 1860-2086, time per frame outside preparing,
  GPU and copy-back 196-303 ms -> 24-37 ms

The frame itself is not shorter on its own: the draws that used to be
dropped now run (750-799 -> 1090-1379 ms per frame).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The clamp of indirect arguments is HLSL compiled at run time by the
system's compiler. Under Wine that is vkd3d-shader's, which has no
methods on byte address buffers and ignores the RootSignature attribute:

    argument clamp: clamp:19:27: E5005: Method 'Load' is not defined on
    type 'RWByteAddressBuffer'.

Without the clamp every indirect execution is dropped ("not bounded"),
which is most of the world's draws and dispatches.

The buffers become structured buffers of uint, indexed in words (the
caller already refuses addresses and strides that are not multiples of
4), and the root signature is serialized beside the shader instead of
read from it. The bounds and the budget are unchanged.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
CheckFeatureSupport returned E_NOTIMPL for D3D12 feature IDs 5 and 6. Report plane counts for depth and stencil format families and the address widths already published through OPTIONS, with the same size and null validation as the other features. Add two unit tests.
The host driver compiles pipelines on our worker threads. On an RTX 5080
(driver 32.0.16.1692) NVIDIA's compiler (nvgpucomp64.dll) recursed past
the default 2 MB stack while creating a world compute pipeline
(c7d7a6283fad3cd6): "thread 'victory-pipelines-4' has overflowed its
stack", 0xc00000fd, then the pipeline was refused with E_OUTOFMEMORY and
its dispatches dropped. A 64 MB stack is reserved address space, committed
only as the compiler uses it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
D3D12CreateDevice(None, …) takes the adapter DXGI calls the default, which
is the one driving the primary output: the integrated GPU on a hybrid
laptop, and on a machine with a remote-desktop or emulator display driver
an adapter that cannot create a device at all. The title needs shader model
6.6 and, for the world, mesh shaders, so neither is a safe default, and
when none of them worked the failure was a bare E_FAIL that named nothing.

Enumerate and probe every adapter — a device, SHADER_MODEL,
D3D12_OPTIONS7's mesh tier, the software flag — then choose: hardware,
SM 6.6, mesh shaders first, then the most dedicated memory, then the
lowest LUID so the choice does not depend on enumeration order. Software
adapters are never chosen (Microsoft Basic Render Driver reports SM 6.6
and mesh shaders too), and WARP stays the explicit VICTORY_D3D12_WARP
switch. When nothing qualifies, the error lists every adapter with what
it offers.

Measured on the machine this was written on (Core Ultra 9 185H, Intel Arc
iGPU, plus a remote-desktop and an emulator display driver): four
adapters, the same GPU listed three times — once per display path, so
which is the default is not stable — and the Basic Render Driver passing a
naive SM 6.6 + mesh test.

cargo test -p victory-gpu: 57 passed, 0 failed, 1 ignored.
cargo clippy --workspace --all-targets --all-features -- -D warnings: clean.
cargo xtask policy: ok.
Transient upload buffers allocated during list recording (buffer copies, large scratch allocations) were previously created as new committed resources on every copy and dropped on list reset. They are now retained in a host-wide pool upon HostList::reset (bounded to 32 buffers, aligned to D3D12 64 KiB placement granularity) and reused by subsequent uploads with matching or compatible capacities.
With TdrLevel 0 Windows never resets a hung GPU: a slow or hung world
frame freezes the whole desktop, and the runtime never sees a device
removal it could report (#1054). With 1 the timeout is a blue screen.
Both are set by hand, often to keep slow frames from being reset, and
reports of "the PC froze" do not say so.

When the host device is made on a hardware adapter, read TdrLevel,
TdrDelay and TdrDdiDelay from HKLM\SYSTEM\CurrentControlSet\Control\
GraphicsDrivers, log them ("default" where a value is not set), and warn
for TdrLevel 0 or 1 with what to set instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The console ignores blending on integer render targets and the title
leaves it on (the world has a mesh pipeline blending into an R8_UINT
target). D3D12 does not allow it: vkd3d-proton refuses such a pipeline
with E_INVALIDARG and its draws are lost. The host pipeline now turns
blending off on integer targets; with one description for all targets,
each target gets its own copy so the others keep theirs.

(cherry picked from commit 169efcb84eb5d9d83c0af7fe525a54ada86f3a0d)
expand_rects now returns early when stride is zero or when 3 * stride or
6 * stride overflows, instead of panicking in chunks_exact(0) or in the
6 * stride slice arithmetic.

Adds three deterministic synthetic tests: the zero/overflow guard, UNORM16
and UNORM8 clamping with unknown formats, and multiple rectangles carrying
f32/f16 vector formats (7 tests in primitive.rs total).

Synthetic tests only; no fixtures or game data.

Cherry-picked from geiyiliyabumo/VIctory@e3c9dd0.
Prepare fully read-only depth views in DEPTH_READ and combine shader-resource states only when the same draw reads the depth texture through an SRV table. Test both table preparation and final depth binding with synthetic descriptors.
f32_to_half adds 0x1000 before dropping the low 13 mantissa bits, so a
value exactly halfway between two halves always rounds up: 1 + 2^-11
packs as 0x3c01 instead of 0x3c00. A rectangle's fourth corner computed
on such a value gets a half one ulp off. fuzeofficlal measured it in
native draws of the direct path on RTX 5090 and WARP (10 of 16 reference
pixels before, 16 of 16 after) and wrote the fix: the retained bit
decides halfway cases.

Co-Authored-By: fuzeofficlal <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A replay shows all visible geometry confined to a 1252-column band of a
2560-wide buffer, its edges on the title's own scissor (742..1994) with
viewport 2560x1440. The rects reach the host unchanged and no state is
cached, so the band is the state the title set; the switch says whether
widening it brings the frame back.

Scissors now widen to the viewport each pairs with (vertical bounds kept)
with VICTORY_WIDE_SCISSOR=1, warning about the rects they change (first
8, then every 512th); diagnostics builds log the first 8 scissor/viewport
pairs of every frame at debug level. The widening is pure logic in
scissor.rs, tested on every platform.
When VICTORY_TEXTURE_MIP_DROP is not explicitly configured in the environment,
query DXGI adapter DedicatedVideoMemory across non-software adapters.
If primary discrete VRAM is <= 8.5 GiB (capturing 4 GB, 6 GB, and 8 GB cards
such as RTX 5070 Laptop, RTX 4060, RX 6600), default mip drop to 1 to prevent
host driver committed memory exhaustion (E_OUTOFMEMORY 0x8007000E). Textures on
>= 10 GB GPUs remain at full native resolution (drop = 0). Explicit user
overrides via VICTORY_TEXTURE_MIP_DROP continue to take precedence.
Merges #124 #119 #515 #934 #484 #143 #1191 #278 #553 #153 #270 #1158 #1204
#1220 #488 #1146 #631 onto main (ffe310e), each head unchanged, no conflicts,
no changes of mine. cargo clippy --workspace --all-targets --locked -- -D
warnings, with and without --all-features, is clean and cargo test
--workspace --locked passes (372 passed, 8 ignored; main has 342 passed,
6 ignored).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Merges #202 #208 #322 #435 #982 #1217 #1283 #123 #251 #1032 #55 #409 #933
#474 #1206 onto main (ffe310e), each head unchanged, no conflicts.

Two changes of mine: clippy::undocumented_unsafe_blocks (an error under -D
warnings) rejected an unsafe block in read_sparse (host.rs, from #202 or
#208) and one in the resource_desc entry point (resource.rs, #409); each now
has a SAFETY comment. No code changes.

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

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Merges #72 #347 #1000 #358 #352 #626 #1152 #1129 #1203 #24 #642 #427 #485
#550 #174 #1279 onto main (ffe310e), each head unchanged, no conflicts.

One change of mine: three of the PRs each add a `mod tests` at the end of
pipeline/host.rs, so the merge defines `tests` three times (E0428). The
second and third are named `library_tests` and `blend_tests`; nothing else
changes.

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

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
- Select the non-software adapter with the most DedicatedVideoMemory during
  D3D12CreateDevice to prevent hybrid laptops (Intel/NVIDIA) from defaulting
  to the 128 MiB integrated GPU.
- Match device.GetAdapterLuid() against DXGI adapter LUIDs to record the exact
  memory of the active device.
- Read device_memory() live in texture_mip_drop to avoid stale caching during
  early device initialization.
- Clamp most_detailed in adjust_mips to host_mips - 1 to guard out-of-range
  guest SRV descriptors.

Reported-and-tested-by: Logan-Gaillard <[email protected]>
Reviewed-by: geiyiliyabumo <[email protected]>
Merges #346 #431 #493 #967 #1082 #1143 #1165 #1173 #1265 #1298 on top of the
three GPU bundles (#1418, #1426, #1439, on main ffe310e), each head
unchanged. #346, #967, #1082 and #1143 conflict in host.rs (and #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 <[email protected]>
- 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
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:38:31 +00:00
github-bot closed this pull request 2026-11-26 04:38:31 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:21 UTC · original

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** on GitHub · 2026-11-25 01:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/1617#issuecomment-7149469979) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:32 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 01:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/1617#issuecomment-7149660949) <!-- victory-triage v1 head=0d79788520a795f413a0bc9f26e9ce3b5c452c71 verdict=needs-rebase at=2026-11-25T01:32:18Z --> 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](https://claude.ai/code)_

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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!1617
No description provided.