54 Commits

Author SHA1 Message Date
Jamie Nicol
2c6f06a82b [naga msl-out] Implement support for external textures
This adds MSL backend support for `ImageClass::External`. (ie WGSL's
`external_texture` texture type). This is implemented very similarily
to the HLSL implementation in #7826.

Each external texture global variable is lowered to 3 `texture2d`s and
a buffer of type NagaExternalTextureParams. As usual in Naga's MSL
backend, these are passed as arguments to the entry point. The
bindings for each of these arguments are provided via the usual
binding map, using a new `BindExternalTextureTarget` variant of
`BindTarget`.

Unlike HLSL, MSL allows textures to be used as fields in structs. We
therefore immediately wrap these variables in a
`NagaExternalTextureWrapper` struct. This wrapper can then
conveniently be passed to either user-defined functions or builtin
implementations that accept an external texture.

The WGSL builtins `textureDimensions()`, `textureLoad()`, and
`textureSampleBaseClampToEdge()` are implemented using wrapper
functions using the regular `write_wrapped_functions()` machinery.
2025-08-21 12:35:19 +01:00
Jamie Nicol
e1ccb6632c [naga hlsl-out] Implement external texture support
This adds HLSL backend support for `ImageClass::External` (ie WGSL's
`external_texture` texture type).

For each external texture global variable in the IR, we declare 3
`Texture2D` globals as well as a `cbuffer` for the params. The
additional bindings required by these are found in the newly added
`external_texture_binding_map`. Unique names for each can be obtained
using `NameKey::ExternalTextureGlobalVariable`.

For functions that contain ImageQuery::Size, ImageLoad, or ImageSample
expressions for external textures, ensure we have generated wrapper
functions for those expressions. When emitting code for the
expressions themselves, simply insert a call to the wrapper function.

For size queries, we return the value provided in the params
struct. If that value is [0, 0] then we query the size of the plane 0
texture and return that.

For load and sample, we sample the textures based on the number of
planes specified in the params struct. If there is more than one plane
we additionally perform YUV to RGB conversion using the provided
matrix.

Unfortunately HLSL does not allow structs to contain textures, meaning
we are unable to wrap the 3 textures and params struct variables in a
single variable that can be passed around.

For our wrapper functions we therefore ensure they take the three
textures and the params as consecutive arguments. Likewise, when
declaring user-defined functions with external texture arguments, we
expand the single external texture argument into 4 consecutive
arguments. (Using NameKey::ExternalTextureFunctionArgument to ensure
unique names for each.)

Thankfully external textures can only be used as either global
variables or function arguments. This means we only have to handle the
`Expression::GlobalVariable` and `Expression::FunctionArgument` cases
of `write_expr()`. Since in both cases we know the external texture
can only be an argument to either a user-defined function or one of
our wrapper functions, we can simply emit the names of the variables
for each three textures and the params struct in a comma-separated
list.
2025-07-30 14:33:00 -07:00
Jamie Nicol
43a4d53107
[naga wgsl-in wgsl-out] WGSL support for texture_external texture type (#7822)
* [naga wgsl-in wgsl-out] WGSL support for texture_external texture type

Make wgsl-in correctly parse `texture_external` texture declarations,
and allow such textures to be used in `textureDimensions()`,
`textureSampleBaseClampToEdge()`, and `textureLoad()` function
calls. In IR these are represented by the `ImageClass::External` image
class, which is a 2D, non-multisampled, non-mipmapped, float-sampled
image.

Adds a new Capability `TEXTURE_EXTERNAL` and ensure validation rejects
shaders containing external textures if this capability flag is not
set. This capability is enabled for validation by wgpu devices which
support the `TEXTURE_EXTERNAL` feature (currently only when using the
noop backend), and by the Naga CLI when validating-only or when
outputting WGSL.

The WGSL backend can of course emit `ImageClass::External` images
directly as `texture_external` textures. Other backends are, for now,
unimplemented.

Lastly, we add a snapshot test covering all the valid uses of a
texture_external texture. These are:
  - As a global variable declaration
  - As an argument to the built-in functions `textureDimensions()`,
    `textureSampleBaseClampToEdge()`, and `textureLoad()`
  - As an argument to user-defined function declarations and calls.

We keep these in their own test so that we can control which targets
to run them against (currently WGSL and IR). When external textures
are supported by all Naga backends we can, if so inclined, integrate
these with existing texture tests.

* fixup! [naga wgsl-in wgsl-out] WGSL support for texture_external texture type

* fixup! [naga wgsl-in wgsl-out] WGSL support for texture_external texture type

---------

Co-authored-by: Jim Blandy <jimb@red-bean.com>
2025-07-22 14:38:32 -07:00
renovate[bot]
cf4a74c6b9 chore(deps): update deps and deny file 2025-07-18 13:02:48 -04:00
Andy Leiserson
0c629bb3c2
[naga] cli support for process_overrides compaction (#7792) 2025-06-26 14:12:18 -07:00
Zachary Harrold
4c39227510
Allow Naga spv-in and spv-out in no_std (#7760)
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
2025-06-26 16:45:47 -04:00
Andy Leiserson
82fa8e2a94 [naga] Remove non-essential override references via compaction
Adds a mode to compaction that removes unused functions, global
variables, and named types and overrides. This mode is used
everywhere except the compaction at the end of lowering, where
it is important to preserve unused items for type checking and
other validation of the module.

Pruning all but the active entry point and then compacting makes
`process_overrides` tolerant of missing values for overrides that are
not used by the active entry point.

Fixes #5885
2025-06-12 14:22:18 +09:00
Andy Leiserson
096f1f1f6d [naga] Remove the compact feature 2025-06-12 14:22:18 +09:00
Andy Leiserson
850c3d4310
[naga] Write only the current entrypoint (#7626)
Changes the MSL and HLSL backends to support writing only a single entry
point, and uses them that way in wgpu-hal.

This is working towards a fix for #5885.

* Increase the limit in test_stack_size
2025-04-30 09:59:41 +02:00
Zachary Harrold
bf8cc43a15
Add stderr and termcolor features to Naga (#7482)
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
Co-authored-by: Erich Gubler <erichdongubler@gmail.com>
2025-04-18 21:06:22 +00:00
Connor Fitzgerald
45d8f42513 Use workspace package information everywhere 2025-04-10 20:41:28 -04:00
Connor Fitzgerald
8c2c2ce203
Release v25 (#7505) 2025-04-10 16:13:02 +00:00
Zachary Harrold
175b66c796
Update codespan-reporting to 0.12 (#7398)
* Update `codespan-reporting` to 0.12

* Use explicit path for `term::termcolor`

* Revert changes to `Cargo.lock`
2025-03-26 02:10:30 +00:00
Bruce Mitchener
f89ede7cd8
[doc] Fix unbalanced backticks (#7385) 2025-03-21 03:03:37 +00:00
Wouter de Bruijn
dfb09c260f
naga-cli: forward '--keep-coordinate-space' flag to GLSL backend (#7206) 2025-02-24 23:21:48 +00:00
Connor Fitzgerald
8caefceb8e
Add rust-version to more crates (#7036) 2025-01-31 10:33:10 +01:00
@brody4hire - C. Jonathan Brody
a8cc83e17a
avoid default features in many dependencies (etc.) (#7031) 2025-01-30 10:30:42 -05:00
Connor Fitzgerald
d8e7ab1ad1
Refactor Cargo.toml Significantly (#6980) 2025-01-23 22:49:48 +00:00
Connor Fitzgerald
779261e64d
Release v24 (#6923) 2025-01-15 16:29:22 -05:00
Connor Fitzgerald
fdb6266d36
Update Some Repository Documentation (#6708)
* Update Some Repository Documentation

* Capitalization
2024-12-12 04:54:42 +00:00
Erich Gubler
16f012bc93 fix(naga-cli): allow output files with --stdin-file-path 2024-10-31 16:13:48 -07:00
Erich Gubler
25f0819edd feat(naga-cli)!: init. logger to INFO by default 2024-10-30 10:25:34 -07:00
Erich Gubler
08c9d8c397 chore: bump WGPU workspace crates to 23 2024-10-30 07:14:10 -07:00
Erich Gubler
7aa00a07e1 refactor(naga-cli): inline emit_annotated_error 2024-10-22 14:42:27 -04:00
Erich Gubler
28912feb00 fix(naga-cli): reimpl. emit_annotated_error with WithSpan::emit_to_stderr_with_path 2024-10-22 14:42:27 -04:00
Hamir Mahal
8e787eb70a
style: simplify string formatting for readability (#6316) 2024-09-24 23:40:53 -04:00
Dzmitry Malyshau
eb18854b46 spv-out: configure source language in debug info 2024-09-13 11:37:23 -07:00
Kornel
222f1ea733 Reduce code size of error handling 2024-08-19 14:38:20 +01:00
teoxoy
ccd6d2ca48 remove BoundsCheckPolicies.image_store 2024-07-26 10:44:22 -07:00
Bruce Mitchener
3166d37754
Use workspace dependencies more. (#6020) 2024-07-26 18:48:01 +02:00
Erich Gubler
6a1432c132 chore: release 22.0.0 2024-07-18 11:54:46 -04:00
Imbris
3a6814770a
Allow unconsumed inputs in fragment shaders (#5531)
* Allow unconsumed inputs in fragment shaders by removing them from vertex
outputs when generating HLSL.

Fixes https://github.com/gfx-rs/wgpu/issues/3748

* Add naga:🔙:hlsl::FragmentEntryPoint for providing information
  about the fragment entry point when generating vertex entry points via
  naga:🔙:hlsl::Writer::write. Vertex outputs not consumed by the
  fragment entry point are omitted in the final output struct.
* Add naga snapshot test for this new feature,
* Remove Features::SHADER_UNUSED_VERTEX_OUTPUT,
  StageError::InputNotConsumed, and associated validation logic.
* Make wgpu dx12 backend pass fragment shader info when generating
  vertex HLSL.
* Add wgpu regression test for allowing unconsumed inputs.

* Address review

* Add note that nesting structs for the inter-stage interface can't
  happen.
* Remove new TODO notes (some addressed and some transferred to an issue
  https://github.com/gfx-rs/wgpu/issues/5577)
* Changed issue that regression test refers to 3748 -> 5553
* Add debug_assert that binding.is_some() in hlsl writer
* Fix typos caught in CI

Also, fix compiling snapshot test when hlsl-out feature is not enabled.
2024-07-04 09:08:46 +02:00
Théo Monnom
0f6abc99ee
[naga-cli] add --defines options for the glsl parser (#5859) 2024-06-23 07:21:56 +00:00
Erich Gubler
f1b06f55ce chore: satisfy clippy::assigning_clones 2024-05-13 10:10:54 -04:00
Andreas Reich
452cf24fa1
Remove unnecessary Cargo.toml dependencies via cargo machete (#5692) 2024-05-12 19:05:00 -04:00
Connor Fitzgerald
4521502da6
Release v0.20.0 (#5619) 2024-04-28 18:06:35 -04:00
matt rice
e0ac24aeab
[naga-cli] Add input-kind and shader-stage args (#5411) 2024-04-18 12:41:18 +02:00
Alexander Meißner
ea77d5674d
Subgroup Operations (#5301)
Co-authored-by: Jacob Hughes <j@distanthills.org>
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
Co-authored-by: atlas dostal <rodol@rivalrebels.com>
2024-04-17 15:25:52 -04:00
vero
911baf3e8c
Add DirectX ShaderModel 6.1-6.7 detection (#5498) 2024-04-06 11:35:59 +02:00
teoxoy
7df0aa6364 move the burden of evaluating override-expressions to users of naga's API 2024-04-05 18:07:41 +02:00
Jim Blandy
7bed9e8bce [naga-cli] Add --override option. 2024-04-05 18:07:41 +02:00
teoxoy
3bda381812 add pipeline constants plumbing 2024-04-05 18:07:41 +02:00
Patrick Cleavelin
a63bec8cd6 add cli arg to choose metal version 2024-03-15 10:39:40 +01:00
dependabot[bot]
e04a9f4c6f
build(deps): bump the patch-updates group with 29 updates (#5376)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-14 13:00:43 -04:00
wayne
c4b5cc94ad
don't panic if naga parsing of shader source fails (#5034)
* naga: glsl parser should return singular ParseError similar to wgsl

* wgpu: treat glsl the same as wgsl when creating ShaderModule

* naga: update glsl parser tests to use new ParseError type

* naga: glsl ParseError errors field should be public

* wgpu-core: add 'glsl' feature

* fix some minor bugs in glsl parse error refactor

* naga/wgpu/wgpu-core: improve spirv parse error handling

* wgpu-core: feature gate use of glsl and spv naga modules

* wgpu: enable wgpu-core glsl and spirv features when appropriate

* obey clippy

* naga: derive Clone in Type

* naga: don't feature gate Clone derivation for Type

* obey cargo fmt

* wgpu-core: use bytemuck instead of zerocopy

* wgpu-core: apply suggested edit

* wgpu-core: no need to borrow spirv code

* Update wgpu/src/backend/wgpu_core.rs

Co-authored-by: Alphyr <47725341+a1phyr@users.noreply.github.com>

---------

Co-authored-by: Alphyr <47725341+a1phyr@users.noreply.github.com>
2024-01-23 10:25:25 -05:00
Connor Fitzgerald
8b2098bd4e
Release 0.19 (#5082) 2024-01-17 14:42:11 -05:00
Connor Fitzgerald
a2dced12b3 Disable naga-cli's docs 2024-01-08 08:48:13 +01:00
Jim Blandy
9013e226c3 [naga-cli] Add --bulk-validate option. 2023-12-24 12:03:28 -08:00
Jim Blandy
79a6a4b0d2 [naga-cli] Abstract out parsing of input file. 2023-12-24 12:03:28 -08:00
Connor Fitzgerald
06e9876adf
Move to A Single Example Executable (#4756)
* Move to combined examples

* Fix paths

* Curtail some tests

* Format

* Clippy

* Fix wasm

* Refactor main for wasm

* Style sheet

* Readme

* Lock
2023-11-23 05:26:42 -05:00