Define a new trait, `proc::builtins::OverloadSet`, for types that
represent a Naga IR builtin function's set of overloads. The
`OverloadSet` trait includes operations needed to validate calls,
choose automatic type conversions, and generate diagnostics.
Add a new function, `ir::MathFunction::overloads`, which returns the
given `MathFunction`'s set of overloads as an `impl OverloadSet`
value. Use this in the WGSL front end, the validator, and the
typifier.
To support `MathFunction::overloads`, provide two implementations
of `OverloadSet`:
- `List` is flexible but verbose.
- `Regular` is concise but more restrictive.
Some snapshot output is affected because `TypeResolution::Handle`
values turn into `TypeResolution::Value`, since the function database
constructs the return type directly.
To work around #7405, avoid offering abstract-typed overloads of some
functions.
This addresses #6443 for `MathFunction`, although that issue covers
other categories of operations as well.
Define a new helper function on `naga::ir::TypeInner`,
`scalar_for_conversions`, that returns the leaf scalar of a type as
relevant for WGSL-style automatic conversions. Specifically, this
means that, unlike `TypeInner::scalar`, arrays are considered to have
leaf scalars if their elements do.
In `naga::front::wgsl::lower`, add a new method,
`ExpressionContext::is_const`, for looking up the constness of a given
expression. Change existing code to use it.
Define two new types in `naga::common`, `DiagnosticDisplay` and
`DiagnosticDebug`, that allow Naga IR types to be formatted using
`core::fmt::Display` and `core::fmt::Debug`.
In `naga::common::wgsl`, add supporting implementations of
`TypeContext` for `GlobalCtx` and `UniqueArena<Type>`
In the implementation of `TryToWgsl` for `Scalar`, order types within
each representation from smallest to largest. This is just a cleanup;
the change has no effect on behavior.
Add a new module, `naga::common::predeclared`, which implements a new
`struct_name` method on `naga::ir::PredeclaredType`, to produce the
name of the struct type corresponding to that `PredeclaredType` value.
Use this new method in `naga::front::type_gen`.
Make the associated function `TypeInner::automatically_converts_to`
available outside the WGSL front end by moving it into the
`proc::type_methods` module.
* Fix validation error when configuring the surface on WebGL
* Remove unneeded `webgl` feature
* Fix compilation of the `noop` backend on `wasm32`
* Prevent `webgpu` examples from incorrectly falling back to WebGL
* Reduce dependency set when building wasm examples
* Fix various warnings
This will make it easier for contributors to understand the file layout,
at the cost of said layout containing several more nested directories.
I will personally appreciate not having to remember to look for
`root.rs` instead of `main.rs`.
I also renamed the test targets so that they do not *all* share the
superfluous suffix “-test” (test targets live in a different namespace
than other target types and packages, so the name can presume that it
is always known that they are tests).
The Naga snapshot data sets `naga/tests/{in,out}` have been left in
their original positions.
* init files, dir structure
* wip: it's working need to suss out the readme and some of the consts...
* ok that's probably good enough for a first pass...
* chore: spelling
* chore: readme tweaks
* chore: clippy and fmt
* chore: add self and changes to changelog.md
* fix: typo and remove env_logger via cfg flag for wasm builds (which this doesn't supprot anyway)
* refactor: bring inline with newer wgpu
* refactor: bring inline with newer wgpu
* chore: work on the readme a bit...
* refactor: remove a bunch of everything, be simple
* wip: get a test going
* wip: remove unrequired pub(s)...
* refactor: remove a bunch of everything, be simple
wip: get a test going
* wip: remove unrequired pub(s)...
wip: remove unrequired pub(s)...
* chore: cleanups, typos, simplifying
* chore: reconcile changelog diffs
* fix: re-add our change to the changelog
* wip: finess the docs a bit per request...
* chore: trying to get the woring right...
* chore: trying to get the woring right...
* fix: typos
* fix: spelling
* Update mod.rs
swap all loops over to 'for' by request.
Flume's sender is already Send/Sync
chunks will already split for us
.unwraps() unwraps everywhere!
* Update CHANGELOG.md
Co-authored-by: Jim Blandy <jimb@red-bean.com>
* 1GB as the example says we'll do
- 1GB as the example says we'll do
- update readme for windows users.
* init files, dir structure
* wip: it's working need to suss out the readme and some of the consts...
* ok that's probably good enough for a first pass...
* chore: spelling
* chore: readme tweaks
* chore: clippy and fmt
* chore: add self and changes to changelog.md
* fix: typo and remove env_logger via cfg flag for wasm builds (which this doesn't supprot anyway)
* refactor: bring inline with newer wgpu
* refactor: bring inline with newer wgpu
* chore: work on the readme a bit...
* refactor: remove a bunch of everything, be simple
* wip: get a test going
* wip: remove unrequired pub(s)...
* wip: remove unrequired pub(s)...
wip: remove unrequired pub(s)...
* chore: cleanups, typos, simplifying
* fix: re-add our change to the changelog
* wip: finess the docs a bit per request...
* chore: trying to get the woring right...
* chore: trying to get the woring right...
* fix: typos
* fix: spelling
* Update mod.rs
swap all loops over to 'for' by request.
Flume's sender is already Send/Sync
chunks will already split for us
.unwraps() unwraps everywhere!
* Update CHANGELOG.md
Co-authored-by: Jim Blandy <jimb@red-bean.com>
* 1GB as the example says we'll do
- 1GB as the example says we'll do
- update readme for windows users.
* bring up to date with trunk
sync with trunk.
make more of Jim's changes
* some of the consts have changed name.
* small tweaks
* what is the flag called now?
what is the flag called now?
* Update shader.wgsl
naming things betterer
* Update README.md
reword readme
* Update README.md
simplify readme
* Update mod.rs
remove unused
* well at least it compiles again
* BUG: ... it seems to run forever and never complete.
* nicer shader module creation
* ... add logging to track down infinite hangtime...
* use 2 buffers in the test
* test and example pass (now they do the same number of buffers..
* that's better...
* fix: remove duplicate entries
* fix: whitespace
* move changelog entry to #unreleased per request
* fix: target_arch != wasm to satiate pipeline
* fix: target_arch != wasm to satiate pipeline
* pipeline want's us to allow allows...
* savage hacks to make the wasm build ignore our test
* fix: allow the allowing of allows that allow the dead_code.
* Fix: no tests on wasm
---------
Co-authored-by: Jim Blandy <jimb@red-bean.com>
Currently we generate code to convert floating point values to integers
using constructor-style casts in HLSL, static_cast in MSL, and
OpConvertFToS/OpConvertFToU instructions in SPV. Unfortunately the
behaviour of these operations is undefined when the original value is
outside of the range of the target type.
This patch avoids undefined behaviour by first clamping the value to
be inside the target type's range, then performing the cast.
Additionally, we specifically clamp to the minimum and maximum values
that are exactly representable in both the original and the target
type, as per the WGSL spec[1]. Note that these may not be the same as
the minimum and maximum values of the target type.
We additionally must ensure we clamp in the same manner for
conversions during const evaluation. Lastly, although not part of the
WGSL spec, we do the same for casting from F64 and/or to I64 or U64.
[1] https://www.w3.org/TR/WGSL/#floating-point-conversion
With the only caveat that device creation will now panic if the `wgsl` feature is not enabled, `InstanceFlags::VALIDATION_INDIRECT_CALL` is set and the device supports `DownlevelFlags::INDIRECT_EXECUTION`.
This avoids a panic due to f16::to_u32()/f16::to_u64() returning None
when the value of the f16 is <= -1.0. The correct behaviour when
converting from a floating point to an integer when the value is out
of range is to clamp to the nearest value that is representable in
both the source and destination type. ie zero for negative numbers.