fix(vk): simulated-turf lists stay within the device's workgroups for one draw or dispatch #2288
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
5 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2288
Loading…
Reference in a new issue
No description provided.
Delete branch "pepe999/Longshot:fix/sim-turf-mesh-limit"
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?
Summary
At very wide simulated-turf ranges, turf patches flicker all over on AMD cards that draw with native mesh shaders, also near the player and standing still. See #2251, which has the steps on
main(Hyrule Field, a fade endpoint towards 195, density 100 %, 24 blades at least).The game's programs turn a simulated-turf list's record count into the workgroups of one indirect command: one for every 32 records of a pool (its mesh draw), one for every 64 of a blade list (the pool producer's dispatch). The only bound on that count is the length of the list's private buffer, and the buffer's length was bounded by the storage buffer range alone. On AMD a pool past 2,097,120 records asks for more than the 65,535 groups of
maxMeshWorkGroupCount[0], an invalid draw (the issue measured 70,195).Now a list's most records also follow the limit of what reads it: the native mesh draw's for a pool (
maxMeshWorkGroupCount[0], and the total count), the compute dispatch's for a blade list and for a pool drawn through the compute fallback. A device with room (NVIDIA's mesh draws, RADV's compute dispatch) keeps the size it had.What it does not do: past the limit the overflow is still dropped in the order the game's atomics give it, so some churn can remain there. Dropping the farthest first (the near-to-far buckets noted in #2241) is a change of its own.
Read first:
sim_turf_max_recordsingpu/vk/vk_draw.cpp; the limit is read ingpu/vk/vk_main.cpp(max_mesh_groups).See #2251.
Testing
Tested: Linux, RX 6700 XT (RADV, Mesa 26.2.7): Hyrule Field, child, standing, ten runs (five of
main, five of this PR), no GPU error in any log and every run closed cleanly. These ran on RADV's default compute path, whose dispatch limit is 4,294,967,295 there, and with the default turf settings (peak demand about 800 of 138,240 pool records): they show nothing else broke, not the limit at work. The limit itself is covered by the game-free test only:tests/test_sim_turf_group_limit.pyfails onmain(queried(true, 65535, 4194304) == 65535: the limit is never asked for) and passes here. Six broken versions of the fix each fail it: the limit dropped, the fallback ignored, the query's assignment gone, its structure out of the chain, the total count left out, the query made with the extension off. g++ only; no clang on this PC.The whole suite (
tests/run_all.py, not--strict) at19bfda96and atmain753fb5af: 882 passed, 14 failed, 62 skipped here; 881 passed, the same 14 failed, 62 skipped onmain. The 14, none new here: nx2/test_mesh_first_types, test_appimage_player_build, test_appimage_source_headers, test_audio_source, test_builtin_compute_unoptimized, test_dev_packs, test_image_view_retry, test_link_skip, test_longshot_launch, test_mise_build, test_mods_list, test_options_path, test_pipeline_state_computes, test_thinlto_tls. 44 of the skips are tools this PC lacks (clang, clang++, spirv-val, glslang, dav1d). The renderer was built whole and linked, its symbols checked, at19bfda96.Still to test:
mainagainst this PR, expecting the patches' flicker gone or only at the far edge, no device lost, and no pool resized past 2,097,120 records in the log (by hand: the farm can't set the turf rows or judge flicker).mainagainst this PR, expecting no change (@Beanstalk, needs a BigBean).Measurements
Verdict: a fix: the oversized draw's size is bounded in the test; no fps difference seen at the default settings.
Setup: Linux 7.3.4, RX 6700 XT, RADV Mesa 26.2.7; Hyrule Field, child (open, far view), window 1280x720, output 2560x1440, resolution 67 %, frame generation and V-Sync off, uncapped (
HOS_FPS_MAX=1000); the frame trace, 60 s each after a warm-up, interleaved pairs (dev.py ab). Measured at 215bb798 against its merge base; this head is the same change rebased.b9bd74a2test_sim_turf_group_limit.pyThe first run of
mainin each A/B, and the first of this PR in the first, were far slower (72-77 fps) than every other (121-123); the cause isn't known, and no conclusion is drawn from them.dev.py abwrote no section for the second A/B (exit 3): the turf menu rows read "Load an area" at one moment of B2 and their values in the others; the options files were the same.Risks
A pool that needs more than the device's limit is now clipped at it, where the oversized draw was submitted before. Nothing changes at the game's settings (4,320 groups a pool). No switch of its own:
RX_VK_SIM_TURF_POOLS=0goes back to the game's lists, and a revert is enough. Saves, options and caches are untouched; players notice nothing after updating.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named). (Run without--strict: spirv-val, glslang and clang are missing here, and those checks skip; see Testing.)main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
mainand passes here.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
Tested in game: Linux, RX 6700 XT (RADV, Mesa 26.2.7), Hyrule Field, child, default turf settings: ten runs (five of main, five of this change), no GPU error in any log, all closed cleanly. It ran on RADV's default compute path, where this limit never applies, and demand was about 800 of 138,240 records: it shows nothing else broke, not the limit at work. Native mesh was not run here (RADV's native path can hang the GPU).
@Beanstalk two runs of this PR against main: (1) Windows, an AMD RX 7000 or 9000 drawing with native mesh shaders (an RX 6000 takes the compute fallback by default), Hyrule Field by day, standing still with a broad view of the turf, first the default turf settings, then the Simulated turf page at fade endpoint 195 (or as near as the row allows), density 100 %, 24 blades at least: expecting no device lost and no VkResult error on either, and on this PR no 'vk: simulated turf: pool ... resized' line past 2097120 records; (2) Windows, any NVIDIA RTX, Hyrule Field with the default turf settings: expecting the same fps and the same 'vk: simulated turf' lines as main. Whether the turf patches still flicker is for a person to judge by eye.
@pepe999 only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.Possibly related, for context:
The rebased head
19bfda96was built whole and linked, its symbols checked; the description says so now.@review
Recommendation: Approve. The capacity calculation is covered, but the test bypasses the device-property initialization that makes the fix work on native mesh shaders. The affected path also still needs an in-game comparison at the reported settings. Nothing blocking is left: what remains is for the author before merging (below). Recommend approval; not approved on the forge.
The change limits adaptive turf-list capacities to the workgroup count accepted by their draw or dispatch. It should prevent oversized indirect commands, at the cost of dropping records once the device limit is reached; the visible result at that limit remains unverified.
Should fix (1): not blocking, but worth doing before merging.
tests/test_sim_turf_group_limit.py:70: The test supplies the mesh limit directly and never exercises its query or assignment in create_device. (more on the line) Do: Add a game-free check that exercises the property-chain query and assignment, including both the X and total limits, and fails when that initialization is removed.Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
gpu/vk/vk_draw.cpp:497: The affected native mesh path has not been tested at the reported turf settings. (more on the line) Do: Compare main and this head in Hyrule Field on Windows AMD native mesh at the reported settings, inspect the turf by eye and check the logs for errors and the installed capacity.@fixcan do L1.Checks: Still running: 9 checks.
More: does it help, other systems, switches, what was read
Does it help: Unproven in the affected game scenario. The author's game-free test reports a cap of 65,535 groups, but its device limit is supplied by the harness; the Linux RX 6700 XT runs used the compute path and reached only about 800 of 138,240 pool records. The reported frame-rate runs were at default settings and do not exercise the fix.
Other systems: The calculation also applies to blade-list dispatches and compute-fallback pool draws; the reported RADV runs covered the fallback at default demand, not its limit. Native AMD mesh and Windows NVIDIA runs are still outstanding. Saves, options, shaders and the renderer API are unchanged.
Switches: None added, changed or removed.
Reviewed:
19bfda9641against753fb5af68: Read the changed test in full, the complete diff and commit messages, repository rules and PR template, and the relevant device initialization, turf binding, capacity policy, shader and draw paths. Skimmed the test runner and related references; the large renderer files were not read in full. docs/review-checklist.md and the adjacent Tooling AGENTS.md were absent.; nothing run (a code review).Checked and fine:
Testing: Read-only review; no commands from the project, builds or tests were run. CI is still running.
Overlaps and merge order: Not checked; network access is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -495,0 +494,4 @@// (a list's reader runs a workgroup for every `group` records, in one indirect command the game's program writes from the// list's length: a pool's mesh draw (its compute fallback's dispatch), a blade list's dispatch. Past what the device takes in// one the command is invalid: AMD's 65535 groups are 2,097,120 pool records, and a longer pool's turf flickered all over)const uint64_t groups = pool && !dev.uses_mesh_fallback(false) ? dev.max_mesh_groups : dev.props.limits.maxComputeWorkGroupCount[0];L2 (should fix): The affected native mesh path has not been tested at the reported turf settings.
When: At a fade endpoint near 195 with high density on Windows AMD native mesh, the calculation caps the list, but the existing runs neither reach that cap nor show whether the reported flicker and invalid draw are gone.
Do: Compare main and this head in Hyrule Field on Windows AMD native mesh at the reported settings, inspect the turf by eye and check the logs for errors and the installed capacity.
@ -0,0 +67,4 @@int main() {// AMD: 65535 groups a mesh draw. The reported scene's demand asked for 70,195dev.max_mesh_groups = 65535;L1 (should fix): The test supplies the mesh limit directly and never exercises its query or assignment in create_device.
When: If the new assignment to dev.max_mesh_groups in vk_main.cpp is removed, the test still passes, while the real device retains UINT32_MAX and an AMD native mesh draw can again exceed 65,535 groups.
Do: Add a game-free check that exercises the property-chain query and assignment, including both the X and total limits, and fails when that initialization is removed.
Beanstalk test farm
Commit
fddd0aa· approved by nobody yet · dashboardA member of
BigBeanscan review this commit and comment@Beanstalkto test it.L1 of the review: the check now cuts create_device's property query out of vk_main.cpp and runs it (the x and the total limit, and only with the extension on); it fails on main and on each of six broken versions of the fix. It is a commit of its own on top (
fddd0aa2), the fix unchanged.L2 and the farm: the farm can't set the turf rows, so the reported settings need a person with an RX 7000/9000 on Windows (@erlo68's RX 7900 XT is the reporter's). Its default-turf alternative is welcome as a smoke run; a BigBean has to ask for it. This PC can't do it: RADV's default is the compute path.
Tested the current head
fddd0aa2on Windows 11 with an RX 7900 XT (native mesh shaders, driver field0x8001a0), against the exact PR base753fb5af.tests/run_all.py sim_turf_group_limit --strictpasses with the Visual Studio Clang toolchain.For the in-game check I entered adult Hyrule Field from adult Market (the town-gate view has substantially more turf than the debug teleport), then held the camera still at 3440x1440 with fade 100 -> 195, density 100, minimum blades 24 and far power 0.5.
The baseline reached 2,795,114 requested main-pool records and grew that pool to 3,493,920. That demand corresponds to 87,348 mesh workgroups, above this device's reported 65,535 X/total mesh-group limit. With this PR, a comparable run reached 2,801,363 requested records but both main pools stopped at exactly 2,097,120 records (
65,535 * 32). There were no device-loss, validation-error or crash messages.I captured 360 images beginning immediately after applying the stress range and another 240 after settling on each side. The capture requests landed every 3 presents at the median. An adjacent-image terrain-cell check found no frames with simultaneous reversals in 10 or more cells on either baseline or PR in these runs, so I did not reproduce the old large-dropout visual signature at this particular stationary view. This still confirms that the PR enforces the valid one-draw prefix during a genuinely over-limit workload without introducing an obvious regression.
One caveat: this is intentionally device-dependent, not an AMD-specific constant. Other GPUs/drivers can report different
maxMeshWorkGroupCount[0]/maxMeshWorkGroupTotalCountvalues (and the compute fallback has its ownmaxComputeWorkGroupCount[0]), so their resulting caps can differ. Also, this patch caps the list but does not order admitted records near-to-far; reservations still arrive in concurrent atomic order. When demand exceeds the cap, the invalid oversized command is avoided, but residual patch churn/flicker is still possible and this test should not be read as proving all visual flicker is gone.@review
Recommendation: Approve. The test now exercises the device property query, and the reported Windows native-mesh run confirms the pool is capped at the device limit under an over-limit workload. The run did not reproduce the original flicker, so its visual resolution remains unproven. Recommend approval; not approved on the forge.
Limits simulated-turf lists to the workgroup count their draw or dispatch can accept, avoiding an invalid oversized command at extreme ranges. Excess records are still dropped in atomic order, so some patch churn may remain.
Since the last review (on
19bfda9641)Resolved: L1 (The test supplies the mesh limit directly and never exercises its query or assignment in c…); L2 (The affected native mesh path has not been tested at the reported turf settings.)
Checks: Still running: 9 checks.
Also noticed (3; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Yes for the invalid-command limit: on an RX 7900 XT, the baseline requested 87,348 mesh groups against a 65,535 limit, while this head capped both pools at 2,097,120 records. The tester did not reproduce the original visual dropout on either version, so the flicker fix itself is unproven.
Other systems: The limit also applies to compute fallback and blade-list dispatches; the game-free test covers their selection. Linux RADV default-compute runs showed no GPU errors; NVIDIA and other affected hardware have not been reported tested.
Switches: None added, changed or removed. The existing RX_VK_SIM_TURF_POOLS=0 disables renderer-owned pools.
Reviewed:
fddd0aa2ceagainst753fb5af68: Read the complete diff, commit list, test file as shown in the diff, repository AGENTS.md, CONTRIBUTING.md and pull request template; inspected the changed portions of the renderer files through the diff, not those files in full.; nothing run (a code review).Checked and fine:
Testing: No commands or tests were run for this review. The author reports the game-free test passing with Visual Studio Clang on the current head, and the native-mesh game run is described in the tester's comment.
Overlaps and merge order: Not checked; network access is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@BeanBot
The native-mesh run establishes the backend guarantee: submitted draws/dispatches stay within the device limit and excess reservations are discarded safely. The discard still follows atomic reservation order, so the set of surviving turf patches change frame-to-frame, still leading to constant flickering on seemingly random patches, even after savely discarding overflow. We’re testing a separate near-to-far ordering follow-up intended to make overflow discard the farthest patches first, and we’ll report its moving-camera visual result separately.
WIP: fix(vk): simulated-turf lists stay within the device's workgroups for one draw or dispatchto fix(vk): simulated-turf lists stay within the device's workgroups for one draw or dispatchJer9 referenced this pull request2026-11-23 16:17:47 +00:00