我在为我的着色器添加一些复杂性后,今天开始收到以下错误:
Execution of the command buffer was aborted due to an error during execution. Discarded (victim of GPU error/recovery) (IOAF code 5)
我发现它与实际添加的代码无关,但实际上我添加了更多变量和函数调用。我尝试从着色器中删除其他复杂性,错误被删除。 我发现的另一件事是,当我将 fast math 设置为 false 时,问题也消失了。
我的第一个猜测是,当快速数学打开时,变量的数量会有某种限制。有这样的限制吗?还有其他想法为什么会发生这种错误吗?
最佳答案
最可能的原因是 Metal 缓冲区或着色器过载 使用 Metal 技术存在局限性,此处进行了描述
我以前遇到过这个问题,我正要从 Metal 切换到 OpenGL 但是 Metal 的优势让我再试一次,然后我发现我的问题是我正在计算和排序大量数据的数组(主要是 float 和 double ) ) 在渲染函数中
我的错误在这里看到注释行
- (void)renderer:(id <SCNSceneRenderer>)renderer updateAtTime:(NSTimeInterval)time
{
[self calculateMyData]; // This Is Wrong
}
- (void)calculateMyData
{
// the Heavy Calculations
}
为避免大多数 IOAF 错误,尽量不要在渲染器中进行繁重或复杂的计算,如排序数据等,请尝试使用外部循环来调用此计算。这是我做的
- (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 : limit on number of variables used in a shader,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43902467/