Opengl es 片段着色器是否有时间限制?iOS使用Brad Larson提供的带有GPUImage的过滤器
我正在iOS 8上使用Brad Larson的优秀库GPUImage 我遇到了一个问题过滤器,它只完成了3/4的任务/片段,在单个图像上运行,但有多个过滤器: 从我正在做的测试来看,我似乎违反了时间限制或缓冲区大小,但奇怪的是,它看起来更像是一个时间限制。。。尽管情况可能并非如此,但更有可能的是,我在某个地方被淹没了 如下图所示,我正在GPUImage中运行一些普通的过滤器,然后应用我在最后创建的新过滤器,这需要5到8秒才能完成。我可以调整新过滤器的片段着色器中的循环数量,并看到它运行得更快,然后最后一个过滤器完成,即使它占用了相同的缓冲区空间(我相信) (另请参见下面片段着色器的代码) 如果我按照我想要的方式保留过滤器,下面的这张图像就是它停止大约3/4秒的结果,奇怪的是,你可以看到下面的第三个过滤器(GPUIMageDirectionalSoEledgeDetectionFilter,而不是第二个过滤器,GPUImageDirectionalNonMaximumSuppressionFilter) 我在Brad Larson的代码中找不到任何限制缓冲区或时间的“限制” 我看起来像是溢出了缓冲区还是遇到了其他限制?记住,我可以通过简单地减少最后一个片段着色器中的一些循环,而不改变任何其他内容来完成此过滤器。。循环没有填充任何缓冲区,只计算一些浮点数和向量(可能会溢出一个) (编辑:可能是某些缓冲区/图像空间正在释放或其他,因为该过程花费的时间太长,以至于有时间释放/释放?) 下面是Brad的一些调试代码,这些代码在程序/过滤器的链接和编译的时间量上 岩芯图形绘制时间:731.258035 GLP程序在5.171001 ms中编译 GLP程序在2.515018毫秒内编译 GLP程序链接在5.878985毫秒内 GLP程序在0.092983毫秒内编译 GLP程序在0.181973毫秒内编译 GLP程序链接在1.731992 ms中 GLP程序在0.275016毫秒内编译 GLP程序在0.414014毫秒内编译 GLP程序链接在1.176000毫秒内 GLP程序在0.074029毫秒内编译 GLP程序在0.380039毫秒内编译 GLP程序链接在0.957966毫秒内 GLP程序在0.078022毫秒内编译 GLP程序在1.359999毫秒内编译 GLP程序链接在5.873978毫秒内 这是片段着色器的一部分,我可以通过多种方式调整循环部分,以缩短时间,并完成过滤器,我遗漏的内容(由etc…etc…表示)在新过滤器的片段着色器的循环中更为相同:Opengl es 片段着色器是否有时间限制?iOS使用Brad Larson提供的带有GPUImage的过滤器,opengl-es,gpuimage,fragment-shader,Opengl Es,Gpuimage,Fragment Shader,我正在iOS 8上使用Brad Larson的优秀库GPUImage 我遇到了一个问题过滤器,它只完成了3/4的任务/片段,在单个图像上运行,但有多个过滤器: 从我正在做的测试来看,我似乎违反了时间限制或缓冲区大小,但奇怪的是,它看起来更像是一个时间限制。。。尽管情况可能并非如此,但更有可能的是,我在某个地方被淹没了 如下图所示,我正在GPUImage中运行一些普通的过滤器,然后应用我在最后创建的新过滤器,这需要5到8秒才能完成。我可以调整新过滤器的片段着色器中的循环数量,并看到它运行得更快,然
[sourcePicture addTarget:theNewFilter];
[theNewFilter useNextFrameForImageCapture];
[sourcePicture processImage];
UIImage *currentFilteredVideoFrame = [theNewFilter imageFromCurrentFramebuffer];
[self.zoomView setImage:currentFilteredVideoFrame];
和片段着色器:
(
precision mediump float;
uniform sampler2D inputImageTexture;
varying mediump vec2 textureCoordinate;
uniform mediump float texelWidth;
uniform mediump float texelHeight;
uniform mediump float texelWidthX2;
uniform mediump float texelHeightX2;
const int numOfConvolutions = 7;
uniform int sAMPLES[numOfConvolutions];
const int sAMPLES0 = 17;
const int sAMPLES1 = 32;
const int sAMPLES2 = 30;
const int sAMPLES3 = 32;
const int sAMPLES4 = 32;
const int sAMPLES5 = 32;
const int sAMPLES6 = 32;
uniform mediump float convolutionCriteria[numOfConvolutions];
uniform mediump vec3 pos0Weight[sAMPLES0];
uniform mediump vec3 pos1Weight[sAMPLES1];
uniform mediump vec3 pos2Weight[sAMPLES2];
uniform mediump vec3 pos3Weight[sAMPLES3];
uniform mediump vec3 pos4Weight[sAMPLES4];
uniform mediump vec3 pos5Weight[sAMPLES5];
uniform mediump vec3 pos6Weight[sAMPLES6];
void main()
{
mediump vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
mediump vec3 weightStep;
mediump vec2 currentStep1;
mediump vec2 currentStep2;
mediump vec2 sideStepRight;
mediump vec2 sideStepLeft;
mediump vec2 bottomStep;
mediump vec2 topStep;
mediump float currentColorf;
mediump float finalColorf1 = 0.0;
mediump float finalColorf2 = 0.0;
mediump float totalColor1f = 0.0;
mediump float totalColor2f = 0.0;
mediump float rightSideColorBotf;
mediump float rightSideColorTopf;
mediump float leftSideColorBotf;
mediump float leftSideColorTopf;
mediump float bottomRightSideColorf;
mediump float topRightSideColorf;
mediump float bottomLeftSideColorf;
mediump float topLeftSideColorf;
mediump vec2 currentCoordinate;
if (textureColor.r > 0.02)
{
for (int j = 0; j < (numOfConvolutions - 1); j++)
{
totalColor2f = 0.0;
totalColor1f = 0.0;
for (int i = 2; i < sAMPLES[j]; i++)
{
if (j == 0) weightStep = pos0Weight[i];
else if (j == 1) weightStep = pos1Weight[i];
else if (j == 2) weightStep = pos2Weight[i];
else if (j == 3) weightStep = pos3Weight[i];
else if (j == 4) weightStep = pos4Weight[i];
else if (j == 5) weightStep = pos5Weight[i];
sideStepLeft = vec2(weightStep.x - texelWidthX2, weightStep.y);
currentStep1 = vec2(weightStep.x, weightStep.y);
sideStepRight = vec2(weightStep.x + texelWidthX2, weightStep.y);
topStep = vec2(weightStep.y, -weightStep.x - texelHeightX2);
currentStep2 = vec2(weightStep.y, -weightStep.x);
bottomStep = vec2(weightStep.y, -weightStep.x + texelHeightX2);
//------------ Bottom first arm Side step right ---------------
currentCoordinate = textureCoordinate.xy + sideStepRight;
rightSideColorBotf = texture2D(inputImageTexture, currentCoordinate).r * weightStep.z;
//------------ top half first arm Side step right ---------------
currentCoordinate = textureCoordinate.xy - sideStepRight;
rightSideColorTopf = texture2D(inputImageTexture, currentCoordinate).r * weightStep.z;
//------------ Bottom first arm Side step left ----------
etc.... etc.... etc.....
//------------ left half second arm ---------------
currentCoordinate = textureCoordinate.xy - currentStep2;
currentColorf = texture2D(inputImageTexture, currentCoordinate).r * weightStep.z;
totalColor2f += currentColorf - (bottomLeftSideColorf + topLeftSideColorf);
}
if (totalColor2f > convolutionCriteria[j]) {finalColorf2 = totalColor2f; break;}
else if (totalColor1f > convolutionCriteria[j]) {finalColorf1 = totalColor1f; break;}
}
if ((finalColorf2 < 0.01) && (finalColorf1 < 0.01))
{
for (int j = 1; j < (numOfConvolutions - 1); j++)
{
totalColor2f = 0.0;
totalColor1f = 0.0;
for (int i = 2; i < sAMPLES[j]; i++)
{
if (j == 1) weightStep = pos1Weight[i];
else if (j == 2) weightStep = pos2Weight[i];
else if (j == 3) weightStep = pos3Weight[i];
else if (j == 4) weightStep = pos4Weight[i];
else if (j == 5) weightStep = pos5Weight[i];
sideStepLeft = vec2(-weightStep.x - texelWidthX2, weightStep.y);
currentStep1 = vec2(-weightStep.x, weightStep.y);
sideStepRight = vec2(-weightStep.x + texelWidthX2, weightStep.y);
topStep = vec2(weightStep.y, weightStep.x - texelHeightX2);
currentStep2 = vec2(weightStep.y, weightStep.x);
bottomStep = vec2(weightStep.y, weightStep.x + texelHeightX2);
//------------ Bottom first arm Side step right ---------------
currentCoordinate = textureCoordinate.xy + sideStepRight;
rightSideColorBotf = texture2D(inputImageTexture, currentCoordinate).r * weightStep.z;
//------------ top half first arm Side step right ---------------
currentCoordinate = textureCoordinate.xy - sideStepRight;
rightSideColorTopf = texture2D(inputImageTexture, currentCoordinate).r * weightStep.z;
//------------ Bottom first arm Side step left ---------------
etc.......etc......etc.....
//------------ left half second arm ---------------
currentCoordinate = textureCoordinate.xy - currentStep2;
currentColorf = texture2D(inputImageTexture, currentCoordinate).r * weightStep.z;
totalColor2f += currentColorf - (bottomLeftSideColorf + topLeftSideColorf);
}
if (totalColor2f > convolutionCriteria[j]) {finalColorf2 = totalColor2f; break;}
else if (totalColor1f > convolutionCriteria[j]) {finalColorf1 = totalColor1f; break;}
}
}
}
if (finalColorf2 > 0.01)
{
gl_FragColor = vec4(textureColor.r * 1.6,0.0,0.0,1.0);
} else if (finalColorf1 > 0.01) {
gl_FragColor = vec4(0.0,0.0,textureColor.r * 1.6,1.0);
} else {
gl_FragColor = textureColor;
}
(
精密中泵浮子;
均匀的二维纹理;
改变mediump vec2纹理坐标;
均匀的中泵浮动texelWidth;
均匀中泵浮动texelHeight;
均匀mediump float texelWidthX2;
均匀中泵浮动texelHeightX2;
常数int numof卷积=7;
均匀整数样本[numof卷积];
const int sAMPLES0=17;
const int sAMPLES1=32;
常数int样本2=30;
const int sAMPLES3=32;
const int sAMPLES4=32;
常数int样本5=32;
常数int样本6=32;
统一mediump浮点卷积准则[Numofcolutions];
均匀mediump vec3 Pos0重量[样本0];
均匀介质vec3位置1重量[样本1];
均匀介质vec3位置2重量[样本2];
均匀介质vec3位置3重量[样本3];
均匀介质vec3位置4重量[样本4];
均匀介质vec3位置5重量[样本5];
均匀介质vec3位置6重量[样本6];
void main()
{
mediump vec4 textureColor=texture2D(输入图像纹理,纹理坐标);
mediump vec3加权步长;
mediump vec2电流步骤1;
mediump vec2 currentStep2;
mediump vec2侧踏板右侧;
mediump vec2侧踏板左侧;
mediump vec2底部台阶;
mediump vec2上台阶;
mediump浮动电流f;
中泵浮动最终颜色F1=0.0;
中间泵浮动最终颜色f2=0.0;
mediump float totalColor1f=0.0;
mediump float totalColor2f=0.0;
mediump float rightSideColorBotf;
mediump float rightSideColorTopf;
mediump float leftSideColorBotf;
mediump float leftSideColorTopf;
mediump float bottomRightSideColorf;
mediump float topRightSideColorf;
mediump float bottomLeftSideColorf;
mediump float topLeftSideColorf;
mediump vec2电流坐标;
如果(textureColor.r>0.02)
{
对于(int j=0;j<(numf卷积-1);j++)
{
totalColor2f=0.0;
totalColor1f=0.0;
对于(int i=2;i