Skip to content

fix(glsl-in): support combined sampler2D uniforms#9558

Open
robertream-m42 wants to merge 5 commits into
gfx-rs:trunkfrom
robertream-m42:fix/glsl-combined-sampler
Open

fix(glsl-in): support combined sampler2D uniforms#9558
robertream-m42 wants to merge 5 commits into
gfx-rs:trunkfrom
robertream-m42:fix/glsl-combined-sampler

Conversation

@robertream-m42
Copy link
Copy Markdown

Summary

GLSL combined image-sampler types (sampler2D, isampler3D, sampler2DShadow, …) were unrecognized by naga's GLSL frontend, causing a NotImplemented('variable qualifier') error when shaders declared uniforms with these types.

Root cause

parse_type handled texture* and image* type names but had no branch for sampler* combined types. The existing inject_standard_builtins code tried to handle them as function-call overloads (MacroCall::Sampler / MacroCall::SamplerShadow), which was never reachable from the variable-declaration path.

Changes

  • types.rs: add sampler_parse to parse_type, mirroring texture_parse and image_parse. Combined samplers map to the same TypeInner::Image as their texture* counterparts. Add is_combined_sampler predicate used by the lexer.
  • lex.rs: emit CombinedSamplerTypeName(t) for combined sampler words so they route through the type-name path.
  • functions.rs: handle sampler2D(tex, samp) constructor syntax in constructor_many. Records the association via ctx.samplers; shadow variant additionally promotes the image to ImageClass::Depth.
  • builtins.rs: remove the now-unreachable MacroCall::Sampler / MacroCall::SamplerShadow overloads.

Test fixtures

  • sampler-combined-types.frag — uniform declarations for all [i|u]sampler* variants
  • sampler-combined-texture.fragtexture() and texelFetch() calls through a sampler2D uniform

🤖 Generated with Claude Code

robertream-m42 and others added 5 commits May 15, 2026 21:42
GLSL combined image-sampler types (`sampler2D`, `isampler3D`, `sampler2DShadow`,
…) were previously unrecognized by naga's GLSL frontend, causing a
`NotImplemented('variable qualifier')` error when shaders declared uniforms
with these types.

Changes:
- `types.rs`: add `sampler_parse` to `parse_type`, mirroring `texture_parse`
  and `image_parse`. Combined samplers map to the same `TypeInner::Image` as
  their `texture*` counterparts. Add `is_combined_sampler` predicate used by
  the lexer to emit `CombinedSamplerTypeName` tokens.
- `lex.rs`: emit `CombinedSamplerTypeName(t)` for combined sampler words so the
  parser routes them correctly through the type-name path.
- `functions.rs`: handle `sampler2D(tex, samp)` constructor syntax in
  `constructor_many`. Records the tex/sampler association via `ctx.samplers`;
  shadow variant additionally promotes the image to `ImageClass::Depth`.
- `builtins.rs`: remove the old `MacroCall::Sampler` / `MacroCall::SamplerShadow`
  overloads and their `inject_standard_builtins` branches — these are now
  unreachable since combined sampler names are lexed as type names, not function
  identifiers.

Fixes shader compilation for shaders that declare `uniform sampler2D` variables
and call `texture(sampler, uv)` or `texelFetch(sampler, coord, lod)`.
- Collapse imports and long lines to satisfy rustfmt
- Use explicit &(_, expr) pattern in find() closures to avoid match
  ergonomics flagged by clippy::pattern_type_mismatch

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
find() passes &Item to predicate but returns Option<Item>;
map() receives the item directly, not a reference.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
[`Context::new`] is private and not visible to rustdoc from mod.rs;
use backtick code instead to pass -D warnings doc check.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants