iOS Metal:着色器中使用的变量数限制 [英] ios metal: limit on number of variables used in a shader

查看:164
本文介绍了iOS Metal:着色器中使用的变量数限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在为着色器添加了一些复杂性之后,我今天开始收到以下错误:

I started receiving the following error today after adding some complexity to my shader:

Execution of the command buffer was aborted due to an error during execution. Discarded (victim of GPU error/recovery) (IOAF code 5)

我发现的是它与实际添加的代码无关,但实际上我添加了更多的变量和函数调用.我尝试从着色器中删除其他复杂性,并删除了错误. 我发现的另一件事是,当我将快速数学设置为false时,该问题也消除了.

What i discovered is that it has nothing to do with the actual added code but with fact i added more variables and function calls. I tried removing other complexities from the shader and the error was removed. Another thing i discovered is that problem also removed when i set fast math to false.

我的第一个猜测是,开启快速数学运算时,变量数量会有某种限制.有这样的限制吗?还有其他想法为什么会发生这种错误?

My first guess is that there is some kind of a limit on number of variables when fast math is on. Is there such a limit? Any other ideas why such error might occur?

推荐答案

最可能的原因是Metal缓冲区或着色器超载 使用金属技术存在局限性,在此进行介绍

Most probable cause is that Metal buffers or shaders are overloaded there is a limitations of using metal technology and it is described here

https://developer.apple .com/library/content/documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/BestPracticesforShaders/BestPracticesforShaders.html

我以前遇到过这个问题,我打算从Metal切换到OpenGL,但是Metal的优点让我再试一次,然后发现我正在计算和排序大量数据的问题(大多数情况是浮点型和双精度型) )在渲染器功能内

I was having this problem before and i was about to switch from Metal to OpenGL But the advantages of Metal let me try again then i discover that my issue that i was Calculating and sorting an Array of Heavy data (Mostly floats and doubles) within the renderer function

我的错误在这里看到备注行

My Mistake was Here See the remarked line

- (void)renderer:(id <SCNSceneRenderer>)renderer updateAtTime:(NSTimeInterval)time
{

    [self calculateMyData];    // This Is Wrong

 }

- (void)calculateMyData
{
   // the Heavy Calculations 
}

为避免大多数IOAF错误,请尽量不要执行繁重或复杂的计算,例如在渲染器中对数据进行排序等,请尝试使用外部循环"来调用此计算.这就是我所做的

to avoid most IOAF Errors try not to do heavy or complex calculations like sorting data or such within the renderer try use External Loops to call this calculations. This is what i have done

- (void)viewDidLoad
{
    // I Use A Timer Loop Every 0.3 Sec to call the heave calculations and sort data

    NSTimer *timerCounter2 = [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(calculateMyData) userInfo:nil repeats: YES]; 

}
- (void)renderer:(id <SCNSceneRenderer>)renderer updateAtTime:(NSTimeInterval)time
{
    //[self calculateMyData];    // Now I Avoid The Mistake    
}

- (void)calculateMyData
{
   // the Heavy Calculations 
}

这篇关于iOS Metal:着色器中使用的变量数限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆