Skip to content

TrailView: the crop rows list their cells in view first - #3794

Merged
timohueser merged 3 commits into
developfrom
claude/trailview-3787-rows-cells
Nov 21, 2026
Merged

timohueser merged 3 commits into
developfrom
claude/trailview-3787-rows-cells

Conversation

@timohueser

@timohueser timohueser commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Mode: change #3787
Requirements: none
Public docs: no

Closes #3787

What changed

The crop rows (vegetation/rows.wgsl) ran one workgroup of 256 lanes per base cell of their 2 km window, about 6,400 workgroups. In each, 255 lanes waited while one lane tested the cell. That cost about 1 ms per run on the M1 Pro, also where no cell was in view.

  • find_rows (new) tests each base cell on one thread, with the same tests as before (reach, ground height, frustum, depth of the last frame). It lists the cells in view with their ground height, as find_cells of the forest does.
  • plantings runs one workgroup per listed cell, through an indirect dispatch. From the crop sample on, it does not change.
  • rows.ts holds one list per view (eye and sun), sized for the window at the highest latitude of the bounds: 0.2 MiB in all at 47° N. update resets each list once per frame. engine.ts passes the config to Rows for the bounds.

The proof that nothing moved

A one-off script copied the staged instances out of the GPU after the view was idle and 20 more frames: the eye's view, then the near and the far shadow map, each redrawn on its own. Views: the starts of the walk, the valley drive, the zoom-out and the bridge and tunnel, at their heading and at +180°. Builds of develop 4a54190 and of this branch against obc data serve (Central Switzerland). The comparison is of the instances as multisets: the order in a list depends on the GPU's atomics.

Run Eye Near map Far map
Phone canvas (tier=phone), develop against branch 8 of 8 equal 8 of 8 equal 6 of 8 equal
Phone canvas, develop against develop 8 of 8 equal 8 of 8 equal 6 of 8 equal, the same 2 differ by the same 147 to 149 instances
2560 × 1600, develop against branch 8 of 8 equal 8 of 8 equal 3 of 8 equal
2560 × 1600, develop against develop 8 of 8 equal 8 of 8 equal 5 of 8 equal
Rows only (other producers off), crop rows on grass*, 2560 × 1600 8 of 8 equal 8 of 8 equal 8 of 8 equal (no rows: under the far map's least height of 3 m)
All producers, crop rows on grass*, phone canvas 8 of 8 equal 8 of 8 equal 6 of 8 equal, tree draws only

* Central Switzerland has no crop rows in the data: with develop, the rows alone stage no instance in any view. For this check the served rules give grassland, pasture and rough grass the vineyard's rows with a reach of 500 m, in both builds.

The far map differs between two runs of develop too. Its differences are in tree draws, and with the rows alone it is equal. Screenshots of the same views differ between develop and the branch by no more than between two runs of develop (at most 0.09 % of the pixels by more than 8 levels, at the same views).

Measurement

M1 Pro, headless Chromium on Metal, the turn (360° in 8 s) and the flight of the walk and the valley drive, develop and the branch in turn, two rounds. Medians over the frames that ran the pass, ms. The load average was 6 to 45: another job ran on the machine.

Canvas Scene, flight vegetation develop → branch Rows (own passes) casters
780 × 1688, tier=phone walk, turn 2.06, 2.07 → 1.04, 1.04 1.15 → 0.14 1.78, 1.80 → 0.77, 0.78
walk, flight 2.38, 2.30 → 1.16, 1.02 1.14 → 0.13 1.74, 3.54 → 0.99, 0.76
valley, turn 2.06, 2.10 → 1.05, 1.06 1.14, 1.18 → 0.14 1.78, 1.80 → 0.76, 0.77
valley, flight 2.14, 2.17 → 1.15, 1.39 1.14, 1.17 → 0.15 1.77, 1.80 → 0.81, 0.75
2560 × 1600 walk, turn 2.92, 2.50 → 1.40, 1.49 1.24 → 0.22 2.15, 1.85 → 0.81, 0.80
walk, flight 2.38, 2.57 → 1.53, 1.74 1.27, 1.23 → 0.27, 0.26 1.73, 1.75 → 0.83, 0.76
valley, turn 2.58, 2.46 → 1.36, 1.53 1.26 → 0.21, 0.24 1.76, 1.79 → 0.75, 1.11
valley, flight 2.68, 2.63 → 1.54, 1.64 1.27 → 0.29, 0.28 1.80, 1.76 → 0.72, 0.78

The far map draws 1 to 14 times per run, so its totals are noisy under the load (2.6 to 13 ms in both builds). In the runs with one pass per dispatch, its rows took 1.72 to 1.80 ms on develop (once 3.28) and 0.78 to 1.33 ms on the branch (the cell search 0.02 to 0.1 ms, once 0.62).

iPhone 13

The owner ran the TrailView Proto app (the prototype branch with this change merged and a throwaway switch rows=grid for develop's grid; not pushed), preset P (tier=phone), 12 runs in one session: grid, then cell list, in the full turn, the look about and the walk, then the cell list first and the grid last. Medians over the timed frames of each run, ms:

Run vegetation casters far-casters terrain GPU per frame
1 grid, turn 4.72 3.93 13.67 19.72 31.66
2 grid, look 4.66 4.91 9.20 16.20 23.75
3 grid, walk 4.99 4.37 11.01 15.06 23.04
4 cells, turn 1.98 1.37 7.39 20.37 29.61
5 cells, look 2.10 1.94 7.91 19.13 24.85
6 cells, walk 2.13 1.63 8.08 18.02 23.37
7 cells, turn 2.46 1.90 5.57 23.57 35.48
8 cells, look 2.41 2.47 11.65 22.08 29.04
9 cells, walk 2.19 1.58 7.33 17.91 23.23
10 grid, turn 6.08 6.98 14.44 23.44 40.90
11 grid, look 7.06 9.01 17.65 24.29 37.31
12 grid, walk 5.80 5.26 13.91 17.83 26.92
  • The vegetation pass falls from 4.7 to 7.1 ms to 2.0 to 2.5 ms, about 2.7 to 4.6 ms less (55 to 65 %). The near shadow map's run falls from 3.9 to 9.0 ms to 1.4 to 2.5 ms; the far map's from 9.2 to 17.7 ms to 5.6 to 11.7 ms.
  • The GPU time per frame does not show the whole gain: the terrain pass rose from 15 to 24 ms over the session in both variants, as the phone grew warm. The session file has no thermal state. Paired runs in the same round: turn 31.7 → 29.6 and 40.9 → 35.5 ms, walk 23.0 → 23.4 and 26.9 → 23.2 ms.

Review

One review round (verdict: mergeable), two small findings, both fixed in the last commit:

  • An eye past the bounds' highest latitude now keeps a window of the list's size, as the forest does (Math.min(this.most, …)), so the list holds every cell and no near rows drop at random. Inside the bounds this changes nothing.
  • A comment states the limit of the one-dimensional indirect dispatch: 65,535 workgroups, which the 2 km reach stays under up to about 79° N.

Checks

  • npx vitest run src/lib/trailview: 489 passed.
  • npm run check: 0 errors, 0 warnings.
  • npm run check:wgsl: rows.wgsl validates.
  • Not run: the browser suites of obc test affected; CI runs them.

🤖 Generated with Claude Code

The rows ran one workgroup of 256 lanes per base cell of their 2 km window, and
255 lanes waited while one tested the cell: about 1 ms per run on the M1 Pro, also
where no cell is in view. find_rows now tests each cell on one thread and lists the
cells in view; plantings runs one workgroup per listed cell, as the forest does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 8 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c8f881dd-b5f3-4584-85a3-ba2a80e7e8a5
Commits

Reviewing files that changed from the base of the PR and between aad42ad and 7227894.

Files selected for processing: 3

  • builder/web/src/lib/trailview/engine.ts
  • builder/web/src/lib/trailview/vegetation/rows.ts
  • builder/web/src/lib/trailview/vegetation/rows.wgsl
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@timohueser
timohueser marked this pull request as ready for review November 21, 2026 21:48
timohueser and others added 2 commits November 21, 2026 22:52
@timohueser
timohueser enabled auto-merge November 21, 2026 21:53
@timohueser
timohueser merged commit 9adc88b into develop Nov 21, 2026
24 checks passed
@timohueser
timohueser deleted the claude/trailview-3787-rows-cells branch November 21, 2026 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TrailView: the crop rows take half of the vegetation pass, mostly on cells out of view

1 participant