-
Notifications
You must be signed in to change notification settings - Fork 344
Description
The WebGPU spec says:
Timestamp query allows application to write timestamp values to a GPUQuerySet by calling writeTimestamp() on GPUComputePassEncoder or GPURenderPassEncoder or GPUCommandEncoder.
Metal is more complicated than this. Each MTLDevice has a function, supportsCounterSampling() which exposes the points at which the device is capable of writing timestamp values. It returns true/false in response to an enum value passed by the application:
atBlitBoundary: ... between blit commands ...atDispatchBoundary: ... between kernel dispatches ...atDrawBoundary: ... between draw commands ...atStageBoundary... at the start and end of a render pass’s vertex and fragment stages, and at the start and end of compute and blit passes ...atTileDispatchBoundary: ... between tile dispatches ...
Therefore, in order for WebGPU's timestamp queries to be implementable on Metal, the device would need to report true for the atBlitBoundary, atDispatchBoundary, and atDrawBoundary enum values.
Apple Silicon devices do not return true for any of these values. Indeed, any TBDR renderer wouldn't be able to return true for atDrawBoundary because draw calls are not discrete items; all the vertex processing of all the draw calls in the render pass execute together, in parallel with all the fragment processing of all the draw calls in the render pass.
Apple Silicon devices only return true for atStageBoundary; all the other enum values return false. The way it's works is for the application to pass additional data into the render pass description. The additional data includes, for that render pass, which indices into which sample buffers that timestamps should be written into for the beginning and end of vertex and fragment processing. Indeed; there is no sampleCounters() call on any object which is available to Apple Silicon devices; the only way to get fine-grained timestamp data is using this declarative mechanism on the render pass descriptor.
One possible path forward here is to just say "well then I guess all TBDR renderers don't get to advertise the timestamp-query feature." This would be quite unfortunate, though, as I believe TBDR renderers represent a significant portion of the WebGPU group's target devices.
(Above, when I say "Apple Silicon devices", I'm referring to devices which support querying - I tested and verified iPhone 11, iPhone 12, and M1. Some older devices don't support querying at all - those shouldn't advertise support for timestamp-query feature.)