Insights from WWDC

Hello everyone -

I had an opportunity to speak with a couple of Apple engineers at WWDC about some questions I have been grappling with in Metal. In case anyone might benefit from their insights, I’ve summarized some of the Q&A, which includes a few “mistakes” they said they are seeing in a lot of Metal apps.

  1. If you allocate a render target from a texture heap, you must call useHeap:usage: and useResource:usage:stages: on each underlying texture resource. Otherwise, due to the way heaps manage their memory, the targets could become corrupted.

  2. Related to the above, you do not need to call useResource:usage:stages if you are writing to a metal buffer allocated from a heap (although they still recommend doing so).

  3. If you are working on a project using indirect command buffers, and you are seeing numerous “redundant binding” warnings in Xcode, please file a feedback report. These should not occur when using indirect command buffers.

  4. The implementations for resetCommandsInBuffer: and optimizeIndirectCommandBuffer have vendor specific implementations. You will not always see an impact to your code when using them. In particular, if you are using an indirect range buffer to tightly pack commands in an icb, you do not need to use optimizeIndirectCommandBuffer.

  5. They were very interested in the technique we learn in Chapter 15 of the book where the model argument buffer contains an embedded texture argument buffer. In the sample code, we pass this as a pointer to a float. You can - in fact - cast this to any basic data type. This technique is the basis for “bindless rendering,” which was the subject of one of this year’s presentations. However, this technique should only work on devices supporting Tier 2 argument buffers. That the code does in fact work is evidently undefined behavior. As an alternative for Tier 1, you can encode a separate argument buffer array and index into it.

6 Likes

Thank you so much for passing this on. This is important information!

1 Like