Skip to content

The coverage of a Surface program keeps the whole program in every traversal, and a tracer stage may never compile #83

Closed

Description

@5hif7y

The coverage of a Surface program keeps the whole program in every traversal, and a tracer stage may never compile

What happens

On a GPU without ray queries, the software tracer stages of a project whose Surface programs have coverage, such as demo with Terrain_Layers, can be too large for the driver to compile.

Measured on an RX 580 (amdvlk, Windows 10, 16 GB), compiling reflect.comp alone in a test, one variant per process, with the driver's VkCache moved aside:

reflect.comp SPIR-V Compile Peak private memory
Engine generation (no programs) 2.24 MB 80–90 s ~5 GB
demo generation 3.37 MB not done after 220 s (killed) > 13 GB, still rising
demo, in the editor 3.37 MB not done after 15 min 19 GB, Windows paging

Effects seen on that machine:

Why

surface_coverage.slang evaluates the alpha of a program with coverage inside the traversal (hit_alpha → mirai_program_alpha → <Program>::evaluate(...).alpha).

  • The alpha of Terrain_Layers depends only on whether the point is over a hole.
  • Its evaluate also reads the normal map, the paint map and up to 4 layers.

Every texture read of a program goes through mirai_sample_texture*, which calls texture_feedback. In a stage with MIRAI_TEXTURE_FEEDBACK (reflect, ddgi_trace, surface_points…), that is an InterlockedMin into the feedback buffer: a side effect. So the optimizer keeps every read and the code around it, the whole program, in every inlined traversal of the stage, although only alpha is used there.

Isolated with slangc (the cook's flags, reproducing the 3,373,500-byte stage exactly):

Change to demo's reflect.comp SPIR-V
None 3.37 MB
Ray hook of the portals off 3.36 MB
Ray, light and probe hooks off 3.21 MB
Terrain_Layers coverage replaced by alpha = 1 2.61 MB
Coverage samples record no feedback 2.66 MB

[loop] on the 2-iteration loops of trace_ray, trace_segment and direct_lighting changes nothing, and neither do spirv-opt -O or Slang -O2: the reads stay because they write.

Expected

The coverage test inside a traversal keeps only what alpha reads, for any program, so a stage that traces costs about the same with or without programs with coverage.

Activity

  1. self-assigned this
    on Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions