使用 OpenGL ES 2.0 在 iPhone/iPad 上共轭渐变
我在评论中将其作为一个问题写下来,但我觉得它本身就值得提出。
我想在 iPhone/iPad 上构建一个共轭梯度求解器,因为它将为这些设备上的 GPGPU 编程开辟新的可能性,例如实时光流/实时模拟/实时有限元。
GpuGems 写得非常好的章节解释了如何使用浮点纹理来完成它。
我遇到的第一个问题是我没有设法创建浮点渲染到纹理。也许我只是没有适合我的纹理设置的正确参数。例如,此代码在第一行成功,但在第二行失败,并出现 GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 错误。
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 256, 256, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureHandle, 0);
所以,我的问题是如何在 iPhone/iPad 上渲染到浮点纹理?
或者还有其他方法来解决这个问题吗? 我认为一个混乱的替代方案是在片段着色器中使用浮点纹理,然后将生成的 16 位半浮点渲染为片段着色器中的常规 gl_FragColor,只需将其前 8 位存储在 R 中,将第二个 8 位存储在 G 中gl_FragColor 的。然后我可以使用 glReadPixels 从 FB 读回这些值,并将它们重新解释为半浮点数,并将该数据传输到新纹理并重复该过程。 这样做的明显问题是,它需要从 GPU 到 CPU,然后再回到 GPU 的非常浪费的往返,而且我很确定它不会带来任何速度提升。
有人有什么想法吗?
I wrote this as a question in a comment but I feel it is worth its own question.
I would like to build a conjugate gradients solver on the iPhone/iPad as it would open up a realm of new possibilities for GPGPU programming on these devices such as real time optical flow/real time simulations/real time finite elements.
The very well written chapter from GpuGems explains how it can be done using floating point textures.
The first problem I have encountered is that I havent managed to create a floating point render-to-texture. Perhaps I simply dont have the right parameters for my texture setup. For example this code succeeds on the first line but then fails on the second one with an GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT error.
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 256, 256, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureHandle, 0);
So, my question is how can I do render-to-floating-point-texture on iPhone/iPad?
Alternatively is there another way to solve this problem?
I thought one messy alternative would be to use floating point textures in a frag shader and then render the resulting 16bit half-float into a regular gl_FragColor in a fragment shader by simply storing its first 8 bits in the R and second 8 bits in the G of gl_FragColor. Then I could read these values back from the FB using glReadPixels and reinterpret them as half floats and transfer that data to a new texture and repeat the process.
The obvious problem with this is that it requires a very wasteful round trip from the GPU back to the CPU and then back to the GPU and im pretty sure it wont give any speed improvement.
Does anyone have any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查找 Accelerate 库、vDSP 函数
Look up the Accelerate library, the vDSP functions