GLSL branching behaviour

前端 未结 2 1830
说谎
说谎 2021-01-01 23:30

I have a rather simple fragment shader with a branch and I\'m a bit unsure how it is handled by the GLSL compiler and how it would affect performance.

unifor         


        
2条回答
  •  说谎
    说谎 (楼主)
    2021-01-02 00:31

    Yes, IIRC you won't hit a performance overhead since all the threads in a single batch (warp) on a single GPU processor will go through a single branch. By 'thread' I mean 'a single execution line of the shader'.

    The efficiency problem arises when a part of threads executed at the given time by a given processor (which'd be up to like 32 threads AFAIK; depends on hardware, I'm giving the numbers for G80 architecture) would branch into several branches - two different instructions at a time cannot be executed by one processor, so firstly the "if" branch would be executed by a part of threads (and the remaining would wait), and then the "else" branch would get executed by the rest.

    That's not the case with your code, so I believe you're safe.

提交回复
热议问题