Prevent unwinding a loop in a fragment shader

I am writing a fragment shader for WebGL (GLSL ES 1.0) using the latest version of Chrome (and Firefox), and I wrote an iterative algorithm.

So, first of all, I found that the length of the loop is quite limited (doc says that it should be guessed at compile time, which means that it should be constant or very close).

In addition, I have to write a loop ( forbecause it is the only one that should be implemented in accordance with the standard), which is potentially long, but which is interrupted almost every time until the end.

Now I noticed that if I set a higher maximum number, compiling and binding the shader takes more time. So, if I'm not mistaken, the compiler does a unwinding cycle.

I'm not sure if something can be done, but I tried a few things and the compiler also seems to be inline even when called in a loop.

It doesn't seem to me that it usually takes a whole minute for a shader to compile almost a hundred loop iterations. Or am I doing wrong? Is a hundred iterations alternating a fragment too much for the GPU? Since it seems to work very well after compiling it.

+5
source share
3 answers

GLSL. , -, , , . . NVIDIA/ATI , , .

, , . . . , , , . , , , .

+4

, , 100 , , ANGLE.

ANGLE - , , WebGL, Windows, GLSL Direct3D HLSL. , Windows Direct3D- OpenGL, D3D. , , , Windows, Intel.

Windows, OpenGL-, nVidia AMD, ANGLE, , . Google Chrome , Chrome, --use-gl=desktop ( "" ) . Firefox about:config webgl webgl.prefer-native-gl true.

ANGLE, . , Windows, , , OpenGL .

+3

, AMD, , , , NVidia . , , "#pragma optionNV (unroll all)" GLSL, , . DenisR 2008 NVidia:

. #pragma unroll . . , , .

, :

#pragma unroll 5

for (int i = 0; i < n; ++i)

5 . , ( , n 5).

#pragma unroll 1 

.

#pragma unroll , , , .

, ,

#pragma optionNV (unroll 1)

GLSL ( WebGL?). (, -nvidia-pragma-optionnvunroll-all, , , GLSL, , .)

, AMD (, GLSL), : AMD OpenCL

(If you use GLSL via WebGL in Chrome / Firefox or even in other scenarios, keep in mind that GLSL compilation can be transmitted via ANGLE , it may be displayed on the HLSL backend in Windows. I have a very limited understanding of this and you don’t want to to disseminate information, so definitely don’t quote it, I just felt the need to share what information So far I have collected this problem and would gladly edit this answer (or people can edit this answer), since more reliable information becomes available mission.)

0
source

All Articles