GPU: speed up packed rectangle vertex expansion #196

Closed
github-bot wants to merge 1 commit from gh-pr/196/head into gh-pr/196/base
Owner

@⁠TG0000 on GitHub · 2026-11-24 01:18 UTC · original
TG0000:perf/rectangle-vertex-expansion → main · +162 −0 · 1 files · 1 commits · closed without merging

Summary

Rectangle draws expand their vertices on the CPU when the command list is submitted. For a 12-byte vertex with a float2 position and four UNORM8 color channels, select the layout once per batch and use fixed-size copies. Compute the fourth vertex's channels as clamp(v0 + v2 - v1, 0, 255) on the original bytes. The generic calculation's floating-point error after rescaling is below half a channel step, so it rounds to the same byte.

The fourth position uses the original addition and subtraction order. The generic path handles other layouts and nonfinite positions. The regression test compares every output byte across all four supported color formats, both element orders, floating-point edge cases, color saturation, and partial input and output.

Synthetic release benchmark

Windows, Ryzen 9 5900X, Rust 1.100.0 x86_64-pc-windows-msvc. The benchmark compares the original general-purpose implementation with the production dispatcher. Both paths use preallocated buffers and deterministic synthetic vertices. Times are medians of nine samples with alternating measurement order.

Rectangles per batch Before (ns/rect) After (ns/rect) Speedup
1 147.21 14.81 9.94×
64 124.05 3.04 40.85×
1,024 126.64 2.95 42.95×

The benchmark measures CPU vertex expansion for this layout. GPU execution, layout frequency in live workloads, and frame time were unmeasured.

cargo +stable-x86_64-pc-windows-msvc test --release --locked -p victory-gpu primitive::tests::benchmark_position_color_expansion -- --ignored --nocapture --test-threads=1

Validation

  • cargo +stable-x86_64-pc-windows-msvc test --workspace --locked -- --test-threads=1 passed (265 passed, five ignored). Test host GPU was an AMD Radeon RX 6800 with Windows driver 32.0.21045.29003.
  • cargo +stable-x86_64-pc-windows-msvc test --release --locked -p victory-gpu primitive::tests -- --test-threads=1 passed.
  • cargo +stable-x86_64-pc-windows-msvc clippy --locked -p victory-gpu --all-targets passed with existing warnings in other files.
  • cargo +stable-x86_64-pc-windows-msvc run --locked -p xtask -- policy passed.

AI-assisted. The benchmark and new test use generated fixtures.

**@⁠TG0000** on GitHub · 2026-11-24 01:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/196) `TG0000:perf/rectangle-vertex-expansion` → `main` · +162 −0 · 1 files · 1 commits · closed without merging ## Summary Rectangle draws expand their vertices on the CPU when the command list is submitted. For a 12-byte vertex with a float2 position and four UNORM8 color channels, select the layout once per batch and use fixed-size copies. Compute the fourth vertex's channels as `clamp(v0 + v2 - v1, 0, 255)` on the original bytes. The generic calculation's floating-point error after rescaling is below half a channel step, so it rounds to the same byte. The fourth position uses the original addition and subtraction order. The generic path handles other layouts and nonfinite positions. The regression test compares every output byte across all four supported color formats, both element orders, floating-point edge cases, color saturation, and partial input and output. ## Synthetic release benchmark Windows, Ryzen 9 5900X, Rust 1.100.0 x86_64-pc-windows-msvc. The benchmark compares the original general-purpose implementation with the production dispatcher. Both paths use preallocated buffers and deterministic synthetic vertices. Times are medians of nine samples with alternating measurement order. | Rectangles per batch | Before (ns/rect) | After (ns/rect) | Speedup | | ---: | ---: | ---: | ---: | | 1 | 147.21 | 14.81 | 9.94× | | 64 | 124.05 | 3.04 | 40.85× | | 1,024 | 126.64 | 2.95 | 42.95× | The benchmark measures CPU vertex expansion for this layout. GPU execution, layout frequency in live workloads, and frame time were unmeasured. ```powershell cargo +stable-x86_64-pc-windows-msvc test --release --locked -p victory-gpu primitive::tests::benchmark_position_color_expansion -- --ignored --nocapture --test-threads=1 ``` ## Validation - `cargo +stable-x86_64-pc-windows-msvc test --workspace --locked -- --test-threads=1` passed (265 passed, five ignored). Test host GPU was an AMD Radeon RX 6800 with Windows driver 32.0.21045.29003. - `cargo +stable-x86_64-pc-windows-msvc test --release --locked -p victory-gpu primitive::tests -- --test-threads=1` passed. - `cargo +stable-x86_64-pc-windows-msvc clippy --locked -p victory-gpu --all-targets` passed with existing warnings in other files. - `cargo +stable-x86_64-pc-windows-msvc run --locked -p xtask -- policy` passed. AI-assisted. The benchmark and new test use generated fixtures.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:54:12 +00:00
github-bot closed this pull request 2026-11-26 03:54:12 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 01:31 UTC · original

Tested 3c0b609 under Wine 11.22 + vkd3d-proton 3.1 (Arch Linux x86_64, AMD RX 9060 XT, RADV 26.3.1), Windows build with a native Microsoft d3dcompiler_47: pass, no regression.

  • victory_gpu: 42 passed, 2 failed, 2 ignored — the two failures are the environment-only a_rejected_blob_gives_an_empty_library and #128; the ignored ones are the texture-check benchmarks.
  • The packed position/color paths this PR specializes are covered by the existing rectangle tests, and they stay green.

No game data used.

**@⁠DaviTostes** on GitHub · 2026-11-24 01:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/196#issuecomment-7119191494) Tested `3c0b609` under **Wine 11.22 + vkd3d-proton 3.1** (Arch Linux x86_64, AMD RX 9060 XT, RADV 26.3.1), Windows build with a native Microsoft `d3dcompiler_47`: **pass, no regression**. - `victory_gpu`: **42 passed, 2 failed, 2 ignored** — the two failures are the environment-only `a_rejected_blob_gives_an_empty_library` and #128; the ignored ones are the texture-check benchmarks. - The packed position/color paths this PR specializes are covered by the existing rectangle tests, and they stay green. No game data used.
Author
Owner

@⁠juliptree on GitHub · 2026-11-24 01:38 UTC · original

Independently tested 3c0b60969f on Windows with a Ryzen 7 7800X3D and Rust 1.100.0 MSVC. All three release primitive::tests passed. Across three runs of the included benchmark, median before → after times were 115.16 → 12.25 ns/rect for batches of 1, 118.28 → 3.08 for 64, and 90.41 → 2.61 for 1,024.

These timings measure CPU vertex expansion for the synthetic packed position/color layout. AI-assisted testing and write-up.

(Chatgpt)

**@⁠juliptree** on GitHub · 2026-11-24 01:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/196#issuecomment-7119300120) Independently tested 3c0b60969ff57091951cdef22dfd99ac3cf66dea on Windows with a Ryzen 7 7800X3D and Rust 1.100.0 MSVC. All three release primitive::tests passed. Across three runs of the included benchmark, median before → after times were 115.16 → 12.25 ns/rect for batches of 1, 118.28 → 3.08 for 64, and 90.41 → 2.61 for 1,024. These timings measure CPU vertex expansion for the synthetic packed position/color layout. AI-assisted testing and write-up. (Chatgpt)

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!196
No description provided.