[WebGPU] Buffer updates part 1: async mapping functions, unmap, and destroy
authorjustin_fan@apple.com <justin_fan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 23 Feb 2019 23:24:27 +0000 (23:24 +0000)
committerjustin_fan@apple.com <justin_fan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 23 Feb 2019 23:24:27 +0000 (23:24 +0000)
commita80cc295b767e8eb38665163e7915f546881ae66
treeceb43d4b5a94df6532b726cdb94a05b51ca55575
parent68ccbcc7e74ed84089f22176859683fc41c90c26
[WebGPU] Buffer updates part 1: async mapping functions, unmap, and destroy
https://bugs.webkit.org/show_bug.cgi?id=194665

Reviewed by Dean Jackson.

Source/WebCore:

Test: map-write-buffers.html. Other tests updated to match new API.

* Modules/webgpu/WebGPUBindGroupDescriptor.cpp: Added.
(WebCore::validateBufferBindingType): Ensure buffer binding usages match the binding type.
(WebCore::WebGPUBindGroupDescriptor::asGPUBindGroupDescriptor const): Logic moved out from WebGPUDevice.cpp.
* Modules/webgpu/WebGPUBindGroupDescriptor.h:
* Modules/webgpu/WebGPUBuffer.cpp: Added GPUBuffer functionality.
(WebCore::WebGPUBuffer::create):
(WebCore::WebGPUBuffer::WebGPUBuffer):
(WebCore::WebGPUBuffer::mapReadAsync):
(WebCore::WebGPUBuffer::mapWriteAsync):
(WebCore::WebGPUBuffer::unmap):
(WebCore::WebGPUBuffer::destroy):
(WebCore::WebGPUBuffer::rejectOrRegisterPromiseCallback): Register a mapping request on the GPUBuffer, if valid.
* Modules/webgpu/WebGPUBuffer.h:
(WebCore::WebGPUBuffer::buffer const):
(WebCore::WebGPUBuffer::mapping const): Deleted.
* Modules/webgpu/WebGPUBuffer.idl: Update to latest API and enable every function except setSubData.
* Modules/webgpu/WebGPUCommandBuffer.cpp:
(WebCore::WebGPUCommandBuffer::beginRenderPass): Renamed descriptor conversion method.
* Modules/webgpu/WebGPUDevice.cpp:
(WebCore::WebGPUDevice::createBuffer const): Update to non-nullable return type.
(WebCore::WebGPUDevice::createBindGroup const): Move descriptor validation logic to descriptor implementation.
* Modules/webgpu/WebGPUDevice.h:
* Modules/webgpu/WebGPURenderPassDescriptor.cpp:
(WebCore::WebGPURenderPassDescriptor::asGPURenderPassDescriptor const): Renamed from validateAndConvertToGPUVersion.
* Modules/webgpu/WebGPURenderPassEncoder.cpp:
(WebCore::WebGPURenderPassEncoder::setVertexBuffers): Add validation for submitted buffers.
* platform/graphics/gpu/GPUBuffer.cpp: Added.
(WebCore::GPUBuffer::PendingMappingCallback::PendingMappingCallback): New struct for retaining a reference to mapping callbacks.
* platform/graphics/gpu/GPUBuffer.h: Add functionality to retain callbacks and usage bits.
(WebCore::GPUBuffer::isVertex const):
(WebCore::GPUBuffer::isUniform const):
(WebCore::GPUBuffer::isStorage const):
(WebCore::GPUBuffer::isReadOnly const):
(WebCore::GPUBuffer::PendingMapPromise::create):
(WebCore::GPUBuffer::isMappable const):
(WebCore::GPUBuffer::isMapWriteable const):
(WebCore::GPUBuffer::isMapReadable const):
(WebCore::GPUBuffer::mapping const): Deleted.
* platform/graphics/gpu/GPUBufferUsage.h: enum class cannot be logical ORed together.
* platform/graphics/gpu/GPUDevice.cpp:
(WebCore::GPUDevice::tryCreateBuffer const): Renamed from createBuffer.
(WebCore::GPUDevice::createBuffer const): Deleted.
* platform/graphics/gpu/GPUDevice.h:
* platform/graphics/gpu/cocoa/GPUBufferMetal.mm:
(WebCore::GPUBuffer::tryCreateSharedBuffer): Attempt to create a MTLBuffer with shared memory.
(WebCore::GPUBuffer::tryCreate): No longer use Gigacage-allocated memory for MTLBuffer.
(WebCore::GPUBuffer::GPUBuffer):
(WebCore::GPUBuffer::~GPUBuffer):
(WebCore::GPUBuffer::registerMappingCallback): Register the provided callback to be executed when the staging buffer can be safely exposed.
(WebCore::GPUBuffer::stagingBufferForRead): Prepare the arrayBuffer for reading and run the mapping callback.
(WebCore::GPUBuffer::stagingBufferForWrite): Ditto, but for writing.
(WebCore::GPUBuffer::unmap): If needed, copy the staging ArrayBuffer to the MTLBuffer. Unregister any mapping callback.
(WebCore::GPUBuffer::destroy): Stub implementation for now. Frees the MTLBuffer as soon as possible.
(WebCore::GPUBuffer::create): Deleted.
* platform/graphics/gpu/cocoa/GPUProgrammablePassEncoderMetal.mm:
(WebCore::GPUProgrammablePassEncoder::setResourceAsBufferOnEncoder): Ensure only read-only GPUBuffers are used as read-only on the GPU.

Add symbols for new files:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:

LayoutTests:

Rewrite buffers.html -> map-write-buffers.html to test new functionality. Rewrite other affected
tests to use mapWriteAsync.

* webgpu/buffer-resource-triangles.html:
* webgpu/buffers-expected.txt: Renamed to map-write-buffers-expected.txt.
* webgpu/buffers.html: Renamed to map-write-buffers.html.
* webgpu/depth-enabled-triangle-strip.html:
* webgpu/map-write-buffers-expected.txt: Renamed from buffers-expected.txt.
* webgpu/map-write-buffers.html: Renamed from buffers.html.
* webgpu/vertex-buffer-triangle-strip.html:

* platform/mac/TestExpectations: Skip all webgpu tests on macOS 10.12 bots.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@241996 268f45cc-cd09-0410-ab3c-d52691b4dbfc
30 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/mac/TestExpectations
LayoutTests/webgpu/buffer-resource-triangles.html
LayoutTests/webgpu/buffers-expected.txt [deleted file]
LayoutTests/webgpu/buffers.html [deleted file]
LayoutTests/webgpu/depth-enabled-triangle-strip.html
LayoutTests/webgpu/map-write-buffers-expected.txt [new file with mode: 0644]
LayoutTests/webgpu/map-write-buffers.html [new file with mode: 0644]
LayoutTests/webgpu/vertex-buffer-triangle-strip.html
Source/WebCore/ChangeLog
Source/WebCore/Modules/webgpu/WebGPUBindGroupDescriptor.cpp [new file with mode: 0644]
Source/WebCore/Modules/webgpu/WebGPUBindGroupDescriptor.h
Source/WebCore/Modules/webgpu/WebGPUBuffer.cpp
Source/WebCore/Modules/webgpu/WebGPUBuffer.h
Source/WebCore/Modules/webgpu/WebGPUBuffer.idl
Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.cpp
Source/WebCore/Modules/webgpu/WebGPUDevice.cpp
Source/WebCore/Modules/webgpu/WebGPUDevice.h
Source/WebCore/Modules/webgpu/WebGPURenderPassDescriptor.cpp
Source/WebCore/Modules/webgpu/WebGPURenderPassDescriptor.h
Source/WebCore/Modules/webgpu/WebGPURenderPassEncoder.cpp
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/graphics/gpu/GPUBuffer.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/gpu/GPUBuffer.h
Source/WebCore/platform/graphics/gpu/GPUBufferUsage.h
Source/WebCore/platform/graphics/gpu/GPUDevice.cpp
Source/WebCore/platform/graphics/gpu/GPUDevice.h
Source/WebCore/platform/graphics/gpu/cocoa/GPUBufferMetal.mm
Source/WebCore/platform/graphics/gpu/cocoa/GPUProgrammablePassEncoderMetal.mm