WIP: feat(vk): vertex input as dynamic state, so one pipeline serves every vertex layout of a program (RX_VK_DYNAMIC_VERTEX_INPUT, opt-in) #801

Draft
dyst wants to merge 1 commit from dyst/Longshot:perf/vk-dynamic-vertex-input into main
Member

Type: feat · Risk: low · Tested on: Windows 11 (the game-free checks; the game A/B is next) · Needs: a game run on NVIDIA, AMD and Intel

Why

Every graphics pipeline's key held its vertex layout, so a program drawn with several layouts was several pipelines: more compiles on first visits in play and more for the shader preparation to build (about 16,000). Vulkan's VK_EXT_vertex_input_dynamic_state lets the draw set the layout instead. Found in an audit of the renderer's pipeline path; no issue on the tracker. This adds it behind a switch, off by default, to be measured.

What changed

With RX_VK_DYNAMIC_VERTEX_INPUT=1 on a device that has the extension, ordinary graphics pipelines take the vertex layout as dynamic state, their play key leaves it out, and each draw sets its layout when it changes. The notes and pipeline state lists keep the layout, so their files mean the same in both modes. Off, nothing changes.

  • device: the extension and feature, Device::vertex_input_dynamic (gpu/vk/vk_main.cpp, vk_internal.h), vkCmdSetVertexInputEXT through the recorder (vk_loader.h, vk_recorder.h, vk_work.h)
  • draw: pipeline_key_of, pipeline_key, pipeline_note_key, note_pipeline_key, build_graphics, vertex_input_of, vertex_input_bind and its invalidations (gpu/vk/vk_draw.cpp); the precompile, warm-up, loader and prediction build each play pipeline once; the built and warmed stamps take the mode
  • docs: docs/development.md's switch row, docs/design.md §3
  • tests: tests/test_fallback_pipeline_state.py runs the real keys and vertex_input_bind; four fixtures' stubs

Measurements

Verdict: not measured yet: A/B runs in the game (this PR against main on one base, interleaved) are next and will replace this section.

Flags and settings

One switch for an A/B.

Flag What it is Before this PR After this PR Effect Helps / doesn't help / untested Recommendation
RX_VK_DYNAMIC_VERTEX_INPUT=1 Vertex input as dynamic state where the device has it - unset (off) On: fewer pipelines, a vertex-input command per layout change untested in the game off until measured on NVIDIA, AMD and Intel

Testing

Tested: Windows 11, llvm-mingw (the builder's v2.0.14 tools): the new and changed checks; every check that reads the
changed code; -fsyntax-only of the changed renderer files with the build's flags and headers; python -I -B tests/run_all.py on this branch and on main @ aa95d35f, same PC and environment: the same results apart from the extended test_fallback_pipeline_state; the failures main has here are named in the first comment.

Not tested: the game yet. This PR is WIP until its A/B is in (next: this PR against main on one dev_packs base of
main @ aa95d35f, on an RTX 3080 with a Ryzen 9 3900X, Windows 11; AMD and Intel need other testers).

Must be tested:

  • NVIDIA, AMD (Windows and RADV) and Intel, with RX_VK_DYNAMIC_VERTEX_INPUT=1: a first start (the preparation's pipeline count and time against main) and Kokiri Forest and Castle Town a few minutes, expecting the same picture, vk: vertex input: set by each draw in the log, fewer pipelines made in play and no new stutter (Test Farm: @Beanstalk nvidia, amd, radv, intel: with RX_VK_DYNAMIC_VERTEX_INPUT=1)

Risks

What could break: Only with the switch on: a driver whose dynamic vertex input is slow (RADV builds a small prologue per layout) or wrong (attributes read with the wrong layout: broken models). Off, the code paths are the old ones.

Turning it off: leave RX_VK_DYNAMIC_VERTEX_INPUT unset (the default)

Compatibility: Off: nothing changes. On: the noted pipelines are built again once (the built and warmed stamps take the mode); the program cache and the driver's pipeline cache are shared between modes.

Checklist

Everyone

  • One topic.
  • The title is a Conventional Commit (type(scope): description) of the status line's type.
  • Why gives the reason plainly and links the issues that fit (the tracker searched).
  • Measurements has a verdict, or one line saying why there is nothing to measure.
  • Testing names what was tested, what wasn't, and what must still be tested, where and how.
  • Rebased on current main.
  • python -I -B tests/run_all.py passes (any failure that also fails on main is named).
  • No game files, dumps, build output or generated files.
  • third_party/ untouched (a new folder with a PROVENANCE.md instead).
  • The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled.

When it applies

  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.
  • Switches documented (docs/development.md; the README for a menu row) and shipped at their recommended value.
  • A check under tests/ that reads changed source updated in this PR, not weakened.
  • A game-free test added for the fix, failing on main and passing here.
  • Docs updated.

🤖 Generated with Claude Code

**Type:** feat · **Risk:** low · **Tested on:** Windows 11 (the game-free checks; the game A/B is next) · **Needs:** a game run on NVIDIA, AMD and Intel ## Why Every graphics pipeline's key held its vertex layout, so a program drawn with several layouts was several pipelines: more compiles on first visits in play and more for the shader preparation to build (about 16,000). Vulkan's `VK_EXT_vertex_input_dynamic_state` lets the draw set the layout instead. Found in an audit of the renderer's pipeline path; no issue on the tracker. This adds it behind a switch, off by default, to be measured. ## What changed With `RX_VK_DYNAMIC_VERTEX_INPUT=1` on a device that has the extension, ordinary graphics pipelines take the vertex layout as dynamic state, their play key leaves it out, and each draw sets its layout when it changes. The notes and pipeline state lists keep the layout, so their files mean the same in both modes. Off, nothing changes. - device: the extension and feature, `Device::vertex_input_dynamic` (`gpu/vk/vk_main.cpp`, `vk_internal.h`), `vkCmdSetVertexInputEXT` through the recorder (`vk_loader.h`, `vk_recorder.h`, `vk_work.h`) - draw: `pipeline_key_of`, `pipeline_key`, `pipeline_note_key`, `note_pipeline_key`, `build_graphics`, `vertex_input_of`, `vertex_input_bind` and its invalidations (`gpu/vk/vk_draw.cpp`); the precompile, warm-up, loader and prediction build each play pipeline once; the built and warmed stamps take the mode - docs: docs/development.md's switch row, docs/design.md §3 - tests: `tests/test_fallback_pipeline_state.py` runs the real keys and `vertex_input_bind`; four fixtures' stubs ## Measurements **Verdict:** not measured yet: A/B runs in the game (this PR against main on one base, interleaved) are next and will replace this section. ### Flags and settings One switch for an A/B. | Flag | What it is | Before this PR | After this PR | Effect | Helps / doesn't help / untested | Recommendation | |---|---|---|---|---|---|---| | `RX_VK_DYNAMIC_VERTEX_INPUT=1` | Vertex input as dynamic state where the device has it | - | unset (off) | On: fewer pipelines, a vertex-input command per layout change | untested in the game | off until measured on NVIDIA, AMD and Intel | ## Testing **Tested:** Windows 11, llvm-mingw (the builder's v2.0.14 tools): the new and changed checks; every check that reads the changed code; `-fsyntax-only` of the changed renderer files with the build's flags and headers; python -I -B tests/run_all.py on this branch and on main @ aa95d35f, same PC and environment: the same results apart from the extended `test_fallback_pipeline_state`; the failures main has here are named in the first comment. **Not tested:** the game yet. This PR is WIP until its A/B is in (next: this PR against main on one dev_packs base of main @ aa95d35f, on an RTX 3080 with a Ryzen 9 3900X, Windows 11; AMD and Intel need other testers). **Must be tested:** - NVIDIA, AMD (Windows and RADV) and Intel, with `RX_VK_DYNAMIC_VERTEX_INPUT=1`: a first start (the preparation's pipeline count and time against main) and Kokiri Forest and Castle Town a few minutes, expecting the same picture, `vk: vertex input: set by each draw` in the log, fewer pipelines made in play and no new stutter (Test Farm: @Beanstalk nvidia, amd, radv, intel: with RX_VK_DYNAMIC_VERTEX_INPUT=1) ## Risks **What could break:** Only with the switch on: a driver whose dynamic vertex input is slow (RADV builds a small prologue per layout) or wrong (attributes read with the wrong layout: broken models). Off, the code paths are the old ones. **Turning it off:** leave `RX_VK_DYNAMIC_VERTEX_INPUT` unset (the default) **Compatibility:** Off: nothing changes. On: the noted pipelines are built again once (the built and warmed stamps take the mode); the program cache and the driver's pipeline cache are shared between modes. ## Checklist ### Everyone - [x] One topic. - [x] The title is a Conventional Commit (`type(scope): description`) of the status line's type. - [x] Why gives the reason plainly and links the issues that fit (the tracker searched). - [x] Measurements has a verdict, or one line saying why there is nothing to measure. - [x] Testing names what was tested, what wasn't, and what must still be tested, where and how. - [x] Rebased on current `main`. - [x] `python -I -B tests/run_all.py` passes (any failure that also fails on `main` is named). - [x] No game files, dumps, build output or generated files. - [x] `third_party/` untouched (a new folder with a `PROVENANCE.md` instead). - [x] The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled. ### When it applies - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. - [x] Switches documented (docs/development.md; the README for a menu row) and shipped at their recommended value. - [x] A check under `tests/` that reads changed source updated in this PR, not weakened. - [x] A game-free test added for the fix, failing on `main` and passing here. - [x] Docs updated. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
feat(vk): vertex input as dynamic state, so one pipeline serves every vertex layout of a program (RX_VK_DYNAMIC_VERTEX_INPUT, opt-in)
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 6s
CI / Conventional Commit title (pull_request) Successful in 3s
CI / Workflow lint (actionlint) (pull_request) Successful in 5s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 5s
Third-party parts / As their notes say (pull_request) Successful in 7s
Website / Website on Cloudflare (pull_request_target) Has been skipped
1e64adc07c
Every graphics pipeline's key held its vertex layout (each attribute's format, offset and stream, each stream's divisor), so a
program drawn with several layouts was several pipelines: more first-visit compiles in play and more to prepare (the
preparation builds ~16,000).

With RX_VK_DYNAMIC_VERTEX_INPUT=1 and a device that has VK_EXT_vertex_input_dynamic_state, ordinary graphics pipelines are made
with an empty vertex input state and VK_DYNAMIC_STATE_VERTEX_INPUT_EXT (instead of the binding-stride state), their key leaves
the layout out (pipeline_key; pipeline_note_key keeps it, so the notes and the pipeline state lists mean the same in both modes),
and each draw records vkCmdSetVertexInputEXT when its layout (with the strides it bound) differs from the one set
(vertex_input_bind), the cache dropped wherever a pipeline with static or no vertex input may have been bound (the mesh
fallback, mesh pipelines, clears, a new recording, the temporal paths). An attribute that reads the zero binding takes the format
of its type. The precompile, the warm-up, the program loader and the prediction build each play pipeline once; the built and
warmed stamps take the mode, so a toggle rebuilds the noted pipelines once. Mesh and fallback pipelines are unchanged. Off (the
default), or on a device without the feature, nothing changes: the extension is not enabled and the keys, stamps and pipelines
are as before (the log's "vk: vertex input:" line says which).

tests/test_fallback_pipeline_state.py runs the real keys, vertex_input_of and vertex_input_bind: one key for two layouts in the
dynamic mode and two in the static one, the layout set once, kept, and set again after a fallback or mesh bind.

Assisted-by: Claude Opus 5.5
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Author
Member

The checks on this PC (Windows 11, RTX 3080, Ryzen 9 3900X, llvm-mingw from the builder's v2.0.14 tools): python -I -B tests/run_all.py on main @ aa95d35f fails these 19 here, and so does this branch: test_appimage_player_build.py, test_bake_portability.py, test_cpm_discovery.py, test_cpp_preflight.py, test_crash_dialog.py, test_env_on.py, test_fpx_sticky.py, test_lift_cleanup_error.py, test_linux_preflight.py, test_make_game_cache.py, test_make_game_prepare.py, test_missing_nup.py, test_oot_state_tap.py, test_options_budget_once.py, test_readback_late.py, test_spawn_emit.py, test_tested_configurations.py, test_vk_pgo.py, test_walk_key.py. Any other failure in a full run on this branch was rerun on its own and passed (the full runs shared the PC with dev_packs builds: timing checks).

Next: an interleaved A/B in the game against main on one dev_packs base of aa95d35f; the numbers will replace the Measurements section.

The checks on this PC (Windows 11, RTX 3080, Ryzen 9 3900X, llvm-mingw from the builder's v2.0.14 tools): `python -I -B tests/run_all.py` on main @ aa95d35f fails these 19 here, and so does this branch: `test_appimage_player_build.py`, `test_bake_portability.py`, `test_cpm_discovery.py`, `test_cpp_preflight.py`, `test_crash_dialog.py`, `test_env_on.py`, `test_fpx_sticky.py`, `test_lift_cleanup_error.py`, `test_linux_preflight.py`, `test_make_game_cache.py`, `test_make_game_prepare.py`, `test_missing_nup.py`, `test_oot_state_tap.py`, `test_options_budget_once.py`, `test_readback_late.py`, `test_spawn_emit.py`, `test_tested_configurations.py`, `test_vk_pgo.py`, `test_walk_key.py`. Any other failure in a full run on this branch was rerun on its own and passed (the full runs shared the PC with dev_packs builds: timing checks). Next: an interleaved A/B in the game against main on one dev_packs base of aa95d35f; the numbers will replace the Measurements section.
HumanBean force-pushed perf/vk-dynamic-vertex-input from 1e64adc07c
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 6s
CI / Conventional Commit title (pull_request) Successful in 3s
CI / Workflow lint (actionlint) (pull_request) Successful in 5s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 5s
Third-party parts / As their notes say (pull_request) Successful in 7s
Website / Website on Cloudflare (pull_request_target) Has been skipped
to 7b51b1cbd5
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 5s
CI / Conventional Commit title (pull_request) Successful in 4s
CI / Workflow lint (actionlint) (pull_request) Successful in 9s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 8s
Third-party parts / As their notes say (pull_request) Successful in 16s
Website / Website on Cloudflare (pull_request_target) Has been skipped
2026-11-15 18:46:48 +00:00
Compare
Owner

Rebased onto main @ 7bacf846. Two conflicts: tests/test_fallback_pipeline_state.py (kept main's new program_modules_dropped stub and this PR's packed nvn_va_st) and gpu/vk/vk_draw.cpp (kept this PR's dynamic-vertex-input block and main's FlatMap for the per-thread mine table). Pushed as 7b51b1cb. No tests were run here; the test boxes stay yours.

Rebased onto `main` @ 7bacf846. Two conflicts: tests/test_fallback_pipeline_state.py (kept main's new `program_modules_dropped` stub and this PR's packed `nvn_va_st`) and gpu/vk/vk_draw.cpp (kept this PR's dynamic-vertex-input block and main's `FlatMap` for the per-thread `mine` table). Pushed as 7b51b1cb. No tests were run here; the test boxes stay yours.
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 5s
CI / Conventional Commit title (pull_request) Successful in 4s
CI / Workflow lint (actionlint) (pull_request) Successful in 9s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 8s
Third-party parts / As their notes say (pull_request) Successful in 16s
Website / Website on Cloudflare (pull_request_target) Has been skipped
This pull request has changes conflicting with the target branch.
  • tests/test_fallback_pipeline_state.py
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'perf/vk-dynamic-vertex-input:dyst-perf/vk-dynamic-vertex-input'
git switch 'dyst-perf/vk-dynamic-vertex-input'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
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
MagicBeanDev/Longshot!801
No description provided.