本文介绍了iOS上视网膜屏幕的着色器优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个使用许多广告牌的3D iphone应用程序。
我的帧缓冲区在视网膜屏幕上大两倍,因为我想在iPhone 4上提高它们的质量。
问题是片段着色器由于帧缓冲区大小而消耗更多时间。
有没有办法管理视网膜屏幕和高清晰度纹理而不增加着色器精度?

I make a 3D iphone application which use many billboards.My frame buffer is twice larger on retina screen because I want to increase their quality on iPhone 4.The problem is that fragment shaders consume much more time due to the framebuffer size.Is there a way to manage retina screen and high definition textures without increase shader precision ?

推荐答案

如果你是在Retina显示器的全分辨率下使用帧缓冲器渲染,与非Retina显示器的相同物理区域相比,它将具有四倍于光栅的像素。如果由于着色器的复杂性而导致填充率受限,则会导致每个帧渲染时间更长。

If you're rendering with a framebuffer at the full resolution of the Retina display, it will have four times as many pixels to raster over when compared with the same physical area of a non-Retina display. If you are fill-rate limited due to the complexity of your shaders, this will cause each frame to take that much longer to render.

首先,您需要验证您确实受到渲染管道的片段处理部分的限制。针对您的应用程序运行OpenGL ES Driver仪器,并查看Tiler和Renderer Utilization统计信息。如果渲染器利用率接近100%,则表示您受片段着色器和推动像素的整体能力的限制。但是,如果您在此处看到Tiler利用率百分比,则表示您的几何受限,并且屏幕分辨率的变化不会影响性能,只会降低顶点数据的复杂性和大小。

First, you'll want to verify that you are indeed limited by the fragment processing part of the rendering pipeline. Run the OpenGL ES Driver instrument against your application and look at the Tiler and Renderer Utilization statistics. If the Renderer Utilization is near 100%, that indicates that you are limited by your fragment shaders and your overall ability to push pixels. However, if you see your Tiler Utilization percentage up there, that means that you are geometry limited and changes in screen resolution won't affect performance as much as reducing the complexity and size of your vertex data.

假设您受到片段着色器的限制,可以采取一些措施来显着提高iOS GPU的性能。

Assuming that you are limited by your fragment shaders, there are a few things you can do to significantly improve performance on the iOS GPUs.

在您的情况下,听起来像纹理大小可能是一个问题。我要做的第一件事是使用PowerVR纹理压缩(PVRTC)纹理而不是标准位图源。 PVRTC纹理以压缩格式存储在内存中,并且可以比等效位图小得多。这可以通过增加纹理读取的缓存命中来实现更快的访问。

In your case, it sounds like texture size might be an issue. The first thing I'd do is use PowerVR Texture Compressed (PVRTC) textures instead of standard bitmap sources. PVRTC textures are stored in a compressed format in memory, and can be much smaller than equivalent bitmaps. This might allow for much faster access by increasing cache hits on texture reads.

使纹理的大小为2,并启用mipmap。我已经看到mipmap真的有助于更大的纹理,通常会缩小以显示在较小的对象上。这肯定听起来像您的应用程序可能需要支持Retina和非Retina设备。

Make your textures a power of two in size, and enable mipmaps. I've seen mipmaps really help out for larger textures that often get shrunken down to appear on smaller objects. This definitely sounds like the case for your application which might need to support Retina and non-Retina devices.

避免像瘟疫一样在片段着色器中使用依赖纹理读取。执行计算以确定纹理坐标或任何属于分支语句的纹理读取的任何内容都会触发依赖纹理读取,这可能比在iOS GPU上执行的速度慢一个数量级。在正常的纹理读取过程中,PowerVR GPU可以在纹理值之前稍微读取一下,但如果使用会导致依赖纹理读取,则可能会失去优化。

Avoid dependent texture reads in your fragment shaders like the plague. Anything that performs a calculation to determine a texture coordinate, or any texture reads that fall within a branching statement, triggers a dependent texture read which can be more than an order of magnitude slower to perform on the iOS GPUs. During normal texture reads, the PowerVR GPUs can do a little reading ahead of texture values, but if you use cause a dependent texture read you can lose that optimization.

我可以继续进行各种优化(在适当的情况下使用lowp或mediump精度而不是highp等),我已经,但这些似乎是我关注的第一件事。最后,您还可以尝试通过运行着色器,它可以为您提供最佳和最差情况的周期时间估算这些着色器的性能。

I could go on about various optimizations (using lowp or mediump precision instead of highp where appropriate, etc.), I've had a little help in this area myself, but these seem like the first things I'd focus on. Finally, you can also try running your shaders through PowerVR's profiling editor which can give you cycle time estimates for the best and worst case performance of these shaders.

在片段着色器限制方面,Retina显示设备甚至不是最严重的违规者。尝试将一些渲染到iPad 1的全屏幕上进行渲染,因为它的像素比iPhone 4 / 4S更多,但GPU比iPad 2/3或iPhone 4S慢得多。如果你可以在iPad 1上运行得很好,那么其他所有东西都会很好(甚至是Retina iPad)。

The Retina display devices are not even the worst offenders when it comes to fragment shader limitations. Try getting something rendering to the full screen of the iPad 1 to be performant, because it has more pixels than the iPhone 4 / 4S, yet a far slower GPU than the iPad 2/3 or iPhone 4S. If you can get something to run well on the iPad 1, it will be good on everything else out there (even the Retina iPad).

这篇关于iOS上视网膜屏幕的着色器优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 06:02