Ios metal: limit on the number of variables used in the shader

I started getting 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)

I found that this has nothing to do with the actual code added, but with the fact I added more variables and function calls. I tried to remove other difficulties from the shader and the error was removed. Another thing I discovered is that the problem is also fixed when I set the quick math to false.

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

+2
source share
1 answer

The most likely reason is that metal buffers or shaders are overloaded, there is a limited use of metal technology, and is described here

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

I had this problem before and was about to switch from Metal to OpenGL. But the advantages of Metal allowed me to try again, and I found that my problem was that I was calculating and sorting an array of heavy data (most often floats and doubles) in the rendering function

My mistake was here. See the marked line.

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

Source: https://habr.com/ru/post/1667839/


All Articles