fix(vk): use vertex divisors only when vertexAttributeInstanceRateDivisor is supported #919
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!919
Loading…
Reference in a new issue
No description provided.
Delete branch "jcabarca/Longshot:fix/vk-vertex-divisor"
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?
Type: fix · Risk: low · Tested on: Windows 11 IoT Enterprise LTSC 24H2 (build 26100.9711), AMD Radeon RX 9070 XT, AMD Software: Adrenalin Edition 26.10.1 · Needs: none
TL;DR
On a GPU that has the vertex divisor extension but turns its divisor feature off, the emulator still used divisors over 1, which Vulkan forbids, so what such a GPU drew was undefined. This PR turns divisors off when the feature is off, like the checks next to it already do. A new test fails on main and passes here.
Breakdown
Why
On a GPU that has VK_EXT_vertex_attribute_divisor but reports the vertexAttributeInstanceRateDivisor feature as off, the pipelines still chained instance-rate divisors over 1, which breaks VUID-VkVertexInputBindingDivisorDescription-vertexAttributeInstanceRateDivisor-02229; what such a driver draws for those instances is undefined.
How to reproduce
Seen on: not seen in the game: found by reading
create_device()ingpu/vk/vk_main.cpp; it happens on any device that exposes the extension with the feature off (the RX 9070 XT reports the feature, so it does not show there)Settings and switches: defaults
Steps: game-free:
python -I -B tests/test_vertex_divisor_feature.pyon main (copy the test from this PR); it readscreate_device()invk_main.cppand the divisor chain invk_draw.cppExpected:
dev.vertex_divisoris on only when the device reportsvertexAttributeInstanceRateDivisorActual: on main it is on whenever the extension is there; the test fails
What changed
create_device()now turnsdev.vertex_divisoroff when the queried feature struct saysvertexAttributeInstanceRateDivisoris not supported, the same way the lines around it already do fornullDescriptorandprovokingVertexLast.create_device()ingpu/vk/vk_main.cpp: one line,dev.vertex_divisor = dev.vertex_divisor && vdiv.vertexAttributeInstanceRateDivisor;, aftervkGetPhysicalDeviceFeatures2and beforevkCreateDevice.tests/test_vertex_divisor_feature.py(new): checks that line, its place between the feature query andvkCreateDevice, and that the pipelines chain divisors only underdev.vertex_divisor.Second commit, "cap the vertex divisor at maxVertexAttribDivisor":
dev.max_vertex_divisoringpu/vk/vk_internal.h, read ingpu/vk/vk_main.cppfromVkPhysicalDeviceVertexAttributeDivisorPropertiesEXT::maxVertexAttribDivisor(chained intovkGetPhysicalDeviceProperties2) whendev.vertex_divisoris set.gpu/vk/vk_draw.cpp: the binding's divisor isstd::min(s.vstream[b].divisor, dev.max_vertex_divisor).tests/test_vertex_divisor_feature.pychecks the query and the cap.The divisor came from the game with no upper bound. VUID-VkVertexInputBindingDivisorDescription-divisor-01870: "divisor must be a value between 0 and VkPhysicalDeviceVertexAttributeDivisorProperties::maxVertexAttribDivisor, inclusive".
The bug, step by step:
create_device()setsdev.vertex_divisorwhen VK_EXT_vertex_attribute_divisor is in the device's extension list, and chains its feature struct (vdiv) into the device asvkGetPhysicalDeviceFeatures2filled it.vdiv.vertexAttributeInstanceRateDivisorback, so on a device with the extension and that feature off,dev.vertex_divisorstays on.vk_draw.cppthen chains every vertex stream's divisor, also the ones over 1:if (dev.vertex_divisor) vdivs.push_back({b, s.vstream[b].divisor});.The rule, from Khronos
validusage.json:Before:
After:
With the flag off, the existing path takes over: the divisor is logged as "(not supported: 1)" and no divisor struct is chained, so every instance reads with the default divisor 1.
Measurements
Verdict: it fixes the bug:
test_vertex_divisor_featurefails on main and passes here. Both interleaved runs gave the same result. No speed change is expected.Hardware: Windows 11 IoT Enterprise LTSC 24H2 (build 26100.9711), AMD Radeon RX 9070 XT, AMD Software: Adrenalin Edition 26.10.1; the tests are game-free (they read source or build a cut-out fixture, they do not use the GPU); Python 3.12
Scene: none, game-free
Method: the tests from this PR run against each side's checkout, 2 runs each, interleaved (main, PR, main, PR); the result is pass/fail, so the median is the result both runs gave
How to reproduce:
python -I -B tests/<test>.pywith--source <checkout>(and--cxx/--headerswhere the test asks for them) on each side6d949cf97fc1a0a1tests/test_vertex_divisor_feature.py, run 1tests/test_vertex_divisor_feature.py, run 2tests/test_vertex_divisor_feature.py, medianFlags and settings
None.
Testing
Tested: on this branch, Windows, Python 3.12:
test_vertex_divisor_featurepasses (fails on main), and the other check that reads the divisor flag passes:test_fallback_pipeline_state.Built and played: this commit builds on Windows (llvm-mingw back end) and on Linux (
longshot_vk.so, without and with AMD FSR 4). Played on Windows 11 IoT Enterprise LTSC 24H2 (build 26100.9711), AMD Radeon RX 9070 XT, AMD Software: Adrenalin Edition 26.10.1: the game runs normally.Not tested: a device with the extension and the feature off: none was at hand (the RX 9070 XT reports the feature, so the change does nothing there). Linux was built, not run.
Must be tested: None: the game-free test covers the change, and on devices that report the feature nothing changes.
Risks
What could break: on a device with the extension and the feature off, streams with a divisor over 1 now read with divisor 1, as they already do on devices without the extension. Before, the same pipelines broke the rule above, so what they drew was undefined anyway. Devices that report the feature are unchanged.
Turning it off: revert the commit.
Compatibility: Nothing changes.
Checklist
Everyone
type(scope): description) of the status line's type.can't be run by hand is in Testing's Not testable by hand, with why.
in Risks.
main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named). (the checks that read the changed code, on this PR, Windows:test_vertex_divisor_feature,test_fallback_pipeline_state, all pass)third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.mainand passing here. (tests/test_vertex_divisor_feature.py)tests/that reads changed source updated in this PR, not weakened. (tests/test_vertex_divisor_feature.pyadded; no check removed)longshot_vk.sowithout and with AMD FSR 4)WIP: fix(vk): use vertex divisors only when vertexAttributeInstanceRateDivisor is supportedto fix(vk): use vertex divisors only when vertexAttributeInstanceRateDivisor is supportedCode-only review of
84a8230df1; informational findings, with final approval left to another reviewer.No introduced correctness defect found. The feature struct is queried only when the extension is enabled, and the new assignment runs after that query and before device creation. The pipeline's existing
dev.vertex_divisorguard then omits divisors greater than 1 when unsupported, matching Khronos's feature requirement and default-divisor rule.Validation limit: the new test checks source strings and their order, rather than exercising extension absent / feature false / feature true cases and inspecting the resulting pipeline state. A behavioral fixture covering those three cases would strengthen the regression coverage. The reported Windows RX 9070 XT run covers the supported-feature path; the affected unsupported-feature path has not been run. Falling back to divisor 1 avoids the invalid Vulkan use but does not reproduce guest divisors greater than 1; that existing limitation is accurately disclosed in the PR.
Merge coordination: the dynamic vertex-input work also uses
dev.vertex_divisorto select divisors, so retain this capability gate when combining the changes. It is complementary, not a duplicate.Read the full diff, device feature-chain setup, static pipeline construction, existing pipeline-state fixture, and the relevant dynamic-input overlap. No tests, builds, or game runs performed in this review.
84a8230df1c6c38854b1New commit, "cap the vertex divisor at maxVertexAttribDivisor" (
c6c38854); the branch is rebased onto main @c167ec67.The divisor came from the game with no upper bound. VUID-VkVertexInputBindingDivisorDescription-divisor-01870: "divisor must be a value between 0 and VkPhysicalDeviceVertexAttributeDivisorProperties::maxVertexAttribDivisor, inclusive".
dev.max_vertex_divisoringpu/vk/vk_internal.h, read ingpu/vk/vk_main.cppfromVkPhysicalDeviceVertexAttributeDivisorPropertiesEXT::maxVertexAttribDivisor(chained intovkGetPhysicalDeviceProperties2) whendev.vertex_divisoris set.gpu/vk/vk_draw.cpp: the binding's divisor isstd::min(s.vstream[b].divisor, dev.max_vertex_divisor).tests/test_vertex_divisor_feature.pychecks the query and the cap.test_vertex_divisor_featurefails on main and passes here. Run twice each side, interleaved; What changed and Measurements in the description are updated.This commit (both commits of the PR) builds on Windows (llvm-mingw back end) and on Linux (
longshot_vk.so, without and with AMD FSR 4), and was played on Windows, AMD Radeon RX 9070 XT: the game runs normally. The description's Built and played line and the Host code builds box are updated.Brought up to the ready-for-review standard (#1454): the checklist's Everyone list has two new boxes, added here from what this PR's description and comments show (please check they match what you know).
51d3b54c437fc1a0a1baRebased onto main @
6d949cf9; the branch head is now7fc1a0a1. New since the last update: the test fixture now also sets dev.max_vertex_divisor. Measured again on the new base: tests/test_vertex_divisor_feature.py fails on main and passes on this PR, in both interleaved runs (Measurements updated). The description also gains a TL;DR and a Breakdown.Rebased onto main @
7daafa7a; the related tests pass on it.4a9469b10e1b88c70dedView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.