GPU: rectangle lists placed by vertex number get a geometry stage #1020

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

@⁠ghost on GitHub · 2026-11-24 15:06 UTC · original
gpu/rect-list-vertex-number → main · +561 −4 · 4 files · 1 commits · closed without merging

AI-assisted (Claude Code). Tested on my own machine: Windows 11, NVIDIA GPU, v1.0.2.1 in Series X mode.

Relates to #255.

What

A rectangle-topology pipeline whose vertex stage reads no per-vertex input gets a geometry stage of ours that completes each rectangle from its three vertices. Its draws keep the title's vertex counts, and its non-indexed indirect draws run with the title's records.

Why

primitive::expand_rects (and the GPU expansion in #282 / #346) make the fourth corner from vertex buffer contents. The title's tiled lighting has no vertex buffer: VS_TiledLighting computes the tile and the corner from SV_VertexID (tile = id / 3, corner = id % 3). Many of its full-screen passes are built the same way. For those draws there is nothing to expand, so on main a direct draw runs count / 3 * 6 vertices with vertex numbers the shader does not expect, and an indirect one is dropped.

This may be part of why the picture stayed black after #346 (louketa's comment on #255): the draws stop being dropped, but the vertices they run still carry the wrong numbers.

How

  • At pipeline creation: topology is the console's rectangle list and no input element is per-vertex → generate HLSL for a geometry stage from the vertex stage's OSG1 signature, compile it, check the compiled stage's output registers equal the vertex stage's, add it to the pipeline, and set cull mode none.
  • The stage takes the corner opposite the longest side as the middle one, so it works whichever of the three vertices the title puts between the other two. The fourth vertex is a + b - middle for every float output; integer outputs take the middle vertex's value.
  • The stage has to be DXIL. With D3DCompile (gs_5_1) the host refused every such pipeline: "Graphics pipeline state mixes shader model 6.0 or above with 5.1 or below".

Limits

  • Compiler dependency. The stage is compiled with the Windows SDK's dxcompiler.dll, loaded at run time (VICTORY_DXC names another path). Without it, these pipelines are made exactly as before. I know #190 moves the other direction (no compiler at run time); emitting this stage with the crate's own DXIL writer would remove the dependency, and I'm happy to rework it that way if that is the preference.
  • Indexed rectangle lists stay undrawn.
  • With #282 or #346 merged as well, their expansion has to skip pipelines that have this stage (they have no per-vertex buffers to expand, and their records must not be rewritten to twice the vertices).

Tests

cargo test -p victory-gpu --lib: 52 passed, 0 failed, 1 ignored. cargo clippy -p victory-gpu --all-targets: clean.

New, on the real GPU (skipped when no compiler is found):

  • rectangles_placed_by_vertex_number_are_completed: three vertices placed by number, for both corner orders, cover all 64 pixels of an 8x8 target through the stage, and only a triangle without it.
  • signature_of_a_compiled_vertex_stage: the signature parser reads a compiled vertex stage's input and output.

Measured in the game (counts only)

On my integration branch (not main), with a pipeline-statistics query around the enabled tiled-lighting draws in the world, 720 vertices each:

draw geometry stage in → out after clipping pixel invocations
no-directional-light variant 240 → 480 120–140 740,000–900,000
directional-light variant 240 → 480 0 0

I have no statistics from before the change, only that the pass's two targets were all zero at the end of the frame. They still are: the no-directional-light pixel stage now runs and writes zero. So the picture is not fixed by this alone on NVIDIA: the directional variant draws no tiles because the tile texture its vertex stage tests is all zero, and the compute passes that feed lighting (shadowmask, cascadeshadows_classify, indirect_light_probes) do not translate on a 32-lane host. About 310 pipelines in a run into the world are of this kind (the count the host refused when the stage was still gs_5_1).

No game-derived content is included.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TydV9AGmPCiUTkG8rHubBQ

**@⁠ghost** on GitHub · 2026-11-24 15:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/1020) `gpu/rect-list-vertex-number` → `main` · +561 −4 · 4 files · 1 commits · closed without merging *AI-assisted (Claude Code). Tested on my own machine: Windows 11, NVIDIA GPU, v1.0.2.1 in Series X mode.* Relates to #255. ## What A rectangle-topology pipeline whose vertex stage reads no per-vertex input gets a geometry stage of ours that completes each rectangle from its three vertices. Its draws keep the title's vertex counts, and its non-indexed indirect draws run with the title's records. ## Why `primitive::expand_rects` (and the GPU expansion in #282 / #346) make the fourth corner from **vertex buffer** contents. The title's tiled lighting has no vertex buffer: `VS_TiledLighting` computes the tile and the corner from `SV_VertexID` (tile = id / 3, corner = id % 3). Many of its full-screen passes are built the same way. For those draws there is nothing to expand, so on `main` a direct draw runs `count / 3 * 6` vertices with vertex numbers the shader does not expect, and an indirect one is dropped. This may be part of why the picture stayed black after #346 (louketa's comment on #255): the draws stop being dropped, but the vertices they run still carry the wrong numbers. ## How - At pipeline creation: topology is the console's rectangle list and no input element is per-vertex → generate HLSL for a geometry stage from the vertex stage's `OSG1` signature, compile it, check the compiled stage's output registers equal the vertex stage's, add it to the pipeline, and set cull mode none. - The stage takes the corner opposite the longest side as the middle one, so it works whichever of the three vertices the title puts between the other two. The fourth vertex is `a + b - middle` for every float output; integer outputs take the middle vertex's value. - The stage has to be DXIL. With `D3DCompile` (`gs_5_1`) the host refused every such pipeline: *"Graphics pipeline state mixes shader model 6.0 or above with 5.1 or below"*. ## Limits - **Compiler dependency.** The stage is compiled with the Windows SDK's `dxcompiler.dll`, loaded at run time (`VICTORY_DXC` names another path). Without it, these pipelines are made exactly as before. I know #190 moves the other direction (no compiler at run time); emitting this stage with the crate's own DXIL writer would remove the dependency, and I'm happy to rework it that way if that is the preference. - Indexed rectangle lists stay undrawn. - With #282 or #346 merged as well, their expansion has to skip pipelines that have this stage (they have no per-vertex buffers to expand, and their records must not be rewritten to twice the vertices). ## Tests `cargo test -p victory-gpu --lib`: 52 passed, 0 failed, 1 ignored. `cargo clippy -p victory-gpu --all-targets`: clean. New, on the real GPU (skipped when no compiler is found): - `rectangles_placed_by_vertex_number_are_completed`: three vertices placed by number, for both corner orders, cover all 64 pixels of an 8x8 target through the stage, and only a triangle without it. - `signature_of_a_compiled_vertex_stage`: the signature parser reads a compiled vertex stage's input and output. ## Measured in the game (counts only) On my integration branch (not `main`), with a pipeline-statistics query around the enabled tiled-lighting draws in the world, 720 vertices each: | draw | geometry stage in → out | after clipping | pixel invocations | |---|---|---|---| | no-directional-light variant | 240 → 480 | 120–140 | 740,000–900,000 | | directional-light variant | 240 → 480 | 0 | 0 | I have no statistics from before the change, only that the pass's two targets were all zero at the end of the frame. They still are: the no-directional-light pixel stage now runs and writes zero. So the picture is **not** fixed by this alone on NVIDIA: the directional variant draws no tiles because the tile texture its vertex stage tests is all zero, and the compute passes that feed lighting (`shadowmask`, `cascadeshadows_classify`, `indirect_light_probes`) do not translate on a 32-lane host. About 310 pipelines in a run into the world are of this kind (the count the host refused when the stage was still `gs_5_1`). No game-derived content is included. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01TydV9AGmPCiUTkG8rHubBQ
A rectangle list gives three vertices per rectangle and the hardware adds
the fourth. The host draws them as triangles after expanding the vertex
buffers (primitive::expand_rects). A vertex shader that reads no vertex
buffer and places the corners from SV_VertexID has nothing to expand: its
draw ran as count / 3 * 6 vertices with the wrong vertex numbers, and an
indirect one was dropped. The title's tiled lighting and many of its
full-screen passes are drawn this way.

A rectangle-topology pipeline without per-vertex inputs now gets a
geometry stage of ours, generated from the vertex stage's output
signature. It takes the three vertices and emits the rectangle as a
four-vertex strip. The corner opposite the longest side is taken as the
middle one, so it does not depend on which of the three the title puts
between the other two; the fourth vertex is the other two's sum less it,
for every interpolated output (integer outputs take the middle vertex's).
Such pipelines are made with cull mode none, their direct draws keep the
title's vertex count and first vertex, and their non-indexed indirect
draws run with the title's records.

The stage is compiled to DXIL: the host refuses a pipeline that mixes
shader model 6 stages with a 5.1 one ("Graphics pipeline state mixes
shader model 6.0 or above with 5.1 or below"), so D3DCompile cannot make
it.

shortcut: the compiler is the Windows SDK's dxcompiler.dll, loaded at run
time (VICTORY_DXC names another). Without it these pipelines are made as
before. Indexed rectangle lists stay undrawn.

Tests (real GPU, skipped without a compiler): three vertices placed by
number cover the whole target through the stage and only a triangle
without it, for both corner orders; the signature parser reads a compiled
vertex stage.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TydV9AGmPCiUTkG8rHubBQ
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:17:21 +00:00
github-bot closed this pull request 2026-11-26 04:17:21 +00:00
Author
Owner

@⁠MichaelSmithAI on GitHub · 2026-11-24 15:14 UTC · original

We checked the non-indexed indirect route on an RTX 4090 under Wine/vkd3d-proton 3.2. A source-built SM 6.8 vertex shader used both SV_VertexID and SV_StartVertexLocation. VIctory’s indirect draw preparation consumed the record [3, 1, 3, 0]. Its 8×8 readback matched the native direct draw starting at vertex 3 pixel for pixel: the left 32 pixels were covered. Starting at vertex 0 covered the right half. Doubling the count in this fixture would cover both halves.

The authored rectangle coverage test passed on the same setup. Together these results check geometry completion and retention of the indirect record’s count and start vertex. The two end-of-frame lighting targets in your title report remain a separate result.

On our gstack integration, the indirect draw produced the same 32-pixel mask, and the existing GPU vertex-buffer expansion still matched CPU expansion. The integration bypasses that buffer expansion only for pipelines that already have the generated rectangle geometry stage. The full GPU suite had 88 passes, one ignored test and the known Wine empty-library failure.

**@⁠MichaelSmithAI** on GitHub · 2026-11-24 15:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/1020#issuecomment-7135705319) We checked the non-indexed indirect route on an RTX 4090 under Wine/vkd3d-proton 3.2. A source-built SM 6.8 vertex shader used both SV_VertexID and SV_StartVertexLocation. VIctory’s indirect draw preparation consumed the record `[3, 1, 3, 0]`. Its 8×8 readback matched the native direct draw starting at vertex 3 pixel for pixel: the left 32 pixels were covered. Starting at vertex 0 covered the right half. Doubling the count in this fixture would cover both halves. The authored rectangle coverage test passed on the same setup. Together these results check geometry completion and retention of the indirect record’s count and start vertex. The two end-of-frame lighting targets in your title report remain a separate result. On our gstack integration, the indirect draw produced the same 32-pixel mask, and the existing GPU vertex-buffer expansion still matched CPU expansion. The integration bypasses that buffer expansion only for pipelines that already have the generated rectangle geometry stage. The full GPU suite had 88 passes, one ignored test and the known Wine empty-library failure.
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 15:40 UTC · original

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 39e056a: cargo test -p victory-gpu passes, 52 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 15:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/1020#issuecomment-7136417674) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 39e056a: `cargo test -p victory-gpu` passes, 52 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Author
Owner

@⁠MartinIndra02 on GitHub · 2026-11-24 17:15 UTC · original

Independent verification at 39e056a on Windows 11, NVIDIA GeForce RTX 3080 (driver 621.24) + WARP, Rust 1.98.1:

  • cargo test -p victory-gpu --lib -- --test-threads=1 (RTX 3080): 52 passed, 0 failed, 1 ignored (including pipeline::host::rect_tests::rectangles_placed_by_vertex_number_are_completed and signature_of_a_compiled_vertex_stage).
  • VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --lib -- --test-threads=1 (WARP): 52 passed, 0 failed, 1 ignored.
  • VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --lib -- --test-threads=1 (D3D12 Debug Layer): 55 passed, 0 failed, 1 ignored (0 debug-layer errors).
  • cargo clippy -p victory-gpu -p victory-shader --all-targets -- -D warnings (default + --features diagnostics): 0 warnings.
  • cargo xtask policy: 154 files ok.

No game data used. AI-assisted; all builds and GPU tests executed on my machine.

**@⁠MartinIndra02** on GitHub · 2026-11-24 17:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/1020#issuecomment-7138935499) Independent verification at `39e056a` on **Windows 11, NVIDIA GeForce RTX 3080 (driver `621.24`) + WARP, Rust `1.98.1`**: - `cargo test -p victory-gpu --lib -- --test-threads=1` (RTX 3080): **52 passed, 0 failed, 1 ignored** (including `pipeline::host::rect_tests::rectangles_placed_by_vertex_number_are_completed` and `signature_of_a_compiled_vertex_stage`). - `VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --lib -- --test-threads=1` (WARP): **52 passed, 0 failed, 1 ignored**. - `VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --lib -- --test-threads=1` (D3D12 Debug Layer): **55 passed, 0 failed, 1 ignored** (0 debug-layer errors). - `cargo clippy -p victory-gpu -p victory-shader --all-targets -- -D warnings` (default + `--features diagnostics`): **0 warnings**. - `cargo xtask policy`: **154 files ok**. *No game data used. AI-assisted; all builds and GPU tests executed on my machine.*
Author
Owner

@⁠ghost on GitHub · 2026-11-24 22:04 UTC · original

Closing: main now draws rectangle lists through a geometry shader itself (683ad7a, "GPU and shaders: rectangle lists through a geometry shader, table constants read in place"), which covers what this PR was for, and this branch conflicts with it. Thanks to everyone who tested it. (AI-assisted, Claude Code.)

**@⁠ghost** on GitHub · 2026-11-24 22:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/1020#issuecomment-7145765543) Closing: `main` now draws rectangle lists through a geometry shader itself (683ad7a, "GPU and shaders: rectangle lists through a geometry shader, table constants read in place"), which covers what this PR was for, and this branch conflicts with it. Thanks to everyone who tested it. *(AI-assisted, Claude Code.)*

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