着色器限制

发布于 2024-08-12 04:18:17 字数 620 浏览 4 评论 0原文

我一直在为我的笔记本电脑(配备 Radeon HD 3850)调整游戏的渲染器。该芯片具有相当大的处理能力,但内存带宽相当有限,因此我一直在尝试将更多着色器工作转移到更少的通道中。

之前,我使用了一个简单的多通道模型:

  • 绑定和清除 FP16 混合缓冲区(带深度缓冲区)
    • 仅深度传递
    • 对于每个灯光,执行附加光通道
  • 绑定后台缓冲区,使用混合缓冲区作为纹理
    • 色调映射通道

为了提高此方法的性能,我编写了一个新的渲染路径,该路径计算灯光的数量和类型以动态构建自定义 GLSL 着色器。这些着色器接受所有灯光参数作为统一参数,并在一次传递中完成所有照明。我预计会遇到某种限制,所以我首先用一盏灯进行了测试。然后是三个。然后是二十一,没有错误或伪影,并且表现出色。这引出了我的实际问题:

可检索的制服数量是否达到上限?

这种方法在较旧的硬件上是否可行,或者制服是否更加有限?

如果我把它推得太远,什么时候会出现错误?着色器编译?程序链接?使用该程序?

I've been tuning my game's renderer for my laptop, which has a Radeon HD 3850. This chip has a decent amount of processing power, but rather limited memory bandwidth, so I've been trying to move more shader work into fewer passes.

Previously, I was using a simple multipass model:

  • Bind and clear FP16 blend buffer (with depth buffer)

    • Depth-only pass
    • For each light, do an additive light pass
  • Bind backbuffer, use blend buffer as a texture

    • Tone mapping pass

In an attempt to improve the performance of this method, I wrote a new rendering path that counts the number and type of lights to dynamically build custom GLSL shaders. These shaders accept all light parameters as uniforms and do all lighting in a single pass. I was expecting to run into some kind of limit, so I tested it first with one light. Then three. Then twenty-one, with no errors or artifacts, and with great performance. This leads me to my actual questions:

Is the maximum number of uniforms retrievable?

Is this method viable on older hardware, or are uniforms much more limited?

If I push it too far, at what point will I get an error? Shader compilation? Program linking? Using the program?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

江城子 2024-08-19 04:18:17

着色器制服通常由硬件作为寄存器来实现(或者有时通过将值直接修补到着色器微代码中,例如 nVidia 片段着色器)。因此,该限制高度依赖于实现。

您可以通过分别查询顶点着色器和片段着色器的 GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARBGL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB 来检索最大值。

Shader uniforms are typically implemented by the hardware as registers (or sometimes by patching the values into shader microcode directly, e.g. nVidia fragment shaders). The limit is therefore highly implementation dependent.

You can retrieve the maximums by querying GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB and GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB for vertex and fragment shaders respectively.

青柠芒果 2024-08-19 04:18:17

请参阅 OpenGL® 着色语言的 4.3.5 Uniform 规格

对于可用于的制服的存储量存在依赖于实现的限制
每种类型的着色器,如果超过此值,将导致编译时或链接时错误。制服
声明但未使用的变量不计入此限制。

它将在链接或编译时失败,但不使用程序。

See 4.3.5 Uniform of The OpenGL® Shading Language specs:

There is an implementation dependent limit on the amount of storage for uniforms that can be used for
each type of shader and if this is exceeded it will cause a compile-time or link-time error. Uniform
variables that are declared but not used do not count against this limit.

It will fail at link or compile-time, but not using the program.

時窥 2024-08-19 04:18:17

有关如何获取 OpenGL 实现支持的最大数量,请参阅 Moonshadow 的答案。

要了解任意 GPU 的实际限制在哪里,我建议查看 GPU 支持的 DX 版本。

DX9级别硬件:

  • vs2_0支持256 vec4。 ps2_0 支持 32 vec4。
  • vs3_0 是 256 vec4,ps3_0 是 224 vec4。

DX10 级别硬件:

vs4_0/ps4_0 每个常量缓冲区至少有 4096 个常量 - 您可以拥有其中 16 个。

简而言之,您不太可能用完任何基于 DX10 的产品。

For how to get the max number supported by your OpenGL implementation, see moonshadow's answer.

For an idea of where the limit actually is for arbitrary GPUs, I'd recommend looking at which DX version that GPU supports.

DX9 level hardware:

  • vs2_0 supports 256 vec4. ps2_0 supports 32 vec4.
  • vs3_0 is 256 vec4, ps3_0 is 224 vec4.

DX10 level hardware:

vs4_0/ps4_0 is a minumum of 4096 constants per constant buffer - and you can have 16 of them.

In short, It's unlikely you'll run out with anything that is DX10 based.

静若繁花 2024-08-19 04:18:17

我猜制服的最大数量是由显存大小决定的,
因为它只是一个变量。 cpu上的正常变量也受到RAM的限制,对吧?

I guess the maximum number of uniforms is determined by the amount of video memory,
as it's just a variable. Normal varaibles on the cpu are limited by your RAM too right?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文