在现代GPU上的制服上分支的成本 [英] Cost of Branching on uniforms on modern GPUs

查看:62
本文介绍了在现代GPU上的制服上分支的成本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在现代(GL3.3 +)GPU上使用GLSL时,在统一上分支的可能成本是多少?

在我的引擎中,我到了很多着色器的地步.我为其中许多设置了几种不同的质量预设.就目前而言,我在着色器中使用带有if()的制服来选择不同的质量预设.但是,我担心通过重新编译着色器并使用#ifdef可能会获得更好的性能.这样做的问题是,当我重新编译着色器时,需要担心跟踪和重置其他制服.

基本上我想知道的是我的担心是否成立.在现代GPU上以统一的廉价分支吗?我自己做了一些测试,发现两者之间的差异很小,但是我只在nVidia 680上进行了测试.

解决方案

我承认我不是专家,但也许我的猜测总比没有好.

我认为穿制服的确很便宜.这显然与在纹理或属性数据上的分支有很大不同,因为SIMD中的所有ALU都将遵循来自着色器的相同代码路径,因此它是真实"分支而不是执行掩码.我不太确定着色器处理器如何在其管道中遭受分支气泡的困扰,但是与使用通用CPU相比,该管道肯定会更浅(特别是考虑到它们通常以较低的时钟速度运行).

我希望我能有所帮助,也希望其他人能提供更多权威性的答案.但是,我不会为穿制服而过分担心.但是,与往常一样,如果有可能,请对着色器进行概要分析,看看它是否有任何明显的区别.

When using GLSL on modern (GL3.3+) GPUs, what is the likely cost of branching on a uniform?

In my engine I'm getting to the point where I have a lot of shaders. And I have several different quality presets for a lot of those. As it stands, I'm using uniforms with if() in the shaders to choose different quality presets. I'm however worried that I might achieve better performance by recompiling the shaders and using #ifdef. The problem with that is the need to worry about tracking and resetting other uniforms when I recompile a shader.

Basically what I want to know is if my fears are unfounded. Is branching on a uniform cheap on modern GPUs? I have done a few tests myself and found very little difference either way, but I've only tested on an nVidia 680.

解决方案

I will admit that I'm not an expert, but perhaps my speculation is better than nothing.

I would think that branching on uniforms is indeed fairly cheap. It's clearly much different from branching on texture or attribute data, since all the ALUs in the SIMD will follow the same code path from the shader, so it is a "real" branch rather than an execution mask. I'm not too sure how shader processors suffer from branch bubbles in their pipeline, but the pipeline is certainly bound to be more shallow than in general-purpose CPUs (particularly given the much lower clock-speeds they typically run at).

I wish I could be more helpful and I'd also appreciate if someone else can answer more authoritatively. I, for one, wouldn't worry too much about branching on uniforms, however. But as always, if you have the possibility, do profile your shader and see if it makes any noticeable difference.

这篇关于在现代GPU上的制服上分支的成本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆