mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
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.