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
Support non-integer loop start and ends when using pragma unroll_loop_* #28020
Comments
This has been discussed previously in #20305 |
@gkjohnson My bad I missed this PR. I guess then that my proposal is refused as it complexifies the unroling mechanism. Since we don't want to complexify the unrolling mechanism, the only way I see is by providing a hook that is executed just before the unrolling, and that let the user change the shader code directly. |
As mentioned in the other issue, this can be done with the |
@gkjohnson Unfortunately, this does not work if the unrollable loop is in an included chunk. It does work if I inline the chunk though. |
Are these unroll loops still necessary? |
Oh, I see... |
@sguimmara Have you tried using the new |
@mrdoob yes, the dynamic index limitation of WebGL is extremely irritating and prevents a lot of cool features. For example I have to recompile the shader every time the number of iterations in the loop changes (luckily it does not change too often).
No, but I'm very interested in WebGPU as it might help with performance. For info, we use three.js to develop Giro3D, a visualization library for geospatial data. This library is all about data streaming, dynamic updates, GPU picking, and WebGL shows its age for this use case. |
Description
Currently, the pragma only supports integer values in its regexp:
/#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g
This makes it impossible to unroll loops with statically defined values, such as:
This would be useful to access samplers in an array, as GLSL forbids the user of dynamic indices to access samplers.
In my situation, I cannot use texture arrays as the various textures in the sampler array do not have the same sizes.
Solution
Currently, in
WebGLProgram.js
, the unrolling is done right after various preprocessing, such as includes:We could make
unrollLoops
aware of the defines in the material, and if the loop end/start are identifiers rather than integers, lookup the indentifiers in the defines of the material to access the actual value:Then, we slightly modify
loopReplace
to capture thedefines
parameter:Alternatives
I also considered adding hooks to the preprocessing of the shader (à la
onBeforeCompile
), so that the user could perform the replacement of the loop-related defines by actual integers:onBeforeUnrollLoops()
onBeforeIncludes()
but it feels a bit too heavy.
Additional context
No response
The text was updated successfully, but these errors were encountered: