GPU: validate index buffer format, alignment, and empty views before binding #3181
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T11:26:19Z.
Problem
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.Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T12:10:03Z.
Review: APPROVED
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).
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T14:43:47Z.
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).
Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T16:06:39Z.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.