-
Notifications
You must be signed in to change notification settings - Fork 247
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
Conditionals and code generation performance #1110
Labels
t: bug
Something isn't working
Comments
does it improve after running through spirv-opt? |
@ickk rust-gpu uses spirv-opt, so no unfortunately. |
It seems like the best option currently it do write it like: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I noticed that a rust gpu shader was running much slower than the equivalent wgsl one.
The wgsl one takes 53ms, and the rust gpu version takes 67ms.
Looking at the SPIRV I tracked part of the issue down to this:
I used spirv-cross to look at the code rust-gpu was producing in glsl and noticed it was producing this:
Whereas if I take wgsl through the same path (wgsl -> spirv -> glsl) it looks like this:
I tried forcing it to not branch but generate a bool, with
u32(uvt.x > 0.0 && uvt.y > 0.0 && uvt.z > 0.0 && uvt.x + uvt.y < 1.0) == 1
, and while it kept the conversion and the equality check, it still had this same nested branching structure.I then tried this which got me a lot closer to the wgsl perf (now 58ms):
This actually results in it using mix here:
Is it possible to improve the code generation in rust gpu to avoid the excessive branching in situations like this?
(I'm aware that this could also be written differently to avoid branching, I'm not concerned about this specific impl, but about the code generation in general)
The text was updated successfully, but these errors were encountered: