Open sguimmara opened 8 months ago
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.
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 onBeforeCompile
callback.
@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? They sure made a difference on iPads 10 years ago but I wonder what the is situation now.
This would be useful to access samplers in an array, as GLSL forbids the user of dynamic indices to access samplers.
Oh, I see...
@sguimmara Have you tried using the new WebGPURenderer
? It comes with a WebGL fallback.
@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).
Have you tried using the new
WebGPURenderer
? It comes with a WebGL fallback.
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:
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