OpenGL|ES Shader代码量逐渐增大,在执行glLinkProgram时返回GL_FALSE,用glGetProgramiv获取不到错误信息。

JonyGuo 2013-03-08 04:56:44
Shader代码流程大致如下:

float processTree(这里传入19个参数)
{
// 根据参数多次利用texture2D获取texture像素值
// 将这些获取到的像素值做一些float类型运算
// 得到一个返回值并返回
}
int stage0(float tmp)
{
float sum += processTree(...);
float sum += processTree(...);
float sum += processTree(...);
float sum += processTree(...);
float sum += processTree(...);
float sum += processTree(...);
float sum += processTree(...);
float sum += processTree(...);
float sum += processTree(...);
float sum += processTree(...);
......
// 用sum和tmp进行比较,然后返回0或1
}
void main()
{
stage0(...);
}


代码编译没有报错,Shader编译也没有报错:
1. 当stage0中processTree的调用次为50次时,Shader进行link时没有报错,程序可以正确执行;
2. 当stage0中processTree的调用次为60次时,Shader的link过程报错,程序结束,但是用glGetProgramiv获取不到错误信息,错误信息为空。

给人的感觉就是OpenGL|ES好像是有某些限制,但是我们又不知道,导致在处理达到一定次数时,link就报错了。

有没有兄弟遇到过同样的问题,或是有自己的看法,欢迎大家回复。
找到出现这个问题的真正原因。

PS:已经被这个问题折腾了2个礼拜了,求高手解答。
...全文
950 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
haishui0902 2013-09-06
  • 打赏
  • 举报
回复
初学者,问个问题哈 遇到这种glLinkProgram失败的时候,如何拆分Fragment Shader? 我没找到相关资料,不知道如何拆分。
JonyGuo 2013-03-27
  • 打赏
  • 举报
回复
请教专家后得到如下结果: 1. OpenGL|ES在编译、link程序时,会将自定义函数按照宏定义全部展开,那么可执行程序所包含的指令会变得很大,而对程序而言,自身占用堆栈大小是有限制的,所以导致堆栈大小占用超过了限制,Link失败。 2. 换句话说,就是OpenGL|ES对整个代码的规模(这个包括运算量、指令数等因素)是有限制的。因为我们的计算量比较大,所以导致超过了限制。 解决办法: 可以将在单个Fragment Shader里面的计算量分拆到多个Fragment Shader中去完成,但这肯定会影响效率。
JonyGuo 2013-03-08
  • 打赏
  • 举报
回复
引用 1 楼 zhao4zhong1 的回复:
崩溃的时候在弹出的对话框按相应按钮进入调试,按Alt+7键查看Call Stack里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处。 判断是否越界访问,可以在数组的最后一个元素之后对应的地址处设置数据读写断点。如果该地址对应其它变量干扰判断,可将数组多声明一个元素,并设置数据读写断点在该多出元素对应的地址上。 ……
1. 我的源码是直接编译成Android平台的可执行文件,直接放到Android手机上进行测试,如:先adb shell,然后直接执行可执行程序,报错就直接在adb shell中,Android界面上没有异常,所以没有调试按钮之类的,你这个说的应该是window平台上? 2. 因为是Android平台,不知道如何查看任务管理器,怎么进行统计、记录? PS:这些代码在Nvidia芯片的显卡(GPU)上执行也是会报错,是在ubuntu环境上编译执行的。
赵4老师 2013-03-08
  • 打赏
  • 举报
回复
崩溃的时候在弹出的对话框按相应按钮进入调试,按Alt+7键查看Call Stack里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处。 判断是否越界访问,可以在数组的最后一个元素之后对应的地址处设置数据读写断点。如果该地址对应其它变量干扰判断,可将数组多声明一个元素,并设置数据读写断点在该多出元素对应的地址上。 检查是否资源泄漏的办法之一: 在任务管理器 进程 查看 选择列 里面选择:内存使用、虚拟内存大小、句柄数、线程数、USER对象、GDI对象 让你的程序(进程)不退出,循环执行主流程很多遍,越多越好,比如1000000次甚至无限循环,记录以上各数值,再隔至少一小时,越长越好,比如一个月,再记录以上各数值。如果以上两组数值的差较大或随时间流逝不断增加,则铁定有对应资源的资源泄漏!
OpenGL® ES™ is the industry’s leading software interface and graphics library for rendering sophisticated 3D graphics on handheld and embedded devices. The newest version, OpenGL ES 3.0, makes it possible to create stunning visuals for new games and apps, without compromising device performance or battery life. In the OpenGL ES 3.0 Programming Guide, 2nd Edition, the authors cover the entire API and Shading Language. They carefully introduce OpenGL ES 3.0 features such as shadow mapping, instancing, multiple render targets, uniform buffer objects, texture compression, program binaries, and transform feedback. Through detailed, downloadable C-based code examples, you’ll learn how to set up and program every aspect of the graphics pipeline. Step by step, you’ll move from introductory techniques all the way to advanced per-pixel lighting and particle systems. Throughout, you’ll find cutting-edge tips for optimizing performance, maximizing efficiency with both the API and hardware, and fully leveraging OpenGL ES 3.0 in a wide spectrum of applications. All code has been built and tested on iOS 7, Android 4.3, Windows (OpenGL ES 3.0 Emulation), and Ubuntu Linux, and the authors demonstrate how to build OpenGL ES code for each platform. Coverage includes EGL API: communicating with the native windowing system, choosing configurations, and creating rendering contexts and surfaces Shaders: creating and attaching shader objects; compiling shaders; checking for compile errors; creating, linking, and querying program objects; and using source shaders and program binaries OpenGL ES Shading Language: variables, types, constructors, structures, arrays, attributes, uniform blocks, I/O variables, precision qualifiers, and invariance Geometry, vertices, and primitives: inputting geometry into the pipeline, and assembling it into primitives 2D/3D, Cubemap, Array texturing: creation, loading, and rendering; texture wrap modes, filtering, and formats; compressed textures, sampler objects, immutable textures, pixel unpack buffer objects, and mipmapping Fragment shaders: multitexturing, fog, alpha test, and user clip planes Fragment operations: scissor, stencil, and depth tests; multisampling, blending, and dithering Framebuffer objects: rendering to offscreen surfaces for advanced effects Advanced rendering: per-pixel lighting, environment mapping, particle systems, image post-processing, procedural textures, shadow mapping, terrain, and projective texturing Sync objects and fences: synchronizing within host application and GPU execution This edition of the book includes a color insert of the OpenGL ES 3.0 API and OpenGL ES Shading Language 3.0 Reference Cards created by Khronos. The reference cards contain a complete list of all of the functions in OpenGL ES 3.0 along with all of the types, operators, qualifiers, built-ins, and functions in the OpenGL ES Shading Language. Table of Contents Chapter 1. Introduction to OpenGL ES 3.0 Chapter 2. Hello Triangle: An OpenGL ES 3.0 Example Chapter 3. An Introduction to EGL Chapter 4. Shaders and Programs Chapter 5. OpenGL ES Shading Language Chapter 6. Vertex Attributes, Vertex Arrays, and Buffer Objects Chapter 7. Primitive Assembly and Rasterization Chapter 8. Vertex Shaders Chapter 9. Texturing Chapter 10. Fragment Shaders Chapter 11. Fragment Operations Chapter 12. Framebuffer Objects Chapter 13. Sync Objects and Fences Chapter 14. Advanced Programming with OpenGL ES 3.0 Chapter 15. State Queries Chapter 16. OpenGL ES Platforms Appendix A. GL_HALF_FLOAT Appendix B. Built-In Functions Appendix C. ES Framework API Book Details Title: OpenGL ES 3.0 Programming Guide, 2nd Edition Author: Aaftab Munshi, Budirijanto Purnomo, Dan Ginsburg, Dave Shreiner Length: 560 pages Edition: 2 Language: English Publisher: Addison-Wesley Professional Publication Date: 2014-03-10 ISBN-10: 0321933885 ISBN-13: 9780321933881

3,882

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧