-
Notifications
You must be signed in to change notification settings - Fork 337
Description
Last meeting we were looking at different API's restriction on where each type of command could be done. This isn't about multi-queue scenarios, and assumes we are on a DIRECT queue on D3D12 and a queue with all bits set that is guaranteed to exist in Vulkan.
Metal
In Metal, to put commands in a MTLCommandList, the application has to use encoders. There are three types of encoders that support mostly disjoint operation subsets (all of them can do synchronization):
- MTLBlitCommandEncoder can encode copies, blits, and friends and that's all.
- MTLComputeCommandEncoder can do dispatch and set state / resources / pipeline / residency for compute shaders
- MTLRenderCommandEncoder is created with a rendertarget bound, which stays for the duration of the encoder. It can do draws and set state / resource / pipeline / residency for graphics work. There's also commands for the Metal equivalent of queries and for setting the "store" operations for render targets.
Vulkan
Operations in Vulkan can either be done inside render passes, outside, or both but are all encoded via the same object.
- Inside-only: Draws, clearing attachments for the current subpass
- Outside-only: Dispatch, copies, and controlling query pools
- Both: Setting [compute / graphics] [pipelines / resources / state], synchronization, beginning and ending queries.
D3D12
@RafaelCintron I haven't been able to find documentation on the restriction in the doc for ID3D12GraphicsCommandList. Is it because you are allowed to do any command anywhere, or because I didn't look hard enough?
Conclusion
Let's forget about Vulkan allowing to set graphics state outside of renderpasses, and compute state inside render passes. Let's also skip over API details we are not ready to look at (queries >_>).
Operations you can do inside Vulkan renderpasses are basically MTLRenderCommandEncoder operations, while operations you can do outside Vulkan renderpasses are both MTLComputeCommandEncoder and MTLBlitCommandEncoder operations. Which is great!
In my opinion, this means that either:
- Changing between Blit and Compute encoders is cheap in Metal, in which case I think it would be nicer to allow mixing blits and compute operations in the API.
- It is expensive, and we'll want to make the API have explicit boundaries between compute and copy operations.
@grorg do you think we could get data on this?
Raw notes for reference
Vulkan:
Inside renderpasses:
Draws:
vkCmdDraw
vkCmdDrawIndexed
vkCmdDrawIndirect
vkCmdDrawIndexedIndirect
vkCmdClearAttachments - (only attachments of the current subpass)
Outside
Dispatch
vkCmdDispatch
vkCmdDispatchIndirect
Copies
vkCmdClearColorImage
vkCmdClearDepthStencilImage
vkCmdFillBuffer
vkCmdUpdateBuffer
vkCmdCopyBuffer
vkCmdCopyImage
vkCmdCopyBufferToImage
vkCmdCopyImageToBuffer
vkCmdBlitImage
vkCmdResolveImage
Controlling queries
vkCmdResetQueryPool
vkCmdCopyQueryPoolResults
Both
vkCmdBindPipeline
vkCmdExecuteCommands - To run secondary command buffers
Synchronization
vkCmdSetEvent
vkCmdResetEvent
vkCmdWaitEvents
vkCmdPipelineBarrier
Binding compute/graphics resources
vkCmdBindDescriptorSets
vkCmdPushConstants
Starting/stopping queries
vkCmdBeginQuery
vkCmdEndQuery
vkCmdWriteTimestamp
Setting graphics state
vkCmdBindIndexBuffer
vkCmdBindVertexBuffers
vkCmdSetViewport
vkCmdSetLineWidth
vkCmdSetDepthBias
vkCmdSetScissor
vkCmdSetDepthBounds
vkCmdSetStencilCompareMask
vkCmdSetStencilWriteMask
vkCmdSetBlendConstants
N/A
vkCmdBeginRenderPass
vkCmdNextSubpass
vkCmdEndRenderPass
Metal:
Blit encoder:
- Copying / blitting to/from/between buffers and textures
- Filling a buffer
- Generate mipmaps
- Fence and synchronization
Compute encoder:
- Setting compute pipeline
- Setting compute resources (includes push constants / root table constants like updates)
- SetThreadGroupMemoryLength
- Dispatch
- Residency control
Render encoder:
- Setting all graphics state
- Setting graphics resources
- Draws
- Synchronization
- Setting the rendertarget "store" actions
- Metal equivalent of queries
- Residency control