0

以下は、パフォーマンスの低いフラグメント シェーダーです。条件分岐を削除してもパフォーマンスは向上しないようです。わずか 150 ポリゴンで、Kindle Fire で 10 fps、Galaxy S3 で 20 fps が得られます。これを最適化する最善の方法について何か考えはありますか? iPad 2 の同様のシェーダーは 30+fps で動作します。

以下のコードでは、texture1 ~ texture8 が 8 つのテクスチャにバインドされています。VertexTexturesOut1 と VertexTexturesOut2 は頂点シェーダーから渡され、ブレンドされるシェーディング量を示す 0.0 ~ 1.0 の値を持ちます。ランドスケープ テクスチャをブレンドして、草が土、岩、砂などに均等に溶け込むようにします。

uniform sampler2D texture1;
uniform sampler2D texture2;
uniform sampler2D texture3;
uniform sampler2D texture4;
uniform sampler2D texture5;
uniform sampler2D texture6;
uniform sampler2D texture7;
uniform sampler2D texture8;

varying mediump vec2 TextureCoordOut;
varying lowp vec4 VertexTexturesOut1;
varying lowp vec4 VertexTexturesOut2;

...

    lowp vec4 Color = vec4( 0.0, 0.0, 0.0, 0.0);

    if (VertexTexturesOut1.x != 0.0) Color = Color + texture2D ( texture1, TextureCoordOut ) * VertexTexturesOut1.x;
    if (VertexTexturesOut1.y != 0.0) Color = Color + texture2D ( texture2, TextureCoordOut ) * VertexTexturesOut1.y;
    if (VertexTexturesOut1.z != 0.0) Color = Color + texture2D ( texture3, TextureCoordOut ) * VertexTexturesOut1.z;
    if (VertexTexturesOut1.w != 0.0) Color = Color + texture2D ( texture4, TextureCoordOut ) * VertexTexturesOut1.w;

    if (VertexTexturesOut2.x != 0.0) Color = Color + texture2D ( texture5, TextureCoordOut ) * VertexTexturesOut2.x;
    if (VertexTexturesOut2.y != 0.0) Color = Color + texture2D ( texture6, TextureCoordOut ) * VertexTexturesOut2.y;
    if (VertexTexturesOut2.z != 0.0) Color = Color + texture2D ( texture7, TextureCoordOut ) * VertexTexturesOut2.z;
    if (VertexTexturesOut2.w != 0.0) Color = Color + texture2D ( texture8, TextureCoordOut ) * VertexTexturesOut2.w;

    gl_FragColor = Color;    
4

1 に答える 1

3

フラグメントシェーダーを設計する場合、シェーダーには多くのDONTがあります。多くの条件ステートメントがあるため、すべてのスレッドは、ワープ(またはバッチ)内の他のすべてのスレッドを常に待機する必要があります。また、8つのテクスチャにアクセスしているため、これらすべてのテクスチャルックアップを待機する必要があります(これにより、メモリ帯域幅も失われます)。Adreno SDK、Mali SDK、または任意のベンダーなどの最適化ツールを使用し、最適化ツールでシェーダーを実行して、GPUがより多くの時間を費やしている場所を特定します。

フルRGB888テクスチャを使用していますか?A

アーカイブしようとしているものを教えていただければ、8つのテクスチャルックアップを使用せずに別のソリューションを検討できます。

于 2013-02-13T11:57:34.977 に答える