[WebGPU] Implement GPUError and error scopes
authorjustin_fan@apple.com <justin_fan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Jul 2019 21:32:06 +0000 (21:32 +0000)
committerjustin_fan@apple.com <justin_fan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Jul 2019 21:32:06 +0000 (21:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=199655

Reviewed by Myles C. Maxfield.

Source/WebCore:

Add GPUErrorFilter, GPUError, and the ability to push and pop error scopes on a GPUDevice.
This will allow us to check for WebGPU errors from JavaScript.
Currently, only some GPUBuffer creation errors are reported for testing; more errors will follow in later patches.

Test: webgpu/error-scopes-test.html

* Modules/webgpu/GPUErrorFilter.idl: Added.
* Modules/webgpu/GPUOutOfMemoryError.idl: Added.
* Modules/webgpu/GPUValidationError.idl: Added.
* Modules/webgpu/WebGPUDevice.cpp:
(WebCore::WebGPUDevice::pushErrorScope):
(WebCore::WebGPUDevice::popErrorScope): Resolve the Promise here, since GPUDevice shouldn't worry about DOM layer.
* Modules/webgpu/WebGPUDevice.h:
* Modules/webgpu/WebGPUDeviceErrorScopes.cpp: Added.
(WebCore::WebGPUDeviceErrorScopes::pushErrorScope): Delegates to WebGPUDevice.
(WebCore::WebGPUDeviceErrorScopes::popErrorScope): Ditto.
* Modules/webgpu/WebGPUDeviceErrorScopes.h: Added.
* Modules/webgpu/WebGPUDeviceErrorScopes.idl: Added.
* platform/graphics/gpu/GPUBuffer.h:
* platform/graphics/gpu/GPUDevice.cpp: The actual error stack lives here.
(WebCore::GPUDevice::pushErrorScope):
(WebCore::GPUDevice::popErrorScope): Calls a callback with a GPUError, if any.
(WebCore::GPUDevice::registerError): Actually creates GPUErrors.
* platform/graphics/gpu/GPUDevice.h:
* platform/graphics/gpu/GPUError.cpp: Added.
(WebCore::createError): Factory function for various error types.
* platform/graphics/gpu/GPUError.h: Added.
* platform/graphics/gpu/GPUErrorFilter.h: Added.
* platform/graphics/gpu/GPUOutOfMemoryError.h: Added.
(WebCore::GPUOutOfMemoryError::create):
* platform/graphics/gpu/GPUValidationError.cpp: Added.
(WebCore::GPUValidationError::create):
(WebCore::GPUValidationError::GPUValidationError):
* platform/graphics/gpu/GPUValidationError.h: Added.
(WebCore::GPUValidationError::message const):
* platform/graphics/gpu/cocoa/GPUBufferMetal.mm:
(WebCore::GPUBuffer::validateBufferUsage): Create an actual GPUValidationError :)
(WebCore::GPUBuffer::tryCreate): Create GPUOutOfMemoryErrors where appropriate.

Add file/name references:
* CMakeLists.txt:
* DerivedSources-input.xcfilelist:
* DerivedSources-output.xcfilelist:
* DerivedSources.make:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/WebCoreBuiltinNames.h:

Missing includes:
* Modules/webgpu/WHLSL/WHLSLCheckTextureReferences.cpp:

LayoutTests:

Add a test to cover the cases outlined in the WebGPU error handling design doc.

* webgpu/error-scopes-test-expected.txt: Added.
* webgpu/error-scopes-test.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@247366 268f45cc-cd09-0410-ab3c-d52691b4dbfc

30 files changed:
LayoutTests/ChangeLog
LayoutTests/webgpu/error-scopes-test-expected.txt [new file with mode: 0644]
LayoutTests/webgpu/error-scopes-test.html [new file with mode: 0644]
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources-input.xcfilelist
Source/WebCore/DerivedSources-output.xcfilelist
Source/WebCore/DerivedSources.make
Source/WebCore/Modules/webgpu/GPUErrorFilter.idl [new file with mode: 0644]
Source/WebCore/Modules/webgpu/GPUOutOfMemoryError.idl [new file with mode: 0644]
Source/WebCore/Modules/webgpu/GPUValidationError.idl [new file with mode: 0644]
Source/WebCore/Modules/webgpu/WHLSL/WHLSLCheckTextureReferences.cpp
Source/WebCore/Modules/webgpu/WebGPUDevice.cpp
Source/WebCore/Modules/webgpu/WebGPUDevice.h
Source/WebCore/Modules/webgpu/WebGPUDeviceErrorScopes.cpp [new file with mode: 0644]
Source/WebCore/Modules/webgpu/WebGPUDeviceErrorScopes.h [new file with mode: 0644]
Source/WebCore/Modules/webgpu/WebGPUDeviceErrorScopes.idl [new file with mode: 0644]
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/WebCoreBuiltinNames.h
Source/WebCore/platform/graphics/gpu/GPUBuffer.h
Source/WebCore/platform/graphics/gpu/GPUDevice.cpp
Source/WebCore/platform/graphics/gpu/GPUDevice.h
Source/WebCore/platform/graphics/gpu/GPUError.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/gpu/GPUError.h [new file with mode: 0644]
Source/WebCore/platform/graphics/gpu/GPUErrorFilter.h [new file with mode: 0644]
Source/WebCore/platform/graphics/gpu/GPUOutOfMemoryError.h [new file with mode: 0644]
Source/WebCore/platform/graphics/gpu/GPUValidationError.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/gpu/GPUValidationError.h [new file with mode: 0644]
Source/WebCore/platform/graphics/gpu/cocoa/GPUBufferMetal.mm

index 21f88e1..9d5375b 100644 (file)
@@ -1,3 +1,15 @@
+2019-07-11  Justin Fan  <justin_fan@apple.com>
+
+        [WebGPU] Implement GPUError and error scopes
+        https://bugs.webkit.org/show_bug.cgi?id=199655
+
+        Reviewed by Myles C. Maxfield.
+
+        Add a test to cover the cases outlined in the WebGPU error handling design doc.
+
+        * webgpu/error-scopes-test-expected.txt: Added.
+        * webgpu/error-scopes-test.html: Added.
+
 2019-07-11  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r247314.
diff --git a/LayoutTests/webgpu/error-scopes-test-expected.txt b/LayoutTests/webgpu/error-scopes-test-expected.txt
new file mode 100644 (file)
index 0000000..4eba67f
--- /dev/null
@@ -0,0 +1,10 @@
+
+PASS Capture a single GPUValidation error. 
+PASS Capture a single GPUOutOfMemory error. 
+PASS Ignore errors past the first. 
+PASS Captured errors match error scope filter. 
+PASS Reject popErrorScope if no scope exists. 
+PASS Filter 'none' should capture but not report errors. 
+PASS Push and pop many error scopes with no rejections. 
+PASS Catch many errors in nested scopes. 
+
diff --git a/LayoutTests/webgpu/error-scopes-test.html b/LayoutTests/webgpu/error-scopes-test.html
new file mode 100644 (file)
index 0000000..5cfcca1
--- /dev/null
@@ -0,0 +1,122 @@
+<!DOCTYPE html>
+<meta charset=utf-8>
+<title>Test Error Scopes.</title>
+<body>
+<script src="js/webgpu-functions.js"></script>
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+<script>
+let tests = {};
+
+tests["Capture a single GPUValidation error."] = async device => {
+    device.pushErrorScope("validation");
+    causeValidationError(device);
+    return popValidationError(device);
+};
+
+tests["Capture a single GPUOutOfMemory error."] = async device => {
+    device.pushErrorScope("out-of-memory");
+    causeMemoryError(device);
+    return popMemoryError(device);
+};
+
+tests["Ignore errors past the first."] = async device => {
+    device.pushErrorScope("validation");
+    device.pushErrorScope("validation");
+    causeValidationError(device);
+    causeValidationError(device);
+    
+    const error = await device.popErrorScope();
+    assertValidationError(error);
+
+    return popNullError(device);
+};
+
+tests["Captured errors match error scope filter."] = async device => {
+    device.pushErrorScope("validation");
+    device.pushErrorScope("out-of-memory");
+    causeValidationError(device);
+
+    const shouldBeNull = await device.popErrorScope();
+    assertNull(shouldBeNull);
+
+    return popValidationError(device);
+};
+
+tests["Reject popErrorScope if no scope exists."] = async device => {
+    const promise = device.popErrorScope().then(() => assert_unreached(), async e => {
+        assert_false(e === undefined);
+        // Pop the extra 'none' scope.
+        await popNullError(device);
+    });
+    // 'promise' should still reject if a scope is pushed here.
+    device.pushErrorScope("none");
+    return promise;
+};
+
+tests["Filter 'none' should capture but not report errors."] = async device => {
+    device.pushErrorScope("out-of-memory");
+    device.pushErrorScope("none");
+    causeMemoryError(device);
+
+    const shouldBeNull = await device.popErrorScope();
+    assertNull(shouldBeNull);
+
+    return popNullError(device);
+};
+
+tests["Push and pop many error scopes with no rejections."] = async device => {
+    const numIterations = 128;
+    for (let i = 0; i < numIterations; ++i)
+        device.pushErrorScope("out-of-memory");
+    
+    for (let i = 0; i < numIterations - 1; ++i)
+        await popNullError(device);
+
+    return popNullError(device);
+};
+
+tests["Catch many errors in nested scopes."] = async device => {
+    const numIterations = 128;
+    for (let i = 0; i < numIterations; ++i) {
+        device.pushErrorScope("validation");
+        causeValidationError(device);
+    }
+
+    for (let i = 0; i < numIterations - 1; ++i)
+        await popValidationError(device);
+
+    return popValidationError(device);
+};
+
+const init = async () => {
+    try {
+        var device = await getBasicDevice();
+    } catch (e) { /* WebGPU is not supported. */ }
+
+    for (let name in tests)
+        devicePromiseTest(device, name);
+};
+
+window.addEventListener("load", init);
+
+/* Helper Functions */
+
+const causeValidationError = device => device.createBuffer({ size: 4, usage: GPUBufferUsage.MAP_READ | GPUBufferUsage.MAP_WRITE });
+const causeMemoryError = device => device.createBuffer({ size: 99999999999, usage: GPUBufferUsage.NONE });
+const popValidationError = device => device.popErrorScope().then(error => assertValidationError(error));
+const popMemoryError = device => device.popErrorScope().then(error => assertMemoryError(error));
+const popNullError = device => device.popErrorScope().then(error => assertNull(error));
+const assertNull = error => assert_true(error === null, "No error expected!");
+const assertValidationError = error => assert_true(error instanceof GPUValidationError, "Expected validation error!");
+const assertMemoryError = error => assert_true(error instanceof GPUOutOfMemoryError, "Expected out-of-memory error!");
+
+const devicePromiseTest = (device, name) => {
+    promise_test(async () => {
+        if (device === undefined)
+            return Promise.resolve();
+        return tests[name](device);
+    }, name);
+};
+</script>
+</body>
\ No newline at end of file
index 3ce5166..84d84ac 100644 (file)
@@ -480,9 +480,11 @@ set(WebCore_NON_SVG_IDL_FILES
     Modules/webgpu/GPUColorWriteBits.idl
     Modules/webgpu/GPUCompareFunction.idl
     Modules/webgpu/GPUDepthStencilStateDescriptor.idl
+    Modules/webgpu/GPUErrorFilter.idl
     Modules/webgpu/GPUExtent3D.idl
     Modules/webgpu/GPULoadOp.idl
     Modules/webgpu/GPUOrigin3D.idl
+    Modules/webgpu/GPUOutOfMemoryError.idl
     Modules/webgpu/GPURequestAdapterOptions.idl
     Modules/webgpu/GPUSamplerDescriptor.idl
     Modules/webgpu/GPUShaderStageBit.idl
@@ -490,6 +492,7 @@ set(WebCore_NON_SVG_IDL_FILES
     Modules/webgpu/GPUTextureDescriptor.idl
     Modules/webgpu/GPUTextureFormat.idl
     Modules/webgpu/GPUTextureUsage.idl
+    Modules/webgpu/GPUValidationError.idl
     Modules/webgpu/GPUVertexAttributeDescriptor.idl
     Modules/webgpu/GPUVertexBufferDescriptor.idl
     Modules/webgpu/GPUVertexInputDescriptor.idl
@@ -508,6 +511,7 @@ set(WebCore_NON_SVG_IDL_FILES
     Modules/webgpu/WebGPUComputePipeline.idl
     Modules/webgpu/WebGPUComputePipelineDescriptor.idl
     Modules/webgpu/WebGPUDevice.idl
+    Modules/webgpu/WebGPUDeviceErrorScopes.idl
     Modules/webgpu/WebGPUPipelineDescriptorBase.idl
     Modules/webgpu/WebGPUPipelineLayout.idl
     Modules/webgpu/WebGPUPipelineLayoutDescriptor.idl
index c1eca61..f2e722a 100644 (file)
@@ -1,3 +1,61 @@
+2019-07-11  Justin Fan  <justin_fan@apple.com>
+
+        [WebGPU] Implement GPUError and error scopes
+        https://bugs.webkit.org/show_bug.cgi?id=199655
+
+        Reviewed by Myles C. Maxfield.
+
+        Add GPUErrorFilter, GPUError, and the ability to push and pop error scopes on a GPUDevice.
+        This will allow us to check for WebGPU errors from JavaScript.
+        Currently, only some GPUBuffer creation errors are reported for testing; more errors will follow in later patches.
+
+        Test: webgpu/error-scopes-test.html
+
+        * Modules/webgpu/GPUErrorFilter.idl: Added.
+        * Modules/webgpu/GPUOutOfMemoryError.idl: Added.
+        * Modules/webgpu/GPUValidationError.idl: Added.
+        * Modules/webgpu/WebGPUDevice.cpp:
+        (WebCore::WebGPUDevice::pushErrorScope):
+        (WebCore::WebGPUDevice::popErrorScope): Resolve the Promise here, since GPUDevice shouldn't worry about DOM layer.
+        * Modules/webgpu/WebGPUDevice.h:
+        * Modules/webgpu/WebGPUDeviceErrorScopes.cpp: Added.
+        (WebCore::WebGPUDeviceErrorScopes::pushErrorScope): Delegates to WebGPUDevice.
+        (WebCore::WebGPUDeviceErrorScopes::popErrorScope): Ditto.
+        * Modules/webgpu/WebGPUDeviceErrorScopes.h: Added.
+        * Modules/webgpu/WebGPUDeviceErrorScopes.idl: Added.
+        * platform/graphics/gpu/GPUBuffer.h:
+        * platform/graphics/gpu/GPUDevice.cpp: The actual error stack lives here.
+        (WebCore::GPUDevice::pushErrorScope):
+        (WebCore::GPUDevice::popErrorScope): Calls a callback with a GPUError, if any.
+        (WebCore::GPUDevice::registerError): Actually creates GPUErrors.
+        * platform/graphics/gpu/GPUDevice.h:
+        * platform/graphics/gpu/GPUError.cpp: Added.
+        (WebCore::createError): Factory function for various error types.
+        * platform/graphics/gpu/GPUError.h: Added.
+        * platform/graphics/gpu/GPUErrorFilter.h: Added.
+        * platform/graphics/gpu/GPUOutOfMemoryError.h: Added.
+        (WebCore::GPUOutOfMemoryError::create):
+        * platform/graphics/gpu/GPUValidationError.cpp: Added.
+        (WebCore::GPUValidationError::create):
+        (WebCore::GPUValidationError::GPUValidationError):
+        * platform/graphics/gpu/GPUValidationError.h: Added.
+        (WebCore::GPUValidationError::message const):
+        * platform/graphics/gpu/cocoa/GPUBufferMetal.mm:
+        (WebCore::GPUBuffer::validateBufferUsage): Create an actual GPUValidationError :)
+        (WebCore::GPUBuffer::tryCreate): Create GPUOutOfMemoryErrors where appropriate.
+
+        Add file/name references:
+        * CMakeLists.txt:
+        * DerivedSources-input.xcfilelist:
+        * DerivedSources-output.xcfilelist:
+        * DerivedSources.make:
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/WebCoreBuiltinNames.h:
+
+        Missing includes:
+        * Modules/webgpu/WHLSL/WHLSLCheckTextureReferences.cpp:
+
 2019-07-11  Tim Horton  <timothy_horton@apple.com>
 
         Null deref of RenderView under FrameView::setNeedsCompositingConfigurationUpdate
index c69d3dd..a681376 100644 (file)
@@ -330,10 +330,12 @@ $(PROJECT_DIR)/Modules/webgpu/GPUColorStateDescriptor.idl
 $(PROJECT_DIR)/Modules/webgpu/GPUColorWriteBits.idl
 $(PROJECT_DIR)/Modules/webgpu/GPUCompareFunction.idl
 $(PROJECT_DIR)/Modules/webgpu/GPUDepthStencilStateDescriptor.idl
+$(PROJECT_DIR)/Modules/webgpu/GPUErrorFilter.idl
 $(PROJECT_DIR)/Modules/webgpu/GPUExtent3D.idl
 $(PROJECT_DIR)/Modules/webgpu/GPUInputStateDescriptor.idl
 $(PROJECT_DIR)/Modules/webgpu/GPULoadOp.idl
 $(PROJECT_DIR)/Modules/webgpu/GPUOrigin3D.idl
+$(PROJECT_DIR)/Modules/webgpu/GPUOutOfMemoryError.idl
 $(PROJECT_DIR)/Modules/webgpu/GPURequestAdapterOptions.idl
 $(PROJECT_DIR)/Modules/webgpu/GPUSamplerDescriptor.idl
 $(PROJECT_DIR)/Modules/webgpu/GPUShaderStageBit.idl
@@ -341,6 +343,7 @@ $(PROJECT_DIR)/Modules/webgpu/GPUStoreOp.idl
 $(PROJECT_DIR)/Modules/webgpu/GPUTextureDescriptor.idl
 $(PROJECT_DIR)/Modules/webgpu/GPUTextureFormat.idl
 $(PROJECT_DIR)/Modules/webgpu/GPUTextureUsage.idl
+$(PROJECT_DIR)/Modules/webgpu/GPUValidationError.idl
 $(PROJECT_DIR)/Modules/webgpu/GPUVertexAttributeDescriptor.idl
 $(PROJECT_DIR)/Modules/webgpu/GPUVertexBufferDescriptor.idl
 $(PROJECT_DIR)/Modules/webgpu/GPUVertexInputDescriptor.idl
@@ -361,6 +364,7 @@ $(PROJECT_DIR)/Modules/webgpu/WebGPUComputePassEncoder.idl
 $(PROJECT_DIR)/Modules/webgpu/WebGPUComputePipeline.idl
 $(PROJECT_DIR)/Modules/webgpu/WebGPUComputePipelineDescriptor.idl
 $(PROJECT_DIR)/Modules/webgpu/WebGPUDevice.idl
+$(PROJECT_DIR)/Modules/webgpu/WebGPUDeviceErrorScopes.idl
 $(PROJECT_DIR)/Modules/webgpu/WebGPUPipelineDescriptorBase.idl
 $(PROJECT_DIR)/Modules/webgpu/WebGPUPipelineLayout.idl
 $(PROJECT_DIR)/Modules/webgpu/WebGPUPipelineLayoutDescriptor.idl
index 37c3c8b..4a26d29 100644 (file)
@@ -609,6 +609,8 @@ $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUCompareFunction.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUCompareFunction.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUDepthStencilStateDescriptor.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUDepthStencilStateDescriptor.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUErrorFilter.cpp
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUErrorFilter.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUExtent3D.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUExtent3D.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUInputStateDescriptor.cpp
@@ -617,6 +619,8 @@ $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPULoadOp.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPULoadOp.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUOrigin3D.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUOrigin3D.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUOutOfMemoryError.cpp
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUOutOfMemoryError.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPURequestAdapterOptions.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPURequestAdapterOptions.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUSamplerDescriptor.cpp
@@ -631,6 +635,8 @@ $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUTextureFormat.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUTextureFormat.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUTextureUsage.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUTextureUsage.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUValidationError.cpp
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUValidationError.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUVertexAttributeDescriptor.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUVertexAttributeDescriptor.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUVertexBufferDescriptor.cpp
@@ -1943,6 +1949,8 @@ $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWebGPUComputePipelineDescriptor.c
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWebGPUComputePipelineDescriptor.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWebGPUDevice.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWebGPUDevice.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWebGPUDeviceErrorScopes.cpp
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWebGPUDeviceErrorScopes.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWebGPUPipelineDescriptorBase.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWebGPUPipelineDescriptorBase.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWebGPUPipelineLayout.cpp
index 7eeb427..c617716 100644 (file)
@@ -386,9 +386,11 @@ JS_BINDING_IDLS = \
     $(WebCore)/Modules/webgpu/GPUBufferUsage.idl \
     $(WebCore)/Modules/webgpu/GPUCompareFunction.idl \
     $(WebCore)/Modules/webgpu/GPUDepthStencilStateDescriptor.idl \
+    $(WebCore)/Modules/webgpu/GPUErrorFilter.idl \
     $(WebCore)/Modules/webgpu/GPUExtent3D.idl \
     $(WebCore)/Modules/webgpu/GPULoadOp.idl \
     $(WebCore)/Modules/webgpu/GPUOrigin3D.idl \
+    $(WebCore)/Modules/webgpu/GPUOutOfMemoryError.idl \
     $(WebCore)/Modules/webgpu/GPURequestAdapterOptions.idl \
     $(WebCore)/Modules/webgpu/GPUSamplerDescriptor.idl \
     $(WebCore)/Modules/webgpu/GPUShaderStageBit.idl \
@@ -396,6 +398,7 @@ JS_BINDING_IDLS = \
     $(WebCore)/Modules/webgpu/GPUTextureDescriptor.idl \
     $(WebCore)/Modules/webgpu/GPUTextureFormat.idl \
     $(WebCore)/Modules/webgpu/GPUTextureUsage.idl \
+    $(WebCore)/Modules/webgpu/GPUValidationError.idl \
     $(WebCore)/Modules/webgpu/GPUVertexAttributeDescriptor.idl \
     $(WebCore)/Modules/webgpu/GPUVertexBufferDescriptor.idl \
        $(WebCore)/Modules/webgpu/GPUVertexInputDescriptor.idl \
@@ -414,6 +417,7 @@ JS_BINDING_IDLS = \
     $(WebCore)/Modules/webgpu/WebGPUComputePipeline.idl \
     $(WebCore)/Modules/webgpu/WebGPUComputePipelineDescriptor.idl \
     $(WebCore)/Modules/webgpu/WebGPUDevice.idl \
+       $(WebCore)/Modules/webgpu/WebGPUDeviceErrorScopes.idl \
     $(WebCore)/Modules/webgpu/WebGPUQueue.idl \
     $(WebCore)/Modules/webgpu/WebGPUPipelineDescriptorBase.idl \
     $(WebCore)/Modules/webgpu/WebGPUPipelineLayout.idl \
diff --git a/Source/WebCore/Modules/webgpu/GPUErrorFilter.idl b/Source/WebCore/Modules/webgpu/GPUErrorFilter.idl
new file mode 100644 (file)
index 0000000..1d6acbb
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+// https://gpuweb.github.io/gpuweb
+
+[
+    Conditional=WEBGPU,
+    EnabledAtRuntime=WebGPU
+] enum GPUErrorFilter {
+    "none",
+    "out-of-memory",
+    "validation"
+};
diff --git a/Source/WebCore/Modules/webgpu/GPUOutOfMemoryError.idl b/Source/WebCore/Modules/webgpu/GPUOutOfMemoryError.idl
new file mode 100644 (file)
index 0000000..d4d3d00
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+// https://gpuweb.github.io/gpuweb
+
+[
+    Conditional=WEBGPU,
+    Constructor(),
+    EnabledAtRuntime=WebGPU,
+    ImplementationLacksVTable
+] interface GPUOutOfMemoryError {};
diff --git a/Source/WebCore/Modules/webgpu/GPUValidationError.idl b/Source/WebCore/Modules/webgpu/GPUValidationError.idl
new file mode 100644 (file)
index 0000000..5e13c18
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+// https://gpuweb.github.io/gpuweb
+
+[
+    Conditional=WEBGPU,
+    Constructor(DOMString message),
+    EnabledAtRuntime=WebGPU,
+    ImplementationLacksVTable
+] interface GPUValidationError {
+    readonly attribute DOMString message;
+};
index c02db89..7386b10 100644 (file)
 #include "config.h"
 #include "WHLSLCheckTextureReferences.h"
 
-#include "WHLSLInferTypes.h"
-
 #if ENABLE(WEBGPU)
 
+#include "WHLSLArrayReferenceType.h"
+#include "WHLSLArrayType.h"
+#include "WHLSLInferTypes.h"
+#include "WHLSLNativeTypeDeclaration.h"
+#include "WHLSLPointerType.h"
+#include "WHLSLVisitor.h"
+
 namespace WebCore {
 
 namespace WHLSL {
index f059ad8..e319e21 100644 (file)
@@ -28,6 +28,7 @@
 
 #if ENABLE(WEBGPU)
 
+#include "Exception.h"
 #include "GPUBindGroup.h"
 #include "GPUBindGroupBinding.h"
 #include "GPUBindGroupDescriptor.h"
@@ -42,6 +43,8 @@
 #include "GPUShaderModuleDescriptor.h"
 #include "GPUTextureDescriptor.h"
 #include "JSDOMConvertBufferSource.h"
+#include "JSGPUOutOfMemoryError.h"
+#include "JSGPUValidationError.h"
 #include "JSWebGPUBuffer.h"
 #include "Logging.h"
 #include "WebGPUBindGroup.h"
@@ -63,6 +66,7 @@
 #include "WebGPUShaderModuleDescriptor.h"
 #include "WebGPUSwapChain.h"
 #include "WebGPUTexture.h"
+#include <wtf/Optional.h>
 
 namespace WebCore {
 
@@ -180,6 +184,21 @@ Ref<WebGPUQueue> WebGPUDevice::getQueue() const
     return makeRef(*m_queue.get());
 }
 
+void WebGPUDevice::pushErrorScope(GPUErrorFilter filter) const
+{
+    m_device->pushErrorScope(filter);
+}
+
+void WebGPUDevice::popErrorScope(ErrorPromise&& promise) const
+{
+    m_device->popErrorScope([promise = WTFMove(promise)] (Optional<GPUError>&& error, const String& failMessage) mutable {
+        if (failMessage.isEmpty())
+            promise.resolve(error);
+        else
+            promise.reject(Exception { OperationError, failMessage });
+    });
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(WEBGPU)
index 21d371a..cc26d2d 100644 (file)
@@ -28,6 +28,7 @@
 #if ENABLE(WEBGPU)
 
 #include "GPUDevice.h"
+#include "JSDOMPromiseDeferred.h"
 #include "WebGPUAdapter.h"
 #include "WebGPUQueue.h"
 #include "WebGPUSwapChainDescriptor.h"
@@ -43,6 +44,8 @@ class JSValue;
 
 namespace WebCore {
 
+class GPUOutOfMemoryError;
+class GPUValidationError;
 class ScriptExecutionContext;
 class WebGPUBindGroup;
 class WebGPUBindGroupLayout;
@@ -66,6 +69,11 @@ struct WebGPUPipelineLayoutDescriptor;
 struct WebGPURenderPipelineDescriptor;
 struct WebGPUShaderModuleDescriptor;
 
+enum class GPUErrorFilter;
+
+using ErrorIDLUnion = IDLUnion<IDLInterface<GPUOutOfMemoryError>, IDLInterface<GPUValidationError>>;
+using ErrorPromise = DOMPromiseDeferred<IDLNullable<ErrorIDLUnion>>;
+
 class WebGPUDevice : public RefCounted<WebGPUDevice> {
 public:
     static RefPtr<WebGPUDevice> tryCreate(Ref<const WebGPUAdapter>&&);
@@ -91,6 +99,9 @@ public:
 
     Ref<WebGPUQueue> getQueue() const;
 
+    void pushErrorScope(GPUErrorFilter) const;
+    void popErrorScope(ErrorPromise&&) const;
+
 private:
     WebGPUDevice(Ref<const WebGPUAdapter>&&, Ref<GPUDevice>&&);
 
diff --git a/Source/WebCore/Modules/webgpu/WebGPUDeviceErrorScopes.cpp b/Source/WebCore/Modules/webgpu/WebGPUDeviceErrorScopes.cpp
new file mode 100644 (file)
index 0000000..7931100
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebGPUDeviceErrorScopes.h"
+
+#if ENABLE(WEBGPU)
+
+#include "GPUErrorFilter.h"
+
+namespace WebCore {
+
+void WebGPUDeviceErrorScopes::pushErrorScope(WebGPUDevice& device, GPUErrorFilter filter)
+{
+    device.pushErrorScope(filter);
+}
+
+void WebGPUDeviceErrorScopes::popErrorScope(WebGPUDevice& device, ErrorPromise&& promise)
+{
+    device.popErrorScope(WTFMove(promise));
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)
diff --git a/Source/WebCore/Modules/webgpu/WebGPUDeviceErrorScopes.h b/Source/WebCore/Modules/webgpu/WebGPUDeviceErrorScopes.h
new file mode 100644 (file)
index 0000000..f20f07a
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBGPU)
+
+#include "WebGPUDevice.h"
+
+namespace WebCore {
+
+enum class GPUErrorFilter;
+
+class WebGPUDeviceErrorScopes {
+public:
+    static void pushErrorScope(WebGPUDevice&, GPUErrorFilter);
+    static void popErrorScope(WebGPUDevice&, ErrorPromise&&);
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)
diff --git a/Source/WebCore/Modules/webgpu/WebGPUDeviceErrorScopes.idl b/Source/WebCore/Modules/webgpu/WebGPUDeviceErrorScopes.idl
new file mode 100644 (file)
index 0000000..ec78527
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+// https://gpuweb.github.io/gpuweb
+
+typedef (GPUOutOfMemoryError or GPUValidationError) GPUError;
+
+[
+    Conditional=WEBGPU,
+    EnabledAtRuntime=WebGPU
+] partial interface WebGPUDevice {
+    void pushErrorScope(GPUErrorFilter filter);
+    Promise<GPUError?> popErrorScope();
+};
index d80f02e..88ae26a 100644 (file)
@@ -367,6 +367,7 @@ Modules/webgpu/WebGPUComputePassEncoder.cpp
 Modules/webgpu/WebGPUComputePipeline.cpp
 Modules/webgpu/WebGPUComputePipelineDescriptor.cpp
 Modules/webgpu/WebGPUDevice.cpp
+Modules/webgpu/WebGPUDeviceErrorScopes.cpp
 Modules/webgpu/WebGPUQueue.cpp
 Modules/webgpu/WebGPUPipelineLayout.cpp
 Modules/webgpu/WebGPUPipelineLayoutDescriptor.cpp
@@ -1827,6 +1828,8 @@ platform/graphics/filters/SourceGraphic.cpp
 platform/graphics/filters/SpotLightSource.cpp
 
 platform/graphics/gpu/GPUDevice.cpp
+platform/graphics/gpu/GPUError.cpp
+platform/graphics/gpu/GPUValidationError.cpp
 platform/graphics/gpu/GPUPipelineLayout.cpp
 platform/graphics/gpu/GPUProgrammablePassEncoder.cpp
 
@@ -2756,9 +2759,11 @@ JSGPUBufferDescriptor.cpp
 JSGPUBufferUsage.cpp
 JSGPUCompareFunction.cpp
 JSGPUDepthStencilStateDescriptor.cpp
+JSGPUErrorFilter.cpp
 JSGPUExtent3D.cpp
 JSGPULoadOp.cpp
 JSGPUOrigin3D.cpp
+JSGPUOutOfMemoryError.cpp
 JSGPURequestAdapterOptions.cpp
 JSGPUSamplerDescriptor.cpp
 JSGPUShaderStageBit.cpp
@@ -2766,6 +2771,7 @@ JSGPUStoreOp.cpp
 JSGPUTextureDescriptor.cpp
 JSGPUTextureFormat.cpp
 JSGPUTextureUsage.cpp
+JSGPUValidationError.cpp
 JSGPUVertexAttributeDescriptor.cpp
 JSGPUVertexBufferDescriptor.cpp
 JSGPUVertexInputDescriptor.cpp
@@ -3318,6 +3324,7 @@ JSWebGPUComputePassEncoder.cpp
 JSWebGPUComputePipeline.cpp
 JSWebGPUComputePipelineDescriptor.cpp
 JSWebGPUDevice.cpp
+JSWebGPUDeviceErrorScopes.cpp
 JSWebGPUQueue.cpp
 JSWebGPUPipelineDescriptorBase.cpp
 JSWebGPUPipelineLayout.cpp
index 9a8ef93..b61302e 100644 (file)
                D093D225217951D400329217 /* GPUCanvasContext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUCanvasContext.h; sourceTree = "<group>"; };
                D093D227217951D400329217 /* GPUCanvasContext.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = GPUCanvasContext.idl; sourceTree = "<group>"; };
                D093D2292179541600329217 /* GPUCanvasContext.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = GPUCanvasContext.cpp; sourceTree = "<group>"; };
+               D09AFAFF22D02E5300C4538C /* WebGPUDeviceErrorScopes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUDeviceErrorScopes.h; sourceTree = "<group>"; };
+               D09AFB0122D02E5300C4538C /* WebGPUDeviceErrorScopes.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUDeviceErrorScopes.cpp; sourceTree = "<group>"; };
+               D09AFB0222D0471900C4538C /* GPUErrorFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUErrorFilter.h; sourceTree = "<group>"; };
+               D09AFB0322D40CC500C4538C /* WebGPUDeviceErrorScopes.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUDeviceErrorScopes.idl; sourceTree = "<group>"; };
+               D09AFB0622D417B300C4538C /* GPUErrorFilter.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = GPUErrorFilter.idl; sourceTree = "<group>"; };
+               D09AFB0722D5391B00C4538C /* GPUError.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUError.h; sourceTree = "<group>"; };
+               D09AFB0822D5542800C4538C /* GPUError.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = GPUError.cpp; sourceTree = "<group>"; };
+               D09AFB0C22D55E9000C4538C /* GPUValidationError.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = GPUValidationError.idl; sourceTree = "<group>"; };
+               D09AFB0D22D55F3B00C4538C /* GPUValidationError.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUValidationError.h; sourceTree = "<group>"; };
+               D09AFB0E22D55FF500C4538C /* GPUValidationError.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = GPUValidationError.cpp; sourceTree = "<group>"; };
+               D09AFB1722D6694E00C4538C /* GPUOutOfMemoryError.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = GPUOutOfMemoryError.idl; sourceTree = "<group>"; };
+               D09AFB1922D6698A00C4538C /* GPUOutOfMemoryError.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUOutOfMemoryError.h; sourceTree = "<group>"; };
+               D09AFB2D22D6C01400C4538C /* GPUError.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = GPUError.cpp; sourceTree = "<group>"; };
                D0A20D542092A0A600E0C259 /* WebGLCompressedTextureASTC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebGLCompressedTextureASTC.h; sourceTree = "<group>"; };
                D0A20D562092A0A600E0C259 /* WebGLCompressedTextureASTC.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebGLCompressedTextureASTC.cpp; sourceTree = "<group>"; };
                D0A3A7301405A39800FB8ED3 /* ResourceLoaderOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceLoaderOptions.h; sourceTree = "<group>"; };
                                D03C849A21FFC6670002227F /* GPUDepthStencilStateDescriptor.h */,
                                312FF8BF21A4C2F100EB199D /* GPUDevice.cpp */,
                                312FF8BE21A4C2F100EB199D /* GPUDevice.h */,
+                               D09AFB0822D5542800C4538C /* GPUError.cpp */,
+                               D09AFB2D22D6C01400C4538C /* GPUError.cpp */,
+                               D09AFB0722D5391B00C4538C /* GPUError.h */,
+                               D09AFB0222D0471900C4538C /* GPUErrorFilter.h */,
                                D026F47D220A2AC600AC5F49 /* GPUExtent3D.h */,
                                D0F7559F2203BA1400118058 /* GPULimits.h */,
                                D08AA02F220D0BD50058C502 /* GPULoadOp.h */,
+                               D09AFB1922D6698A00C4538C /* GPUOutOfMemoryError.h */,
                                312FF8C421A4C2F400EB199D /* GPUPipelineDescriptorBase.h */,
                                D003288721C9A4E500622AA6 /* GPUPipelineLayout.cpp */,
                                D003288621C9A4E500622AA6 /* GPUPipelineLayout.h */,
                                312FF8C321A4C2F300EB199D /* GPUTextureFormat.h */,
                                D026F485220A477200AC5F49 /* GPUTextureUsage.h */,
                                D06EF552220BA26A0018724E /* GPUUtils.h */,
+                               D09AFB0E22D55FF500C4538C /* GPUValidationError.cpp */,
+                               D09AFB0D22D55F3B00C4538C /* GPUValidationError.h */,
                                D0D8649B21BA1C2D003C983C /* GPUVertexAttributeDescriptor.h */,
                                D0D8649C21BA1CE8003C983C /* GPUVertexBufferDescriptor.h */,
                                D0D8649921BA1B1F003C983C /* GPUVertexInputDescriptor.h */,
                                D0B56EAE224ECE200061049C /* GPUColorWriteBits.idl */,
                                D03C849E21FFCF000002227F /* GPUCompareFunction.idl */,
                                D03C84A221FFD7230002227F /* GPUDepthStencilStateDescriptor.idl */,
+                               D09AFB0622D417B300C4538C /* GPUErrorFilter.idl */,
                                D026F480220A2B7000AC5F49 /* GPUExtent3D.idl */,
                                D08AA02D220D0B9C0058C502 /* GPULoadOp.idl */,
                                D0CCA94922299F97006979B6 /* GPUOrigin3D.h */,
                                D0CCA94A22299F97006979B6 /* GPUOrigin3D.idl */,
+                               D09AFB1722D6694E00C4538C /* GPUOutOfMemoryError.idl */,
                                D02C26922181416D00D818E4 /* GPURequestAdapterOptions.idl */,
                                D0ADB26322309D7600A22935 /* GPUSamplerDescriptor.idl */,
                                D0DE8FB8222E09E200882550 /* GPUShaderStageBit.h */,
                                D026F48B220A5B0B00AC5F49 /* GPUTextureDescriptor.idl */,
                                D0EACFAE219E30FD000FA75C /* GPUTextureFormat.idl */,
                                D026F483220A472F00AC5F49 /* GPUTextureUsage.idl */,
+                               D09AFB0C22D55E9000C4538C /* GPUValidationError.idl */,
                                D0D8649621BA18F4003C983C /* GPUVertexAttributeDescriptor.idl */,
                                D0D8649821BA19A7003C983C /* GPUVertexBufferDescriptor.idl */,
                                D0D8649421BA173D003C983C /* GPUVertexInputDescriptor.idl */,
                                D00F595321701D8C000D71DB /* WebGPUDevice.cpp */,
                                D00F595221701D8C000D71DB /* WebGPUDevice.h */,
                                D00F595421701D8C000D71DB /* WebGPUDevice.idl */,
+                               D09AFB0122D02E5300C4538C /* WebGPUDeviceErrorScopes.cpp */,
+                               D09AFAFF22D02E5300C4538C /* WebGPUDeviceErrorScopes.h */,
+                               D09AFB0322D40CC500C4538C /* WebGPUDeviceErrorScopes.idl */,
                                D0C419F02183EB31009EC1DE /* WebGPUPipelineDescriptorBase.h */,
                                D0C419F12183EB31009EC1DE /* WebGPUPipelineDescriptorBase.idl */,
                                D05A99E521C9BF2C00032B75 /* WebGPUPipelineLayout.cpp */,
                                A5A7AA43132F0ECC00D3A3C2 /* AutocapitalizeTypes.h in Headers */,
                                7C1843FE1C8B7283002EB973 /* Autofill.h in Headers */,
                                7C1E97281A9F9834007BF0FB /* AutoFillButtonElement.h in Headers */,
+                               5CCC270922D5483A00964FA0 /* AutofillElements.h in Headers */,
                                C9D467051E60C465008195FB /* AutoplayEvent.h in Headers */,
                                45830D4E1679B4F800ACF8C3 /* AutoscrollController.h in Headers */,
                                A8CFF04E0A154F09000A4234 /* AutoTableLayout.h in Headers */,
                                7C7761AA1F878AA500F869FD /* JSImageBitmapRenderingContextSettings.h in Headers */,
                                A77979290D6B9E64003851B9 /* JSImageData.h in Headers */,
                                7C193C011F5E11050088F3E6 /* JSImageSmoothingQuality.h in Headers */,
-                               5CCC270922D5483A00964FA0 /* AutofillElements.h in Headers */,
                                A86629D309DA2B48009633A6 /* JSInputEvent.h in Headers */,
                                9175CE5E21E281ED00DF2C28 /* JSInspectorAuditAccessibilityObject.h in Headers */,
                                9175CE5C21E281ED00DF2C28 /* JSInspectorAuditDOMObject.h in Headers */,
index f5b5322..46f53e1 100644 (file)
@@ -94,6 +94,7 @@ namespace WebCore {
     macro(GPUComputePassEncoder) \
     macro(GPUComputePipeline) \
     macro(GPUDevice) \
+    macro(GPUOutOfMemoryError) \
     macro(GPUPipelineLayout) \
     macro(GPUProgrammablePassEncoder) \
     macro(GPUQueue) \
@@ -106,6 +107,7 @@ namespace WebCore {
     macro(GPUTexture) \
     macro(GPUTextureUsage) \
     macro(GPUTextureView) \
+    macro(GPUValidationError) \
     macro(HTMLAttachmentElement) \
     macro(HTMLAudioElement) \
     macro(HTMLDataListElement) \
index 42508bc..8da0432 100644 (file)
@@ -108,7 +108,7 @@ private:
     };
 
     GPUBuffer(PlatformBufferSmartPtr&&, Ref<GPUDevice>&&, size_t, OptionSet<GPUBufferUsage::Flags>, bool);
-    static bool validateBufferUsage(const GPUDevice&, OptionSet<GPUBufferUsage::Flags>);
+    static bool validateBufferUsage(GPUDevice&, OptionSet<GPUBufferUsage::Flags>);
 
     JSC::ArrayBuffer* stagingBufferForRead();
     JSC::ArrayBuffer* stagingBufferForWrite();
index a649a60..d63f56c 100644 (file)
@@ -46,6 +46,7 @@
 #include "GPUSwapChainDescriptor.h"
 #include "GPUTexture.h"
 #include "GPUTextureDescriptor.h"
+#include <algorithm>
 #include <wtf/Optional.h>
 
 namespace WebCore {
@@ -108,6 +109,40 @@ void GPUDevice::setSwapChain(RefPtr<GPUSwapChain>&& swapChain)
     m_swapChain = WTFMove(swapChain);
 }
 
+void GPUDevice::pushErrorScope(GPUErrorFilter filter)
+{
+    m_errorScopes.append(ErrorScope { filter, WTF::nullopt });
+}
+
+void GPUDevice::popErrorScope(ErrorCallback&& callback)
+{
+    if (!m_platformDevice)
+        callback(WTF::nullopt, "GPUDevice::popErrorScope(): Invalid GPUDevice!");
+    else if (m_errorScopes.isEmpty())
+        callback(WTF::nullopt, "GPUDevice::popErrorScope(): No error scope exists!");
+    else {
+        auto scope = m_errorScopes.takeLast();
+        callback(scope.filter == GPUErrorFilter::None ? WTF::nullopt : WTFMove(scope.error), { });
+    }
+}
+
+void GPUDevice::registerError(const String& message, GPUErrorFilter filter)
+{
+    auto iterator = std::find_if(m_errorScopes.rbegin(), m_errorScopes.rend(), [filter](const ErrorScope& scope) {
+        return scope.filter == GPUErrorFilter::None || scope.filter == filter;
+    });
+
+    // FIXME: https://webkit.org/b/199676 Uncaptured errors need to be fired as GPUUncapturedErrorEvents.
+    if (iterator == m_errorScopes.rend())
+        return;
+
+    // If the scope has already captured an error, ignore this new one.
+    if (iterator->error)
+        return;
+
+    iterator->error = createError(filter, message);
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(WEBGPU)
index a713954..90b461a 100644 (file)
 
 #if ENABLE(WEBGPU)
 
+#include "GPUError.h"
+#include "GPUErrorFilter.h"
 #include "GPUQueue.h"
 #include "GPUSwapChain.h"
+#include <wtf/Function.h>
+#include <wtf/Optional.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RetainPtr.h>
+#include <wtf/Vector.h>
 #include <wtf/WeakPtr.h>
+#include <wtf/text/WTFString.h>
 
 OBJC_PROTOCOL(MTLDevice);
 
@@ -57,7 +63,7 @@ struct GPUSamplerDescriptor;
 struct GPUShaderModuleDescriptor;
 struct GPUSwapChainDescriptor;
 struct GPUTextureDescriptor;
-    
+
 using PlatformDevice = MTLDevice;
 using PlatformDeviceSmartPtr = RetainPtr<MTLDevice>;
 
@@ -84,12 +90,25 @@ public:
     GPUSwapChain* swapChain() const { return m_swapChain.get(); }
     void setSwapChain(RefPtr<GPUSwapChain>&&);
 
+    void pushErrorScope(GPUErrorFilter);
+
+    using ErrorCallback = WTF::Function<void(Optional<GPUError>&&, const String&)>;
+    void popErrorScope(ErrorCallback&&);
+    void registerError(const String&, GPUErrorFilter = GPUErrorFilter::Validation);
+
 private:
+    struct ErrorScope {
+        const GPUErrorFilter filter;
+        Optional<GPUError> error;
+    };
+
     explicit GPUDevice(PlatformDeviceSmartPtr&&);
 
     PlatformDeviceSmartPtr m_platformDevice;
     mutable RefPtr<GPUQueue> m_queue;
     RefPtr<GPUSwapChain> m_swapChain;
+
+    Vector<ErrorScope> m_errorScopes;
 };
 
 } // namespace WebCore
diff --git a/Source/WebCore/platform/graphics/gpu/GPUError.cpp b/Source/WebCore/platform/graphics/gpu/GPUError.cpp
new file mode 100644 (file)
index 0000000..e864a3d
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "GPUError.h"
+
+#if ENABLE(WEBGPU)
+
+#include "GPUErrorFilter.h"
+
+namespace WebCore {
+
+Optional<GPUError> createError(GPUErrorFilter filter, const String& message)
+{
+    switch (filter) {
+    case GPUErrorFilter::OutOfMemory:
+        return GPUError(RefPtr<GPUOutOfMemoryError>(GPUOutOfMemoryError::create()));
+    case GPUErrorFilter::Validation:
+        return GPUError(RefPtr<GPUValidationError>(GPUValidationError::create(message)));
+    default:
+        ASSERT_NOT_REACHED();
+        return WTF::nullopt;
+    }
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)
diff --git a/Source/WebCore/platform/graphics/gpu/GPUError.h b/Source/WebCore/platform/graphics/gpu/GPUError.h
new file mode 100644 (file)
index 0000000..e67c35a
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBGPU)
+
+#include "GPUOutOfMemoryError.h"
+#include "GPUValidationError.h"
+#include <wtf/Optional.h>
+#include <wtf/RefPtr.h>
+#include <wtf/Variant.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+enum class GPUErrorFilter;
+
+using GPUError = Variant<RefPtr<GPUOutOfMemoryError>, RefPtr<GPUValidationError>>;
+
+Optional<GPUError> createError(GPUErrorFilter, const String&);
+
+} // namespace WebCore
+
+#endif
diff --git a/Source/WebCore/platform/graphics/gpu/GPUErrorFilter.h b/Source/WebCore/platform/graphics/gpu/GPUErrorFilter.h
new file mode 100644 (file)
index 0000000..d569fef
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBGPU)
+
+namespace WebCore {
+    
+enum class GPUErrorFilter {
+    None,
+    OutOfMemory,
+    Validation,
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)
diff --git a/Source/WebCore/platform/graphics/gpu/GPUOutOfMemoryError.h b/Source/WebCore/platform/graphics/gpu/GPUOutOfMemoryError.h
new file mode 100644 (file)
index 0000000..9f420e9
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBGPU)
+
+#include <wtf/Ref.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class GPUOutOfMemoryError : public RefCounted<GPUOutOfMemoryError> {
+public:
+    static Ref<GPUOutOfMemoryError> create() { return adoptRef(*new GPUOutOfMemoryError); }
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)
diff --git a/Source/WebCore/platform/graphics/gpu/GPUValidationError.cpp b/Source/WebCore/platform/graphics/gpu/GPUValidationError.cpp
new file mode 100644 (file)
index 0000000..397e545
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "GPUValidationError.h"
+
+#if ENABLE(WEBGPU)
+
+namespace WebCore {
+
+Ref<GPUValidationError> GPUValidationError::create(const String& message)
+{
+    return adoptRef(*new GPUValidationError(message));
+}
+
+GPUValidationError::GPUValidationError(const String& message)
+    : m_message(message)
+{
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)
diff --git a/Source/WebCore/platform/graphics/gpu/GPUValidationError.h b/Source/WebCore/platform/graphics/gpu/GPUValidationError.h
new file mode 100644 (file)
index 0000000..7225ac2
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBGPU)
+
+#include <wtf/Ref.h>
+#include <wtf/RefCounted.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class GPUValidationError : public RefCounted<GPUValidationError> {
+public:
+    static Ref<GPUValidationError> create(const String& message);
+
+    String message() const { return m_message; }
+
+private:
+    explicit GPUValidationError(const String& message);
+
+    String m_message;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)
index 59a07ff..0246031 100644 (file)
@@ -42,7 +42,7 @@ namespace WebCore {
 static constexpr auto readOnlyFlags = OptionSet<GPUBufferUsage::Flags> { GPUBufferUsage::Flags::Index, GPUBufferUsage::Flags::Vertex, GPUBufferUsage::Flags::Uniform, GPUBufferUsage::Flags::TransferSource };
 
 
-bool GPUBuffer::validateBufferUsage(const GPUDevice& device, OptionSet<GPUBufferUsage::Flags> usage)
+bool GPUBuffer::validateBufferUsage(GPUDevice& device, OptionSet<GPUBufferUsage::Flags> usage)
 {
     if (!device.platformDevice()) {
         LOG(WebGPU, "GPUBuffer::tryCreate(): Invalid GPUDevice!");
@@ -50,7 +50,7 @@ bool GPUBuffer::validateBufferUsage(const GPUDevice& device, OptionSet<GPUBuffer
     }
 
     if (usage.containsAll({ GPUBufferUsage::Flags::MapWrite, GPUBufferUsage::Flags::MapRead })) {
-        LOG(WebGPU, "GPUBuffer::tryCreate(): Buffer cannot have both MAP_READ and MAP_WRITE usage!");
+        device.registerError("GPUBuffer::tryCreate(): Buffer cannot have both MAP_READ and MAP_WRITE usage!");
         return false;
     }
 
@@ -67,7 +67,7 @@ RefPtr<GPUBuffer> GPUBuffer::tryCreate(Ref<GPUDevice>&& device, const GPUBufferD
     // MTLBuffer size (NSUInteger) is 32 bits on some platforms.
     NSUInteger size = 0;
     if (!WTF::convertSafely(descriptor.size, size)) {
-        LOG(WebGPU, "GPUBuffer::tryCreate(): Buffer size is too large!");
+        device->registerError("", GPUErrorFilter::OutOfMemory);
         return nullptr;
     }
 
@@ -102,7 +102,7 @@ RefPtr<GPUBuffer> GPUBuffer::tryCreate(Ref<GPUDevice>&& device, const GPUBufferD
     END_BLOCK_OBJC_EXCEPTIONS;
 
     if (!mtlBuffer) {
-        LOG(WebGPU, "GPUBuffer::tryCreate(): Unable to create MTLBuffer!");
+        device->registerError("", GPUErrorFilter::OutOfMemory);
         return nullptr;
     }