Skip to content

[naga: glsl-out] partially fix sampling depth texture in GL backend - #10631

Closed
newDINO wants to merge 5 commits into
gfx-rs:trunkfrom
newDINO:trunk
Closed

newDINO wants to merge 5 commits into
gfx-rs:trunkfrom
newDINO:trunk

Conversation

@newDINO

@newDINO newDINO commented Oct 15, 2026 •

Copy link
Copy Markdown

Connections

This partially fix #4524.

Description

Motivatoin

Allow user to sample depth texture when using GL backend.

Main changes

  • When writing image types, if the image is a depth image, check if the image is sampled by a comparing sampler, if not, change image type to sampler2D. In order to be able to get the image's corresponding sampler, FunctionInfo::sampler_set is renamed to sampler_map and use HashMap to get sampler.
  • Because when sampling a texture using texture() in glsl always returns vec4, add .r to convert it to float when sampling a depth texture.
  • Add an additional test. (naga/tests/in/wgsl/4524-sample-depth.wgsl)

Other changes

Running the test changes some of the files in naga/tests/out.

Drawbacks

User still can only use one sampler for each texture in GL backend.
So, if user sample from a depth texture, they can't use textureSampleCompare() on it, vice versa.

Testing

I have run all naga test, but not cargo xtask test, because it doesn't pass before the changes.
I also tested this version of wgpu on my own project.

LLM Use?

Code is written by human.
I used LLM to learn something about OpenGL.

Checklist

  • I self-reviewed and fully understand this PR.
  • CHANGELOG.md entries for the user-facing effects of this change are present.
  • The PR is minimal, and doesn't make sense to land as multiple PRs.
  • Commits are logically scoped and individually reviewable.
  • The PR description has enough context to understand the motivation and solution implemented.
  • (If applicable) WebGPU implementations built with wgpu may be affected behaviorally.
  • (If applicable) Validation and feature gates are in place to confine behavioral changes.
  • (If applicable) Tests demonstrate the validation and altered logic works.

@newDINO newDINO changed the title Partially fix sampling depth texture in GL backend [naga] partially fix sampling depth texture in GL backend Oct 15, 2026
@newDINO newDINO changed the title [naga] partially fix sampling depth texture in GL backend [naga: gles-out] partially fix sampling depth texture in GL backend Oct 15, 2026
@newDINO newDINO changed the title [naga: gles-out] partially fix sampling depth texture in GL backend [naga: glsl-out] partially fix sampling depth texture in GL backend Oct 15, 2026
@newDINO

newDINO commented Oct 15, 2026 •

Copy link
Copy Markdown
Author

There is a similar PR in the past #8696 that is closed.

The solution from the user side is to use texture_2d<f32> in wgsl, and create BindGroupLayoutEntry with TextureSampleType::Float. This way, I can bind depth texture as texture_2d.

@newDINO newDINO closed this Oct 15, 2026
@github-project-automation github-project-automation Bot moved this from To triage to Done in Triage Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Unable to sample depth texture

1 participant