Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
GLSL 和 OpenCL 都有一个钳制函数,如果值超出界限,它将把一个数字钳制到插入的上限或下限。如果我尝试在 C++ 中实现类似的东西,它看起来像下面的代码:
if(i < min){ i=min; }else if(i > max){ i=max; }
但是,这有多个分支路径,据我了解,这会大大降低 GPU 的速度,因为它们中的大多数都必须执行所有分支。
那么 GLSL/OpenCL 钳位是如何工作的,如果它使用分支,你会建议尽可能避免使用它吗?