Diff
Modified: trunk/Source/WebGPU/ChangeLog (292727 => 292728)
--- trunk/Source/WebGPU/ChangeLog 2022-04-11 21:59:00 UTC (rev 292727)
+++ trunk/Source/WebGPU/ChangeLog 2022-04-11 22:03:54 UTC (rev 292728)
@@ -1,3 +1,57 @@
+2022-04-11 Myles C. Maxfield <[email protected]>
+
+ [WebGPU] Implement missing validity checks
+ https://bugs.webkit.org/show_bug.cgi?id=238722
+
+ Reviewed by Kimmo Kinnunen.
+
+ Now that WebGPU objects have a notion of validity, we can implement all the
+ FIXMEs for validity checks.
+
+ * WebGPU/Buffer.mm:
+ (WebGPU::validateCreateBuffer):
+ (WebGPU::Buffer::validateMapAsync const):
+ * WebGPU/CommandEncoder.h:
+ (WebGPU::CommandEncoder::makeInvalid):
+ * WebGPU/CommandEncoder.mm:
+ (WebGPU::CommandEncoder::validateCopyBufferToBuffer):
+ (WebGPU::validateImageCopyBuffer):
+ (WebGPU::CommandEncoder::validateClearBuffer):
+ (WebGPU::CommandEncoder::validateFinish const):
+ (WebGPU::CommandEncoder::finish):
+ (WebGPU::CommandEncoder::popDebugGroup):
+ (WebGPU::validateCopyBufferToBuffer): Deleted.
+ (WebGPU::validateClearBuffer): Deleted.
+ * WebGPU/ComputePassEncoder.h:
+ (WebGPU::ComputePassEncoder::makeInvalid):
+ * WebGPU/ComputePassEncoder.mm:
+ (WebGPU::ComputePassEncoder::popDebugGroup):
+ * WebGPU/ObjectBase.h:
+ (WebGPU::ObjectBase::isValidToUseWith const):
+ (WebGPU::ObjectBase::device const):
+ * WebGPU/Queue.h:
+ (WebGPU::Queue::device const):
+ * WebGPU/Queue.mm:
+ (WebGPU::Queue::validateSubmit const):
+ (WebGPU::Queue::submit):
+ (WebGPU::Queue::validateWriteBuffer const):
+ * WebGPU/RenderBundleEncoder.h:
+ (WebGPU::RenderBundleEncoder::makeInvalid):
+ * WebGPU/RenderBundleEncoder.mm:
+ (WebGPU::RenderBundleEncoder::popDebugGroup):
+ * WebGPU/RenderPassEncoder.h:
+ (WebGPU::RenderPassEncoder::makeInvalid):
+ * WebGPU/RenderPassEncoder.mm:
+ (WebGPU::RenderPassEncoder::popDebugGroup):
+ * WebGPU/Sampler.mm:
+ (WebGPU::validateCreateSampler):
+ * WebGPU/Texture.mm:
+ (WebGPU::Device::validateCreateTexture):
+ (WebGPU::Device::createTexture):
+ (WebGPU::Texture::validateCreateView const):
+ (WebGPU::Texture::createView):
+ (WebGPU::Texture::validateImageCopyTexture):
+
2022-04-08 Myles C. Maxfield <[email protected]>
[WebGPU] Fix the release build
Modified: trunk/Source/WebGPU/WebGPU/Buffer.mm (292727 => 292728)
--- trunk/Source/WebGPU/WebGPU/Buffer.mm 2022-04-11 21:59:00 UTC (rev 292727)
+++ trunk/Source/WebGPU/WebGPU/Buffer.mm 2022-04-11 22:03:54 UTC (rev 292728)
@@ -51,7 +51,8 @@
static bool validateCreateBuffer(const Device& device, const WGPUBufferDescriptor& descriptor)
{
- // FIXME: "this is a valid GPUDevice."
+ if (!device.isValid())
+ return false;
if (!validateDescriptor(device, descriptor))
return false;
@@ -208,8 +209,11 @@
bool Buffer::validateMapAsync(WGPUMapModeFlags mode, size_t offset, size_t rangeSize) const
{
- // FIXME: "this is a valid GPUBuffer. TODO: check destroyed state?"
+ if (!isValid())
+ return false;
+ // FIXME: The spec says "TODO: check destroyed state?"
+
if (offset % 8)
return false;
Modified: trunk/Source/WebGPU/WebGPU/CommandEncoder.h (292727 => 292728)
--- trunk/Source/WebGPU/WebGPU/CommandEncoder.h 2022-04-11 21:59:00 UTC (rev 292727)
+++ trunk/Source/WebGPU/WebGPU/CommandEncoder.h 2022-04-11 22:03:54 UTC (rev 292728)
@@ -80,9 +80,13 @@
CommandEncoder(id<MTLCommandBuffer>, Device&);
CommandEncoder(Device&);
+ bool validateCopyBufferToBuffer(const Buffer& source, uint64_t sourceOffset, const Buffer& destination, uint64_t destinationOffset, uint64_t size);
+ bool validateClearBuffer(const Buffer&, uint64_t offset, uint64_t size);
bool validateFinish() const;
bool validatePopDebugGroup() const;
+ void makeInvalid() { m_commandBuffer = nil; }
+
void ensureBlitCommandEncoder();
void finalizeBlitCommandEncoder();
Modified: trunk/Source/WebGPU/WebGPU/CommandEncoder.mm (292727 => 292728)
--- trunk/Source/WebGPU/WebGPU/CommandEncoder.mm 2022-04-11 21:59:00 UTC (rev 292727)
+++ trunk/Source/WebGPU/WebGPU/CommandEncoder.mm 2022-04-11 22:03:54 UTC (rev 292728)
@@ -31,6 +31,7 @@
#import "CommandBuffer.h"
#import "ComputePassEncoder.h"
#import "Device.h"
+#import "IsValidToUseWith.h"
#import "QuerySet.h"
#import "RenderPassEncoder.h"
#import "Texture.h"
@@ -97,11 +98,13 @@
return RenderPassEncoder::createInvalid(m_device);
}
-static bool validateCopyBufferToBuffer(const Buffer& source, uint64_t sourceOffset, const Buffer& destination, uint64_t destinationOffset, uint64_t size)
+bool CommandEncoder::validateCopyBufferToBuffer(const Buffer& source, uint64_t sourceOffset, const Buffer& destination, uint64_t destinationOffset, uint64_t size)
{
- // FIXME: "source is valid to use with this."
+ if (!isValidToUseWith(source, *this))
+ return false;
- // FIXME: "destination is valid to use with this."
+ if (!isValidToUseWith(destination, *this))
+ return false;
if (!(source.usage() & WGPUBufferUsage_CopySrc))
return false;
@@ -160,7 +163,8 @@
{
// https://gpuweb.github.io/gpuweb/#abstract-opdef-validating-gpuimagecopybuffer
- // FIXME: "imageCopyBuffer.buffer must be a valid GPUBuffer."
+ if (!fromAPI(imageCopyBuffer.buffer).isValid())
+ return false;
if (imageCopyBuffer.layout.bytesPerRow % 256)
return false;
@@ -674,9 +678,10 @@
}
}
-static bool validateClearBuffer(const Buffer& buffer, uint64_t offset, uint64_t size)
+bool CommandEncoder::validateClearBuffer(const Buffer& buffer, uint64_t offset, uint64_t size)
{
- // FIXME: "buffer is valid to use with this."
+ if (!isValidToUseWith(buffer, *this))
+ return false;
if (!(buffer.usage() & WGPUBufferUsage_CopyDst))
return false;
@@ -718,7 +723,8 @@
bool CommandEncoder::validateFinish() const
{
- // FIXME: "this must be valid."
+ if (!isValid())
+ return false;
if (m_state != EncoderState::Open)
return false;
@@ -786,7 +792,7 @@
return;
if (!validatePopDebugGroup()) {
- // FIXME: "make this invalid, and stop."
+ makeInvalid();
return;
}
Modified: trunk/Source/WebGPU/WebGPU/ComputePassEncoder.h (292727 => 292728)
--- trunk/Source/WebGPU/WebGPU/ComputePassEncoder.h 2022-04-11 21:59:00 UTC (rev 292727)
+++ trunk/Source/WebGPU/WebGPU/ComputePassEncoder.h 2022-04-11 22:03:54 UTC (rev 292728)
@@ -78,8 +78,10 @@
bool validatePopDebugGroup() const;
- const id<MTLComputeCommandEncoder> m_computeCommandEncoder { nil };
+ void makeInvalid() { m_computeCommandEncoder = nil; }
+ id<MTLComputeCommandEncoder> m_computeCommandEncoder { nil };
+
uint64_t m_debugGroupStackSize { 0 };
const Ref<Device> m_device;
Modified: trunk/Source/WebGPU/WebGPU/ComputePassEncoder.mm (292727 => 292728)
--- trunk/Source/WebGPU/WebGPU/ComputePassEncoder.mm 2022-04-11 21:59:00 UTC (rev 292727)
+++ trunk/Source/WebGPU/WebGPU/ComputePassEncoder.mm 2022-04-11 22:03:54 UTC (rev 292728)
@@ -100,7 +100,7 @@
return;
if (!validatePopDebugGroup()) {
- // FIXME: "make this invalid, and stop."
+ makeInvalid();
return;
}
Modified: trunk/Source/WebGPU/WebGPU/Queue.h (292727 => 292728)
--- trunk/Source/WebGPU/WebGPU/Queue.h 2022-04-11 21:59:00 UTC (rev 292727)
+++ trunk/Source/WebGPU/WebGPU/Queue.h 2022-04-11 22:03:54 UTC (rev 292728)
@@ -69,11 +69,13 @@
id<MTLCommandQueue> commandQueue() const { return m_commandQueue; }
+ const Device& device() const { return m_device; }
+
private:
Queue(id<MTLCommandQueue>, Device&);
Queue(Device&);
- bool validateSubmit() const;
+ bool validateSubmit(const Vector<std::reference_wrapper<const CommandBuffer>>&) const;
bool validateWriteBuffer(const Buffer&, uint64_t bufferOffset, size_t) const;
void ensureBlitCommandEncoder();
Modified: trunk/Source/WebGPU/WebGPU/Queue.mm (292727 => 292728)
--- trunk/Source/WebGPU/WebGPU/Queue.mm 2022-04-11 21:59:00 UTC (rev 292727)
+++ trunk/Source/WebGPU/WebGPU/Queue.mm 2022-04-11 22:03:54 UTC (rev 292728)
@@ -30,6 +30,7 @@
#import "Buffer.h"
#import "CommandBuffer.h"
#import "Device.h"
+#import "IsValidToUseWith.h"
#import "Texture.h"
namespace WebGPU {
@@ -101,9 +102,12 @@
callbacks.append(WTFMove(callback));
}
-bool Queue::validateSubmit() const
+bool Queue::validateSubmit(const Vector<std::reference_wrapper<const CommandBuffer>>& commands) const
{
- // FIXME: "Every {{GPUCommandBuffer}} in |commandBuffers| is [$valid to use with$] |this|."
+ for (auto command : commands) {
+ if (!isValidToUseWith(command.get(), *this))
+ return false;
+ }
// FIXME: "Every GPUBuffer referenced in any element of commandBuffers is in the "unmapped" buffer state."
@@ -134,7 +138,7 @@
{
// https://gpuweb.github.io/gpuweb/#dom-gpuqueue-submit
- if (!validateSubmit()) {
+ if (!validateSubmit(commands)) {
m_device.generateAValidationError("Validation failure."_s);
return;
}
@@ -155,7 +159,8 @@
bool Queue::validateWriteBuffer(const Buffer& buffer, uint64_t bufferOffset, size_t size) const
{
- // FIXME: "buffer is valid to use with this."
+ if (!isValidToUseWith(buffer, *this))
+ return false;
if (buffer.state() != Buffer::State::Unmapped)
return false;
Modified: trunk/Source/WebGPU/WebGPU/RenderBundleEncoder.h (292727 => 292728)
--- trunk/Source/WebGPU/WebGPU/RenderBundleEncoder.h 2022-04-11 21:59:00 UTC (rev 292727)
+++ trunk/Source/WebGPU/WebGPU/RenderBundleEncoder.h 2022-04-11 22:03:54 UTC (rev 292728)
@@ -80,8 +80,10 @@
bool validatePopDebugGroup() const;
- const id<MTLIndirectCommandBuffer> m_indirectCommandBuffer { nil };
+ void makeInvalid() { m_indirectCommandBuffer = nil; }
+ id<MTLIndirectCommandBuffer> m_indirectCommandBuffer { nil };
+
uint64_t m_debugGroupStackSize { 0 };
const Ref<Device> m_device;
Modified: trunk/Source/WebGPU/WebGPU/RenderBundleEncoder.mm (292727 => 292728)
--- trunk/Source/WebGPU/WebGPU/RenderBundleEncoder.mm 2022-04-11 21:59:00 UTC (rev 292727)
+++ trunk/Source/WebGPU/WebGPU/RenderBundleEncoder.mm 2022-04-11 22:03:54 UTC (rev 292728)
@@ -115,7 +115,7 @@
return;
if (!validatePopDebugGroup()) {
- // FIXME: "make this invalid, and stop."
+ makeInvalid();
return;
}
Modified: trunk/Source/WebGPU/WebGPU/RenderPassEncoder.h (292727 => 292728)
--- trunk/Source/WebGPU/WebGPU/RenderPassEncoder.h 2022-04-11 21:59:00 UTC (rev 292727)
+++ trunk/Source/WebGPU/WebGPU/RenderPassEncoder.h 2022-04-11 22:03:54 UTC (rev 292728)
@@ -91,8 +91,10 @@
bool validatePopDebugGroup() const;
- const id<MTLRenderCommandEncoder> m_renderCommandEncoder { nil };
+ void makeInvalid() { m_renderCommandEncoder = nil; }
+ id<MTLRenderCommandEncoder> m_renderCommandEncoder { nil };
+
uint64_t m_debugGroupStackSize { 0 };
const Ref<Device> m_device;
Modified: trunk/Source/WebGPU/WebGPU/RenderPassEncoder.mm (292727 => 292728)
--- trunk/Source/WebGPU/WebGPU/RenderPassEncoder.mm 2022-04-11 21:59:00 UTC (rev 292727)
+++ trunk/Source/WebGPU/WebGPU/RenderPassEncoder.mm 2022-04-11 22:03:54 UTC (rev 292728)
@@ -134,7 +134,7 @@
return;
if (!validatePopDebugGroup()) {
- // FIXME: "make this invalid, and stop."
+ makeInvalid();
return;
}
Modified: trunk/Source/WebGPU/WebGPU/Sampler.mm (292727 => 292728)
--- trunk/Source/WebGPU/WebGPU/Sampler.mm 2022-04-11 21:59:00 UTC (rev 292727)
+++ trunk/Source/WebGPU/WebGPU/Sampler.mm 2022-04-11 22:03:54 UTC (rev 292728)
@@ -32,11 +32,12 @@
namespace WebGPU {
-static bool validateCreateSampler(Device&, const WGPUSamplerDescriptor& descriptor)
+static bool validateCreateSampler(Device& device, const WGPUSamplerDescriptor& descriptor)
{
// https://gpuweb.github.io/gpuweb/#abstract-opdef-validating-gpusamplerdescriptor
- // FIXME: "device is valid."
+ if (!device.isValid())
+ return false;
if (std::isnan(descriptor.lodMinClamp) || descriptor.lodMinClamp < 0)
return false;
Modified: trunk/Source/WebGPU/WebGPU/Texture.mm (292727 => 292728)
--- trunk/Source/WebGPU/WebGPU/Texture.mm 2022-04-11 21:59:00 UTC (rev 292727)
+++ trunk/Source/WebGPU/WebGPU/Texture.mm 2022-04-11 22:03:54 UTC (rev 292728)
@@ -1228,7 +1228,8 @@
bool Device::validateCreateTexture(const WGPUTextureDescriptor& descriptor, const Vector<WGPUTextureFormat>& viewFormats)
{
- // FIXME: "this must be a valid GPUDevice."
+ if (!isValid())
+ return false;
if (!descriptor.usage)
return false;
@@ -1985,7 +1986,6 @@
if (!validateCreateTexture(descriptor, viewFormats)) {
generateAValidationError("Validation failure."_s);
- // FIXME: "Return a new invalid GPUTexture."
return Texture::createInvalid(*this);
}
@@ -2144,7 +2144,8 @@
bool Texture::validateCreateView(const WGPUTextureViewDescriptor& descriptor) const
{
- // FIXME: "this is valid"
+ if (!isValid())
+ return false;
switch (descriptor.aspect) {
case WGPUTextureAspect_All:
@@ -2427,7 +2428,8 @@
uint32_t blockHeight = Texture::texelBlockHeight(fromAPI(imageCopyTexture.texture).descriptor().format);
- // FIXME: "imageCopyTexture.texture must be a valid GPUTexture."
+ if (!fromAPI(imageCopyTexture.texture).isValid())
+ return false;
if (imageCopyTexture.mipLevel >= fromAPI(imageCopyTexture.texture).descriptor().mipLevelCount)
return false;