GPU: validate index buffer format, alignment, and empty views before binding #3183
No reviewers
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!3183
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3183"
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?
@fuzeofficlal on GitHub · 2026-11-26 11:26 UTC · original
fuzeofficlal:fix/gpu-index-buffer-validation→main· +345 −15 · 2 files · 1 commits · openProblem
In
crates/victory-gpu/src/draw.rs,State::prepare_forforwardedself.indexdirectly toshadow::findandID3D12GraphicsCommandList::IASetIndexBufferwithout checking D3D12's index buffer view rules:SizeInBytes > 0, passing any format other thanDXGI_FORMAT_R16_UINTorDXGI_FORMAT_R32_UINT(such asDXGI_FORMAT_UNKNOWN,R32_FLOAT, orR8_UINT) emits a D3D12 Debug Layer error:ID3D12CommandList::IASetIndexBuffer: The Format (...) is not valid for usage as an index buffer format.BufferLocation: WhenSizeInBytes > 0, passing a host GPU address not aligned to 2 bytes (R16_UINT) or 4 bytes (R32_UINT) emits a D3D12 Debug Layer error:ID3D12CommandList::IASetIndexBuffer: Buffer address (...) is not aligned properly. The Format (...) imposes an alignment of (2|4) on the address.size == 0) and null-address (address == 0, size > 0) views: Both fell through toshadow::find(0, ...), which fell back toshadow::loose(0, ...)and allocated a 4 MiB host buffer around address0instead of clearing the host index buffer (IASetIndexBuffer(None)) for empty views or rejecting null-address non-empty views.Fix
Extract
State::bind_index(used by bothState::draw_indexedand indexedState::execute_indirectthroughState::prepare_for):v.size == 0, calllist.list.IASetIndexBuffer(None)and returntrueso valid empty/cleared index buffer draws continue to work without allocating a shadow buffer or leaving a stale index buffer bound.v.size > 0, rejectv.address == 0, reject formats other thanDXGI_FORMAT_R16_UINT(2-byte alignment) andDXGI_FORMAT_R32_UINT(4-byte alignment), and verifyshadow.gpu(v.address).is_multiple_of(align)before refreshing and callingIASetIndexBuffer. Valid odd byte sizes (e.g., 3 bytes forR16_UINT, 6 bytes forR32_UINT) remain accepted as permitted by D3D12.Verification
Added end-to-end D3D12 test
draw::tests::prepare_validates_index_buffer_format_alignment_and_empty_views(plus#[cfg(all(test, windows))]helperShader::register_testinpipeline.rs):origin/main): fails on both RTX 5090 +VICTORY_D3D12_DEBUG=1and WARP +VICTORY_D3D12_DEBUG=1withID3D12CommandList::IASetIndexBuffer: The Format (0, UNKNOWN) is not valid for usage as an index buffer format.(and fails rejection of unaligned and null-address non-empty views).--features diagnostics+VICTORY_D3D12_DEBUG=1, and WARP--features diagnostics+VICTORY_D3D12_DEBUG=1withhost.log_messages() == None.cargo test -p victory-gpu --lib --lockedpasses on hardware default (230 passed), hardwarediagnostics + DEBUG=1(244 passed), and WARPdiagnostics + DEBUG=1(246 passed).cargo clippy --workspace --all-targets --locked -- -D warnings(default and--all-features) andxtaskpolicy checks pass cleanly.State::prepare_for previously forwarded self.index directly to shadow::find and ID3D12GraphicsCommandList::IASetIndexBuffer without validating the D3D12 index buffer view contract: - Non-empty index views with a format other than DXGI_FORMAT_R16_UINT or DXGI_FORMAT_R32_UINT trigger D3D12 Debug Layer errors ('The Format (...) is not valid for usage as an index buffer format'). - Non-empty index views whose host BufferLocation is not 2-byte aligned (R16_UINT) or 4-byte aligned (R32_UINT) trigger D3D12 Debug Layer alignment errors. - Empty views (size == 0) or null-address non-empty views (address == 0, size > 0) fell through to shadow::find, allocating a 4 MiB loose shadow buffer around address 0 instead of clearing the index buffer or rejecting the null view. Extract State::bind_index to: 1. Clear the host index buffer with IASetIndexBuffer(None) when size == 0 (preserving valid empty/cleared index buffer draws without allocating a shadow copy). 2. Reject non-empty views with address == 0, formats other than R16_UINT / R32_UINT, or host GPU addresses not aligned to 2 / 4 bytes before calling IASetIndexBuffer.@Dukestar69 on GitHub · 2026-11-26 12:10 UTC · original · approved these changes
Verified on RTX 5090 against
origin/main(63bcca4):cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 21/21 passed (includingprepare_validates_index_buffer_format_alignment_and_empty_views).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Cleanly validates index buffer format, alignment, and empty views before binding.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@oni-swr on GitHub · 2026-11-26 14:43 UTC · original
WARP verification of head
4b235220(base = current main63bcca4).Setup: Windows 11,
VICTORY_WARP=1+VICTORY_D3D12_WARP=1,--features diagnostics(software adapter only, no physical GPU), Windows SDKdxil.dll, synthetic tests only.cargo test -p victory-gpu --lib: 247 passed, 0 failed, 1 ignoreddraw::tests::prepare_validates_index_buffer_format_alignment_and_empty_views: pass#[cfg(test)]register_testhelper, no fix): fails (expected rejection for unknown_format)Verified with Claude Code (Claude Sonnet 5.5).
@Jackster on GitHub · 2026-11-26 16:06 UTC · original · edited 2026-11-26 16:08 UTC
AMD check on a Radeon RX 7900 XTX (gfx1100, 32.0.32029.2010):
draw::tests::prepare_validates_index_buffer_format_alignment_and_empty_viewspasses on the hardware adapter.victory-gpusuite: 232 passed / 0 failed / 1 ignored.Synthetic only. AI-assisted.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.