Repository navigation
Add portable shader instance IDs - #34
Merged
Merged
Conversation
treeform
marked this pull request as ready for review
August 13, 2026 03:44
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
gl_InstanceIDas Shady's portable instance identifiergl_InstanceIDfor desktop/Web GLSL,gl_InstanceIndexfor Vulkan GLSL,
SV_InstanceIDfor HLSL, and[[instance_id]]for Metal
gl_VertexIndexconstructors
tests
Why
Stateless GPU particle systems and other instanced vertex shaders need a
per-instance identifier without uploading a CPU-generated ID buffer. Every
supported graphics API provides this concept, but each backend uses a
different builtin spelling or semantic.
Impact
Shader authors can use
gl_InstanceIDonce in Shady source and generate validdesktop GLSL, WebGL 2 GLSL, Vulkan GLSL, HLSL, and Metal output. Complex
instanced shaders can also assemble and pass flat local parameter structs
without Shady inventing an unsupported default constructor.
Root cause
Shady exposed
gl_VertexIDbut had no shared instance-ID builtin or targetmappings. Vulkan also inherited OpenGL's vertex builtin name, while HLSL and
Metal entry generation did not inject their native instance semantics.
Validation
nim r tests/test_backends.nimnim r tests/test_shady.nimnim r tests/test_cpu.nimnim r -d:shadyRunMetal tests/test_metal.nim