Title: [291385] trunk/Source/WebGPU
- Revision
- 291385
- Author
- [email protected]
- Date
- 2022-03-16 20:06:12 -0700 (Wed, 16 Mar 2022)
Log Message
[WebGPU] Implement first draft of CommandEncoder::clearBuffer() according to the spec
https://bugs.webkit.org/show_bug.cgi?id=237877
Reviewed by Kimmo Kinnunen.
Implement CommandEncoder::clearBuffer() according to the algorithms in the spec.
There are a few things which the spec lists which we can't do yet (like reporting
validation errors), so those things are left with FIXMEs. Every step is listed
with links to the spec where appropriate, and with quotes to the spec describing
what is being implemented.
* WebGPU/CommandEncoder.mm:
(WebGPU::validateClearBuffer):
(WebGPU::CommandEncoder::clearBuffer):
Modified Paths
Diff
Modified: trunk/Source/WebGPU/ChangeLog (291384 => 291385)
--- trunk/Source/WebGPU/ChangeLog 2022-03-17 03:02:09 UTC (rev 291384)
+++ trunk/Source/WebGPU/ChangeLog 2022-03-17 03:06:12 UTC (rev 291385)
@@ -1,5 +1,22 @@
2022-03-16 Myles C. Maxfield <[email protected]>
+ [WebGPU] Implement first draft of CommandEncoder::clearBuffer() according to the spec
+ https://bugs.webkit.org/show_bug.cgi?id=237877
+
+ Reviewed by Kimmo Kinnunen.
+
+ Implement CommandEncoder::clearBuffer() according to the algorithms in the spec.
+ There are a few things which the spec lists which we can't do yet (like reporting
+ validation errors), so those things are left with FIXMEs. Every step is listed
+ with links to the spec where appropriate, and with quotes to the spec describing
+ what is being implemented.
+
+ * WebGPU/CommandEncoder.mm:
+ (WebGPU::validateClearBuffer):
+ (WebGPU::CommandEncoder::clearBuffer):
+
+2022-03-16 Myles C. Maxfield <[email protected]>
+
[WebGPU] Use block-based WebGPU API instead of function pointer & userdata API
https://bugs.webkit.org/show_bug.cgi?id=237932
Modified: trunk/Source/WebGPU/WebGPU/CommandEncoder.mm (291384 => 291385)
--- trunk/Source/WebGPU/WebGPU/CommandEncoder.mm 2022-03-17 03:02:09 UTC (rev 291384)
+++ trunk/Source/WebGPU/WebGPU/CommandEncoder.mm 2022-03-17 03:06:12 UTC (rev 291385)
@@ -173,11 +173,53 @@
UNUSED_PARAM(copySize);
}
+static bool validateClearBuffer(const Buffer& buffer, uint64_t offset, uint64_t size)
+{
+ // FIXME: "buffer is valid to use with this."
+
+ // "buffer.[[usage]] contains COPY_DST."
+ if (!(buffer.usage() & WGPUBufferUsage_CopyDst))
+ return false;
+
+ // "size is a multiple of 4."
+ if (size % 4)
+ return false;
+
+ // "offset is a multiple of 4."
+ if (offset % 4)
+ return false;
+
+ // "buffer.[[size]] is greater than or equal to (offset + size)."
+ // FIXME: Use checked arithmetic.
+ if (buffer.size() < offset + size)
+ return false;
+
+ return true;
+}
+
void CommandEncoder::clearBuffer(const Buffer& buffer, uint64_t offset, uint64_t size)
{
- UNUSED_PARAM(buffer);
- UNUSED_PARAM(offset);
- UNUSED_PARAM(size);
+ // https://gpuweb.github.io/gpuweb/#dom-gpucommandencoder-clearbuffer
+
+ // "Prepare the encoder state of this. If it returns false, stop."
+ if (!prepareTheEncoderState())
+ return;
+
+ // "If size is missing, set size to max(0, |buffer|.{{GPUBuffer/[[size]]}} - |offset|)."
+ if (size == WGPU_WHOLE_SIZE) {
+ // FIXME: Use checked arithmetic.
+ size = buffer.size() - offset;
+ }
+
+ // "If any of the following conditions are unsatisfied"
+ if (!validateClearBuffer(buffer, offset, size)) {
+ // FIXME: "generate a validation error and stop."
+ return;
+ }
+
+ ensureBlitCommandEncoder();
+
+ [m_blitCommandEncoder fillBuffer:buffer.buffer() range:NSMakeRange(offset, size) value:0];
}
bool CommandEncoder::validateFinish() const
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes