You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When we initially discussed timestamp queries for WebGPU there was some concern that they were not implementable on all Metal devices, in particular iOS devices. On these devices the only way to time the execution of commands is MTLCommandBuffer:: gpuStartTime and gpuEndTime. That's why we added GPUCommandBuffer.executionTime to the specification.
Two issues change the basis for this decision a bit.
In #2046 the timestamp queries are changed such that they are implementable on a wider range of Metal devices. In particular @litherum noted that they work on semi-recent Apple GPUs, including iPhone ones, meaning that iOS now will at least sometimes get timestamp query support:
(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.)
In #1773@toji raised the issue that some devices (at least Vulkan and maybe also some D3D12 ones) don't expose the functionality required to produce sensible values for GPUCommandBuffer.executionTime. It was meant to be the always-available option, but turns out that it isn't always available.
Given that timestamp-query will be supported on an extended range of devices and that executionTime can't be supported on all device, I don't think we need executionTime as the "ubiquitous" time measurement API. So it can be removed.
I assume @kvark meant to reply here instead of #1773:
I did some investigation on which devices report 0 bits of precision in kainino0x/query-gpuinfo-data#1, and it appears to be Mali-GXX. They seem to otherwise not be filtered out. So the trade-off here is: if we have executionTime, we'll expose the Metal API almost directly, which is useful, and also implementable on most other platforms, except for Mali-G devices. If we don't have this API, we'll force the users to use an optional feature, and in addition they'd have to download the data by mapping the buffer.
executionTime is implementable as soon as you have the optional timestamp-query, but it can be done just as easily by a user, and the code will written at most once per project. Exposing an API unconditionally while it is not implementable everywhere seems wrong. We could also make executionTime an optional feature. I'm happy to write a shim for executionTime if you think that's necessary for developer nicety.
The API in #2046 requires at least macOS 11 and iOS 14, while gpu start/end times are available on all Apple devices. So if we go this route, there will be a set of Apple devices that could otherwise give you the executionTime but would not have a way to expose this.
Why does it require macOS 11? You can implement timestamp queries on previous versions of macOS.
So if we go this route, there will be a set of Apple devices that could otherwise give you the executionTime but would not have a way to expose this.
I'd happily trade less API surface for tiny missing reach of something like executionTime given it cannot be implemented on all of the WebGPU targets anyway (looking at Vulkan on Mali and potentially other chips, but also GLES in the future etc)
GPUStartTime and GPUEndTime give results in "host time". I'm unclear on whether that means it's timed from the CPU or just converted to host time, but can we possibly paper over those Mali devices by implementing executionTime from the CPU?
I think it means it gives you a timestamp you can compare with other CPU timestamps, but I don't think this means that we can do the same thing on Vulkan because we don't get interrupts immediately when works finishes (there can be a lot of latency), nor when it starts.
When viewed through the lens of this issue, there are 3 classes Metal devices:
Devices which do not support MTLCommonCounterSet.timestamp, or for which MTLDevice.supportsCounterSampling() returns false for every input
Devices that do support MTLCommonCounterSet.timestamp but MTLDevice.supportsCounterSampling() only reports true for MTLCounterSamplingPoint.atStageBoundary
Other devices (aka devices that support MTLCommonCounterSet.timestamp and where MTLDevice.supportsCounterSampling() returns true for other locations)
GPUCommandBuffer.executionTime is necessary to get timing information on the first class of devices.
How common are these devices? It would be unfortunate if a sizable chunk of devices had to report bogus answers for GPUCommandBuffer.executionTime.
Maybe another question - on these devices, is it possible to get any timing at all anywhere anyhow?
Unfortunately these devices represent a sizeable chunk of Android Vulkan devices. ARM GPUs are used in many MediaTek SOCs AFAIK. On these devices I don't think there's any way to get valid GPU timestamps (except by faking them with best-guess CPU timestamps), which is why I think we should remove executionTime.
@kainino0x also mentioned that in D3D12 there might not always be valid bits for timestamps but I can't find that in the doc. @RafaelCintron can there be D3D12 devices with no support for timestamp queries?
Looking at the Vulkan spec following today's call:
timestampValidBits is the unsigned integer count of meaningful bits in the timestamps written via vkCmdWriteTimestamp. The valid range for the count is 36..64 bits, or a value of 0, indicating no support for timestamps. Bits outside the valid range are guaranteed to be zeros.
Disjoint timer queries also have a 0 guaranteed bits of precision (and you are supposed to query them). @vonture confirmed there are many ARM devices that have essentially no timestamps in GLES. (that matches the same thing in Vulkan).
Resolution: Remove executionTime. Don't need to bump it to an optional feature; we already have timestamp queries.
Developers on platforms that can't support any kind of timing should try to use platform or vendor profiling tools (like xcode or whatever) instead.
Activity
Kangz commentedon Oct 4, 2021
I assume @kvark meant to reply here instead of #1773:
executionTimeis implementable as soon as you have the optionaltimestamp-query, but it can be done just as easily by a user, and the code will written at most once per project. Exposing an API unconditionally while it is not implementable everywhere seems wrong. We could also makeexecutionTimean optional feature. I'm happy to write a shim forexecutionTimeif you think that's necessary for developer nicety.kvark commentedon Oct 4, 2021
The API in #2046 requires at least macOS 11 and iOS 14, while gpu start/end times are available on all Apple devices. So if we go this route, there will be a set of Apple devices that could otherwise give you the
executionTimebut would not have a way to expose this.Kangz commentedon Oct 4, 2021
Why does it require macOS 11? You can implement timestamp queries on previous versions of macOS.
I'd happily trade less API surface for tiny missing reach of something like
executionTimegiven it cannot be implemented on all of the WebGPU targets anyway (looking at Vulkan on Mali and potentially other chips, but also GLES in the future etc)kvark commentedon Oct 4, 2021
I was looking at the availability of https://developer.apple.com/documentation/metal/mtldevice/3564459-supportscountersampling?language=objc .
Kangz commentedon Oct 4, 2021
MTLCounterSetsare supported from macOS 10.15 https://developer.apple.com/documentation/metal/mtldevice/3081739-countersets?language=objc thesupportsCounterSamplingis something that was added in 11.0 as (at least my understanding) a decrease in features because the M1 doesn't support sampling timestamps at all locations previously used mac GPUs can.kainino0x commentedon Oct 5, 2021
GPUStartTime and GPUEndTime give results in "host time". I'm unclear on whether that means it's timed from the CPU or just converted to host time, but can we possibly paper over those Mali devices by implementing executionTime from the CPU?
Kangz commentedon Oct 8, 2021
I think it means it gives you a timestamp you can compare with other CPU timestamps, but I don't think this means that we can do the same thing on Vulkan because we don't get interrupts immediately when works finishes (there can be a lot of latency), nor when it starts.
litherum commentedon Oct 12, 2021
When viewed through the lens of this issue, there are 3 classes Metal devices:
MTLCommonCounterSet.timestamp, or for whichMTLDevice.supportsCounterSampling()returns false for every inputMTLCommonCounterSet.timestampbutMTLDevice.supportsCounterSampling()only reports true forMTLCounterSamplingPoint.atStageBoundaryMTLCommonCounterSet.timestampand whereMTLDevice.supportsCounterSampling()returns true for other locations)GPUCommandBuffer.executionTimeis necessary to get timing information on the first class of devices.litherum commentedon Oct 12, 2021
How common are these devices? It would be unfortunate if a sizable chunk of devices had to report bogus answers for
GPUCommandBuffer.executionTime.Maybe another question - on these devices, is it possible to get any timing at all anywhere anyhow?
litherum commentedon Oct 12, 2021
It's the time of an event which happened on the GPU, recorded as a timestamp relative to the CPU's timeline.
Kangz commentedon Oct 12, 2021
Unfortunately these devices represent a sizeable chunk of Android Vulkan devices. ARM GPUs are used in many MediaTek SOCs AFAIK. On these devices I don't think there's any way to get valid GPU timestamps (except by faking them with best-guess CPU timestamps), which is why I think we should remove
executionTime.@kainino0x also mentioned that in D3D12 there might not always be valid bits for timestamps but I can't find that in the doc. @RafaelCintron can there be D3D12 devices with no support for timestamp queries?
Kangz commentedon Oct 18, 2021
Looking at the Vulkan spec following today's call:
There are no other guarantees in Vulkan. Even in WebGL disjoint timer queries are an extension. Same for OpenGL ES (never promoted to core).
Kangz commentedon Oct 22, 2021
Based on the comment above I think we should still remove
executionTimeas sad as it is.litherum commentedon Oct 22, 2021
I think the question is "of the devices which have 0 bits of precision for timestamps, do they also support disjoint timer queries?"
Kangz commentedon Oct 22, 2021
Disjoint timer queries also have a 0 guaranteed bits of precision (and you are supposed to query them). @vonture confirmed there are many ARM devices that have essentially no timestamps in GLES. (that matches the same thing in Vulkan).
kainino0x commentedon Oct 25, 2021
Resolution: Remove
executionTime. Don't need to bump it to an optional feature; we already have timestamp queries.Developers on platforms that can't support any kind of timing should try to use platform or vendor profiling tools (like xcode or whatever) instead.
Remove GPUCommandBuffer.executionTime
Remove GPUCommandBuffer.executionTime (#2214)
Remove GPUCommandBuffer.executionTime (gpuweb#2214)