用ios14的Shader Validation功能可以定位大概是shader哪一块报错https://developer.apple.com/videos/play/wwdc2020/10616/
打开Shader Validation 之前Log提示
Execution of the command buffer was aborted due to an error during execution. Ignored (for causing prior/excessive GPU errors) (IOAF code 4)
打开Shader Validation之后Log提示
[GPUDebug] Invalid device load executing fragment function “xlatMtlMain” encoder: “4”, draw: 10, at offset 1099511627696 file:///program_source:121:0 – xlatMtlMain()
并且断点在

后续排查下来,发现是Dither8x8Bayer的时候由于顶点没有转到裁切空间,导致下标为负数,导致数组越界,产生上述错误。
错误代码:o.screenPos = ComputeScreenPos(v.vertex);
修复之后:o.screenPos = ComputeScreenPos(UnityObjectToClipPos(v.vertex));
修改之后,报错消失,多次重复之前会卡死的操作,游戏正常运行。
其中观察到一个现象,使用Shader Validation之后,会一直有报错提示。但是在实际运行中,并不是100%会导致游戏卡死。
注意:需要ios14以上设备,需要设置IOS在14.0API下编译,我用的是iphone12,似乎在旧设备上即使是IOS14系统,Shader Validation依然没有生效。
