MarkDirtyResourceon a buffer ifcontentsis called and the returned pointer is not NULL (type should beMTLStorageModeShared).MarkDirtyResourceon a buffer ifdidModifyRangeis called (type should beMTLStorageModeManaged).MarkDirtyResourceon a buffer if buffer type isMTLStorageModePrivate.MTLBuffertype is only known at creation time.
- How do dirty resources interact with frame referenced resources. Will dirty resources always be output or is it only if they are frame referenced also?
- TODO
- Metal Documentation: Choosing a Resource Storage Mode in macOS
- MTLBuffer Storage Modes
MTLStorageModeShared: Stored in CPU memory accessible by the GPU.- Application manages synchronisation:
- CPU->GPU:
MTLCommandBuffer::commit - GPU->CPU: when command buffer completes execution ie.
MTLCommandBuffer::status == MTLCommandBufferStatusCompleted
MTLStorageModeManaged: Stored in CPU and GPU memory.- Metal driver manages synchronisation:
- CPU->GPU:
MTLBuffer::didModifyRange - GPU->CPU:
MTLBlitCommandEncoder::synchronizeResource
MTLStorageModePrivate: Stored in GPU memory.- Only accessible by copying to a
MTLStorageModeSharedbuffer.
- Only accessible by copying to a
MTLBufferCPU contents locked / submitted to GPU onMTLCommandBuffer:: commit.- RenderCommandEncoder has APIs to use
MTLBufferie.setVertexBuffer,setFragmentBuffer.
- To read buffer data will need to convert
MTLStorageModePrivatebuffers toMTLStorageModeManagedor use a temporary intermediateMTLStorageModeManagedbuffer. - Mark buffer dirty if
contentsis called and returned pointer is not NULL : type should beMTLStorageModeShared - Mark buffer dirty if
didModifyRangeis called, type should beMTLStorageModeManaged - Mark buffer dirty if buffer type is
MTLStorageModePrivateie. GPU only - Should
MTLStorageModeManagedbuffers only be tracked ifcontentsis called on them?- In theory yes if the returned pointer is not NULL.
- In practice might be easier to snashot the buffer without explicit tracking.
- Should buffers only be tracked if they can reside in CPU memory?
- GPU only buffers do not need to be tracked for CPU modification. They need to be tracked for GPU modification which is hard to do for all situations.
- In practice easier to snashot the buffer without explicit tracking.
- CPU buffers with explicit synchronization can be handled in the serialization of the synchronization APIs
- In practice might be easier to snashot the buffer without explicit tracking.
- GPU only buffers do not need to be tracked for CPU modification. They need to be tracked for GPU modification which is hard to do for all situations.
- Attach the buffers to the
MTLRenderCommandEncoderparentMTLCommandBufferinsetVertexBuffer,setFragmentBufferAPIs. - On
MTLCommandBuffer::commitin active capture serialize attached buffer contents. - On
MTLCommandBuffer::commitreplay de-serialize buffer contents.