gpt4 book ai didi

ios - OpenGL ES - iPhone4 - 片段着色器变量计数

转载 作者:行者123 更新时间:2023-11-29 12:46:42 24 4
gpt4 key购买 nike

我在片段着色器中有大量变量(30 个制服(主要是 vec4),着色器中大约有 20 个变量(vec3、float、vec4))。它在 iPhone5S 上运行得很好,但我在 iPhone4 上遇到了严重的问题。 GPU 时间为 1 秒/帧,98% 的时间是着色器运行时间。

根据 Apple API

OpenGL ES limits the number of each variable type you can use in a vertex or fragment shader. The OpenGL ES specification doesn’t require implementations to provide a software fallback when these limits are exceeded; instead, the shader simply fails to compile or link. When developing your app you must ensure that no errors occur during shader compilation, as shown in Listing 10-1.

但是对此我很不理解。他们是否提供 SW 后备?因为我在着色器的编译或链接期间没有错误,但性能很差。我几乎把所有的东西都注释掉了,只留下 2 个纹理查找和定向光计算。我更改了其他函数以仅返回 vec4(0,0,0,0)。

最佳答案

制服的限制远不止于此。 GLSL ES (2.0) 要求每个顶点着色器有 512 个标量统一分量(尽管 ES 用向量的数量来描述这一点——128)。假设你所有的 30 件制服都是 vec4,你仍然有足够的存储空间来容纳另外 98 件。

相关限制是 gl_MaxVertexUniformVectorsgl_MaxFragmentUniformVectors。实现只需要在片段着色器中支持 16 个,但大多数将远远超过最小值 - 请自行检查值。从 GL ES 查询限制,而不是尝试使用一些 Frankenstein 着色器代码在 GLSL 程序中找出它们;)

OpenGL ES 2.0 Shading Language - Appendix A: Limitations - pp. 113

const mediump int gl_MaxVertexAttribs             = 8; 
const mediump int gl_MaxVertexUniformVectors = 128;
const mediump int gl_MaxVaryingVectors = 8;
const mediump int gl_MaxVertexTextureImageUnits = 0;
const mediump int gl_MaxCombinedTextureImageUnits = 8;
const mediump int gl_MaxTextureImageUnits = 8;
const mediump int gl_MaxFragmentUniformVectors = 16;
const mediump int gl_MaxDrawBuffers = 1;

事实上,查询所有 GLSL 程序/着色器限制只是为了更好地了解您需要在目标软件/硬件下工作的约束是个好主意。最好提前计划,而不是等到程序崩溃后再解决这些问题。


至于软件回退,我对此表示怀疑。这是一个嵌入式环境,没有太多需要这样的东西。在 PC/Mac 上开发实际软件时,他们通常会附带一个引用软件实现,主要用于测试目的。个别组件有时可能会回退到软件以克服硬件限制,但这是必要的,因为仅 Apple 的 Mac 产品线就有各种各样的硬件。但是,当您编写专门为单一硬件规范编写的应用程序时,如果您尝试执行超出限制(您应该熟悉)的操作,则完全失败通常是可以接受的。

关于ios - OpenGL ES - iPhone4 - 片段着色器变量计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23514049/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com