buildPipelineState() limits?

So I’ve been working from the materials in the book and trying to develop my own project with GPU-driven rendering like Chapter 15, but running from generated meshes rather than imported models. And everything seemed well and good until I tried making a few hundred models during my scene set-up.

What was happening was that it would be fine up to a certain number, after which it would return an erase-color render only. Oddly, I found that if I captured a GPU-frame, everything would look fine (the CAMetalLayer Drawable appears correct, and everything looks good).

After tinkering for many hours, I began to narrow it down - it wasn’t the number of models being rendered that were causing the problem, but in fact the number created (if I created the same problem-inducing amount, but only added 1/3 of them to [Renderables], it still wouldn’t render correctly). I thought it would be the number of MTLBuffers I was creating, but it turned out to be either the calls to buildPipelineState in my Model class, or the number of MTLRenderPipelineStates created overall.

So, 1, I’d love any insight into this generally speaking. Like what it might signify that the live render isn’t working but the GPU capture frame is, and whether having ~300 pipeline states should be an issue like this appeared to be. I should note that they were only being created on scene setup, and when I checked the various places where the number of Models are checked in Renderer, they all reported the correct amount (i.e. scene setup appeared to complete successfully).

The 2nd thing is, I couldn’t get ICB.metal working from a Material-held pipelineState. I could get it to run, but nothing would draw, and if I captured the GPU state, I’d get an access error on commandBuffer.commit(), so I could never take a peek in the GPU state. I’m assuming this had to do with my access into Materials in the ICB compute function, and that I was sending Materials as a regular ole’ buffer instead of through an Argument Encoder like the models array buffer. I realize this is difficult to speculate on without poking about in my code, but does that sound like a possible explanation? I ended up encoding the Models Array with the pipeline state retrieved from my Material struct, and it works, but ultimately I’d like to properly pass it into the compute shader as part of Materials…

  1. The book’s way of dealing with pipeline states is not the best - it duplicates them unnecessarily. Are all your 300 pipeline states different? Or can they be centralised?

  2. I don’t know the answer to this, I’m afraid.