-
Notifications
You must be signed in to change notification settings - Fork 921
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
[naga] Built-in function database #6443
Comments
Note that the WGSL built-in functions that might require their arguments to be converted are a broader category than
|
One way to look at this is to say that we need a mapping from these operations to function types. However:
I think this means that we want a separate Here is a sketch of an argument type (I doubt it would survive an attempt to implement it unchanged): enum ScalarArgumentPattern {
/// A specific scalar type.
Exact(Scalar),
/// Any scalar of the given kind.
Kind(ScalarKind),
/// Any integral type, abstract or concrete.
AnyInt,
/// Any floating-point type, abstract or concrete.
AnyFloat,
/// Any numeric type, abstract or concrete.
AnyNumeric,
/// The same scalar as the n'th argument. Must be a lower-numbered argument.
Same(usize),
}
enum ArgumentPattern {
/// A scalar.
Scalar(ScalarArgumentPattern),
/// A vector of any length.
VecN(ScalarArgumentPattern),
/// A scalar or vector of any length.
ScalarOrVecN(ScalarArgumentPattern),
/// The same type as the n'th argument. Must be a lower-numbered argument.
Same(usize),
} The WGSL
The WGSL
Using These two forms both capture a lot of overloads in a single form, and I think it should be simple to consume. Perhaps the return type could be described using this same type: There are some functions with more complex overload patterns, like |
The shape above looks good to me, there are probably more variants we'd need for example for |
Here's how they do it in dawn: https://github.com/google/dawn/blob/main/docs/tint/intrinsic_definition_files.md |
Dawn's definition files are nice, but it seems like overkill. They have a whole separate language, which has its own maintenance cost, and build time cost. If necessary, we could put my Rust types and the data in a separate crate, so that it could be used by other applications. |
To solve #5523, Naga needs information about built-in function argument and result types in a form that the WGSL front end can consume to apply WGSL automatic type conversions.
At the moment, builtins appear in Naga in the following places:
BuiltIn
andMathFunction
.typifier
module knows the result types.valid
module knows the argument types.But automatic conversions apply anywhere that they would turn an ill-typed program into a well-typed program, so one needs argument type information to apply them.
Ideally, the first three should be brought together, and the last two should be unified.
It may be the case that we can keep the WGSL front end innocent of these things, and handle automatic conversions with a processing phase.
The text was updated successfully, but these errors were encountered: