Occlusion Testing on iOS Metal.

Hello,


I have been working on getting occlusion testing working on iOS Metal. My question is how I can reliably access the result buffer when the GPU has

finished writing the contents of the visibility test.


For Example:


I create the buffer where contents will be written to.


m_pBuffer = cMetalRenderer->m_pcDevice.newBufferWithLength (1 * 8, 0);


I set the visibility mode in the render command encoder.


uint32 iOffset = 0;


sRenderCommandEncoder.setVisibilityResultMode (MTLVisibilityResultModeBoolean, iOffset);


Now to access the contents I do something like this:


uint64 result = (uint64 *) m_pBuffer.contents ();

My question is how do I set this up so that I can reliably access the contents of the buffer when the GPU has written the results to the buffer. I want

to avoid causing a stall if I just read the buffer while the GPU is updating it.


Perhaps someone can point me to some code examples or some resources that would allow me to do this. Or is it "guaranteed" that I can read the contents

next frame?


Thanks in advance for anyones help....

Accepted Reply

Hello I'd add a complete handler to the command buffer into which you encode render command in question. That completion handler will get called once rendering (well, all the operations in the command buffer, but it is up to you what goes there) is complete. It should be safe to read from the m_pBuffer then. Regards Michal

Replies

Hello I'd add a complete handler to the command buffer into which you encode render command in question. That completion handler will get called once rendering (well, all the operations in the command buffer, but it is up to you what goes there) is complete. It should be safe to read from the m_pBuffer then. Regards Michal

Thanks, that is what I was searching for. I can definitely do my work there for occlusion checks.