Fix splat overlay rendering performance#833
Merged
slimbuck merged 1 commit intoplaycanvas:mainfrom Mar 12, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR targets a performance leak in the splat overlay rendering path by ensuring the engine can reuse/caches the WebGL VAO for the overlay draw and by removing unnecessary per-frame shader/material work.
Changes:
- Add a dummy 1-vertex
VertexBufferto the overlayMeshso PlayCanvas hits the VAO caching path (avoiding per-frame VAO creation/leak). - Remove per-frame
material.update()fromSplatOverlay.onPreRender()and rely onsetParameter()for uniform updates. - Simplify the overlay shader by removing the
vZWvarying andgl_FragDepthwrite.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/splat-overlay.ts |
Adds a dummy vertex buffer to enable VAO caching and removes per-frame material.update() calls. |
src/shaders/splat-overlay-shader.ts |
Removes custom fragment depth output and an unused varying to reduce shader overhead. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
SEMANTIC_POSITION, which makes the engine cache the VAO on the vertex buffermaterial.update()call fromonPreRender()— onlysetParameter()is needed for uniform changes;update()was clearing shader variant caches every frame due toShaderMaterial._dirtyShaderbeing permanently truegl_FragDepthandvZWvarying from the overlay shader —depthWriteisfalseso the written depth was unused, andgl_FragDepthdisables Early-Z optimizationDetails
The overlay mesh uses attributeless
PRIMITIVE_POINTSrendering viagl_VertexID(0 vertex buffers). The engine'ssetBuffersonly caches VAOs for the single-VB path (vertexBuffers.length === 1); the 0-VB case falls through tocreateVertexArraywhich hasuseCache = vertexBuffers.length > 1, so a brand new WebGL VAO was created and leaked every frame. On macOS with ANGLE (WebGL-to-Metal), this caused significant overhead from repeated Metal pipeline state lookups.The workaround adds a dummy 1-vertex VB with
format.instancing = true(setsvertexAttribDivisor(loc, 1)) so only 1 vertex is needed regardless of draw count. This also resolves the "No vertex attribute is mapped to location 0" Safari compatibility warning.A proper engine fix (caching an empty VAO for the 0-VB case in
setBuffers) will follow separately.