[WebGPU] Move error scopes out of GPUDevice for more portable error generation
authorjustin_fan@apple.com <justin_fan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 Jul 2019 21:07:49 +0000 (21:07 +0000)
committerjustin_fan@apple.com <justin_fan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 Jul 2019 21:07:49 +0000 (21:07 +0000)
commitefe12ed1653c7e5d400605d7b0149832b243469e
treed104350007a43d8c97c2583c30f0919ac05eaeda
parent1c2e22f8d0b3ef232efc5c1de10339ad85563015
[WebGPU] Move error scopes out of GPUDevice for more portable error generation
https://bugs.webkit.org/show_bug.cgi?id=199740

Reviewed by Myles C. Maxfield.

Move error generation into a separate RefCounted class to allow GPU objects to generate
errors independent of any GPUDevice.
Create GPUObjectBase to delegate error generation and refactor GPUBuffer to inherit from GPUObjectBase.

No behavior change or new tests. Error scopes covered by error-scopes-test.html.

* Modules/webgpu/WebGPUDevice.cpp:
(WebCore::WebGPUDevice::WebGPUDevice): Now creates a GPUErrorGenerator.
(WebCore::WebGPUDevice::createBuffer const): Pass the GPUErrorGenerator to any created GPUBuffer.
(WebCore::WebGPUDevice::createBufferMapped const): Ditto.
(WebCore::WebGPUDevice::popErrorScope): Shouldn't be const. Can just ask for the GPUError rather than passing a lambda.
(WebCore::WebGPUDevice::pushErrorScope const): Deleted.
(WebCore::WebGPUDevice::popErrorScope const): Deleted.
* Modules/webgpu/WebGPUDevice.h:
(WebCore::WebGPUDevice::pushErrorScope):
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* platform/graphics/gpu/GPUBuffer.h: Now inherits from GPUObjectBase for error generation ease.
* platform/graphics/gpu/GPUDevice.cpp:
(WebCore::GPUDevice::tryCreateBuffer): Ensure GPUBuffers reference the GPUErrorGenerator.
(WebCore::GPUDevice::pushErrorScope): Deleted. No longer needed here.
(WebCore::GPUDevice::popErrorScope): Deleted.
(WebCore::GPUDevice::registerError): Deleted.
* platform/graphics/gpu/GPUDevice.h: Move error scope logic out.
* platform/graphics/gpu/GPUErrorGenerator.cpp: Added.
(WebCore::GPUErrorGenerator::pushErrorScope):
(WebCore::GPUErrorGenerator::popErrorScope):
(WebCore::GPUErrorGenerator::generateError):
* platform/graphics/gpu/GPUErrorGenerator.h: Added.
(WebCore::GPUErrorGenerator::create):
* platform/graphics/gpu/GPUObjectBase.h: Added.
(WebCore::GPUObjectBase::generateError):
(WebCore::GPUObjectBase::GPUObjectBase):
* platform/graphics/gpu/cocoa/GPUBufferMetal.mm: Use the GPUErrorGenerator directly during buffer creation.
(WebCore::GPUBuffer::validateBufferUsage):
(WebCore::GPUBuffer::tryCreate):
(WebCore::GPUBuffer::GPUBuffer):
* platform/graphics/gpu/cocoa/GPUQueueMetal.mm:
(WebCore::GPUQueue::submit): Prevent possible null dereference.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@247397 268f45cc-cd09-0410-ab3c-d52691b4dbfc
14 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/webgpu/WebGPUDevice.cpp
Source/WebCore/Modules/webgpu/WebGPUDevice.h
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/graphics/gpu/GPUBuffer.h
Source/WebCore/platform/graphics/gpu/GPUBufferDescriptor.h
Source/WebCore/platform/graphics/gpu/GPUDevice.cpp
Source/WebCore/platform/graphics/gpu/GPUDevice.h
Source/WebCore/platform/graphics/gpu/GPUErrorScopes.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/gpu/GPUErrorScopes.h [new file with mode: 0644]
Source/WebCore/platform/graphics/gpu/GPUObjectBase.h [new file with mode: 0644]
Source/WebCore/platform/graphics/gpu/cocoa/GPUBufferMetal.mm
Source/WebCore/platform/graphics/gpu/cocoa/GPUQueueMetal.mm