简体   繁体   English

关于具有8个纹理单元的opengl es多纹理着色器的思考

[英]Thoughts on opengl es multitexture shader with 8 texture units

Below is a fragment shader that is performing poorly. 下面是性能不佳的片段着色器。 Removing the conditional branches doesnt seem to improve performance. 删除条件分支似乎并不能提高性能。 With just 150 polys I get 10fps on Kindle Fire and 20fps on Galaxy S3. 仅用150个多边形,我在Kindle Fire上获得10fps的速度,在Galaxy S3上获得20fps。 Any thoughts on the best way to optimize this, if at all? 如果有的话,是否有最佳方法来进行优化? Similar shader on iPad 2 runs 30+fps. iPad 2上类似的着色器的运行速度为30 + fps。

In the code below, texture1 to texture8 are bound to the eight textures. 在下面的代码中,texture1到texture8绑定到八个纹理。 VertexTexturesOut1 and VertexTexturesOut2 are passed from the vertex shader and have values 0.0 to 1.0 to indicate the shading amount to be blended. 从顶点着色器传递VertexTexturesOut1和VertexTexturesOut2,其值介于0.0到1.0之间,以指示要混合的着色量。 The idea is to blend a landscape texture, so the grass blends evenly into dirt, rock, sand, etc. 想法是混合景观纹理,以便草均匀地混合到泥土,岩石,沙子等中。

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;    

You shader has many of the DONT's when designing fragment shaders. 在设计片段着色器时,您的着色器具有许多DONT。 You have many conditional statements so all the threads need to wait always for all the other threads in the warp (or batch). 您有许多条件语句,因此所有线程都需要始终等待扭曲(或批处理)中的所有其他线程。 You are also accessing 8 textures which means you need to wait for all those texture lookups (which also kills memory bandwidth). 您还将访问8个纹理,这意味着您需要等待所有这些纹理查找(这也会浪费内存带宽)。 Use any optimization tools, for example the Adreno SDK, the Mali SDK or any vendor of your choice and run the shader in their optimization tools to spot where is the GPU is spending more time. 使用任何优化工具,例如Adreno SDK,Mali SDK或您选择的任何供应商,并在其优化工具中运行着色器,以发现GPU在哪里花费了更多时间。

Are you using full RGB888 textures? 您是否在使用完整的RGB888纹理? A 一种

Maybe if you tell us what are you trying to archive we can think on another solution without using 8 texture lookups. 也许如果您告诉我们您要归档什么,我们可以考虑使用另一种解决方案而无需使用8个纹理查找。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM