Skip to content

[naga] Support textureSampleBaseClampToEdge() for texture2d #7709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from

Conversation

jamienicol
Copy link
Contributor

@jamienicol jamienicol commented May 21, 2025

Adds a new flag to the IR indicating when image sample coordinates are to be clamped. Adds wgsl-in support for parsing and lowering to IR. Validation ensures this flag is only used when sampling a 2D non-arrayed sampled texture, without offset, gather, or depth comparison. This matches the WGSL requirements, with the exception of supporting texture_external textures, which will follow in a later patch.

SPIRV, HLSL, and Metal backends are supported so far, with GLSL left for a follow up. (In GLSL the texture will simply be sampled without the coordinates being clamped.)

It may seem unfortunate to have to handle this separately for each backend, and indeed it would have been possible to implement this simply in the WGSL frontend. However, future patches will add support for using textureSampleBaseClampToEdge() with external textures, which will actually have to be handled by each backend. This patch is laying the groundwork for that.

Connections
Part of #4386

Testing
Added snapshot test

Makes these CTS tests pass

Squash or Rebase?

Rebase

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • If this contains user-facing changes, add a CHANGELOG.md entry.

Adds a new flag to the IR indicating when image sample coordinates are
to be clamped. Adds wgsl-in support for parsing and lowering to
IR. Validation ensures this flag is only used when sampling a 2D
non-arrayed sampled texture, without offset, gather, or depth
comparison. This matches the WGSL requirements, with the exception of
supporting `texture_external` textures, which will follow in a later
patch.

SPIRV, HLSL, and Metal backends are supported so far, with GLSL left
for a follow up. (In GLSL the texture will simply be sampled without
the coordinates being clamped.)

It may seem unfortunate to have to handle this separately for each
backend, and indeed it would have been possible to implement this simply
in the WGSL frontend. However, future patches will add support for using
textureSampleBaseClampToEdge() with external textures, which will
actually have to be handled by each backend. This patch is laying the
groundwork for that.
@jamienicol jamienicol force-pushed the texture-sample-base-clamp-to-edge branch from b25453c to 466e9b8 Compare May 27, 2025 08:34
@jamienicol jamienicol requested review from crowlKats and a team as code owners May 27, 2025 08:34
@jamienicol jamienicol added the PR: run CTS PRs that should trigger the GitHub actions workflow for the WebGPU conformance test suite (CTS) label May 27, 2025
This doesn't do anything yet, but unblocks running some CTS tests.
@jamienicol jamienicol force-pushed the texture-sample-base-clamp-to-edge branch from 466e9b8 to 133ad63 Compare May 27, 2025 14:46
@jamienicol jamienicol force-pushed the texture-sample-base-clamp-to-edge branch from 133ad63 to b27265b Compare May 27, 2025 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: run CTS PRs that should trigger the GitHub actions workflow for the WebGPU conformance test suite (CTS)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants