I'm experiencing 100% reproducible bug with Xcode. It took me days to figure it out. After many tears shed.
Xcode is producing a corrupt binary. It seems like my metal buffers are being mis-aligned or something.
The problem showed up after changing the Deployment to iOS 15. It had been at iOS 13 and built and ran without any related issues - for years that I've been developing this app.
So at some point after changing the target to iOS 15, compiling the shaders went from about 0.001 seconds to 30 seconds. When that happens, the GPU will also hang with the messages:
GPUDebug] Invalid device load executing kernel function "computeArtPointsToRender" encoder: "0", dispatch: 0, at offset 22080048
Shaders.metal:1290:41 - computeArtPointsToRender()
To fix the issue, I have to change the build target to iOS 13, clean, build, change to iOS 15, clean, build and then works again as expected (until it doesn't at some random point or until I have restarted the machine).
This is 100% reproducible:
- Restart mac
- Build project
- Issue occurs
- Change build target to iOS 13
- Clean build folder
- Build
- Change build target to iOS 15
- Delete derived files
- Build
- Works as expected
Xcode: Version 13.1 (13A1030d) macOS: 11.5.2 (20G95) Mac mini (M1, 2020)
In my 11+ years as a full time iOS developer, I've never encountered such a serious issue with Xcode. If I don't have stable tools, it is impossible for me to develop.
It turns out that the slow compile only occurs (intermittently) when Shader Validation is enabled. If I disable Shader Validation it compiles as expected.
When compiling for iOS 13, since Shader Validation is not supported, the slow compile would not occur since it was not being validated.
As for the runtime hang, it turns out that I was indeed accessing a buffer out-of-bounds. Why it was never an issue before I can't say, but it was my bad. I was just super suspicious of the build since it was taking abnormally long to compile.
As for the apparent bug with Shader Validation, I have updated my FeedBack Assistant report with sysdiagnose reports.