-
Notifications
You must be signed in to change notification settings - Fork 193
[wgsl-in] Allow sign() to take int argument #2463
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This mostly LGTM (noting that I don't have merge authority), minus nits and one question: would it be possible to omit this new polyfill unless needed? I'm not familiar with the matter, but I know we've thought about lazily emitting supporting polyfills WRT constructing array members of HLSL structures before. EDIT: 😅 I see that you're also asking this question in the OP:
Currently the metal backend always emits the naga_isign polyfill. What is a good way to only do that if necessary? We need to declare the function before it's used, so we can't do it after writing out the functions. Is there some mechanism to visit all expressions without duplicating a lot of logic?
☝🏻I think @jimblandy or @teoxoy would know the answer to this.
a445fcd
to
34e043c
Compare
34e043c
to
33aaa28
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than generating a definition for a polyfill, consider simply emitting the code inline. See the way the Metal backend handles MathFunction::Dot
for an example:
- It calls
back::msl::Writer::put_dot_product
to emit the expression at the point of use. - In
back::msl::Writer::update_expressions_to_bake
, we ensure that the operand is placed in a temporary variable first, so that we don't evaluate the argument expression more than once.
e209bd9
to
d64d40c
Compare
d64d40c
to
32e96a5
Compare
Thanks for the pointers @jimblandy! Changed to emitting inline in 32e96a5. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much!
Fixes #2458.
The main work here is to make it work on metal, which does not have an
int
overload ofsign()
. So we introduce anaga_isign
polyfill function there.Currently the metal backend always emits the
naga_isign
polyfill. What is a good way to only do that if necessary? We need to declare the function before it's used, so we can't do it after writing out the functions. Is there some mechanism to visit all expressions without duplicating a lot of logic?