Skip to content

Commit

Permalink
[WebGPU] api,validation,error_scope,* is failing
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=267287
<radar://120727304>

Reviewed by Tadeu Zagallo.

Add validation and passing expectations for api,validation,error_scope,*

* LayoutTests/http/tests/webgpu/webgpu/api/validation/error_scope-expected.txt:
* Source/WebCore/Modules/WebGPU/GPUAdapter.cpp:
(WebCore::GPUAdapter::requestDevice):
* Source/WebCore/Modules/WebGPU/GPUDevice.cpp:
(WebCore::createGPUErrorFromWebGPUError):
(WebCore::GPUDevice::popErrorScope):
(WebCore::GPUDevice::addEventListener):
* Source/WebCore/Modules/WebGPU/GPUDevice.h:
* Source/WebCore/Modules/WebGPU/GPUUncapturedErrorEvent.cpp:
(WebCore::GPUUncapturedErrorEvent::GPUUncapturedErrorEvent):
(WebCore::GPUUncapturedErrorEvent::error const):
(WebCore::GPUUncapturedErrorEvent::eventInterface const):
* Source/WebCore/Modules/WebGPU/GPUUncapturedErrorEvent.h:
* Source/WebCore/Modules/WebGPU/GPUUncapturedErrorEvent.idl:
* Source/WebCore/Modules/WebGPU/Implementation/WebGPUDeviceImpl.cpp:
(WebCore::WebGPU::DeviceImpl::~DeviceImpl):
(WebCore::WebGPU::setUncapturedScopeCallback):
(WebCore::WebGPU::DeviceImpl::popErrorScope):
(WebCore::WebGPU::DeviceImpl::resolveUncapturedErrorEvent):
* Source/WebCore/Modules/WebGPU/Implementation/WebGPUDeviceImpl.h:
* Source/WebCore/Modules/WebGPU/InternalAPI/WebGPUDevice.h:
* Source/WebCore/Modules/WebGPU/InternalAPI/WebGPUError.h:
* Source/WebCore/dom/EventInterfaces.in:
* Source/WebCore/dom/TaskSource.h:
* Source/WebCore/html/HTMLAttributeNames.in:
* Source/WebGPU/WebGPU/Device.mm:
(WebGPU::Device::generateAValidationError):
(WebGPU::Device::generateAnOutOfMemoryError):
(WebGPU::Device::generateAnInternalError):
(WebGPU::Device::popErrorScope):
* Source/WebGPU/WebGPU/Texture.mm:
(WebGPU::Device::createTexture):
* Source/WebKit/CMakeLists.txt:
* Source/WebKit/DerivedSources-input.xcfilelist:
* Source/WebKit/DerivedSources.make:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteDevice.cpp:
(WebKit::RemoteDevice::popErrorScope):
(WebKit::RemoteDevice::resolveUncapturedErrorEvent):
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteDevice.h:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteDevice.messages.in:
* Source/WebKit/Shared/WebGPU/WebGPUError.cpp:
(WebKit::WebGPU::ConvertToBackingContext::convertToBacking):
(WebKit::WebGPU::ConvertFromBackingContext::convertFromBacking):
* Source/WebKit/Shared/WebGPU/WebGPUError.h:
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:
* Source/WebKit/WebProcess/GPU/graphics/WebGPU/RemoteDeviceProxy.cpp:
(WebKit::WebGPU::RemoteDeviceProxy::popErrorScope):
(WebKit::WebGPU::RemoteDeviceProxy::resolveUncapturedErrorEvent):
* Source/WebKit/WebProcess/GPU/graphics/WebGPU/RemoteDeviceProxy.h:

Canonical link: https://commits.webkit.org/274229@main
  • Loading branch information
mwyrzykowski committed Feb 7, 2024
1 parent 3fb7287 commit 63997b1
Show file tree
Hide file tree
Showing 33 changed files with 324 additions and 122 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
(Populate me when we're ready to investigate this test)

PASS :simple:errorType="out-of-memory";errorFilter="internal"
PASS :simple:errorType="out-of-memory";errorFilter="out-of-memory"
PASS :simple:errorType="out-of-memory";errorFilter="validation"
PASS :simple:errorType="validation";errorFilter="internal"
PASS :simple:errorType="validation";errorFilter="out-of-memory"
PASS :simple:errorType="validation";errorFilter="validation"
PASS :empty:
PASS :parent_scope:errorFilter="out-of-memory";stackDepth=1
PASS :parent_scope:errorFilter="out-of-memory";stackDepth=10
PASS :parent_scope:errorFilter="out-of-memory";stackDepth=100
PASS :parent_scope:errorFilter="out-of-memory";stackDepth=1000
PASS :parent_scope:errorFilter="validation";stackDepth=1
PASS :parent_scope:errorFilter="validation";stackDepth=10
PASS :parent_scope:errorFilter="validation";stackDepth=100
PASS :parent_scope:errorFilter="validation";stackDepth=1000
PASS :current_scope:errorFilter="out-of-memory";stackDepth=1
PASS :current_scope:errorFilter="out-of-memory";stackDepth=10
PASS :current_scope:errorFilter="out-of-memory";stackDepth=100
PASS :current_scope:errorFilter="out-of-memory";stackDepth=1000
PASS :current_scope:errorFilter="out-of-memory";stackDepth=100000
PASS :current_scope:errorFilter="validation";stackDepth=1
PASS :current_scope:errorFilter="validation";stackDepth=10
PASS :current_scope:errorFilter="validation";stackDepth=100
PASS :current_scope:errorFilter="validation";stackDepth=1000
PASS :current_scope:errorFilter="validation";stackDepth=100000
PASS :balanced_siblings:errorFilter="internal";numErrors=1
PASS :balanced_siblings:errorFilter="internal";numErrors=10
PASS :balanced_siblings:errorFilter="internal";numErrors=100
PASS :balanced_siblings:errorFilter="internal";numErrors=1000
PASS :balanced_siblings:errorFilter="out-of-memory";numErrors=1
PASS :balanced_siblings:errorFilter="out-of-memory";numErrors=10
PASS :balanced_siblings:errorFilter="out-of-memory";numErrors=100
PASS :balanced_siblings:errorFilter="out-of-memory";numErrors=1000
PASS :balanced_siblings:errorFilter="validation";numErrors=1
PASS :balanced_siblings:errorFilter="validation";numErrors=10
PASS :balanced_siblings:errorFilter="validation";numErrors=100
PASS :balanced_siblings:errorFilter="validation";numErrors=1000
PASS :balanced_nesting:errorFilter="internal";numErrors=1
PASS :balanced_nesting:errorFilter="internal";numErrors=10
PASS :balanced_nesting:errorFilter="internal";numErrors=100
PASS :balanced_nesting:errorFilter="internal";numErrors=1000
PASS :balanced_nesting:errorFilter="out-of-memory";numErrors=1
PASS :balanced_nesting:errorFilter="out-of-memory";numErrors=10
PASS :balanced_nesting:errorFilter="out-of-memory";numErrors=100
PASS :balanced_nesting:errorFilter="out-of-memory";numErrors=1000
PASS :balanced_nesting:errorFilter="validation";numErrors=1
PASS :balanced_nesting:errorFilter="validation";numErrors=10
PASS :balanced_nesting:errorFilter="validation";numErrors=100
PASS :balanced_nesting:errorFilter="validation";numErrors=1000

42 changes: 21 additions & 21 deletions LayoutTests/platform/mac-wk2/TestExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -1879,31 +1879,31 @@ webkit.org/b/263396 css3/color/text.html [ Skip ]
webkit.org/b/263754 [ Sonoma+ x86_64 ] css3/filters/effect-drop-shadow-clip-abspos.html [ ImageOnlyFailure ]

# WebGPU
http/tests/webgpu/webgpu/idl/constructable.html [ Pass ]
http/tests/webgpu/webgpu/idl/constants/flags.html [ Pass ]
http/tests/webgpu/webgpu/idl/constructable.html [ Skip ]
http/tests/webgpu/webgpu/idl/constants/flags.html [ Skip ]

http/tests/webgpu/webgpu/api/operation/compute_pipeline/overrides.html [ Pass ]
http/tests/webgpu/webgpu/api/operation/device/lost.html [ Pass ]
http/tests/webgpu/webgpu/api/operation/rendering/stencil.html [ Pass ]
http/tests/webgpu/webgpu/api/operation/rendering/indirect_draw.html [ Pass ]
http/tests/webgpu/webgpu/api/operation/compute_pipeline/overrides.html [ Skip ]
http/tests/webgpu/webgpu/api/operation/device/lost.html [ Skip ]
http/tests/webgpu/webgpu/api/operation/rendering/stencil.html [ Skip ]
http/tests/webgpu/webgpu/api/operation/rendering/indirect_draw.html [ Skip ]
http/tests/webgpu/webgpu/api/operation/reflection.html [ Skip ]
http/tests/webgpu/webgpu/api/operation/vertex_state/index_format.html [ Pass ]
http/tests/webgpu/webgpu/api/operation/rendering/draw.html [ Pass ]
http/tests/webgpu/webgpu/api/operation/vertex_state/index_format.html [ Skip ]
http/tests/webgpu/webgpu/api/operation/rendering/draw.html [ Skip ]
http/tests/webgpu/webgpu/api/operation/sampling/filter_mode.html [ Skip ]
http/tests/webgpu/webgpu/api/operation/sampling/lod_clamp.html [ Pass ]
http/tests/webgpu/webgpu/api/operation/sampling/anisotropy.html [ Pass ]
http/tests/webgpu/webgpu/api/operation/adapter/requestAdapterInfo.html [ Pass ]
http/tests/webgpu/webgpu/api/operation/adapter/requestAdapter.html [ Pass ]
http/tests/webgpu/webgpu/api/operation/sampling/lod_clamp.html [ Skip ]
http/tests/webgpu/webgpu/api/operation/sampling/anisotropy.html [ Skip ]
http/tests/webgpu/webgpu/api/operation/adapter/requestAdapterInfo.html [ Skip ]
http/tests/webgpu/webgpu/api/operation/adapter/requestAdapter.html [ Skip ]
http/tests/webgpu/webgpu/api/operation/adapter/requestDevice.html [ Skip ]
http/tests/webgpu/webgpu/api/operation/onSubmittedWorkDone.html [ Pass ]
http/tests/webgpu/webgpu/api/operation/queue/writeBuffer.html [ Pass ]
http/tests/webgpu/webgpu/api/operation/render_pipeline/culling_tests.html [ Pass ]
http/tests/webgpu/webgpu/api/operation/render_pipeline/overrides.html [ Pass ]
http/tests/webgpu/webgpu/api/operation/render_pipeline/primitive_topology.html [ Pass ]
http/tests/webgpu/webgpu/api/operation/memory_sync/buffer/single_buffer.html [ Pass ]
http/tests/webgpu/webgpu/api/operation/memory_sync/buffer/multiple_buffers.html [ Pass ]
http/tests/webgpu/webgpu/api/operation/memory_sync/texture/same_subresource.html [ Pass ]
http/tests/webgpu/webgpu/api/operation/command_buffer/programmable/state_tracking.html [ Pass ]
http/tests/webgpu/webgpu/api/operation/onSubmittedWorkDone.html [ Skip ]
http/tests/webgpu/webgpu/api/operation/queue/writeBuffer.html [ Skip ]
http/tests/webgpu/webgpu/api/operation/render_pipeline/culling_tests.html [ Skip ]
http/tests/webgpu/webgpu/api/operation/render_pipeline/overrides.html [ Skip ]
http/tests/webgpu/webgpu/api/operation/render_pipeline/primitive_topology.html [ Skip ]
http/tests/webgpu/webgpu/api/operation/memory_sync/buffer/single_buffer.html [ Skip ]
http/tests/webgpu/webgpu/api/operation/memory_sync/buffer/multiple_buffers.html [ Skip ]
http/tests/webgpu/webgpu/api/operation/memory_sync/texture/same_subresource.html [ Skip ]
http/tests/webgpu/webgpu/api/operation/command_buffer/programmable/state_tracking.html [ Skip ]

webkit.org/b/263920 svg/transforms/transformed-text-fill-gradient.html [ Pass ImageOnlyFailure ]

Expand Down
11 changes: 7 additions & 4 deletions Source/WebCore/Modules/WebGPU/GPUAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,18 @@ static WebGPU::DeviceDescriptor convertToBacking(const std::optional<GPUDeviceDe
return options->convertToBacking();
}

void GPUAdapter::requestDevice(ScriptExecutionContext&, const std::optional<GPUDeviceDescriptor>& deviceDescriptor, RequestDevicePromise&& promise)
void GPUAdapter::requestDevice(ScriptExecutionContext& scriptExecutionContext, const std::optional<GPUDeviceDescriptor>& deviceDescriptor, RequestDevicePromise&& promise)
{
m_backing->requestDevice(convertToBacking(deviceDescriptor), [deviceDescriptor, promise = WTFMove(promise)](RefPtr<WebGPU::Device>&& device) mutable {
m_backing->requestDevice(convertToBacking(deviceDescriptor), [deviceDescriptor, promise = WTFMove(promise), scriptExecutionContextRef = Ref { scriptExecutionContext }](RefPtr<WebGPU::Device>&& device) mutable {
if (!device.get())
promise.reject(Exception(ExceptionCode::OperationError));
else if (deviceDescriptor && deviceDescriptor->requiredFeatures.size() > device->features().features().size())
promise.reject(Exception(ExceptionCode::TypeError));
else
promise.resolve(GPUDevice::create(nullptr, device.releaseNonNull()));
else {
Ref<GPUDevice> gpuDevice = GPUDevice::create(scriptExecutionContextRef.ptr(), device.releaseNonNull());
gpuDevice->suspendIfNeeded();
promise.resolve(WTFMove(gpuDevice));
}
});
}

Expand Down
51 changes: 39 additions & 12 deletions Source/WebCore/Modules/WebGPU/GPUDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "GPUDevice.h"

#include "DOMPromiseProxy.h"
#include "EventNames.h"
#include "GPUBindGroup.h"
#include "GPUBindGroupDescriptor.h"
#include "GPUBindGroupLayout.h"
Expand Down Expand Up @@ -57,13 +58,15 @@
#include "GPUSupportedLimits.h"
#include "GPUTexture.h"
#include "GPUTextureDescriptor.h"
#include "GPUUncapturedErrorEvent.h"
#include "JSDOMPromiseDeferred.h"
#include "JSGPUComputePipeline.h"
#include "JSGPUDeviceLostInfo.h"
#include "JSGPUInternalError.h"
#include "JSGPUOutOfMemoryError.h"
#include "JSGPUPipelineError.h"
#include "JSGPURenderPipeline.h"
#include "JSGPUUncapturedErrorEvent.h"
#include "JSGPUValidationError.h"
#include <wtf/IsoMallocInlines.h>

Expand Down Expand Up @@ -277,24 +280,48 @@ void GPUDevice::pushErrorScope(GPUErrorFilter errorFilter)
m_backing->pushErrorScope(convertToBacking(errorFilter));
}

static GPUError createGPUErrorFromWebGPUError(auto& webGPUError)
{
return WTF::switchOn(WTFMove(*webGPUError), [](Ref<WebGPU::OutOfMemoryError>&& outOfMemoryError) {
GPUError error = RefPtr<GPUOutOfMemoryError>(GPUOutOfMemoryError::create(WTFMove(outOfMemoryError)));
return error;
}, [](Ref<WebGPU::ValidationError>&& validationError) {
GPUError error = RefPtr<GPUValidationError>(GPUValidationError::create(WTFMove(validationError)));
return error;
}, [](Ref<WebGPU::InternalError>&& internalError) {
GPUError error = RefPtr<GPUInternalError>(GPUInternalError::create(WTFMove(internalError)));
return error;
});
}

void GPUDevice::popErrorScope(ErrorScopePromise&& errorScopePromise)
{
m_backing->popErrorScope([promise = WTFMove(errorScopePromise)](std::optional<WebGPU::Error>&& error) mutable {
m_backing->popErrorScope([promise = WTFMove(errorScopePromise)](bool success, std::optional<WebGPU::Error>&& error) mutable {
if (!error) {
promise.resolve(std::nullopt);
if (success)
promise.resolve(std::nullopt);
else
promise.reject(Exception { ExceptionCode::OperationError, "popErrorScope failed"_s });
return;
}
WTF::switchOn(WTFMove(*error), [&promise](Ref<WebGPU::OutOfMemoryError>&& outOfMemoryError) {
GPUError error = RefPtr<GPUOutOfMemoryError>(GPUOutOfMemoryError::create(WTFMove(outOfMemoryError)));
promise.resolve(error);
}, [&promise](Ref<WebGPU::ValidationError>&& validationError) {
GPUError error = RefPtr<GPUValidationError>(GPUValidationError::create(WTFMove(validationError)));
promise.resolve(error);
}, [&promise](Ref<WebGPU::InternalError>&& internalError) {
GPUError error = RefPtr<GPUInternalError>(GPUInternalError::create(WTFMove(internalError)));
promise.resolve(error);
});
promise.resolve(createGPUErrorFromWebGPUError(error));
});
}

bool GPUDevice::addEventListener(const AtomString& eventType, Ref<EventListener>&& eventListener, const AddEventListenerOptions& options)
{
auto result = EventTarget::addEventListener(eventType, WTFMove(eventListener), options);
#if PLATFORM(COCOA)
if (eventType == WebCore::eventNames().uncapturederrorEvent) {
m_backing->resolveUncapturedErrorEvent([eventType, weakThis = WeakPtr { *this }](bool hasUncapturedError, std::optional<WebGPU::Error>&& error) {
if (!weakThis || !hasUncapturedError)
return;

queueTaskToDispatchEvent(*weakThis.get(), TaskSource::WebGPU, GPUUncapturedErrorEvent::create(WebCore::eventNames().uncapturederrorEvent, GPUUncapturedErrorEventInit { .error = createGPUErrorFromWebGPUError(error) }));
});
}
#endif
return result;
}

}
2 changes: 2 additions & 0 deletions Source/WebCore/Modules/WebGPU/GPUDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ class GPUDevice : public RefCounted<GPUDevice>, public ActiveDOMObject, public E
using ErrorScopePromise = DOMPromiseDeferred<IDLNullable<IDLUnion<IDLInterface<GPUOutOfMemoryError>, IDLInterface<GPUValidationError>, IDLInterface<GPUInternalError>>>>;
void popErrorScope(ErrorScopePromise&&);

bool addEventListener(const AtomString& eventType, Ref<EventListener>&&, const AddEventListenerOptions&) override;

using LostPromise = DOMPromiseProxy<IDLInterface<GPUDeviceLostInfo>>;
LostPromise& lost();

Expand Down
21 changes: 11 additions & 10 deletions Source/WebCore/Modules/WebGPU/GPUUncapturedErrorEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,20 @@ namespace WebCore {

WTF_MAKE_ISO_ALLOCATED_IMPL(GPUUncapturedErrorEvent);

GPUError GPUUncapturedErrorEvent::error() const
GPUUncapturedErrorEvent::GPUUncapturedErrorEvent(const AtomString& type, GPUUncapturedErrorEventInit&& uncapturedErrorEventInit)
: Event(type, uncapturedErrorEventInit, IsTrusted::Yes)
, m_uncapturedErrorEventInit(WTFMove(uncapturedErrorEventInit))
{
if (!m_backing)
return m_uncapturedErrorEventInit.error;
}

return WTF::switchOn(WebGPU::Error(m_backing->error()), [](Ref<WebGPU::OutOfMemoryError>&& outOfMemoryError) -> GPUError {
return RefPtr<GPUOutOfMemoryError>(GPUOutOfMemoryError::create(WTFMove(outOfMemoryError)));
}, [](Ref<WebGPU::ValidationError>&& validationError) -> GPUError {
return RefPtr<GPUValidationError>(GPUValidationError::create(WTFMove(validationError)));
}, [](Ref<WebGPU::InternalError>&& internalError) -> GPUError {
return RefPtr<GPUInternalError>(GPUInternalError::create(WTFMove(internalError)));
});
GPUError GPUUncapturedErrorEvent::error() const
{
return m_uncapturedErrorEventInit.error;
}

EventInterface GPUUncapturedErrorEvent::eventInterface() const
{
return GPUUncapturedErrorEventInterfaceType;
}

}
Expand Down
25 changes: 5 additions & 20 deletions Source/WebCore/Modules/WebGPU/GPUUncapturedErrorEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,36 +38,21 @@ namespace WebCore {
class GPUUncapturedErrorEvent final : public Event {
WTF_MAKE_ISO_ALLOCATED(GPUUncapturedErrorEvent);
public:
static Ref<GPUUncapturedErrorEvent> create(String&& type, const GPUUncapturedErrorEventInit& gpuUncapturedErrorEventInitDict)
{
return adoptRef(*new GPUUncapturedErrorEvent(WTFMove(type), gpuUncapturedErrorEventInitDict));
}
virtual ~GPUUncapturedErrorEvent() = default;

static Ref<GPUUncapturedErrorEvent> create(Ref<WebGPU::UncapturedErrorEvent>&& backing)
static Ref<GPUUncapturedErrorEvent> create(const AtomString& type, GPUUncapturedErrorEventInit&& gpuUncapturedErrorEventInitDict)
{
return adoptRef(*new GPUUncapturedErrorEvent(WTFMove(backing)));
return adoptRef(*new GPUUncapturedErrorEvent(type, WTFMove(gpuUncapturedErrorEventInitDict)));
}

GPUError error() const;

WebGPU::UncapturedErrorEvent* backing() { return m_backing.get(); }
const WebGPU::UncapturedErrorEvent* backing() const { return m_backing.get(); }
EventInterface eventInterface() const override;

private:
GPUUncapturedErrorEvent(String&& type, const GPUUncapturedErrorEventInit& uncapturedErrorEventInit)
: m_type(WTFMove(type))
, m_uncapturedErrorEventInit(uncapturedErrorEventInit)
{
}

GPUUncapturedErrorEvent(Ref<WebGPU::UncapturedErrorEvent>&& backing)
: m_backing(WTFMove(backing))
{
}
GPUUncapturedErrorEvent(const AtomString&, GPUUncapturedErrorEventInit&&);

String m_type;
GPUUncapturedErrorEventInit m_uncapturedErrorEventInit;
RefPtr<WebGPU::UncapturedErrorEvent> m_backing;
};

}
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/WebGPU/GPUUncapturedErrorEvent.idl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ typedef (GPUOutOfMemoryError or GPUValidationError or GPUInternalError) GPUError
]
interface GPUUncapturedErrorEvent : Event {
constructor(
DOMString type,
[AtomString] DOMString type,
GPUUncapturedErrorEventInit gpuUncapturedErrorEventInitDict
);
readonly attribute GPUError error;
Expand Down
Loading

0 comments on commit 63997b1

Please sign in to comment.