Repository navigation
Conversation
Each phase of the G-buffer now draws the visibility of the view: the vertices of a visible cluster hand the fragment only the instance, the cluster and the triangle, and each pixel keeps the nearest one. After both phases, gbuffer_visible.frag rebuilds what the rasterizer would have handed gbuffer.frag at each pixel from its triangle, with the derivatives taken from the triangle at the next pixels (MATERIAL_GRADIENTS), and runs the same material and targets once. A forest of triangles smaller than a pixel spent its time computing and passing every attribute of three vertices a triangle and shading every fragment; the rasterizer itself costs little. The entries of the visible lists carry where the triangles and the posed vertices of a cluster are (visible_entry), which shortens the reads of the vertex. Clusters whose triangles are not small go to bin 0 of the program list, as those of Surface programs do: they leave their depth before the visibility and draw their G-buffer after it with the depth test ahead of the stage, so each pixel is shaded once and scenes of large triangles keep their cost. The visibility writes the linear depth the pyramid between the phases reads, and decides masks as the rasterizer samples them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A cluster of large triangles is listed in bin 0 of the program list, one of small ones in the visible list: the test of the posed levels reads both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The clusters of the program list leave their depth before the visibility with gbuffer.vert and a stage that decides their fade and their mask as gbuffer.frag does (gbuffer_depth.frag, one per Surface program), so the depth their G-buffer tests for equality after it is the same, whatever the device computes, and the mask of a program is its own. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
foliage_extreme: 842 trees of three kinds on a forest floor, without impostors, 27M triangles at level 0, with the foliage plugin on in the demo. With light probes on Medium or High the frame that shows it anew runs the warm-up of the probe volume past what Windows lets one submission run, and the driver resets; the pull request describes it for a separate fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
Looks really heavy but it is only Odin: +135-20 diff lines at 4a70663 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The G-buffer rasterizes the visibility of the view and draws its material once a pixel. A forest of triangles smaller than a pixel costs a quarter of what it did; scenes of large triangles keep their cost.
Why
Measured on a GTX 1070 with a forest of 12.6M visible triangles, splitting the G-buffer pass by shader variants:
The rasterizer costs little. The cost was the vertex shader running three times a triangle (non-indexed clusters) and computing and passing every attribute (normal, tangent, UVs, colors, previous position, material), then the material per fragment. When the fragment reads only ids, the driver drops the rest.
Changes
visibility_pass,visibility.vert/.frag): each phase draws the visible clusters with vertices that hand the fragment only the instance, the cluster and the triangle. Each pixel keeps its nearest triangle (RG32: instance, primitive) and its linear depth, which the depth pyramid between the phases reads. Fades and masks are decided there, the mask sampled as the rasterizer would.gbuffer_visible.frag): after both phases, it rebuilds what the rasterizer would have handedgbuffer.fragat each pixel (visible_input.slang): each attribute ofgbuffer.vertinterpolated where the ray of the pixel crosses the triangle, with the derivatives taken from the triangle at the next pixels (MATERIAL_GRADIENTS:SampleGrad, footprint, specular antialiasing). Then it runs the same body asgbuffer.frag(gbuffer_fragment.slang).visible_entry): they carry where the triangles and the posed vertices of a cluster are, so a vertex reads its corner without going through the mesh and its pages.VISIBILITY_TRIANGLE_PIXELSover the pixels across its box at rest) goes to bin 0 of the program list, like Surface programs. Before the visibility, these clusters leave their depth with the vertices of their G-buffer and its fade and mask (gbuffer_depth.frag, one per program). After it, they drawgbuffer.fragwith the depth test ahead of the stage (aftervariants,[earlydepthstencil]; the texture feedback writes had kept early-Z off). Each pixel is shaded once.gbuffer_pass.foliage_extreme(842 trees, no impostors), with thefoliageplugin on.frame-graph.mdandscene.mddescribe the passes.Measurements
mirai bench compare, 5 alternating pairs, 1440x900, dev, GTX 1070, againstmainat 623c6a8. The forest isfoliage_extreme(842 trees, 27M triangles at level 0, no impostors), which this PR adds to the demo; for the base it was copied into a checkout ofmainwith the foliage plugin on.main_vitralOn the forest, the G-buffer goes from 79.2 to 4.6 ms, plus 13.0 ms of visibility. On the gallery, it goes from 0.72 to 0.47 ms, plus 0.09 ms of visibility. Captures against
main: SSIM 0.99988 to 0.99998 on the forest, 0.9999 on the gallery, 1.0 oncontrol.mirai render check demo --base main(dev, GTX 1070, 1440x900): No regressions. Frame p50, ms:The luminance of every view is unchanged. The scenes of large triangles pay up to ~0.3 ms for the passes of the visibility (raft, sky); the ones with more geometry gain up to 5 %. 18 of the base measures came from the saved base of 623c6a8.
Tests
mirai check render;mirai test cook/shaders: 83/83 (the per-program stages of the newgbufferandgbuffer_depthvariants).mirai test renderwith validation: 284/284.gpu_skins_with_influences_of_every_level…now finds the chosen level in the list it went to: its cluster of two large triangles is listed in bin 0.check_docs.pydid not run: theuvof this machine is too old for it. I checked the lines of the docs by hand.[earlydepthstencil], thestaticgradients ofMATERIAL_GRADIENTS). On a Mac:mirai test renderand a capture ofgallery/main.sceneagainstmain.Known differences
ddx(n)of the mapped normal had.Known issue in the forest (of
main, left for a separate fix)Opening
foliage_extremewith Light probes on Medium or High resets the GPU driver on a GTX 1070 (Windows TDR; the editor reportsdevice lost … the GPU stopped in ddgi, with the pipeline Ddgi_Trace). On Low it works. It does not come from this PR: the probe volume and its rays are the code ofmain.GI_WARM_UPDATES(64) times, up toPROBE_WARM_BUDGET(2048) probes each, all in one submission (pass_world_lighting). In this forest that frame took 2.05 s of GPU on Low (ddgi2047 ms,profile.capturefrom[30,4,70]toward[0,7,20]), and that with the probe rays already through coarser cuts of the trees (a trial not in this PR); Windows resets a GPU that runs one submission past 2 s. Medium and High trace 1.5x and 4x the rays.mesh_ray_errorsgives no ray cuts, and batches trace the cut they always have (ray_cut_always, level 0), so every probe ray meets ~32k triangles a tree.ddgithere.IMPORTER_VERSIONwhile trying a fix, use a number no other branch uses: the mesh cache is shared by every checkout of the clone, andfoliage-perfandvis-bufferalready use 12, so an import there reads their meshes.🤖 Generated with Claude Code