-
Notifications
You must be signed in to change notification settings - Fork 937
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/wgsl-out]: polyfill inverse
function
#6385
Conversation
0cb32f3
to
ba0b5b3
Compare
ba0b5b3
to
0c93797
Compare
Fixed clippy errors and applied the suggestion from @teoxoy. Will await consensus from @jimblandy before moving forward with whether to keep the flag. I don't mind either way, but the idea to have the flag stemmed from concerns in #4330 where OP seemed to have reservations about the injected polyfill being "quite long". |
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.
Unless I'm missing something, the polyfill names all need to start with __
, a double underscore. A single underscore isn't a reserved prefix (see back::wgsl::Writer::reset
's call to Namer::reset
), so these injected polyfills could conflict with a definition supplied by the user for _naga_inverse_blah
.
7a37872
to
c4b141c
Compare
@jimblandy Made the emitted polyfills start with a double underscore and further namespaced them as |
@chyyran No, you're right, double underscore isn't something that the code that we generate can define. We should be producing WGSL that other WGSL implementations would accept. Sorry for the bad advice. I think instead you should change the polyfill names back, so they start with |
c4b141c
to
8309067
Compare
@jimblandy dropped the changes to add the double underscore and added |
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.
LGTM, thanks!
@chyyran it looks like the snapshots need updating. |
Looks like its sensitive to insertion order. I’ll switch it to use an indexset. |
8309067
to
083d7e9
Compare
Connections
MathFunction::Inverse
for matrices #4330inverse
in GLSL appears to cause an issue when parsing resulting WGSL (wgpu v0.8.1) naga#893Description
inverse
is not currently supported by WGSL and might never be. However this leaves shaders that do need these functions fundamentally incompatible with WGSL unless they get polyfilled. This PR allowswgsl-out
to emit polyfills for GLSLinverse
functions.The polyfills provided are ported from an old Mesa commit, and have been pre-validated with
naga-cli
.outer
is not included as part of this patch as it's much more rarer thaninverse
, and another approach would probably be better. For example SPIRV-Cross just expands the calculation inline.Pre-emptive support for f16 is included as well. Note that the polyfill files are intentionally not templated to reduce large allocations during shader compilation. This allows
InversePolyfill
to be 2’static
pointers and no larger.Testing
Added an
inverse-polyfill.frag
test to thein/glsl
folder.This test is then run to validate the changes.
Checklist
cargo fmt
.cargo clippy
. If applicable, add:--target wasm32-unknown-unknown
--target wasm32-unknown-emscripten
cargo xtask test
to run tests.CHANGELOG.md
. See simple instructions inside file.