Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 7db946a6f19e50aa9ff1243097142c2a46a89e43
      
https://github.com/WebKit/WebKit/commit/7db946a6f19e50aa9ff1243097142c2a46a89e43
  Author: Myles C. Maxfield <[email protected]>
  Date:   2023-02-06 (Mon, 06 Feb 2023)

  Changed paths:
    M Source/WebGPU/WebGPU/CommandEncoder.h
    M Source/WebGPU/WebGPU/CommandEncoder.mm
    M Source/WebGPU/WebGPU/ComputePassEncoder.h
    M Source/WebGPU/WebGPU/ComputePassEncoder.mm
    M Source/WebGPU/WebGPU/HardwareCapabilities.h
    M Source/WebGPU/WebGPU/HardwareCapabilities.mm
    M Source/WebGPU/WebGPU/RenderPassEncoder.h
    M Source/WebGPU/WebGPU/RenderPassEncoder.mm
    M Source/WebGPU/WebGPU/RenderPipeline.mm

  Log Message:
  -----------
  [WebGPU] Timestamp writes only work in vary specific situations
https://bugs.webkit.org/show_bug.cgi?id=251773
rdar://105067419

Reviewed by Tadeu Zagallo.

Before this patch, the infrastructure for timestamp writes is very specific:
- Only Apple Silicon machines are supported
- CommandEncoder.writeTimestamp() is not supported
- ComputePassDescriptor.timestampWrites are not supported
- RenderPassDescriptor.timestampWrites is supported, but only for the first 
element,
      and only for specific hardcoded values of queryIndex

This patch generalizes support:

In Metal, different devices support different query set APIs. You have to call
[MTLDevice supportsCounterSampling:] to know which kind of device you're on. 
Apple
Silicon devices report that they only support counter sampling on stage 
boundaries,
via the pass descriptors' sampleBufferAttachments. All other devices (that I've
tried) report that they support counter sampling on individual command 
boundaries.
If a device doesn't support either of these granularities, then it just won't
support the timestamp queries feature in the first place.

For pass descriptors' timestampWrites array, if the device is an Apple Silicon 
device,
we are supposed to be able to naively transform the timestampWrites into
sampleBufferAttachments, which is what this patch does. However, 
rdar://91371495 is
about how that doesn't actually work; a follow-up patch is necessary to work 
around
this. For non-Apple-Silicon devices, we implement the timestampWrites array by 
just
calling -[CommandEncoder sampleCountersInBuffer:] at the beginning and end of 
the pass.

For CommandEncoder.writeTimestamp(), we can implement this on Apple Silicon 
devices by
creating a dummy blit pass, and setting sampleBufferAttachments on it. We want 
to
coalesce multiple writes into a single blit pass, so we defer doing this as 
long as
possible - until either we would have had to make a blit pass anyway, we have 
to start
a new pass, or the command encoder is ending. For non-Apple-Silicon devices,
CommandEncoder.writeTimestamp() directly turns into
-[MTLBlitCommandEncoder sampleCountersInBuffer:].

Because of rdar://91371495, this patch isn't actually fully-functional; however,
the existing infrastructure wasn't fully-functional either, so I'm kind of 
viewing this
patch as not-a-regression. My next patch will work around rdar://91371495.

* Source/WebGPU/WebGPU/CommandEncoder.h:
* Source/WebGPU/WebGPU/CommandEncoder.mm:
(WebGPU::CommandEncoder::ensureBlitCommandEncoder):
(WebGPU::CommandEncoder::finalizeBlitCommandEncoder):
(WebGPU::CommandEncoder::validateComputePassDescriptor const):
(WebGPU::CommandEncoder::beginComputePass):
(WebGPU::CommandEncoder::validateRenderPassDescriptor const):
(WebGPU::CommandEncoder::beginRenderPass):
(WebGPU::CommandEncoder::writeTimestamp):
* Source/WebGPU/WebGPU/ComputePassEncoder.h:
(WebGPU::ComputePassEncoder::create):
* Source/WebGPU/WebGPU/ComputePassEncoder.mm:
(WebGPU::ComputePassEncoder::ComputePassEncoder):
(WebGPU::ComputePassEncoder::endPass):
* Source/WebGPU/WebGPU/HardwareCapabilities.h:
* Source/WebGPU/WebGPU/HardwareCapabilities.mm:
(WebGPU::baseCapabilities):
(WebGPU::mergeBaseCapabilities):
* Source/WebGPU/WebGPU/RenderPassEncoder.h:
(WebGPU::RenderPassEncoder::create):
* Source/WebGPU/WebGPU/RenderPassEncoder.mm:
(WebGPU::RenderPassEncoder::RenderPassEncoder):
(WebGPU::RenderPassEncoder::endPass):
* Source/WebGPU/WebGPU/RenderPipeline.mm:
(WebGPU::createVertexDescriptor):

Canonical link: https://commits.webkit.org/259914@main


_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to