Skip to content

Cache RT shader table state and skip unused RT work - #123

Open
JohnGreenFC wants to merge 1 commit into
mainfrom
optimization-rt-shader-table-cache
Open

JohnGreenFC wants to merge 1 commit into
mainfrom
optimization-rt-shader-table-cache

Conversation

@JohnGreenFC

@JohnGreenFC JohnGreenFC commented Oct 16, 2026 •

Copy link
Copy Markdown

Summary

Goal: stop redoing raytraced-shadow setup work every frame when its result has not changed. The RT shader table is rebuilt from scratch each frame from every RT geometry entry, even though the set of shaders, libraries and hit groups is the same from one frame to the next, and some of its passes run even when they have nothing to do. This change caches what is stable, reuses GPU buffers instead of recreating them, and skips passes early when there is no work, so the main-thread cost of raytraced shadows stops scaling with object count in busy scenes.

The new cache has two halves:

  • Shader table description (PrepareShaderTableDescription). While walking the RT geometry entries, two small maps are kept: one keyed by shader (RtShaderState: the resolved RT shadow technique index and a pointer to the library state) and one keyed by raytracing library handle (RtLibraryState: the library, its hit-group name per raycaster, the material index it was first assigned, whether it has been seen yet, and whether its local root signature declares any registers, i.e. whether it adds per-entry records). The first entry that uses a shader resolves its technique and library once; the first entry that uses a library registers its hit group with each pipeline manager once; every later entry is two lookups. Before, each entry re-resolved the technique index and searched a per-raycaster map of maps, copying hit-group name strings as it went. An entry whose library has already been seen and adds no local records now takes the library's material index and skips building and applying a material description altogether, which is where the remaining per-entry cost sat.

  • Shader table buffers (Tr2RtShaderTableAL, DX12). Instead of creating a committed upload resource, mapping it and releasing it every frame, the table keeps one persistent mapped upload buffer per back buffer (TableBuffer: resource, mapped pointer, capacity). The table is assembled in a CPU staging vector and copied in; a buffer is only recreated when the table outgrows it, with 25 % headroom rounded up to 64 KB. Shader identifiers are resolved from the pipeline once per distinct raygen, miss or hit-group name per table build rather than once per record.

Linked issue (optional)

Testing

Windows, DX12, release build. Measured in the EVE Frontier client on the QA Megastructure route (1080p, low preset) against origin/main: about -1.0 ms frame mean with raytraced shadows, neutral with cascaded shadows (single flights, ~0.5 ms noise band). Smoke test of this branch alone: full route flown with raytraced shadows, no frames over 100 ms, no crash dumps. Not built on Mac.

AI assistance

AI testing, investigation and CL explanation

…sed RT work

Cache per-shader technique and per-library hit-group state in RT shader table preparation.
Reuse per-back-buffer shader table buffers and cache shader info in RT shader table creation.
Skip TransformMeshes when no skinned or morphed geometry was added this frame.
Skip RT material data application for shader-table entries whose library adds no records.
Copilot AI balanced review requested due to automatic review settings October 16, 2026 12:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@JohnGreenFC
JohnGreenFC marked this pull request as ready for review October 16, 2026 13:10
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