GPU: GetResourceAllocationInfo(2) inflates sub-64 KiB texture alignments and overflows on large totals (fix on a fork) #782
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory#782
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@AndyLatimer on GitHub · 2026-11-24 10:36 UTC · original
Problem
In
crates/victory-gpu/src/resource.rs,place()(shared byID3D12Device::GetResourceAllocationInfoat slot0xc8andID3D12Device8::GetResourceAllocationInfo2at slot0x360) has three defects:Sub-64 KiB texture alignments are inflated to 64 KiB:
footprint()intentionally returns the console layout's own alignment (4 KiB forSW_4KB_Stextures, 256 bytes for linear /SW_256B_*textures), matchingXGCreateTextureComputerandCreatePlacedResource. However,place()initializestotal.alignment = KIB_64and updatestotal.alignment = total.alignment.max(one.alignment), clamping every query up to 64 KiB.sizes_cover_every_mip(footprint={ size: 0x56000, alignment: 0x1000 }),GetResourceAllocationInforeturns{ size: 0x56000, alignment: 0x10000 }.GetResourceAllocationInfo2contradicts itself on the same call:pResourceAllocationInfos1[0]receivesalignment: 0x1000, while the returnedD3D12_RESOURCE_ALLOCATION_INFOreportsalignment: 0x10000.SW_256B_*textures (256-byte alignment) are similarly inflated to 64 KiB.Unchecked
u64arithmetic inplace():total.size.next_multiple_of(one.alignment)andoffset + one.sizecan panic in debug builds (or wrap in release builds) when placing multiple large resources whose aligned sum exceedsu64::MAX, instead of returning{ size: u64::MAX, alignment: 0 }and writing the failure sentinel toeach[i].Null descriptor pointer with non-zero count:
When
count > 0anddescsis null, bothallocation_infoandallocation_info2silently substitute&[]and report{ size: 0, alignment: 65536 }instead of{ size: u64::MAX, alignment: 0 }. Forcount == 0, host Windows D3D12 (ID3D12Device/ID3D12Device8) returns{ SizeInBytes: 0, Alignment: 1 }.Fix on a fork
Branch:
AndyLatimer/VIctory@fix/gpu-allocation-info-alignment(based onorigin/mainffe310e, commitccdfb2e)Summary of changes (
crates/victory-gpu/src/resource.rsonly):total.alignmentto1inplace()so empty queries return{ size: 0, alignment: 1 }(matching host D3D12) and non-empty queries return the exact maximum alignment of the requested resources (preserving 4 KiB and 256-byte console alignments).checked_next_multiple_ofandchecked_addbefore writingeach[i], returning{ size: u64::MAX, alignment: 0 }and writing{ offset: u64::MAX, alignment: 0, size: u64::MAX }on overflow.{ size: u64::MAX, alignment: 0 }whencount > 0anddescsis null, and guardoutwithas_mut().resource::tests::allocation_info_keeps_console_alignments_and_checks_bounds) exercisingGetResourceAllocationInfo(0xc8) andGetResourceAllocationInfo2(0x360) on 4 KiB BC7 textures, linear textures, mixed 4 KiB/64 KiB batches, empty/null inputs, and both addition and alignment-padding overflows (verified to fail onffe310ebefore the fix and pass after).Verification
cargo test -p victory-gpu: 51 passed, 0 failed, 1 ignored (benchmark)cargo test -p victory-gpu --features diagnostics: 54 passed, 0 failed, 1 ignored (benchmark)cargo clippy -p victory-gpu --all-targets -- -D warnings(default and--features diagnostics): 0 warningscargo check -p victory --features diagnostics: cleancargo xtask policy:asset policy: 154 files okrustfmt --edition 2024 --check crates/victory-gpu/src/resource.rs: no diffs in any modified lines (only the pre-existing untouched line onorigin/main)Disclosure
@LAKSHYA-cmd-tech on GitHub · 2026-11-24 11:13 UTC · original
Cherry-picked and merged downstream in https://github.com/LAKSHYA-cmd-tech/VIctory/pull/13.
Verified on Windows 11 D3D12 runtime: all 88 \ictory-gpu\ tests pass cleanly including
esource::tests::allocation_info_keeps_console_alignments_and_checks_bounds.
@BastienRodz on GitHub · 2026-11-24 16:35 UTC · original
Two more sizing rules for
crates/victory-gpu/src/resource.rs. I'm adding them here rather than opening a PR that would compete withccdfb2e:Tail padding in
place(). Per theGetResourceAllocationInfoRemarks, several descriptions are laid out the way a C++ struct is. Two tiny 64 KB-aligned resources and a tiny 4 MB-aligned one total 12 MB when the 4 MB resource is in the middle, and 8 MB otherwise.place()aligns each member's offset, but it never padstotal.sizetototal.alignment.mainffe310e, a 64 KiB bufferband a 4 MiB-aligned 64×64 RGBA8 texturem):[b, m, b]gives0x81_0000where 12 MiB (0xC0_0000) is expected, and[m, b, b]gives0x42_0000where 8 MiB is expected.total.sizetototal.alignmentat the end ofplace(), in the style of #782's overflow checks.sizes_cover_every_mipasserts the unpadded0x65000and would change.footprint()'s fallback path. Line 224 returnsbytes.checked_next_multiple_of(KIB_64)?even whenalignmentis 4 MiB (MSAA, or an explicit 4 MiB alignment on a layout or format the console layout path doesn't handle). The size can then be smaller than the alignment. The layout path above it (line 189) already rounds toalignment.layout: 2,alignment: 4 MiB, 64×64 RGBA8 gives{ size: 65536, alignment: 4194304 }instead of a 4 MiB size. Both rules are needed for the doc's 8 MB / 12 MB totals to add up.@AndyLatimer, I can send these two lines and their tests as a commit for your branch, or leave them to you.
@Marvisak on GitHub · 2026-11-25 03:52 UTC · original
Automated triage for the maintainers. Confirmed on
maininplace()(crates/victory-gpu/src/resource.rs), which bothallocation_infoandallocation_info2use. The total alignment starts at 64 KiB, so 4 KiB and 256-byte console alignments come back as 64 KiB, andallocation_info2then reports a smaller alignment per resource than in the total.next_multiple_ofand the offset addition are unchecked. A nulldescswith a non-zero count is treated as an empty list. The tail-padding point in the comment above also holds:place()never roundstotal.sizeup tototal.alignment.Open PR #1396 (preserve sub-64 KiB alignments and check bounds in
allocation_info) addresses this; the tail-padding rule could be reviewed together with it there.Generated by Claude Code