pygfx / shadertoy

Shadertoy implementation based on wgpu-py
BSD 2-Clause "Simplified" License
15 stars 2 forks source link

infinite for loops due to iTime can hang and panic. #35

Open Vipitis opened 3 months ago

Vipitis commented 3 months ago

connection: gfx-rs/wgpu#5926

I seem to run into this quite a bit recently. Some for loop is eventually dependant on some uniform (often iTime) and therefore might be an infinite loop. Infinite loops with hard coded values do get compiled away and are not an issue it seems.

since this behaviour isn't going to be changed in wgpu-core, and the uncaptured error isn't captured in wgpu-py this will panic with a "device is lost", after essentially some timeout. If we want to mimic the behaviour on the website, this should somehow just work. Maybe by skipping the 0th frame or something, if it starts to hang.

I tried to help the compiler by wrapping the uniforms in max(), min() or maybe abs() (since negative numbers in that examples are a problem) - but nothing seems to help.

Using this issue to track changes to the behaviour in the upstream deps and maybe finding a solution someday.

Vipitis commented 2 months ago

with 22.1 Vulkan seems to handle some infinite loops (0 increment), but not others(negative). I will try to figure out what the exact difference is, I suspect it might be the compiler putting in a while True instead.

There is also a translation issue regarding loops, that cause loops to unintentionally become infinite: https://github.com/gfx-rs/wgpu/issues/6208