Stop the Shader constructor modifying the supplied definition - #9281
Merged
Conversation
The constructor replaced `definition.vshader`, `definition.fshader` and `definition.cshader` with their pre-processed versions and assigned `definition.attributes`, all on the object supplied by the caller. Reusing a definition object for a second shader therefore pre-processed already pre-processed sources. Shallow copy the definition up front so these writes land on an engine-owned object. The compute path had the same problem with `definition.cincludes`, whose map was mutated to add the built-in `halfTypesCS` include, so copy that too. Note this does not change what `shader.definition` contains - it still holds the pre-processed sources, just on a copy. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Build size reportThis PR changes the size of the minified bundles.
|
mvaligursky
approved these changes
Sep 2, 2026
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.
Description
The
Shaderconstructor modified the definition object supplied by the caller.It replaced
definition.vshader,definition.fshaderanddefinition.cshaderwith their pre-processed versions, and assigned
definition.attributeswhenextracting attribute names:
Reusing a definition object to create a second shader therefore pre-processed
already pre-processed sources.
This PR shallow copies the definition at the top of the constructor, so these
writes land on an engine-owned object instead. The compute path had the same
problem with
definition.cincludes— the caller's map was mutated to add thebuilt-in
halfTypesCSinclude — so that is now copied as well. Both copieshappen once per shader creation, which is not a hot path.
Nothing in the engine reads back from the original object, and
ProgramLibrary.getProgramalready built a fresh object literal beforeconstructing a
Shader, so its cached definitions were never affected.Note this does not change what
shader.definitioncontains — it still holdsthe pre-processed sources, just on a copy rather than on the caller's object.
Also adds
test/platform/graphics/shader.test.mjs. Three of its cases failwithout this fix.
Checklist
🤖 Generated with Claude Code