Skip to content

feat(kyty): answer guest BVH walks over several TLASes from the host query - #366

Merged
simnJS merged 1 commit into
simnJS:Brainrotfrom
Raghav314:feat/kyty-rt-multi-tlas-walks
Nov 27, 2026
Merged

simnJS merged 1 commit into
simnJS:Brainrotfrom
Raghav314:feat/kyty-rt-multi-tlas-walks

Conversation

@Raghav314

@Raghav314 Raghav314 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

What

Guest BVH walks over more than one top-level tree (TLAS) now get host ray-query answers for every tree, not only the first.

  • The bug this fixes: some compute shaders run several walk loops, each reading its TLAS header from a different user-data slot. The host query bound only the primary TLAS. A lane whose walk starts in another tree never matched it, fell back to the guest intersection, and that returns no children at box nodes. Those rays missed, although the site was counted as answered by the host query. 12 programs of the surveyed title were affected this way, 2 of them only at wave64.
  • Source analysis: DeriveOracleWalks now reports which TLAS headers each walk loop starts from. In TraceNativeTraversals:
    • a walk that starts only from other trees binds them as extra sources (deduplicated, bounded by MaxRayQuerySources) and marks its intersections BvhIntersectOracleMulti;
    • a walk that also starts from the primary tree keeps the single-tree query, as before;
    • a tree another walk already bound is reused when its root matches and its record layout differs at most in the mask fields, the rule the primary tree already used (now CompatibleRecordLayouts);
    • a walk the new path refuses falls back to the previous source matching, with nothing it added kept. If that puts a walk on the primary tree although it starts from another tree, it is logged.
  • Emitter: only shaders with a marked intersection change. They load each extra source's context once at entry, and each lane picks its tree when its walk starts, by matching its start node against every bound tree's root node. Resume and instance-slot reads then use the lane's tree. A lane that matches no tree does not start, as before.
  • Negated rays: the world-ray match also accepts a walk that uses a negated ray component. This lets 4 single-tree programs that ran empty derive a source.
  • No runtime change: the runtime already prepares one context per extra source.

Tested

Arch Linux (CachyOS kernel 7.3.6), NVIDIA GeForce RTX 4090, driver 620.73.04.

Offline survey of the title's pipeline cache (68 compute programs, --subgroup 32 --oracle 33), compared with the base:

wave32 sites base this PR
Native ray query 410 410
Guest loop with host-query answers 104 128
Running empty (rays miss) 36 12
  • Across wave32 and wave64 rows: empty sites drop from 64 to 30. No row gets worse, and native stays at 551.
  • The counts don't show the main fix: those 12 programs were already counted as host query. Their second-tree walks now get answers.
  • 757d and 47b9 also walk several trees; their 12 and 3 empty sites now get answers.

Unchanged programs emit identical SPIR-V: every program was compiled with the base and with this PR, and the SPIR-V compared byte for byte (97 variants covering all 68 programs; the other 27 rows stop before SPIR-V on both sides). Only the 18 programs this PR targets differ: the 14 multi-tree programs (12 already served plus 757d and 47b9) and 4 single-tree programs that ran empty. So no other shader's cost changes.

Validation layer: agc_kyty_shaders and kyty_shim_* ran under VK_LAYER_KHRONOS_validation on the base and on this PR, with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_LOADER_DEBUG=layer.

  • The layer was inserted in every run (42 inserts each) and was never reported missing.
  • This PR passes 129 of 132. Its three failures are present on the base too: kyty_shim_lod_stats_destination (does not link), kyty_shim_memory_sparse_reads_switch (timeout) and kyty_shim_prepared_variant_first_use. The base run also reports kyty_shim_compute_recipes as not run, because its binary was not built in that run; it passes on this PR.
  • Both sides log the same VUID- IDs, with no new ones.

Tests: RtOracle.cpp adds TwoTlasWalks(). One program has two walk loops whose TLAS headers come from user-data offsets 0x20 and 0x40. The second walk's tree must be bound as an extra source and only its intersection marked multi-tree. Two walks over one tree must bind nothing extra. The test fails on the base. The hand-built walk was split into helpers so one program can hold two walks. RecordLayouts() checks CompatibleRecordLayouts with the layouts of a real shader: layouts that differ only in mask fields are compatible, ones that place record fields differently are not. It fails if the rule falls back to exact equality or drops the unmasked comparison.

Performance: not measured in game. The cost is confined to the 16 programs whose SPIR-V changes: rays that used to miss are now traced, and multi-tree programs select a tree per lane and bind 2 or 3 tree contexts per dispatch instead of 1.

In game: an earlier version of this change reached gameplay in the title and looked correct. The final version was not run in game.

Note: programs found only in the code cache have guessed dispatch inputs, and the survey compiles them at both wave sizes. Their wave64 rows are therefore variants that may never be dispatched; only the 12 manifest programs, all wave32, have real dispatch inputs.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4090, driver 620.73.04, Arch Linux (CachyOS kernel 7.3.6)
  • AI-assisted: yes

@Raghav314
Raghav314 temporarily deployed to repository-maintenance November 27, 2026 13:59 — with GitHub Actions Inactive
@simnJS
simnJS changed the base branch from AnyKyty to Brainrot November 27, 2026 14:04
@Raghav314
Raghav314 force-pushed the feat/kyty-rt-multi-tlas-walks branch from 148e9d3 to b90571f Compare November 27, 2026 14:18
@Raghav314
Raghav314 temporarily deployed to repository-maintenance November 27, 2026 14:18 — with GitHub Actions Inactive
…query

A compute shader can walk more than one top-level tree: its walk loops
read their TLAS header from different user-data slots. The host query
bound only the primary TLAS, so a lane starting in another tree never
matched it, and its box intersections returned no children. Those rays
missed although the site counted as served.

The source analysis now records which TLAS headers each walk loop starts
from. A walk that starts only from other trees binds them as extra
sources and marks its intersections BvhIntersectOracleMulti. A walk that
also starts from the primary tree keeps the single-tree query, and one
the new path refuses falls back to the previous source matching.

A tree another walk already bound is reused when its root matches and
its record layout differs at most in the mask fields, the rule the
primary tree already used (now CompatibleRecordLayouts). A walk that
still ends up on the primary tree although it starts from another tree
is logged.

Only shaders with a marked intersection change. They load each extra
source's context once at entry, and each lane picks its tree when its
walk starts by matching its start node, then resumes and reads instance
slots from that tree. Every other shader emits the same SPIR-V as before.

The world-ray match also accepts a walk that uses a negated ray component.
@Raghav314
Raghav314 force-pushed the feat/kyty-rt-multi-tlas-walks branch from b90571f to 884f24c Compare November 27, 2026 14:44
@Raghav314
Raghav314 temporarily deployed to repository-maintenance November 27, 2026 14:44 — with GitHub Actions Inactive
@simnJS
simnJS merged commit 884f24c into simnJS:Brainrot Nov 27, 2026
8 of 9 checks passed

This branch was previously deployed

1 inactive deployment
repository-maintenance — 884f24c7 Deployed Nov 27, 2026 by Raghav314 via review #329
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.

2 participants