[Web GPU] Indexed drawing and GPUCommandEncoder crash prevention
authorjustin_fan@apple.com <justin_fan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Apr 2019 20:48:38 +0000 (20:48 +0000)
committerjustin_fan@apple.com <justin_fan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Apr 2019 20:48:38 +0000 (20:48 +0000)
commit56e0272876c6999fe6fb3586815890a461423907
tree246fc8fc97bdda0a1020a0419e54c34720d519c7
parent79c5bad70bc66805057b747dd35938ded99fee97
[Web GPU] Indexed drawing and GPUCommandEncoder crash prevention
https://bugs.webkit.org/show_bug.cgi?id=196758

Reviewed by Dean Jackson.

Source/WebCore:

Test: webgpu/draw-indexed-triangles.html

Implement GPURenderPassEncoder::setIndexBuffer and GPURenderPassEncoder::drawIndexed to enable indexed drawing.
Disable GPUCommandEncoders with active pass encoders from being submitted or encoding blits.

Prevent active GPUCommandEncoders from being submitted or encoding blit commands:
* Modules/webgpu/WebGPUCommandEncoder.cpp:
(WebCore::WebGPUCommandEncoder::finish):
* platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm:
(WebCore::GPUCommandBuffer::copyBufferToBuffer):
(WebCore::GPUCommandBuffer::copyBufferToTexture):
(WebCore::GPUCommandBuffer::copyTextureToBuffer):
(WebCore::GPUCommandBuffer::copyTextureToTexture):

Implement GPURenderPassEncoder::setIndexBuffer and GPURenderPassEncoder::drawIndexed:
* Modules/webgpu/WebGPURenderPassEncoder.cpp:
(WebCore::WebGPURenderPassEncoder::setIndexBuffer):
(WebCore::WebGPURenderPassEncoder::setVertexBuffers): Remove unnecessary move operations.
(WebCore::WebGPURenderPassEncoder::drawIndexed): Added.
* Modules/webgpu/WebGPURenderPassEncoder.h:
* Modules/webgpu/WebGPURenderPassEncoder.idl:
* platform/graphics/gpu/GPUBuffer.h:
(WebCore::GPUBuffer::isIndex const):
* platform/graphics/gpu/GPUInputStateDescriptor.h:
* platform/graphics/gpu/GPURenderPassEncoder.h: Cache the index buffer, as Metal does not set the index buffer separate from the draw call.
* platform/graphics/gpu/GPURenderPipeline.h:
(WebCore::GPURenderPipeline::indexFormat const):
* platform/graphics/gpu/cocoa/GPURenderPassEncoderMetal.mm:
(WebCore::GPURenderPassEncoder::setIndexBuffer):
(WebCore::GPURenderPassEncoder::setVertexBuffers):
(WebCore::mtlPrimitiveTypeForGPUPrimitiveTopology):
(WebCore::GPURenderPassEncoder::draw):
(WebCore::mtlIndexTypeForGPUIndexFormat): Added.
(WebCore::GPURenderPassEncoder::drawIndexed): Added.
(WebCore::primitiveTypeForGPUPrimitiveTopology): Deleted.
* platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm:
(WebCore::GPURenderPipeline::tryCreate):
(WebCore::GPURenderPipeline::GPURenderPipeline):

LayoutTests:

Add draw-indexed-triangles to test drawing a green square using GPURenderPassEncoder::setIndexBuffer and drawIndexed.

* webgpu/draw-indexed-triangles-expected.html: Added.
* webgpu/draw-indexed-triangles.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244147 268f45cc-cd09-0410-ab3c-d52691b4dbfc
15 files changed:
LayoutTests/ChangeLog
LayoutTests/webgpu/draw-indexed-triangles-expected.html [new file with mode: 0644]
LayoutTests/webgpu/draw-indexed-triangles.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/webgpu/WebGPUCommandEncoder.cpp
Source/WebCore/Modules/webgpu/WebGPURenderPassEncoder.cpp
Source/WebCore/Modules/webgpu/WebGPURenderPassEncoder.h
Source/WebCore/Modules/webgpu/WebGPURenderPassEncoder.idl
Source/WebCore/platform/graphics/gpu/GPUBuffer.h
Source/WebCore/platform/graphics/gpu/GPUInputStateDescriptor.h
Source/WebCore/platform/graphics/gpu/GPURenderPassEncoder.h
Source/WebCore/platform/graphics/gpu/GPURenderPipeline.h
Source/WebCore/platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm
Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPassEncoderMetal.mm
Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm