Metal render crash on iPhone X/XR/XS compiled with Xcode 15 beta

We're getting some strange rendering crashes on various devices running both ios16 and ios17 beta.

The problems all appear when compiling with any of the Xcode 15 betas, including 8. This code has worked fine for years.

The clearest error we get is on the iPhone X and XR where newRenderPipelineStateWithDescriptor returns: "Inlining all functions due to use of indirect argument bufferbuffer(15): Unable to map argument buffer access to resource"

Buffer 15 is where we stash our textures and looks like this:

typedef struct RegularTextures {
    // A bit per texture that's present
    uint32_t texPresent                          [[ id(WKSTexBufTexPresent) ]];
    // Texture indirection (for accessing sub-textures)
    const metal::array<float, 2*WKSTextureMax> offset     [[ id(WKSTexBuffIndirectOffset) ]];
    const metal::array<float, 2*WKSTextureMax> scale      [[ id(WKSTexBuffIndirectScale) ]];
    const metal::array<metal::texture2d<float, metal::access::sample>, WKSTextureMax> tex    [[ id(WKSTexBuffTextures) ]];
} RegularTextures;

The program we're trying to set up looks like this:

vertex ProjVertexTriB vertexTri_multiTex(
                VertexTriB vert [[stage_in]],
                constant Uniforms &uniforms [[ buffer(WKSVertUniformArgBuffer) ]],
                constant Lighting &lighting [[ buffer(WKSVertLightingArgBuffer) ]],
                constant VertexTriArgBufferB & vertArgs [[buffer(WKSVertexArgBuffer)]],
                constant RegularTextures & texArgs [[buffer(WKSVertTextureArgBuffer)]])
{
// Do things
}

Fairly benign as these things go.

Even more curiously, a different program with the same RegularTextures argument buffer is sometimes set up first without complaint.

I strongly suspect Apple introduced a bug here, but with the impending release, we're just trying to figure out how to work around it.

So we got ahold of an iPhone XR for testing and got different results. Running 16.6, compiling with the new Xcode 15 beta 8.

The error was reliable, and though unrelated to the device in question, I moved the textures out of the argument buffer, turned off indirect rendering and tried again.

Metal had some problems with some index based lookups on that device, so I turned those off and got this gem:

newArgumentEncoder:85: failed assertion `Function fragmentTri_precip does not have a buffer argument with buffer index 2'

Aaand the function in question:

fragment float4 fragmentTri_precip(ProjVertexTriB vert [[stage_in]], constant Uniforms &uniforms [[ buffer(WKSFragUniformArgBuffer) ]], constant FragTriArgBufferPrecip &fragArgs [[ buffer(2) ]], constant TextureInfo &texArgs [[buffer(WKSFragTextureArgBuffer)]], metal::array<metal::texture2d<float, metal::access::sample>, WKSTextureMax> tex [[ texture(0) ]])

This is definitely a Metal compiler problem. I'm surprised no one else is running into it.

I get samle error on iPhone XR with Xcode15.0.2, render with metal using argument buffer, How to resolve it?

Metal render crash on iPhone X/XR/XS compiled with Xcode 15 beta
 
 
Q