ios metal:限制着色器中使用的variables数量

添加一些复杂度到我的着色器后,我开始收到以下错误:

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

我发现,它与实际添加的代码没有任何关系,但事实上我添加了更多的variables和函数调用。 我尝试从着色器中删除其他复杂性,并删除了错误。 另一件我发现的问题是,当我把快速的math设置为false时,问题也消除了。

我的第一个猜测是,当快速math运算时,variables的数量有一些限制。 有这样的限制吗? 任何其他想法为什么会出现这样的错误?

最可能的原因是金属缓冲区或着色器过载,使用金属技术存在局限性,这里将对其进行描述

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

我以前有这个问题,我正要从金属切换到OpenGL但金属的优势让我再试一次,然后我发现我的问题,我计算和sorting重型数据(主要是浮动和双打)渲染器function

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

 - (void)renderer:(id <SCNSceneRenderer>)renderer updateAtTime:(NSTimeInterval)time { [self calculateMyData]; // This Is Wrong } - (void)calculateMyData { // the Heavy Calculations } 

为了避免大部分的IOAF错误,尽量不要进行繁重或复杂的计算,比如在渲染器中sorting数据等,请尝试使用外部循环来调用这个计算。 这就是我所做的

 - (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 }