WIP: feat(vk): Grass distance, how far the grass stays full (2x by default) #1382
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!1382
Loading…
Reference in a new issue
No description provided.
Delete branch "winterelfeas/Longshot:grass-distance"
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: feat · Risk: low · Tested on: Windows 11, RTX 5090 (NVIDIA 621.01) · Needs: AMD, Intel; Steam Deck
Why
Kokiri Forest's short grass blades and the moss on its stones stop about 20 m from the camera. From the stepping stones the ground in front of the forest's exit looks bare, and the blades only grow in as Link walks up to it. Hyrule Field's grass is full only within 8 m of the camera and thins out quickly beyond, so the field looks barren in the middle distance. Players asked for more grass draw distance in #950 and #205. See #950, #205.
What changed
A new Graphics row, Grass distance (Game's, 2x, 3x, 4x; 2x by default), makes the short blades reach that many times as far and keeps Hyrule Field's grass full that many times as far. It changes only the copy of a few uniform values the GPU reads, never the game's memory. The short blades change at once; the field's grass as the game makes its ground tiles (Link moving on, the area loading).
Why three values in three programs: the game draws the blades from patches that the compute program 383a566958350efe picks around Link (word 75 of its scene buffer: a 22 m radius). Each blade then goes through a random cut by its distance in the task stage of both programs that draw it, 43ec86f35fd937b9 (the colour) and 8a8304edb7bdf4bf (a second pass over the same blades); words 46 and 47 of their scene buffer make a fade from 12 m to about 20 m. Lifting the cut in only one of the two passes changes nothing on screen, which is why this took a while to find.
The main grass (Hyrule Field's): compute d5a9475f2790532e gives each ground tile a blade count of the density times 1 - (1 + w97 - w96/d²): full to √w96 (8 m), then falling as 1/d² to none at √(w96/w97) (65 m). The game's own foliage setting for it (the foliage object's +0x7c) moves both words together; the row multiplies both by n², so the full count reaches n times as far and the end stays at 65 m.
grass_reach()andgrass_words()ingpu/vk/vk_draw.cpp;uniform_range()copies a binding c3 of those three programs into the stream and scales the words (radius times n, both fade ends divided by n). Only positive values are changed: the same slot holds other numbers in other stages.draw()anddispatch()telluniform_range()the program (ub_prog_key). d5a9475f2790532e's words 96 and 97 times n². Each changed word is logged once:vk: Grass distance 2x: program ... word ... a -> b.gpu/vk/vk_menu.cpp(tx_grass_distance),opts.grass_distanceingpu/vk/vk_menu.h; no Quality preset sets it (preset-exempt, as Anisotropic filtering).RX_VK_GRASS_DISTANCE=<n>(1 to 8) over the row for one run, ingpu/vk/switches.def.grass_distancein docs/development.md's options file table.tests/test_grass_distance.pykeeps the row, its labels and the reach table in step, and names the three programs.Measurements
Verdict: helps: from Kokiri's stepping stones the blades reach the ground before the exit, and Hyrule Field's grass stays full further out (30 to 48 % more blades in the middle distance at 3x, as the game's own foliage setting gives); the short blades' area in the upper half of the frame goes from about 1300 px (Game's) to 3650 px (2x) and 4400 px (4x), and the GPU frame grows by 0.19 ms at 2x, 0.42 ms at 4x in Kokiri Forest and about 0.35 ms at 4x in Hyrule Field, 2x there within the noise (RTX 5090, 2560x1440).
Hardware: Windows 11, RTX 5090, NVIDIA 621.01, 32 threads
Scene: Kokiri Forest, the save's start walked to the stepping stones (1.1, 3.25), the camera tilted up a little to show the ground before the exit; output 2560x1440, DLSS, no frame generation, 60 fps cap
Method: GPU time:
RX_VK_PASS_TIMING=1(the "ms a frame in all" line, every 600 presents), one run, the row changed live through the control bridge in the order Game's, 4x, 2x, 3x, Game's, 4x, 2x, 3x, 25 s each; the median of the blocks that lie wholly inside each value's time. Blade area: a debug build that skips 43ec86f35fd937b9's draws (the blades then show white where the second pass drew them), two shots per value, white pixels in the upper half.Baseline: this PR at Game's, which leaves the three values as main has them, in the same run, so the row can be switched live and the values interleaved (main has no row to switch). The blade counts come from the debug build with the same values set through a uniform patch switch.
The Kokiri Forest numbers were taken on
ed84459d, the first commit;095a6434adds the main grass and leaves the short blades' code as it was.How to reproduce: Kokiri Forest, stand on the stepping stones looking at the exit, switch Grass distance between Game's and 4x.
095a6434095a6434095a6434095a6434Hyrule Field's grass (by the Kakariko gate, debug build, white view, one run from one spot, the tiles made again after each change by nudging the foliage object's +0x7c): white px per 40 px screen band from the middle distance to near, the game's values 6501 / 5756 / 3718 / 2925, the falloff 3x 7010 / 7426 / 5498 / 4000 (+8 to +48 %), the game's own +0x7c = 24 (also 3x) 6246 / 7517 / 6682 / 4502 for comparison.
Screenshots are in the comments: Kokiri Forest's normal picture at Game's, 2x and 4x and the debug view with the short blades white; Hyrule Field's debug view with the grass white.
Flags and settings
A new menu row and ini key, and a switch for it.
grass_distance)RX_VK_GRASS_DISTANCETesting
Tested: Windows 11, RTX 5090: the row in the menu, saved as
grass_distance, changed live through the control bridge at Kokiri's stepping stones (pictures and timings above); Hyrule Field by the Kakariko gate, the log showing each program's words changed once, GPU time at Game's, 2x and 4x;python -I -B tests/run_all.py: 592 passed, 40 failed, 90 skipped; main @544229a2on the same PC: 591 passed, the same 40 failed, 90 skipped. The 40 fail on main too on this PC (tools and compilers it lacks):test_auto_handheld.py,test_bug_report_defaults.py,test_cpu_report.py,test_crash_dialog.py,test_crt_options.py,test_damage_debug_menu.py,test_display_startup_failure.py,test_dlss_feature_size.py,test_failed_compile_keeps_objects.py,test_fastfp_fma.py,test_fpx_sticky.py,test_framegen_preset.py,test_guest_imported.py,test_hud_layout_row.py,test_invalidate_vcore.py,test_job_queue.py,test_linux_preflight.py,test_linux_pressure.py,test_mirror_budget.py,test_missing_nup.py,test_pads_after_menu.py,test_pending_guest_import.py,test_perf_report.py,test_pipeline_play_cache.py,test_present_thread.py,test_profiling_mode.py,test_readback_timeout_source.py,test_rumble_menu.py,test_run_all_changed.py,test_slow_frames.py,test_spawn_emit.py,test_switch_table.py,test_target_image_pool.py,test_tested_configurations.py,test_upscaler_round_trip.py,test_upscaler_rows.py,test_vcore_escape.py,test_vk_occlusion_queries.py,test_vk_swapchain_compat.py,test_walk_key.py. The new test passes.Not tested: AMD and Intel GPUs, Linux, the Steam Deck; other areas with these blades than Kokiri Forest.
Must be tested:
Risks
What could break: a program that shares one of the three keys in another game version would get its values scaled; only positive values of the named words of binding c3 are touched. The patched copy goes through the same stream as other uniform copies.
Turning it off: Grass distance: Game's, or
RX_VK_GRASS_DISTANCE=1.Compatibility: a new key in longshot_options.ini (
grass_distance=1by default); no shader or pipeline cache change, no vk ABI change.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. Not ticked yet: Measurements covers only the RTX 5090, and the Steam Deck frame-rate cost is expected but not measured.
main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named).third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.tests/that reads changed source updated in this PR, not weakened.🤖 Generated with Claude Code
Tested in game: Windows 11, RTX 5090 (NVIDIA 621.01): Kokiri Forest, the save's start walked to the stepping stones facing the exit. Grass distance switched live between Game's, 2x, 3x and 4x: at 2x and 4x the short blades grow on the ground before the exit, nothing else changes; GPU frame +0.19 ms at 2x, +0.42 ms at 4x (2560x1440, RX_VK_PASS_TIMING=1).
Screenshots, Kokiri Forest from the stepping stones facing the exit, 2560x1440 output (shots at 1280x720, cropped to the far ground).
The normal picture, this PR @
ed84459d, Grass distance Game's, 2x and 4x: more short blades on the ground before the exit and around the purple flowers.The same spot in a debug build that skips 43ec86f35fd937b9's draws, so the short blades show white where the second pass (8a8304edb7bdf4bf) draws them; the values set as the row sets them at Game's, 2x and 4x. At Game's they stop at the first stones; at 2x and 4x they cover the ground before the exit and the slopes beside it.
The main grass (Hyrule Field's) gets its blade count per ground tile from compute d5a9475f2790532e: the density times 1 - (1 + w97 - w96 / d^2), so full to sqrt(w96) (8 m), then falling as 1 / d^2 to none at sqrt(w96 / w97) (65 m). The game's own foliage setting for it (the foliage object's +0x7c) moves both words together; the row now multiplies both by n^2, so the full count reaches n times as far and the end stays at 65 m. The compute runs when the game makes a tile, so a change of the row reaches the main grass as Link moves on or the area loads again. grass_words gives each word the power of the reach it is multiplied by; each changed word is logged once ("vk: Grass distance ..."). Measured in Hyrule Field by the Kakariko gate: the blades in the middle distance 30 to 48 % more at 3x, as the game's own +0x7c = 24 gives; GPU +0.35 ms a frame at 4x on an RTX 5090 at 1440p, 2x within the noise. Co-Authored-By: Claude Opus 5.5 <[email protected]>WIP: feat(vk): Grass distance, how far the short grass blades reach (2x by default)to WIP: feat(vk): Grass distance, how far the grass stays full (2x by default)New commit
095a6434: Grass distance now also keeps Hyrule Field's grass full further out. Compute d5a9475f2790532e thins the main grass per ground tile as 1 - (1 + w97 - w96/d²): full to 8 m, none at 65 m. The row multiplies w96 and w97 by n², as the game's own foliage setting for it (+0x7c) does, so the full count reaches n times as far. It reaches tiles as the game makes them (Link moving on, the area loading). Each changed word is now logged once.Hyrule Field by the Kakariko gate, the debug view with the grass white, one run from one spot, the tiles made again after each change. White px per screen band from the middle distance to near: game's values 6501 / 5756 / 3718 / 2925; the falloff 3x 7010 / 7426 / 5498 / 4000; the game's own +0x7c = 24, for comparison, 6246 / 7517 / 6682 / 4502. GPU time there (RTX 5090, 1440p, 10 s blocks): Game's 9.29 / 9.49 ms, 2x 9.72 / 9.12 ms, 4x 9.84 / 9.86 / 9.46 ms. The description has the details.
@Beanstalk please test
095a6434(the branch's head; nothing more will be pushed before your run) on windows amd, linux radv and steamdeck.In longshot_log.txt each changed value is logged once, e.g. "vk: Grass distance 4x: program 383a566958350efe word 75 22 -> 88": please include those lines and the GPU / driver with the results.
@winterelfeas only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.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).
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.