GPU: align appended input-element offsets like D3D12 #618
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!618
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/618/head"
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?
@JFIREonFIRE on GitHub · 2026-11-24 05:43 UTC · original
JFIREonFIRE:fix/append-aligned-input-offsets→main· +72 −2 · 1 files · 1 commits · merged 2026-11-25 00:11 UTCGraphicsState::elements()(crates/victory-gpu/src/pipeline/host.rs) works out each input element's byte offset. ForD3D12_APPEND_ALIGNED_ELEMENTit used the end of the previous element as-is. D3D12 (and vkd3d-proton) start an appended element at the next multiple of min(4, its size), so after a 1- or 2-byte element (R8,R16_FLOAT,R8G8_UNORM...) the computed offset was too small:R8G8_UNORM@0,R32G32_FLOATappendedR8_UNORM@0,R16_FLOATappended,R8_UNORMappendedR8G8B8A8_UNORM@0,R32G32_FLOAT,R32G32B32_FLOATappendedThe host pipeline gets the title's descriptions unchanged, so ordinary draws were never affected. The offsets computed here feed only
draw.rs's rectangle-list expansion, which then read the fourth vertex's attributes from the wrong bytes for such layouts. I have not checked whether the title's rectangle-list pipelines use a layout like this; this is a correctness fix found by reading the code.Also: an explicit
AlignedByteOffsetnear 4 GiB overflowedoffset + bytes(a panic in debug builds). It now saturates.Tests
pipeline::host::testsmodule:appended_elements_are_alignedanda_huge_explicit_offset_does_not_overflow. Both fail onmain; both pass with this change.cargo test --workspacepasses on Windows 11 with an RTX 3090, including the hardware shader tests.I searched open and closed PRs and issues for
APPEND_ALIGNED,AlignedByteOffsetand input-element offsets and found nothing touching this.AI use: Claude Code (Claude Opus 5.5 / Fable 5.2) found the issue, wrote the change and tests, and ran them.
🤖 Generated with Claude Code
@fuzeofficlal on GitHub · 2026-11-24 07:26 UTC · original
I ran a synthetic 4×4 rectangle through
GraphicsState::elementsandprimitive::expand_rects, then rasterized and read it back in native D3D12. The last input follows a 16-bit element and needs to start at byte 12. NativeAPPEND_ALIGNED_ELEMENTand an explicit byte-12 layout produced identical pixels.On
d2a4bae, the CPU layout resolved to[0, 8, 10]and matched the native reference at 10/16 pixels. On691236d, it resolved to[0, 8, 12]and matched all 16. The RTX 5090 and WARP agreed on both results, with zero D3D12 debug-layer errors. This covers layout resolution and rectangle expansion with actual rasterization.@Yaekai on GitHub · 2026-11-24 16:03 UTC · original
Independent test & review on Windows 11 + NVIDIA RTX 3070 (Rust 1.98.1) at head
eb9a10d:cargo test -p victory-gpu --lib: 45 passed, 0 failed (includingappended_elements_are_alignedanda_huge_explicit_offset_does_not_overflow).cargo clippy -p victory-gpu -- -D warnings: 0 warnings.bytes.clamp(1, 4)withchecked_next_multiple_of+saturating_add): matches D3D12'sD3D12_APPEND_ALIGNED_ELEMENTrules cleanly with no overflow paths.Looks clean and ready to merge!