Chapter 15 GPU Draw Call and Frame Capture

Hello - I have two questions from Chapter 15 of the book. In the part of the chapter that teaches us how to encode draw commands on the GPU the compute shader has the following:

cmd.draw_indexed_primitives( primitive type::triangle . . . model.indexBuffer + drawArguments.indexStart . . .

Why do we add model.indexBuffer to drawArugments.indexStart? If I understand correctly, the buffer on model is the same as the index buffer on submesh.indexBuffer.buffer that would be called in a render pass on the CPU and indexStart is the offset from the index buffer. Would this not cause the GPU to skip the data in the index buffer by the offset?

I am also wondering if anyone else has issues with GPU frame capture in this chapter. I get a message that says Unexpected Replayer Termination with an error code of 512. Frame capture works fine with other projects in the book. Is frame capture incompatible with indirect command buffers?

Incidentally, I can export the frame capture and replay it, but I cannot see the contents of the buffers. They all say “resource not available”.

The Metal Shading Language Specification https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf defines that particular parameter as uint *index_buffer.

So that’s the pointer to the index buffer. If the drawing should start at a particular offset, then you add the offset to the pointer. To be honest, I don’t think I’ve ever tried with drawArguments.indexStart containing anything but zero. I certainly haven’t stress-tested GPU rendering yet.

Yes, I can confirm that running the final project and doing GPU frame capture results in the error. It used to work :slightly_frowning_face:

Having said that, in fairness to Apple :slight_smile: , it is always possible that the code might be slightly incorrect somewhere. When I was putting this together, I found GPU capture to be very sensitive, and all buffers had to be exactly just so.

Very helpful thank you! I do hope Apple works out the bug in the GPU frame capture. It’s such a valuable tool.