| Differences between
and this patch
- a/Source/WebCore/ChangeLog +121 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2019-03-05  Justin Fan  <justin_fan@apple.com>
2
3
        [Web GPU] GPUTexture and GPUTextureView updates, and related GPUBindGroup updates
4
        https://bugs.webkit.org/show_bug.cgi?id=195347
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        Test: webgpu/texture-triangle-strip.html
9
10
        * Modules/webgpu/WebGPUBindGroupDescriptor.cpp:
11
        (WebCore::WebGPUBindGroupDescriptor::asGPUBindGroupDescriptor const): Update to validate GPUTextureView resources.
12
        * Modules/webgpu/WebGPUCommandBuffer.cpp: Move instead of copy the converted view objects.
13
        (WebCore::WebGPUCommandBuffer::copyBufferToTexture):
14
        (WebCore::WebGPUCommandBuffer::copyTextureToBuffer):
15
        (WebCore::WebGPUCommandBuffer::copyTextureToTexture):
16
        * Modules/webgpu/WebGPUCommandBuffer.h:
17
        (WebCore::WebGPUCommandBuffer::commandBuffer const): No longer returns const so used resources can be registered on it.
18
        * Modules/webgpu/WebGPUDevice.cpp:
19
        (WebCore::WebGPUDevice::createBindGroupLayout const): Rename WebGPUBindGroupLayoutDescriptor and replace unnecessary rvalue reference.
20
        * Modules/webgpu/WebGPUDevice.h: Ditto.
21
        * Modules/webgpu/WebGPUDevice.idl: Ditto.
22
        * Modules/webgpu/WebGPUProgrammablePassEncoder.cpp:
23
        (WebCore::WebGPUProgrammablePassEncoder::setBindGroup const):
24
        * Modules/webgpu/WebGPUProgrammablePassEncoder.h:
25
        * Modules/webgpu/WebGPUQueue.cpp:
26
        (WebCore::WebGPUQueue::submit):
27
        * Modules/webgpu/WebGPURenderPassDescriptor.cpp:
28
        (WebCore::WebGPURenderPassDescriptor::asGPURenderPassDescriptor const):
29
        * Modules/webgpu/WebGPUTexture.cpp:
30
        (WebCore::WebGPUTexture::~WebGPUTexture): Clean up any resources created for and from this WebGPUTexture.
31
        (WebCore::WebGPUTexture::createDefaultTextureView): Now returns an empty object other than null on failure.
32
        (WebCore::WebGPUTexture::destroy):
33
        (WebCore::WebGPUTexture::destroyImpl):
34
        * Modules/webgpu/WebGPUTexture.h: Keep a list of any views created from this texture.
35
        * Modules/webgpu/WebGPUTexture.idl: Enable destroy.
36
        * Modules/webgpu/WebGPUTextureView.cpp:
37
        (WebCore::WebGPUTextureView::create):
38
        (WebCore::WebGPUTextureView::WebGPUTextureView):
39
        (WebCore::WebGPUTextureView::destroy):
40
        * Modules/webgpu/WebGPUTextureView.h:
41
        (WebCore::WebGPUTextureView::~WebGPUTextureView): Clean up any resources backing this WebGPUTextureView.
42
        (WebCore::WebGPUTextureView::texture const):
43
        (WebCore::WebGPUTextureView::texture): Deleted.
44
        * platform/graphics/gpu/GPUBindGroupLayout.h:
45
        * platform/graphics/gpu/GPUCommandBuffer.h:
46
        (WebCore::GPUCommandBuffer::usedTextures const): Keep a list of all texture resources that will be used by this command buffer on submit.
47
        (WebCore::GPUCommandBuffer::isEncodingPass const): Added to prevent multiple pass encoders from being active on one command buffer.
48
        (WebCore::GPUCommandBuffer::setIsEncodingPass):
49
        (WebCore::GPUCommandBuffer::useTexture):
50
        * platform/graphics/gpu/GPUDevice.cpp:
51
        (WebCore::GPUDevice::tryCreateBindGroupLayout const):
52
        * platform/graphics/gpu/GPUDevice.h:
53
        * platform/graphics/gpu/GPUPipelineLayout.cpp:
54
        (WebCore::GPUPipelineLayout::GPUPipelineLayout):
55
        * platform/graphics/gpu/GPUProgrammablePassEncoder.cpp:
56
        (WebCore::GPUProgrammablePassEncoder::GPUProgrammablePassEncoder):
57
        * platform/graphics/gpu/GPUProgrammablePassEncoder.h:
58
        (WebCore::GPUProgrammablePassEncoder::setVertexBuffer):
59
        (WebCore::GPUProgrammablePassEncoder::setFragmentBuffer):
60
        (): Deleted.
61
        * platform/graphics/gpu/GPUQueue.h:
62
        * platform/graphics/gpu/GPURenderPassEncoder.h:
63
        * platform/graphics/gpu/GPUTexture.h:
64
        (WebCore::GPUTexture::isReadOnly const):
65
        (WebCore::GPUTexture::destroy):
66
        * platform/graphics/gpu/cocoa/GPUBindGroupLayoutMetal.mm:
67
        (WebCore::MTLDataTypeForBindingType):
68
        (WebCore::GPUBindGroupLayout::tryCreate):
69
        * platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm:
70
        (WebCore::GPUCommandBuffer::create):
71
        (WebCore::GPUCommandBuffer::~GPUCommandBuffer): Ensure blitEncoder is ended before releasing it.
72
        (WebCore::GPUCommandBuffer::endBlitEncoding):
73
        (WebCore::GPUCommandBuffer::copyBufferToTexture): Ensure textures are marked for usage before submission occurs.
74
        (WebCore::GPUCommandBuffer::copyTextureToBuffer):
75
        (WebCore::GPUCommandBuffer::copyTextureToTexture):
76
        * platform/graphics/gpu/cocoa/GPUDeviceMetal.mm:
77
        (WebCore::GPUDevice::create):
78
        (WebCore::GPUDevice::GPUDevice):
79
        * platform/graphics/gpu/cocoa/GPUProgrammablePassEncoderMetal.mm:
80
        (WebCore::GPUProgrammablePassEncoder::endPass):
81
        (WebCore::GPUProgrammablePassEncoder::setBindGroup): Now supports texture resources.
82
        (WebCore::GPUProgrammablePassEncoder::setResourceAsBufferOnEncoder): Just moved.
83
        (WebCore::GPUProgrammablePassEncoder::setResourceAsTextureOnEncoder):
84
        * platform/graphics/gpu/cocoa/GPUQueueMetal.mm:
85
        (WebCore::GPUQueue::submit): Ensures destroyed GPUTextures are not submitted.
86
        * platform/graphics/gpu/cocoa/GPURenderPassEncoderMetal.mm:
87
        (WebCore::GPURenderPassEncoder::tryCreate): Ensure any other encoders are ended before attempting to activate a new one.
88
        (WebCore::GPURenderPassEncoder::platformPassEncoder const):
89
        (WebCore::GPURenderPassEncoder::endPass): Invalidates the MTLCommandEncoder upon success.
90
        (WebCore::GPURenderPassEncoder::setPipeline):
91
        (WebCore::GPURenderPassEncoder::setVertexBuffers):
92
        (WebCore::GPURenderPassEncoder::draw):
93
        (WebCore::GPURenderPassEncoder::useResource):
94
        (WebCore::GPURenderPassEncoder::setVertexBuffer):
95
        (WebCore::GPURenderPassEncoder::setFragmentBuffer):
96
        * platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm:
97
        (WebCore::GPUSwapChain::getNextTexture):
98
        * platform/graphics/gpu/cocoa/GPUTextureMetal.mm:
99
        (WebCore::storageModeForPixelFormatAndSampleCount): 
100
                Always create MTLStorageModePrivate textures on macOS, as Web GPU doesn't provide CPU access to textures anyway.
101
        (WebCore::tryCreateMtlTextureDescriptor):
102
        (WebCore::GPUTexture::create):
103
        (WebCore::GPUTexture::GPUTexture):
104
        (WebCore::GPUTexture::tryCreateDefaultTextureView): Renamed from createDefaultTextureView.
105
106
        Update files and symbols in project:
107
        * CMakeLists.txt:
108
        * DerivedSources-input.xcfilelist:
109
        * DerivedSources-output.xcfilelist:
110
        * DerivedSources.make:
111
        * Modules/streams/WebGPUBindGroupLayoutDescriptor.h: Removed.
112
        * Modules/webgpu/GPUBindGroupLayoutBinding.h: Renamed from Source/WebCore/platform/graphics/gpu/GPUBindGroupLayoutBinding.h.
113
        * Modules/webgpu/GPUBindGroupLayoutBinding.idl: Renamed from Source/WebCore/Modules/webgpu/WebGPUBindGroupLayoutBinding.idl.
114
        * Modules/webgpu/GPUBindGroupLayoutDescriptor.h: Renamed from Source/WebCore/platform/graphics/gpu/GPUBindGroupLayoutDescriptor.h.
115
        * Modules/webgpu/GPUBindGroupLayoutDescriptor.idl: Renamed from Source/WebCore/Modules/webgpu/WebGPUBindGroupLayoutDescriptor.idl.
116
        * Modules/webgpu/GPUShaderStageBit.h: Renamed from Source/WebCore/Modules/webgpu/WebGPUShaderStageBit.h.
117
        * Modules/webgpu/GPUShaderStageBit.idl: Renamed from Source/WebCore/Modules/webgpu/WebGPUShaderStageBit.idl.
118
        * Sources.txt:
119
        * WebCore.xcodeproj/project.pbxproj:
120
        * bindings/js/WebCoreBuiltinNames.h:
121
1
2019-03-04  Justin Fan  <justin_fan@apple.com>
122
2019-03-04  Justin Fan  <justin_fan@apple.com>
2
123
3
        [Web GPU] Blitting function prototypes
124
        [Web GPU] Blitting function prototypes
- a/Source/WebCore/CMakeLists.txt -3 / +3 lines
Lines 462-467 set(WebCore_NON_SVG_IDL_FILES a/Source/WebCore/CMakeLists.txt_sec1
462
    Modules/webdriver/NavigatorWebDriver.idl
462
    Modules/webdriver/NavigatorWebDriver.idl
463
463
464
    Modules/webgpu/DOMWindowWebGPU.idl
464
    Modules/webgpu/DOMWindowWebGPU.idl
465
    Modules/webgpu/GPUBindGroupLayoutBinding.idl
466
    Modules/webgpu/GPUBindGroupLayoutDescriptor.idl
465
    Modules/webgpu/GPUBufferDescriptor.idl
467
    Modules/webgpu/GPUBufferDescriptor.idl
466
    Modules/webgpu/GPUBufferUsage.idl
468
    Modules/webgpu/GPUBufferUsage.idl
467
    Modules/webgpu/GPUColor.idl
469
    Modules/webgpu/GPUColor.idl
Lines 471-476 set(WebCore_NON_SVG_IDL_FILES a/Source/WebCore/CMakeLists.txt_sec2
471
    Modules/webgpu/GPULoadOp.idl
473
    Modules/webgpu/GPULoadOp.idl
472
    Modules/webgpu/GPUOrigin3D.idl
474
    Modules/webgpu/GPUOrigin3D.idl
473
    Modules/webgpu/GPURequestAdapterOptions.idl
475
    Modules/webgpu/GPURequestAdapterOptions.idl
476
    Modules/webgpu/GPUShaderStageBit.idl
474
    Modules/webgpu/GPUStoreOp.idl
477
    Modules/webgpu/GPUStoreOp.idl
475
    Modules/webgpu/GPUTextureDescriptor.idl
478
    Modules/webgpu/GPUTextureDescriptor.idl
476
    Modules/webgpu/GPUTextureDimension.idl
479
    Modules/webgpu/GPUTextureDimension.idl
Lines 482-489 set(WebCore_NON_SVG_IDL_FILES a/Source/WebCore/CMakeLists.txt_sec3
482
    Modules/webgpu/WebGPUBindGroupBinding.idl
485
    Modules/webgpu/WebGPUBindGroupBinding.idl
483
    Modules/webgpu/WebGPUBindGroupDescriptor.idl
486
    Modules/webgpu/WebGPUBindGroupDescriptor.idl
484
    Modules/webgpu/WebGPUBindGroupLayout.idl
487
    Modules/webgpu/WebGPUBindGroupLayout.idl
485
    Modules/webgpu/WebGPUBindGroupLayoutBinding.idl
486
    Modules/webgpu/WebGPUBindGroupLayoutDescriptor.idl
487
    Modules/webgpu/WebGPUBuffer.idl
488
    Modules/webgpu/WebGPUBuffer.idl
488
    Modules/webgpu/WebGPUBufferBinding.idl
489
    Modules/webgpu/WebGPUBufferBinding.idl
489
    Modules/webgpu/WebGPUCommandBuffer.idl
490
    Modules/webgpu/WebGPUCommandBuffer.idl
Lines 504-510 set(WebCore_NON_SVG_IDL_FILES a/Source/WebCore/CMakeLists.txt_sec4
504
    Modules/webgpu/WebGPURenderingContext.idl
505
    Modules/webgpu/WebGPURenderingContext.idl
505
    Modules/webgpu/WebGPUShaderModule.idl
506
    Modules/webgpu/WebGPUShaderModule.idl
506
    Modules/webgpu/WebGPUShaderModuleDescriptor.idl
507
    Modules/webgpu/WebGPUShaderModuleDescriptor.idl
507
    Modules/webgpu/WebGPUShaderStageBit.idl
508
    Modules/webgpu/WebGPUSwapChain.idl
508
    Modules/webgpu/WebGPUSwapChain.idl
509
    Modules/webgpu/WebGPUTexture.idl
509
    Modules/webgpu/WebGPUTexture.idl
510
    Modules/webgpu/WebGPUTextureView.idl
510
    Modules/webgpu/WebGPUTextureView.idl
- a/Source/WebCore/DerivedSources-input.xcfilelist +3 lines
Lines 321-326 $(PROJECT_DIR)/Modules/webdatabase/SQLTransactionCallback.idl a/Source/WebCore/DerivedSources-input.xcfilelist_sec1
321
$(PROJECT_DIR)/Modules/webdatabase/SQLTransactionErrorCallback.idl
321
$(PROJECT_DIR)/Modules/webdatabase/SQLTransactionErrorCallback.idl
322
$(PROJECT_DIR)/Modules/webdriver/NavigatorWebDriver.idl
322
$(PROJECT_DIR)/Modules/webdriver/NavigatorWebDriver.idl
323
$(PROJECT_DIR)/Modules/webgpu/DOMWindowWebGPU.idl
323
$(PROJECT_DIR)/Modules/webgpu/DOMWindowWebGPU.idl
324
$(PROJECT_DIR)/Modules/webgpu/GPUBindGroupLayoutBinding.idl
325
$(PROJECT_DIR)/Modules/webgpu/GPUBindGroupLayoutDescriptor.idl
324
$(PROJECT_DIR)/Modules/webgpu/GPUBufferDescriptor.idl
326
$(PROJECT_DIR)/Modules/webgpu/GPUBufferDescriptor.idl
325
$(PROJECT_DIR)/Modules/webgpu/GPUBufferUsage.idl
327
$(PROJECT_DIR)/Modules/webgpu/GPUBufferUsage.idl
326
$(PROJECT_DIR)/Modules/webgpu/GPUColor.idl
328
$(PROJECT_DIR)/Modules/webgpu/GPUColor.idl
Lines 330-335 $(PROJECT_DIR)/Modules/webgpu/GPUExtent3D.idl a/Source/WebCore/DerivedSources-input.xcfilelist_sec2
330
$(PROJECT_DIR)/Modules/webgpu/GPULoadOp.idl
332
$(PROJECT_DIR)/Modules/webgpu/GPULoadOp.idl
331
$(PROJECT_DIR)/Modules/webgpu/GPUOrigin3D.idl
333
$(PROJECT_DIR)/Modules/webgpu/GPUOrigin3D.idl
332
$(PROJECT_DIR)/Modules/webgpu/GPURequestAdapterOptions.idl
334
$(PROJECT_DIR)/Modules/webgpu/GPURequestAdapterOptions.idl
335
$(PROJECT_DIR)/Modules/webgpu/GPUShaderStageBit.idl
333
$(PROJECT_DIR)/Modules/webgpu/GPUStoreOp.idl
336
$(PROJECT_DIR)/Modules/webgpu/GPUStoreOp.idl
334
$(PROJECT_DIR)/Modules/webgpu/GPUTextureDescriptor.idl
337
$(PROJECT_DIR)/Modules/webgpu/GPUTextureDescriptor.idl
335
$(PROJECT_DIR)/Modules/webgpu/GPUTextureDimension.idl
338
$(PROJECT_DIR)/Modules/webgpu/GPUTextureDimension.idl
- a/Source/WebCore/DerivedSources-output.xcfilelist +6 lines
Lines 577-582 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSFontFaceSet.cpp a/Source/WebCore/DerivedSources-output.xcfilelist_sec1
577
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSFontFaceSet.h
577
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSFontFaceSet.h
578
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGCObservation.cpp
578
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGCObservation.cpp
579
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGCObservation.h
579
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGCObservation.h
580
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUBindGroupLayoutBinding.cpp
581
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUBindGroupLayoutBinding.h
582
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUBindGroupLayoutDescriptor.cpp
583
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUBindGroupLayoutDescriptor.h
580
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUBufferDescriptor.cpp
584
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUBufferDescriptor.cpp
581
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUBufferDescriptor.h
585
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUBufferDescriptor.h
582
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUBufferUsage.cpp
586
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUBufferUsage.cpp
Lines 595-600 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUOrigin3D.cpp a/Source/WebCore/DerivedSources-output.xcfilelist_sec2
595
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUOrigin3D.h
599
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUOrigin3D.h
596
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPURequestAdapterOptions.cpp
600
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPURequestAdapterOptions.cpp
597
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPURequestAdapterOptions.h
601
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPURequestAdapterOptions.h
602
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUShaderStageBit.cpp
603
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUShaderStageBit.h
598
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUStoreOp.cpp
604
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUStoreOp.cpp
599
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUStoreOp.h
605
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUStoreOp.h
600
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUTextureDescriptor.cpp
606
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUTextureDescriptor.cpp
- a/Source/WebCore/DerivedSources.make -3 / +3 lines
Lines 373-378 JS_BINDING_IDLS = \ a/Source/WebCore/DerivedSources.make_sec1
373
    $(WebCore)/Modules/webdriver/NavigatorWebDriver.idl \
373
    $(WebCore)/Modules/webdriver/NavigatorWebDriver.idl \
374
    $(WebCore)/Modules/webgpu/DOMWindowWebGPU.idl \
374
    $(WebCore)/Modules/webgpu/DOMWindowWebGPU.idl \
375
    $(WebCore)/Modules/webgpu/GPUColor.idl \
375
    $(WebCore)/Modules/webgpu/GPUColor.idl \
376
    $(WebCore)/Modules/webgpu/GPUBindGroupLayoutBinding.idl \
377
    $(WebCore)/Modules/webgpu/GPUBindGroupLayoutDescriptor.idl \
376
    $(WebCore)/Modules/webgpu/GPUBufferDescriptor.idl \
378
    $(WebCore)/Modules/webgpu/GPUBufferDescriptor.idl \
377
    $(WebCore)/Modules/webgpu/GPUBufferUsage.idl \
379
    $(WebCore)/Modules/webgpu/GPUBufferUsage.idl \
378
    $(WebCore)/Modules/webgpu/GPUCompareFunction.idl \
380
    $(WebCore)/Modules/webgpu/GPUCompareFunction.idl \
Lines 381-386 JS_BINDING_IDLS = \ a/Source/WebCore/DerivedSources.make_sec2
381
    $(WebCore)/Modules/webgpu/GPULoadOp.idl \
383
    $(WebCore)/Modules/webgpu/GPULoadOp.idl \
382
    $(WebCore)/Modules/webgpu/GPUOrigin3D.idl \
384
    $(WebCore)/Modules/webgpu/GPUOrigin3D.idl \
383
    $(WebCore)/Modules/webgpu/GPURequestAdapterOptions.idl \
385
    $(WebCore)/Modules/webgpu/GPURequestAdapterOptions.idl \
386
    $(WebCore)/Modules/webgpu/GPUShaderStageBit.idl \
384
    $(WebCore)/Modules/webgpu/GPUStoreOp.idl \
387
    $(WebCore)/Modules/webgpu/GPUStoreOp.idl \
385
    $(WebCore)/Modules/webgpu/GPUTextureDescriptor.idl \
388
    $(WebCore)/Modules/webgpu/GPUTextureDescriptor.idl \
386
    $(WebCore)/Modules/webgpu/GPUTextureDimension.idl \
389
    $(WebCore)/Modules/webgpu/GPUTextureDimension.idl \
Lines 392-399 JS_BINDING_IDLS = \ a/Source/WebCore/DerivedSources.make_sec3
392
    $(WebCore)/Modules/webgpu/WebGPUBindGroupBinding.idl \
395
    $(WebCore)/Modules/webgpu/WebGPUBindGroupBinding.idl \
393
    $(WebCore)/Modules/webgpu/WebGPUBindGroupDescriptor.idl \
396
    $(WebCore)/Modules/webgpu/WebGPUBindGroupDescriptor.idl \
394
    $(WebCore)/Modules/webgpu/WebGPUBindGroupLayout.idl \
397
    $(WebCore)/Modules/webgpu/WebGPUBindGroupLayout.idl \
395
    $(WebCore)/Modules/webgpu/WebGPUBindGroupLayoutBinding.idl \
396
    $(WebCore)/Modules/webgpu/WebGPUBindGroupLayoutDescriptor.idl \
397
    $(WebCore)/Modules/webgpu/WebGPUBuffer.idl \
398
    $(WebCore)/Modules/webgpu/WebGPUBuffer.idl \
398
	$(WebCore)/Modules/webgpu/WebGPUBufferBinding.idl \
399
	$(WebCore)/Modules/webgpu/WebGPUBufferBinding.idl \
399
    $(WebCore)/Modules/webgpu/WebGPUCommandBuffer.idl \
400
    $(WebCore)/Modules/webgpu/WebGPUCommandBuffer.idl \
Lines 414-420 JS_BINDING_IDLS = \ a/Source/WebCore/DerivedSources.make_sec4
414
    $(WebCore)/Modules/webgpu/WebGPURenderingContext.idl \
415
    $(WebCore)/Modules/webgpu/WebGPURenderingContext.idl \
415
    $(WebCore)/Modules/webgpu/WebGPUShaderModule.idl \
416
    $(WebCore)/Modules/webgpu/WebGPUShaderModule.idl \
416
    $(WebCore)/Modules/webgpu/WebGPUShaderModuleDescriptor.idl \
417
    $(WebCore)/Modules/webgpu/WebGPUShaderModuleDescriptor.idl \
417
    $(WebCore)/Modules/webgpu/WebGPUShaderStageBit.idl \
418
    $(WebCore)/Modules/webgpu/WebGPUSwapChain.idl \
418
    $(WebCore)/Modules/webgpu/WebGPUSwapChain.idl \
419
    $(WebCore)/Modules/webgpu/WebGPUTexture.idl \
419
    $(WebCore)/Modules/webgpu/WebGPUTexture.idl \
420
    $(WebCore)/Modules/webgpu/WebGPUTextureView.idl \
420
    $(WebCore)/Modules/webgpu/WebGPUTextureView.idl \
- a/Source/WebCore/Modules/streams/WebGPUBindGroupLayoutDescriptor.h -38 lines
Lines 1-38 a/Source/WebCore/Modules/streams/WebGPUBindGroupLayoutDescriptor.h_sec1
1
/*
2
 * Copyright (C) 2018 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#pragma once
27
28
#if ENABLE(WEBGPU)
29
30
#include "GPUBindGroupLayoutDescriptor.h"
31
32
namespace WebCore {
33
34
using WebGPUBindGroupLayoutDescriptor = GPUBindGroupLayoutDescriptor;
35
36
} // namespace WebCore
37
38
#endif // ENABLE(WEBGPU)
- a/Source/WebCore/Modules/webgpu/GPUBindGroupLayoutBinding.h +52 lines
Line 0 a/Source/WebCore/Modules/webgpu/GPUBindGroupLayoutBinding.h_sec1
1
/*
2
 * Copyright (C) 2018 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#pragma once
27
28
#if ENABLE(WEBGPU)
29
30
#include "GPUShaderStageBit.h"
31
#include <wtf/OptionSet.h>
32
33
namespace WebCore {
34
35
struct GPUBindGroupLayoutBinding {
36
    enum class BindingType {
37
        UniformBuffer,
38
        DynamicUniformBuffer,
39
        Sampler,
40
        SampledTexture,
41
        StorageBuffer,
42
        DynamicStorageBuffer
43
    };
44
45
    unsigned long binding;
46
    GPUShaderStageFlags visibility;
47
    BindingType type;
48
};
49
50
} // namespace WebCore
51
52
#endif // ENABLE(WEBGPU)
- a/Source/WebCore/Modules/webgpu/GPUBindGroupLayoutBinding.idl +50 lines
Line 0 a/Source/WebCore/Modules/webgpu/GPUBindGroupLayoutBinding.idl_sec1
1
/*
2
 * Copyright (C) 2019 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
// https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl
26
27
typedef unsigned long u32;
28
typedef u32 GPUShaderStageFlags;
29
30
[
31
    Conditional=WEBGPU,
32
    EnabledAtRuntime=WebGPU
33
] enum GPUBindingType {
34
    "uniform-buffer",
35
    "dynamic-uniform-buffer",
36
    "sampler",
37
    "sampled-texture",
38
    "storage-buffer",
39
    "dynamic-storage-buffer"
40
    // TODO other binding types
41
};
42
43
[
44
    Conditional=WEBGPU,
45
    EnabledAtRuntime=WebGPU
46
] dictionary GPUBindGroupLayoutBinding {
47
    u32 binding;
48
    GPUShaderStageFlags visibility;
49
    GPUBindingType type;
50
};
- a/Source/WebCore/Modules/webgpu/GPUBindGroupLayoutDescriptor.h +41 lines
Line 0 a/Source/WebCore/Modules/webgpu/GPUBindGroupLayoutDescriptor.h_sec1
1
/*
2
 * Copyright (C) 2019 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#pragma once
27
28
#if ENABLE(WEBGPU)
29
30
#include "GPUBindGroupLayoutBinding.h"
31
#include <wtf/Vector.h>
32
33
namespace WebCore {
34
35
struct GPUBindGroupLayoutDescriptor {
36
    Vector<GPUBindGroupLayoutBinding> bindings;
37
};
38
39
} // namespace WebCore
40
41
#endif // ENABLE(WEBGPU)
- a/Source/WebCore/Modules/webgpu/GPUBindGroupLayoutDescriptor.idl +32 lines
Line 0 a/Source/WebCore/Modules/webgpu/GPUBindGroupLayoutDescriptor.idl_sec1
1
/*
2
 * Copyright (C) 2019 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
// https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl
26
27
[
28
    Conditional=WEBGPU,
29
    EnabledAtRuntime=WebGPU
30
] dictionary GPUBindGroupLayoutDescriptor {
31
    sequence<GPUBindGroupLayoutBinding> bindings;
32
};
- a/Source/WebCore/Modules/webgpu/GPUShaderStageBit.h +49 lines
Line 0 a/Source/WebCore/Modules/webgpu/GPUShaderStageBit.h_sec1
1
/*
2
 * Copyright (C) 2019 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#pragma once
27
28
#if ENABLE(WEBGPU)
29
30
#include <wtf/RefCounted.h>
31
32
namespace WebCore {
33
34
using GPUShaderStageFlags = unsigned;
35
36
class GPUShaderStageBit : public RefCounted<GPUShaderStageBit> {
37
public:
38
    enum Flags : GPUShaderStageFlags {
39
        None = 0,
40
        Vertex = 1 << 0,
41
        Fragment = 1 << 1,
42
        Compute = 1 << 2,
43
    };
44
};
45
46
47
} // namespace WebCore
48
49
#endif // ENABLE(WEBGPU)
- a/Source/WebCore/Modules/webgpu/GPUShaderStageBit.idl +39 lines
Line 0 a/Source/WebCore/Modules/webgpu/GPUShaderStageBit.idl_sec1
1
/*
2
 * Copyright (C) 2019 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
// https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl
26
27
typedef unsigned long u32;
28
29
[
30
    Conditional=WEBGPU,
31
    DoNotCheckConstants,
32
    EnabledAtRuntime=WebGPU,
33
    ImplementationLacksVTable
34
] interface GPUShaderStageBit {
35
    const u32 NONE = 0;
36
    const u32 VERTEX = 1;
37
    const u32 FRAGMENT = 2;
38
    const u32 COMPUTE = 4;
39
};
- a/Source/WebCore/Modules/webgpu/WebGPUBindGroupDescriptor.cpp -9 / +15 lines
Lines 88-113 Optional<GPUBindGroupDescriptor> WebGPUBindGroupDescriptor::asGPUBindGroupDescri a/Source/WebCore/Modules/webgpu/WebGPUBindGroupDescriptor.cpp_sec1
88
88
89
        const auto layoutBinding = iterator->value;
89
        const auto layoutBinding = iterator->value;
90
90
91
        auto bindingResourceVisitor = WTF::makeVisitor([] (RefPtr<WebGPUTextureView> view) -> Optional<GPUBindingResource> {
91
        auto bindingResourceVisitor = WTF::makeVisitor([](const RefPtr<WebGPUTextureView>& view) -> Optional<GPUBindingResource> {
92
            // FIXME: Validate binding type with the texture's usage flags.
93
            if (!view)
92
            if (!view)
94
                return WTF::nullopt;
93
                return WTF::nullopt;
94
            auto texture = view->texture();
95
            if (!texture)
96
                return WTF::nullopt;
95
97
96
            return static_cast<GPUBindingResource>(view->texture());
98
            return static_cast<GPUBindingResource>(texture.releaseNonNull());
97
        }, [&layoutBinding, functionName] (WebGPUBufferBinding bufferBinding) -> Optional<GPUBindingResource> {
99
        }, [&layoutBinding, functionName] (WebGPUBufferBinding bufferBinding) -> Optional<GPUBindingResource> {
98
            if (!bufferBinding.buffer || !bufferBinding.buffer->buffer()) {
100
            if (!bufferBinding.buffer)
99
                LOG(WebGPU, "%s: Invalid GPUBufferBinding for binding %lu in GPUBindGroupBindings!", functionName, layoutBinding.binding);
101
                return WTF::nullopt;
102
            auto buffer = bufferBinding.buffer->buffer();
103
            if (!buffer)
100
                return WTF::nullopt;
104
                return WTF::nullopt;
101
            }
105
102
            if (!validateBufferBindingType(bufferBinding.buffer->buffer().get(), layoutBinding, functionName))
106
            if (!validateBufferBindingType(buffer.get(), layoutBinding, functionName))
103
                return WTF::nullopt;
107
                return WTF::nullopt;
104
108
105
            return static_cast<GPUBindingResource>(GPUBufferBinding { bufferBinding.buffer->buffer().releaseNonNull(), bufferBinding.offset, bufferBinding.size });
109
            return static_cast<GPUBindingResource>(GPUBufferBinding { buffer.releaseNonNull(), bufferBinding.offset, bufferBinding.size });
106
        });
110
        });
107
111
108
        auto bindingResource = WTF::visit(bindingResourceVisitor, binding.resource);
112
        auto bindingResource = WTF::visit(bindingResourceVisitor, binding.resource);
109
        if (!bindingResource)
113
        if (!bindingResource) {
114
            LOG(WebGPU, "%s: Invalid resource for binding %lu!", functionName, layoutBinding.binding);
110
            return WTF::nullopt;
115
            return WTF::nullopt;
116
        }
111
117
112
        bindGroupBindings.uncheckedAppend(GPUBindGroupBinding { binding.binding, WTFMove(bindingResource.value()) });
118
        bindGroupBindings.uncheckedAppend(GPUBindGroupBinding { binding.binding, WTFMove(bindingResource.value()) });
113
    }
119
    }
- a/Source/WebCore/Modules/webgpu/WebGPUBindGroupLayoutBinding.h -41 lines
Lines 1-41 a/Source/WebCore/Modules/webgpu/WebGPUBindGroupLayoutBinding.h_sec1
1
/*
2
 * Copyright (C) 2018 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#pragma once
27
28
#if ENABLE(WEBGPU)
29
30
#include "GPUBindGroupLayoutBinding.h"
31
#include "WebGPUShaderStageBit.h"
32
33
namespace WebCore {
34
35
using WebGPUBindGroupLayoutBinding = GPUBindGroupLayoutBinding;
36
using WebGPUBindingType = GPUBindGroupLayoutBinding::BindingType;
37
using WebGPUShaderStageFlags = GPUShaderStageFlags;
38
39
} // namespace WebCore
40
41
#endif // ENABLE(WEBGPU)
- a/Source/WebCore/Modules/webgpu/WebGPUBindGroupLayoutBinding.idl -49 lines
Lines 1-49 a/Source/WebCore/Modules/webgpu/WebGPUBindGroupLayoutBinding.idl_sec1
1
/*
2
 * Copyright (C) 2018 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
// https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl
26
27
typedef unsigned long u32;
28
typedef u32 WebGPUShaderStageFlags;
29
30
[
31
    Conditional=WEBGPU,
32
    EnabledAtRuntime=WebGPU
33
] enum WebGPUBindingType {
34
    "uniformBuffer",
35
    "sampler",
36
    "sampledTexture",
37
    "storageBuffer"
38
    // TODO other binding types
39
};
40
41
[
42
    Conditional=WEBGPU,
43
    EnabledAtRuntime=WebGPU
44
] dictionary WebGPUBindGroupLayoutBinding {
45
    u32 binding;
46
    WebGPUShaderStageFlags visibility;
47
    WebGPUBindingType type;
48
};
49
- a/Source/WebCore/Modules/webgpu/WebGPUBindGroupLayoutDescriptor.idl -32 lines
Lines 1-32 a/Source/WebCore/Modules/webgpu/WebGPUBindGroupLayoutDescriptor.idl_sec1
1
/*
2
 * Copyright (C) 2018 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
// https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl
26
27
[
28
    Conditional=WEBGPU,
29
    EnabledAtRuntime=WebGPU
30
] dictionary WebGPUBindGroupLayoutDescriptor {
31
    sequence<WebGPUBindGroupLayoutBinding> bindings;
32
};
- a/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.cpp -3 / +3 lines
Lines 104-110 void WebGPUCommandBuffer::copyBufferToTexture(const WebGPUBufferCopyView& srcBuf a/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.cpp_sec1
104
104
105
    // FIXME: Add Web GPU validation.
105
    // FIXME: Add Web GPU validation.
106
106
107
    m_commandBuffer->copyBufferToTexture(*gpuBufferView, *gpuTextureView, size);
107
    m_commandBuffer->copyBufferToTexture(WTFMove(*gpuBufferView), WTFMove(*gpuTextureView), size);
108
}
108
}
109
109
110
void WebGPUCommandBuffer::copyTextureToBuffer(const WebGPUTextureCopyView& srcTexture, const WebGPUBufferCopyView& dstBuffer, const GPUExtent3D& size)
110
void WebGPUCommandBuffer::copyTextureToBuffer(const WebGPUTextureCopyView& srcTexture, const WebGPUBufferCopyView& dstBuffer, const GPUExtent3D& size)
Lines 117-123 void WebGPUCommandBuffer::copyTextureToBuffer(const WebGPUTextureCopyView& srcTe a/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.cpp_sec2
117
117
118
    // FIXME: Add Web GPU validation.
118
    // FIXME: Add Web GPU validation.
119
119
120
    m_commandBuffer->copyTextureToBuffer(*gpuTextureView, *gpuBufferView, size);
120
    m_commandBuffer->copyTextureToBuffer(WTFMove(*gpuTextureView), WTFMove(*gpuBufferView), size);
121
}
121
}
122
122
123
void WebGPUCommandBuffer::copyTextureToTexture(const WebGPUTextureCopyView& src, const WebGPUTextureCopyView& dst, const GPUExtent3D& size)
123
void WebGPUCommandBuffer::copyTextureToTexture(const WebGPUTextureCopyView& src, const WebGPUTextureCopyView& dst, const GPUExtent3D& size)
Lines 130-136 void WebGPUCommandBuffer::copyTextureToTexture(const WebGPUTextureCopyView& src, a/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.cpp_sec3
130
130
131
    // FIXME: Add Web GPU validation.
131
    // FIXME: Add Web GPU validation.
132
132
133
    m_commandBuffer->copyTextureToTexture(*gpuSrcView, *gpuDstView, size);
133
    m_commandBuffer->copyTextureToTexture(WTFMove(*gpuSrcView), WTFMove(*gpuDstView), size);
134
}
134
}
135
135
136
} // namespace WebCore
136
} // namespace WebCore
- a/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.h -1 / +1 lines
Lines 59-65 class WebGPUCommandBuffer : public RefCounted<WebGPUCommandBuffer> { a/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.h_sec1
59
public:
59
public:
60
    static Ref<WebGPUCommandBuffer> create(Ref<GPUCommandBuffer>&&);
60
    static Ref<WebGPUCommandBuffer> create(Ref<GPUCommandBuffer>&&);
61
61
62
    const GPUCommandBuffer& commandBuffer() const { return m_commandBuffer.get(); }
62
    GPUCommandBuffer& commandBuffer() const { return m_commandBuffer.get(); }
63
63
64
    RefPtr<WebGPURenderPassEncoder> beginRenderPass(WebGPURenderPassDescriptor&&);
64
    RefPtr<WebGPURenderPassEncoder> beginRenderPass(WebGPURenderPassDescriptor&&);
65
    void copyBufferToBuffer(const WebGPUBuffer&, unsigned long srcOffset, const WebGPUBuffer&, unsigned long dstOffset, unsigned long size);
65
    void copyBufferToBuffer(const WebGPUBuffer&, unsigned long srcOffset, const WebGPUBuffer&, unsigned long dstOffset, unsigned long size);
- a/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp -3 / +3 lines
Lines 31-36 a/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp_sec1
31
#include "GPUBindGroup.h"
31
#include "GPUBindGroup.h"
32
#include "GPUBindGroupBinding.h"
32
#include "GPUBindGroupBinding.h"
33
#include "GPUBindGroupDescriptor.h"
33
#include "GPUBindGroupDescriptor.h"
34
#include "GPUBindGroupLayoutDescriptor.h"
34
#include "GPUBufferBinding.h"
35
#include "GPUBufferBinding.h"
35
#include "GPUBufferDescriptor.h"
36
#include "GPUBufferDescriptor.h"
36
#include "GPUCommandBuffer.h"
37
#include "GPUCommandBuffer.h"
Lines 41-47 a/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp_sec2
41
#include "Logging.h"
42
#include "Logging.h"
42
#include "WebGPUBindGroup.h"
43
#include "WebGPUBindGroup.h"
43
#include "WebGPUBindGroupBinding.h"
44
#include "WebGPUBindGroupBinding.h"
44
#include "WebGPUBindGroupDescriptor.h"
45
#include "WebGPUBindGroupLayout.h"
45
#include "WebGPUBindGroupLayout.h"
46
#include "WebGPUBuffer.h"
46
#include "WebGPUBuffer.h"
47
#include "WebGPUBufferBinding.h"
47
#include "WebGPUBufferBinding.h"
Lines 84-92 Ref<WebGPUTexture> WebGPUDevice::createTexture(GPUTextureDescriptor&& descriptor a/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp_sec3
84
    return WebGPUTexture::create(WTFMove(texture));
84
    return WebGPUTexture::create(WTFMove(texture));
85
}
85
}
86
86
87
Ref<WebGPUBindGroupLayout> WebGPUDevice::createBindGroupLayout(WebGPUBindGroupLayoutDescriptor&& descriptor) const
87
Ref<WebGPUBindGroupLayout> WebGPUDevice::createBindGroupLayout(const GPUBindGroupLayoutDescriptor& descriptor) const
88
{
88
{
89
    auto layout = m_device->tryCreateBindGroupLayout(GPUBindGroupLayoutDescriptor { descriptor.bindings });
89
    auto layout = m_device->tryCreateBindGroupLayout(descriptor);
90
    return WebGPUBindGroupLayout::create(WTFMove(layout));
90
    return WebGPUBindGroupLayout::create(WTFMove(layout));
91
}
91
}
92
92
- a/Source/WebCore/Modules/webgpu/WebGPUDevice.h -2 / +2 lines
Lines 29-35 a/Source/WebCore/Modules/webgpu/WebGPUDevice.h_sec1
29
29
30
#include "GPUDevice.h"
30
#include "GPUDevice.h"
31
#include "WebGPUAdapter.h"
31
#include "WebGPUAdapter.h"
32
#include "WebGPUBindGroupLayoutDescriptor.h"
33
#include "WebGPUQueue.h"
32
#include "WebGPUQueue.h"
34
33
35
#include <wtf/Ref.h>
34
#include <wtf/Ref.h>
Lines 48-53 class WebGPURenderPipeline; a/Source/WebCore/Modules/webgpu/WebGPUDevice.h_sec2
48
class WebGPUShaderModule;
47
class WebGPUShaderModule;
49
class WebGPUTexture;
48
class WebGPUTexture;
50
49
50
struct GPUBindGroupLayoutDescriptor;
51
struct GPUBufferDescriptor;
51
struct GPUBufferDescriptor;
52
struct GPUTextureDescriptor;
52
struct GPUTextureDescriptor;
53
struct WebGPUBindGroupDescriptor;
53
struct WebGPUBindGroupDescriptor;
Lines 65-71 public: a/Source/WebCore/Modules/webgpu/WebGPUDevice.h_sec3
65
    Ref<WebGPUBuffer> createBuffer(GPUBufferDescriptor&&) const;
65
    Ref<WebGPUBuffer> createBuffer(GPUBufferDescriptor&&) const;
66
    Ref<WebGPUTexture> createTexture(GPUTextureDescriptor&&) const;
66
    Ref<WebGPUTexture> createTexture(GPUTextureDescriptor&&) const;
67
67
68
    Ref<WebGPUBindGroupLayout> createBindGroupLayout(WebGPUBindGroupLayoutDescriptor&&) const;
68
    Ref<WebGPUBindGroupLayout> createBindGroupLayout(const GPUBindGroupLayoutDescriptor&) const;
69
    Ref<WebGPUPipelineLayout> createPipelineLayout(WebGPUPipelineLayoutDescriptor&&) const;
69
    Ref<WebGPUPipelineLayout> createPipelineLayout(WebGPUPipelineLayoutDescriptor&&) const;
70
    Ref<WebGPUBindGroup> createBindGroup(WebGPUBindGroupDescriptor&&) const;
70
    Ref<WebGPUBindGroup> createBindGroup(WebGPUBindGroupDescriptor&&) const;
71
71
- a/Source/WebCore/Modules/webgpu/WebGPUDevice.idl -2 / +1 lines
Lines 34-40 a/Source/WebCore/Modules/webgpu/WebGPUDevice.idl_sec1
34
    WebGPUBuffer createBuffer(GPUBufferDescriptor descriptor);
34
    WebGPUBuffer createBuffer(GPUBufferDescriptor descriptor);
35
    WebGPUTexture createTexture(GPUTextureDescriptor descriptor);
35
    WebGPUTexture createTexture(GPUTextureDescriptor descriptor);
36
36
37
    WebGPUBindGroupLayout createBindGroupLayout(WebGPUBindGroupLayoutDescriptor descriptor);
37
    WebGPUBindGroupLayout createBindGroupLayout(GPUBindGroupLayoutDescriptor descriptor);
38
    WebGPUPipelineLayout createPipelineLayout(WebGPUPipelineLayoutDescriptor descriptor);
38
    WebGPUPipelineLayout createPipelineLayout(WebGPUPipelineLayoutDescriptor descriptor);
39
    WebGPUBindGroup createBindGroup(WebGPUBindGroupDescriptor descriptor);
39
    WebGPUBindGroup createBindGroup(WebGPUBindGroupDescriptor descriptor);
40
40
Lines 50-56 a/Source/WebCore/Modules/webgpu/WebGPUDevice.idl_sec2
50
    // readonly attribute WebGPUExtensions extensions;
50
    // readonly attribute WebGPUExtensions extensions;
51
    // readonly attribute WebGPULimits limits;
51
    // readonly attribute WebGPULimits limits;
52
52
53
    // WebGPUTexture createTexture(WebGPUTextureDescriptor descriptor);
54
    // WebGPUSampler createSampler(WebGPUSamplerDescriptor descriptor);
53
    // WebGPUSampler createSampler(WebGPUSamplerDescriptor descriptor);
55
54
56
    // WebGPUComputePipeline createComputePipeline(WebGPUComputePipelineDescriptor descriptor);
55
    // WebGPUComputePipeline createComputePipeline(WebGPUComputePipelineDescriptor descriptor);
- a/Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.cpp -1 / +1 lines
Lines 45-51 Ref<WebGPUCommandBuffer> WebGPUProgrammablePassEncoder::endPass() a/Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.cpp_sec1
45
    return m_commandBuffer.copyRef();
45
    return m_commandBuffer.copyRef();
46
}
46
}
47
47
48
void WebGPUProgrammablePassEncoder::setBindGroup(unsigned long index, WebGPUBindGroup& bindGroup) const
48
void WebGPUProgrammablePassEncoder::setBindGroup(unsigned index, WebGPUBindGroup& bindGroup) const
49
{
49
{
50
    // Maximum number of bind groups supported in Web GPU.
50
    // Maximum number of bind groups supported in Web GPU.
51
    if (index >= 4) {
51
    if (index >= 4) {
- a/Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.h -1 / +1 lines
Lines 41-47 public: a/Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.h_sec1
41
    virtual ~WebGPUProgrammablePassEncoder() = default;
41
    virtual ~WebGPUProgrammablePassEncoder() = default;
42
42
43
    Ref<WebGPUCommandBuffer> endPass();
43
    Ref<WebGPUCommandBuffer> endPass();
44
    void setBindGroup(unsigned long, WebGPUBindGroup&) const;
44
    void setBindGroup(unsigned, WebGPUBindGroup&) const;
45
    void setPipeline(Ref<WebGPURenderPipeline>&&);
45
    void setPipeline(Ref<WebGPURenderPipeline>&&);
46
46
47
protected:
47
protected:
- a/Source/WebCore/Modules/webgpu/WebGPUQueue.cpp -1 / +1 lines
Lines 46-52 WebGPUQueue::WebGPUQueue(Ref<GPUQueue>&& queue) a/Source/WebCore/Modules/webgpu/WebGPUQueue.cpp_sec1
46
46
47
void WebGPUQueue::submit(Vector<RefPtr<WebGPUCommandBuffer>>&& buffers)
47
void WebGPUQueue::submit(Vector<RefPtr<WebGPUCommandBuffer>>&& buffers)
48
{
48
{
49
    auto gpuBuffers = buffers.map([] (const auto& buffer) -> Ref<const GPUCommandBuffer> {
49
    auto gpuBuffers = buffers.map([] (auto& buffer) -> Ref<GPUCommandBuffer> {
50
        return buffer->commandBuffer();
50
        return buffer->commandBuffer();
51
    });
51
    });
52
    m_queue->submit(WTFMove(gpuBuffers));
52
    m_queue->submit(WTFMove(gpuBuffers));
- a/Source/WebCore/Modules/webgpu/WebGPURenderPassDescriptor.cpp -4 / +8 lines
Lines 56-76 Optional<GPURenderPassDescriptor> WebGPURenderPassDescriptor::asGPURenderPassDes a/Source/WebCore/Modules/webgpu/WebGPURenderPassDescriptor.cpp_sec1
56
    Vector<GPURenderPassColorAttachmentDescriptor> gpuColorAttachments;
56
    Vector<GPURenderPassColorAttachmentDescriptor> gpuColorAttachments;
57
57
58
    for (const auto& colorAttachment : colorAttachments) {
58
    for (const auto& colorAttachment : colorAttachments) {
59
        if (!colorAttachment.attachment || !colorAttachment.attachment->texture()->isOutputAttachment()) {
59
        if (!colorAttachment.attachment
60
            || !colorAttachment.attachment->texture()
61
            || !colorAttachment.attachment->texture()->isOutputAttachment()) {
60
            LOG(WebGPU, "GPURenderPassDescriptor: Invalid attachment in GPURenderPassColorAttachmentDescriptor!");
62
            LOG(WebGPU, "GPURenderPassDescriptor: Invalid attachment in GPURenderPassColorAttachmentDescriptor!");
61
            return WTF::nullopt;
63
            return WTF::nullopt;
62
        }
64
        }
63
        gpuColorAttachments.append(GPURenderPassColorAttachmentDescriptor { colorAttachment.attachment->texture(), colorAttachment });
65
        gpuColorAttachments.append(GPURenderPassColorAttachmentDescriptor { colorAttachment.attachment->texture().releaseNonNull(), colorAttachment });
64
    }
66
    }
65
67
66
    Optional<GPURenderPassDepthStencilAttachmentDescriptor> gpuDepthAttachment;
68
    Optional<GPURenderPassDepthStencilAttachmentDescriptor> gpuDepthAttachment;
67
69
68
    if (depthStencilAttachment) {
70
    if (depthStencilAttachment) {
69
        if (!depthStencilAttachment->attachment || !depthStencilAttachment->attachment->texture()->isOutputAttachment()) {
71
        if (!depthStencilAttachment->attachment
72
            || !depthStencilAttachment->attachment->texture()
73
            || !depthStencilAttachment->attachment->texture()->isOutputAttachment()) {
70
            LOG(WebGPU, "GPURenderPassDescriptor: Invalid attachment in GPURenderPassDepthStencilAttachmentDescriptor!");
74
            LOG(WebGPU, "GPURenderPassDescriptor: Invalid attachment in GPURenderPassDepthStencilAttachmentDescriptor!");
71
            return WTF::nullopt;
75
            return WTF::nullopt;
72
        }
76
        }
73
        gpuDepthAttachment = GPURenderPassDepthStencilAttachmentDescriptor { depthStencilAttachment->attachment->texture(), *depthStencilAttachment };
77
        gpuDepthAttachment = GPURenderPassDepthStencilAttachmentDescriptor { depthStencilAttachment->attachment->texture().releaseNonNull(), *depthStencilAttachment };
74
    }
78
    }
75
79
76
    return GPURenderPassDescriptor { WTFMove(gpuColorAttachments), WTFMove(gpuDepthAttachment) };
80
    return GPURenderPassDescriptor { WTFMove(gpuColorAttachments), WTFMove(gpuDepthAttachment) };
- a/Source/WebCore/Modules/webgpu/WebGPUShaderStageBit.h -38 lines
Lines 1-38 a/Source/WebCore/Modules/webgpu/WebGPUShaderStageBit.h_sec1
1
/*
2
 * Copyright (C) 2018 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#pragma once
27
28
#if ENABLE(WEBGPU)
29
30
#include "GPUBindGroupLayoutBinding.h"
31
32
namespace WebCore {
33
34
using WebGPUShaderStageBit = GPUShaderStageBit;
35
36
} // namespace WebCore
37
38
#endif // ENABLE(WEBGPU)
- a/Source/WebCore/Modules/webgpu/WebGPUShaderStageBit.idl -38 lines
Lines 1-38 a/Source/WebCore/Modules/webgpu/WebGPUShaderStageBit.idl_sec1
1
/*
2
 * Copyright (C) 2018 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
// https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl
26
27
typedef unsigned long u32;
28
29
[
30
    Conditional=WEBGPU,
31
    EnabledAtRuntime=WebGPU,
32
    ImplementationLacksVTable
33
] interface WebGPUShaderStageBit {
34
    const u32 NONE = 0;
35
    const u32 VERTEX = 1;
36
    const u32 FRAGMENT = 2;
37
    const u32 COMPUTE = 4;
38
};
- a/Source/WebCore/Modules/webgpu/WebGPUTexture.cpp -4 / +33 lines
Lines 42-52 WebGPUTexture::WebGPUTexture(RefPtr<GPUTexture>&& texture) a/Source/WebCore/Modules/webgpu/WebGPUTexture.cpp_sec1
42
{
42
{
43
}
43
}
44
44
45
RefPtr<WebGPUTextureView> WebGPUTexture::createDefaultTextureView()
45
WebGPUTexture::~WebGPUTexture()
46
{
46
{
47
    if (auto gpuTexture = m_texture->createDefaultTextureView())
47
    if (m_texture)
48
        return WebGPUTextureView::create(gpuTexture.releaseNonNull());
48
        destroyImpl();
49
    return nullptr;
49
}
50
51
Ref<WebGPUTextureView> WebGPUTexture::createDefaultTextureView()
52
{
53
    if (!m_texture) {
54
        LOG(WebGPU, "GPUTexture::createDefaultTextureView(): Invalid operation!");
55
        return WebGPUTextureView::create(nullptr);
56
    }
57
58
    auto view = WebGPUTextureView::create(m_texture->tryCreateDefaultTextureView());
59
    m_textureViews.append(view.copyRef());
60
    return view;
61
}
62
63
void WebGPUTexture::destroy()
64
{
65
    if (!m_texture)
66
        LOG(WebGPU, "GPUTexture::destroy(): Invalid operation!");
67
    else
68
        destroyImpl();
69
}
70
71
void WebGPUTexture::destroyImpl()
72
{
73
    for (auto& view : m_textureViews)
74
        view->destroy();
75
    m_textureViews.clear();
76
77
    m_texture->destroy();
78
    m_texture = nullptr;
50
}
79
}
51
80
52
} // namespace WebCore
81
} // namespace WebCore
- a/Source/WebCore/Modules/webgpu/WebGPUTexture.h -1 / +7 lines
Lines 31-36 a/Source/WebCore/Modules/webgpu/WebGPUTexture.h_sec1
31
31
32
#include <wtf/RefCounted.h>
32
#include <wtf/RefCounted.h>
33
#include <wtf/RefPtr.h>
33
#include <wtf/RefPtr.h>
34
#include <wtf/Vector.h>
34
35
35
namespace WebCore {
36
namespace WebCore {
36
37
Lines 39-53 class WebGPUTextureView; a/Source/WebCore/Modules/webgpu/WebGPUTexture.h_sec2
39
class WebGPUTexture : public RefCounted<WebGPUTexture> {
40
class WebGPUTexture : public RefCounted<WebGPUTexture> {
40
public:
41
public:
41
    static Ref<WebGPUTexture> create(RefPtr<GPUTexture>&&);
42
    static Ref<WebGPUTexture> create(RefPtr<GPUTexture>&&);
43
    ~WebGPUTexture();
42
44
43
    RefPtr<GPUTexture> texture() const { return m_texture; }
45
    RefPtr<GPUTexture> texture() const { return m_texture; }
44
46
45
    RefPtr<WebGPUTextureView> createDefaultTextureView();
47
    Ref<WebGPUTextureView> createDefaultTextureView();
48
    void destroy();
46
49
47
private:
50
private:
48
    explicit WebGPUTexture(RefPtr<GPUTexture>&&);
51
    explicit WebGPUTexture(RefPtr<GPUTexture>&&);
49
52
53
    void destroyImpl();
54
50
    RefPtr<GPUTexture> m_texture;
55
    RefPtr<GPUTexture> m_texture;
56
    Vector<Ref<WebGPUTextureView>> m_textureViews;
51
};
57
};
52
58
53
} // namespace WebCore
59
} // namespace WebCore
- a/Source/WebCore/Modules/webgpu/WebGPUTexture.idl -4 / +3 lines
Lines 30-38 a/Source/WebCore/Modules/webgpu/WebGPUTexture.idl_sec1
30
    ImplementationLacksVTable
30
    ImplementationLacksVTable
31
] interface WebGPUTexture {
31
] interface WebGPUTexture {
32
    WebGPUTextureView createDefaultTextureView();
32
    WebGPUTextureView createDefaultTextureView();
33
/* Not Yet Implemented:
34
    WebGPUTextureView createTextureView(WebGPUTextureViewDescriptor desc);
35
36
    void destroy();
33
    void destroy();
37
*/
34
35
    // Not Yet Implemented:
36
    // WebGPUTextureView createTextureView(WebGPUTextureViewDescriptor desc);
38
};
37
};
- a/Source/WebCore/Modules/webgpu/WebGPUTextureView.cpp -2 / +13 lines
Lines 28-45 a/Source/WebCore/Modules/webgpu/WebGPUTextureView.cpp_sec1
28
28
29
#if ENABLE(WEBGPU)
29
#if ENABLE(WEBGPU)
30
30
31
#include "GPUTexture.h"
32
31
namespace WebCore {
33
namespace WebCore {
32
34
33
Ref<WebGPUTextureView> WebGPUTextureView::create(Ref<GPUTexture>&& view)
35
Ref<WebGPUTextureView> WebGPUTextureView::create(RefPtr<GPUTexture>&& view)
34
{
36
{
35
    return adoptRef(*new WebGPUTextureView(WTFMove(view)));
37
    return adoptRef(*new WebGPUTextureView(WTFMove(view)));
36
}
38
}
37
39
38
WebGPUTextureView::WebGPUTextureView(Ref<GPUTexture>&& view)
40
WebGPUTextureView::WebGPUTextureView(RefPtr<GPUTexture>&& view)
39
    : m_texture(WTFMove(view))
41
    : m_texture(WTFMove(view))
40
{
42
{
41
}
43
}
42
44
45
void WebGPUTextureView::destroy()
46
{
47
    if (!m_texture)
48
        return;
49
50
    m_texture->destroy();
51
    m_texture = nullptr;
52
}
53
43
} // namespace WebCore
54
} // namespace WebCore
44
55
45
#endif // ENABLE(WEBGPU)
56
#endif // ENABLE(WEBGPU)
- a/Source/WebCore/Modules/webgpu/WebGPUTextureView.h -5 / +9 lines
Lines 27-47 a/Source/WebCore/Modules/webgpu/WebGPUTextureView.h_sec1
27
27
28
#if ENABLE(WEBGPU)
28
#if ENABLE(WEBGPU)
29
29
30
#include "GPUTexture.h"
31
#include <wtf/Ref.h>
30
#include <wtf/Ref.h>
32
#include <wtf/RefCounted.h>
31
#include <wtf/RefCounted.h>
33
32
34
namespace WebCore {
33
namespace WebCore {
35
34
35
class GPUTexture;
36
36
class WebGPUTextureView : public RefCounted<WebGPUTextureView> {
37
class WebGPUTextureView : public RefCounted<WebGPUTextureView> {
37
public:
38
public:
38
    static Ref<WebGPUTextureView> create(Ref<GPUTexture>&&);
39
    static Ref<WebGPUTextureView> create(RefPtr<GPUTexture>&&);
40
    ~WebGPUTextureView() { destroy(); }
41
42
    RefPtr<GPUTexture> texture() const { return m_texture; }
39
43
40
    Ref<GPUTexture> texture() { return m_texture.copyRef(); }
44
    void destroy();
41
private:
45
private:
42
    explicit WebGPUTextureView(Ref<GPUTexture>&&);
46
    explicit WebGPUTextureView(RefPtr<GPUTexture>&&);
43
    
47
    
44
    Ref<GPUTexture> m_texture;
48
    RefPtr<GPUTexture> m_texture;
45
};
49
};
46
50
47
} // namespace WebCore
51
} // namespace WebCore
- a/Source/WebCore/Sources.txt -3 / +3 lines
Lines 2769-2774 JSFocusEvent.cpp a/Source/WebCore/Sources.txt_sec1
2769
JSFontFace.cpp
2769
JSFontFace.cpp
2770
JSFontFaceSet.cpp
2770
JSFontFaceSet.cpp
2771
JSGPUColor.cpp
2771
JSGPUColor.cpp
2772
JSGPUBindGroupLayoutBinding.cpp
2773
JSGPUBindGroupLayoutDescriptor.cpp
2772
JSGPUBufferDescriptor.cpp
2774
JSGPUBufferDescriptor.cpp
2773
JSGPUBufferUsage.cpp
2775
JSGPUBufferUsage.cpp
2774
JSGPUCompareFunction.cpp
2776
JSGPUCompareFunction.cpp
Lines 2777-2782 JSGPUExtent3D.cpp a/Source/WebCore/Sources.txt_sec2
2777
JSGPULoadOp.cpp
2779
JSGPULoadOp.cpp
2778
JSGPUOrigin3D.cpp
2780
JSGPUOrigin3D.cpp
2779
JSGPURequestAdapterOptions.cpp
2781
JSGPURequestAdapterOptions.cpp
2782
JSGPUShaderStageBit.cpp
2780
JSGPUStoreOp.cpp
2783
JSGPUStoreOp.cpp
2781
JSGPUTextureDescriptor.cpp
2784
JSGPUTextureDescriptor.cpp
2782
JSGPUTextureDimension.cpp
2785
JSGPUTextureDimension.cpp
Lines 3316-3323 JSWebGPUBindGroup.cpp a/Source/WebCore/Sources.txt_sec3
3316
JSWebGPUBindGroupBinding.cpp
3319
JSWebGPUBindGroupBinding.cpp
3317
JSWebGPUBindGroupDescriptor.cpp
3320
JSWebGPUBindGroupDescriptor.cpp
3318
JSWebGPUBindGroupLayout.cpp
3321
JSWebGPUBindGroupLayout.cpp
3319
JSWebGPUBindGroupLayoutBinding.cpp
3320
JSWebGPUBindGroupLayoutDescriptor.cpp
3321
JSWebGPUBuffer.cpp
3322
JSWebGPUBuffer.cpp
3322
JSWebGPUBufferBinding.cpp
3323
JSWebGPUBufferBinding.cpp
3323
JSWebGPUCommandBuffer.cpp
3324
JSWebGPUCommandBuffer.cpp
Lines 3338-3344 JSWebGPURenderPipeline.cpp a/Source/WebCore/Sources.txt_sec4
3338
JSWebGPURenderPipelineDescriptor.cpp
3339
JSWebGPURenderPipelineDescriptor.cpp
3339
JSWebGPUShaderModule.cpp
3340
JSWebGPUShaderModule.cpp
3340
JSWebGPUShaderModuleDescriptor.cpp
3341
JSWebGPUShaderModuleDescriptor.cpp
3341
JSWebGPUShaderStageBit.cpp
3342
JSWebGPUSwapChain.cpp
3342
JSWebGPUSwapChain.cpp
3343
JSWebGPUTexture.cpp
3343
JSWebGPUTexture.cpp
3344
JSWebGPUTextureView.cpp
3344
JSWebGPUTextureView.cpp
- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj -15 / +11 lines
Lines 13968-13974 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec1
13968
		D026F489220A539800AC5F49 /* GPUTextureDimension.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = GPUTextureDimension.idl; sourceTree = "<group>"; };
13968
		D026F489220A539800AC5F49 /* GPUTextureDimension.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = GPUTextureDimension.idl; sourceTree = "<group>"; };
13969
		D026F48B220A5B0B00AC5F49 /* GPUTextureDescriptor.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = GPUTextureDescriptor.idl; sourceTree = "<group>"; };
13969
		D026F48B220A5B0B00AC5F49 /* GPUTextureDescriptor.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = GPUTextureDescriptor.idl; sourceTree = "<group>"; };
13970
		D026F48C220A5BAD00AC5F49 /* GPUTextureDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUTextureDescriptor.h; sourceTree = "<group>"; };
13970
		D026F48C220A5BAD00AC5F49 /* GPUTextureDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUTextureDescriptor.h; sourceTree = "<group>"; };
13971
		D02B83ED21C8397A00F85473 /* WebGPUBindGroupLayoutDescriptor.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUBindGroupLayoutDescriptor.idl; sourceTree = "<group>"; };
13972
		D02C26922181416D00D818E4 /* GPURequestAdapterOptions.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = GPURequestAdapterOptions.idl; sourceTree = "<group>"; };
13971
		D02C26922181416D00D818E4 /* GPURequestAdapterOptions.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = GPURequestAdapterOptions.idl; sourceTree = "<group>"; };
13973
		D02F854E21682A4A0088EE74 /* WebMetalCommandQueue.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebMetalCommandQueue.idl; sourceTree = "<group>"; };
13972
		D02F854E21682A4A0088EE74 /* WebMetalCommandQueue.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebMetalCommandQueue.idl; sourceTree = "<group>"; };
13974
		D02F855021682A560088EE74 /* WebMetalComputeCommandEncoder.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = WebMetalComputeCommandEncoder.idl; sourceTree = "<group>"; };
13973
		D02F855021682A560088EE74 /* WebMetalComputeCommandEncoder.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = WebMetalComputeCommandEncoder.idl; sourceTree = "<group>"; };
Lines 14068-14075 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec2
14068
		D06EF553220BA26A0018724E /* GPUUtilsMetal.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = GPUUtilsMetal.mm; sourceTree = "<group>"; };
14067
		D06EF553220BA26A0018724E /* GPUUtilsMetal.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = GPUUtilsMetal.mm; sourceTree = "<group>"; };
14069
		D07DEAB70A36554A00CA30F8 /* InsertListCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = InsertListCommand.cpp; sourceTree = "<group>"; };
14068
		D07DEAB70A36554A00CA30F8 /* InsertListCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = InsertListCommand.cpp; sourceTree = "<group>"; };
14070
		D07DEAB80A36554A00CA30F8 /* InsertListCommand.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = InsertListCommand.h; sourceTree = "<group>"; };
14069
		D07DEAB80A36554A00CA30F8 /* InsertListCommand.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = InsertListCommand.h; sourceTree = "<group>"; };
14071
		D083D98421C48050008E8EFF /* GPUBindGroupLayoutDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUBindGroupLayoutDescriptor.h; sourceTree = "<group>"; };
14072
		D083D98621C4813E008E8EFF /* WebGPUBindGroupLayoutDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WebGPUBindGroupLayoutDescriptor.h; path = Modules/streams/WebGPUBindGroupLayoutDescriptor.h; sourceTree = SOURCE_ROOT; };
14073
		D084033A221CBF5400007205 /* GPUBuffer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = GPUBuffer.cpp; sourceTree = "<group>"; };
14070
		D084033A221CBF5400007205 /* GPUBuffer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = GPUBuffer.cpp; sourceTree = "<group>"; };
14074
		D084033D221E186400007205 /* WebGPUBindGroupDescriptor.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUBindGroupDescriptor.cpp; sourceTree = "<group>"; };
14071
		D084033D221E186400007205 /* WebGPUBindGroupDescriptor.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUBindGroupDescriptor.cpp; sourceTree = "<group>"; };
14075
		D0843A4A20FEBE3D00FE860E /* GraphicsContext3DManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GraphicsContext3DManager.h; sourceTree = "<group>"; };
14072
		D0843A4A20FEBE3D00FE860E /* GraphicsContext3DManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GraphicsContext3DManager.h; sourceTree = "<group>"; };
Lines 14100-14109 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec3
14100
		D0B0556609C6700100307E43 /* CreateLinkCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CreateLinkCommand.h; sourceTree = "<group>"; };
14097
		D0B0556609C6700100307E43 /* CreateLinkCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CreateLinkCommand.h; sourceTree = "<group>"; };
14101
		D0B0556709C6700100307E43 /* CreateLinkCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CreateLinkCommand.cpp; sourceTree = "<group>"; };
14098
		D0B0556709C6700100307E43 /* CreateLinkCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CreateLinkCommand.cpp; sourceTree = "<group>"; };
14102
		D0B8BB0121C46E78000C7681 /* GPUBindGroupLayoutBinding.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUBindGroupLayoutBinding.h; sourceTree = "<group>"; };
14099
		D0B8BB0121C46E78000C7681 /* GPUBindGroupLayoutBinding.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUBindGroupLayoutBinding.h; sourceTree = "<group>"; };
14103
		D0B8BB0321C4711D000C7681 /* WebGPUShaderStageBit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUShaderStageBit.h; sourceTree = "<group>"; };
14104
		D0B8BB0421C4711D000C7681 /* WebGPUShaderStageBit.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUShaderStageBit.idl; sourceTree = "<group>"; };
14105
		D0B8BB0521C47256000C7681 /* WebGPUBindGroupLayoutBinding.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUBindGroupLayoutBinding.h; sourceTree = "<group>"; };
14106
		D0B8BB0621C47256000C7681 /* WebGPUBindGroupLayoutBinding.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUBindGroupLayoutBinding.idl; sourceTree = "<group>"; };
14107
		D0BC54481443AC4A00E105DA /* CachedStyleSheetClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CachedStyleSheetClient.h; sourceTree = "<group>"; };
14100
		D0BC54481443AC4A00E105DA /* CachedStyleSheetClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CachedStyleSheetClient.h; sourceTree = "<group>"; };
14108
		D0BD4F5A1408850F006839B6 /* DictationCommandIOS.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DictationCommandIOS.cpp; sourceTree = "<group>"; };
14101
		D0BD4F5A1408850F006839B6 /* DictationCommandIOS.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DictationCommandIOS.cpp; sourceTree = "<group>"; };
14109
		D0BD4F5B1408850F006839B6 /* DictationCommandIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DictationCommandIOS.h; sourceTree = "<group>"; };
14102
		D0BD4F5B1408850F006839B6 /* DictationCommandIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DictationCommandIOS.h; sourceTree = "<group>"; };
Lines 14138-14143 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec4
14138
		D0CAAE9E216824A8001C91C7 /* WebMetalCommandBuffer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebMetalCommandBuffer.cpp; sourceTree = "<group>"; };
14131
		D0CAAE9E216824A8001C91C7 /* WebMetalCommandBuffer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebMetalCommandBuffer.cpp; sourceTree = "<group>"; };
14139
		D0CCA94922299F97006979B6 /* GPUOrigin3D.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUOrigin3D.h; sourceTree = "<group>"; };
14132
		D0CCA94922299F97006979B6 /* GPUOrigin3D.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUOrigin3D.h; sourceTree = "<group>"; };
14140
		D0CCA94A22299F97006979B6 /* GPUOrigin3D.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = GPUOrigin3D.idl; sourceTree = "<group>"; };
14133
		D0CCA94A22299F97006979B6 /* GPUOrigin3D.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = GPUOrigin3D.idl; sourceTree = "<group>"; };
14134
		D0D69C9C222E00C20032927E /* GPUBindGroupLayoutDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUBindGroupLayoutDescriptor.h; sourceTree = "<group>"; };
14135
		D0D69C9D222E00C20032927E /* GPUBindGroupLayoutDescriptor.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = GPUBindGroupLayoutDescriptor.idl; sourceTree = "<group>"; };
14136
		D0D69C9F222E015E0032927E /* GPUBindGroupLayoutBinding.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = GPUBindGroupLayoutBinding.idl; sourceTree = "<group>"; };
14141
		D0D8648721B64CAA003C983C /* GPUBufferDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUBufferDescriptor.h; sourceTree = "<group>"; };
14137
		D0D8648721B64CAA003C983C /* GPUBufferDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUBufferDescriptor.h; sourceTree = "<group>"; };
14142
		D0D8648C21B70676003C983C /* WebGPUBuffer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUBuffer.h; sourceTree = "<group>"; };
14138
		D0D8648C21B70676003C983C /* WebGPUBuffer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUBuffer.h; sourceTree = "<group>"; };
14143
		D0D8648D21B70676003C983C /* WebGPUBuffer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUBuffer.cpp; sourceTree = "<group>"; };
14139
		D0D8648D21B70676003C983C /* WebGPUBuffer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUBuffer.cpp; sourceTree = "<group>"; };
Lines 14156-14161 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec5
14156
		D0DA0BE4217930E2007FE2AC /* WebGPUSwapChain.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUSwapChain.h; sourceTree = "<group>"; };
14152
		D0DA0BE4217930E2007FE2AC /* WebGPUSwapChain.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUSwapChain.h; sourceTree = "<group>"; };
14157
		D0DA0BE5217930E2007FE2AC /* WebGPUSwapChain.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUSwapChain.cpp; sourceTree = "<group>"; };
14153
		D0DA0BE5217930E2007FE2AC /* WebGPUSwapChain.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUSwapChain.cpp; sourceTree = "<group>"; };
14158
		D0DA0BE6217930E2007FE2AC /* WebGPUSwapChain.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUSwapChain.idl; sourceTree = "<group>"; };
14154
		D0DA0BE6217930E2007FE2AC /* WebGPUSwapChain.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUSwapChain.idl; sourceTree = "<group>"; };
14155
		D0DE8FB8222E09E200882550 /* GPUShaderStageBit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUShaderStageBit.h; sourceTree = "<group>"; };
14156
		D0DE8FB9222E09E200882550 /* GPUShaderStageBit.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = GPUShaderStageBit.idl; sourceTree = "<group>"; };
14159
		D0EACF7621937228000FA75C /* WebGPUCommandBuffer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUCommandBuffer.h; sourceTree = "<group>"; };
14157
		D0EACF7621937228000FA75C /* WebGPUCommandBuffer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUCommandBuffer.h; sourceTree = "<group>"; };
14160
		D0EACF7721937228000FA75C /* WebGPUCommandBuffer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUCommandBuffer.cpp; sourceTree = "<group>"; };
14158
		D0EACF7721937228000FA75C /* WebGPUCommandBuffer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUCommandBuffer.cpp; sourceTree = "<group>"; };
14161
		D0EACF7821937228000FA75C /* WebGPUCommandBuffer.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUCommandBuffer.idl; sourceTree = "<group>"; };
14159
		D0EACF7821937228000FA75C /* WebGPUCommandBuffer.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUCommandBuffer.idl; sourceTree = "<group>"; };
Lines 18462-18469 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec6
18462
				D0BE104E21E695E200E42A89 /* GPUBindGroupBinding.h */,
18460
				D0BE104E21E695E200E42A89 /* GPUBindGroupBinding.h */,
18463
				D0BE105121E6A70E00E42A89 /* GPUBindGroupDescriptor.h */,
18461
				D0BE105121E6A70E00E42A89 /* GPUBindGroupDescriptor.h */,
18464
				D02454D021C4A41C00B73628 /* GPUBindGroupLayout.h */,
18462
				D02454D021C4A41C00B73628 /* GPUBindGroupLayout.h */,
18465
				D0B8BB0121C46E78000C7681 /* GPUBindGroupLayoutBinding.h */,
18466
				D083D98421C48050008E8EFF /* GPUBindGroupLayoutDescriptor.h */,
18467
				D084033A221CBF5400007205 /* GPUBuffer.cpp */,
18463
				D084033A221CBF5400007205 /* GPUBuffer.cpp */,
18468
				D0D8649221B760F2003C983C /* GPUBuffer.h */,
18464
				D0D8649221B760F2003C983C /* GPUBuffer.h */,
18469
				D0BE104A21E6872F00E42A89 /* GPUBufferBinding.h */,
18465
				D0BE104A21E6872F00E42A89 /* GPUBufferBinding.h */,
Lines 26068-26073 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec7
26068
				D00F5941216ECC7A000D71DB /* DOMWindowWebGPU.cpp */,
26064
				D00F5941216ECC7A000D71DB /* DOMWindowWebGPU.cpp */,
26069
				D00F5940216ECC7A000D71DB /* DOMWindowWebGPU.h */,
26065
				D00F5940216ECC7A000D71DB /* DOMWindowWebGPU.h */,
26070
				D00F5942216ECC7A000D71DB /* DOMWindowWebGPU.idl */,
26066
				D00F5942216ECC7A000D71DB /* DOMWindowWebGPU.idl */,
26067
				D0B8BB0121C46E78000C7681 /* GPUBindGroupLayoutBinding.h */,
26068
				D0D69C9F222E015E0032927E /* GPUBindGroupLayoutBinding.idl */,
26069
				D0D69C9C222E00C20032927E /* GPUBindGroupLayoutDescriptor.h */,
26070
				D0D69C9D222E00C20032927E /* GPUBindGroupLayoutDescriptor.idl */,
26071
				D01B811922135EB900627B6C /* GPUBufferDescriptor.idl */,
26071
				D01B811922135EB900627B6C /* GPUBufferDescriptor.idl */,
26072
				D01B811C2213627300627B6C /* GPUBufferUsage.idl */,
26072
				D01B811C2213627300627B6C /* GPUBufferUsage.idl */,
26073
				D01B811222125AFC00627B6C /* GPUColor.idl */,
26073
				D01B811222125AFC00627B6C /* GPUColor.idl */,
Lines 26078-26083 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec8
26078
				D0CCA94922299F97006979B6 /* GPUOrigin3D.h */,
26078
				D0CCA94922299F97006979B6 /* GPUOrigin3D.h */,
26079
				D0CCA94A22299F97006979B6 /* GPUOrigin3D.idl */,
26079
				D0CCA94A22299F97006979B6 /* GPUOrigin3D.idl */,
26080
				D02C26922181416D00D818E4 /* GPURequestAdapterOptions.idl */,
26080
				D02C26922181416D00D818E4 /* GPURequestAdapterOptions.idl */,
26081
				D0DE8FB8222E09E200882550 /* GPUShaderStageBit.h */,
26082
				D0DE8FB9222E09E200882550 /* GPUShaderStageBit.idl */,
26081
				D08AA031220D0CE60058C502 /* GPUStoreOp.idl */,
26083
				D08AA031220D0CE60058C502 /* GPUStoreOp.idl */,
26082
				D026F48B220A5B0B00AC5F49 /* GPUTextureDescriptor.idl */,
26084
				D026F48B220A5B0B00AC5F49 /* GPUTextureDescriptor.idl */,
26083
				D026F489220A539800AC5F49 /* GPUTextureDimension.idl */,
26085
				D026F489220A539800AC5F49 /* GPUTextureDimension.idl */,
Lines 26100-26109 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec9
26100
				D003287A21C8645B00622AA6 /* WebGPUBindGroupLayout.cpp */,
26102
				D003287A21C8645B00622AA6 /* WebGPUBindGroupLayout.cpp */,
26101
				D003287921C8645B00622AA6 /* WebGPUBindGroupLayout.h */,
26103
				D003287921C8645B00622AA6 /* WebGPUBindGroupLayout.h */,
26102
				D003287B21C8645B00622AA6 /* WebGPUBindGroupLayout.idl */,
26104
				D003287B21C8645B00622AA6 /* WebGPUBindGroupLayout.idl */,
26103
				D0B8BB0521C47256000C7681 /* WebGPUBindGroupLayoutBinding.h */,
26104
				D0B8BB0621C47256000C7681 /* WebGPUBindGroupLayoutBinding.idl */,
26105
				D083D98621C4813E008E8EFF /* WebGPUBindGroupLayoutDescriptor.h */,
26106
				D02B83ED21C8397A00F85473 /* WebGPUBindGroupLayoutDescriptor.idl */,
26107
				D0D8648D21B70676003C983C /* WebGPUBuffer.cpp */,
26105
				D0D8648D21B70676003C983C /* WebGPUBuffer.cpp */,
26108
				D0D8648C21B70676003C983C /* WebGPUBuffer.h */,
26106
				D0D8648C21B70676003C983C /* WebGPUBuffer.h */,
26109
				D0D8648E21B70676003C983C /* WebGPUBuffer.idl */,
26107
				D0D8648E21B70676003C983C /* WebGPUBuffer.idl */,
Lines 26155-26162 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec10
26155
				D0615FCE217FE5C6008A48A8 /* WebGPUShaderModule.idl */,
26153
				D0615FCE217FE5C6008A48A8 /* WebGPUShaderModule.idl */,
26156
				D060D8872182697000339318 /* WebGPUShaderModuleDescriptor.h */,
26154
				D060D8872182697000339318 /* WebGPUShaderModuleDescriptor.h */,
26157
				D060D88421825D5F00339318 /* WebGPUShaderModuleDescriptor.idl */,
26155
				D060D88421825D5F00339318 /* WebGPUShaderModuleDescriptor.idl */,
26158
				D0B8BB0321C4711D000C7681 /* WebGPUShaderStageBit.h */,
26159
				D0B8BB0421C4711D000C7681 /* WebGPUShaderStageBit.idl */,
26160
				D0DA0BE5217930E2007FE2AC /* WebGPUSwapChain.cpp */,
26156
				D0DA0BE5217930E2007FE2AC /* WebGPUSwapChain.cpp */,
26161
				D0DA0BE4217930E2007FE2AC /* WebGPUSwapChain.h */,
26157
				D0DA0BE4217930E2007FE2AC /* WebGPUSwapChain.h */,
26162
				D0DA0BE6217930E2007FE2AC /* WebGPUSwapChain.idl */,
26158
				D0DA0BE6217930E2007FE2AC /* WebGPUSwapChain.idl */,
- a/Source/WebCore/bindings/js/WebCoreBuiltinNames.h -1 / +1 lines
Lines 82-87 namespace WebCore { a/Source/WebCore/bindings/js/WebCoreBuiltinNames.h_sec1
82
    macro(GamepadButton) \
82
    macro(GamepadButton) \
83
    macro(GamepadEvent) \
83
    macro(GamepadEvent) \
84
    macro(GPUBufferUsage) \
84
    macro(GPUBufferUsage) \
85
    macro(GPUShaderStageBit) \
85
    macro(GPUTextureUsage) \
86
    macro(GPUTextureUsage) \
86
    macro(HTMLAttachmentElement) \
87
    macro(HTMLAttachmentElement) \
87
    macro(HTMLAudioElement) \
88
    macro(HTMLAudioElement) \
Lines 208-214 namespace WebCore { a/Source/WebCore/bindings/js/WebCoreBuiltinNames.h_sec2
208
    macro(WebGPURenderPassEncoder) \
209
    macro(WebGPURenderPassEncoder) \
209
    macro(WebGPURenderPipeline) \
210
    macro(WebGPURenderPipeline) \
210
    macro(WebGPUShaderModule) \
211
    macro(WebGPUShaderModule) \
211
    macro(WebGPUShaderStageBit) \
212
    macro(WebGPUSwapChain) \
212
    macro(WebGPUSwapChain) \
213
    macro(WebGPUTexture) \
213
    macro(WebGPUTexture) \
214
    macro(WebGPUTextureView) \
214
    macro(WebGPUTextureView) \
- a/Source/WebCore/platform/graphics/gpu/GPUBindGroupLayout.h -1 / +1 lines
Lines 45-51 class GPUDevice; a/Source/WebCore/platform/graphics/gpu/GPUBindGroupLayout.h_sec1
45
45
46
class GPUBindGroupLayout : public RefCounted<GPUBindGroupLayout> {
46
class GPUBindGroupLayout : public RefCounted<GPUBindGroupLayout> {
47
public:
47
public:
48
    static RefPtr<GPUBindGroupLayout> tryCreate(const GPUDevice&, GPUBindGroupLayoutDescriptor&&);
48
    static RefPtr<GPUBindGroupLayout> tryCreate(const GPUDevice&, const GPUBindGroupLayoutDescriptor&);
49
49
50
    using BindingsMapType = HashMap<unsigned long long, GPUBindGroupLayoutBinding, WTF::IntHash<unsigned long long>, WTF::UnsignedWithZeroKeyHashTraits<unsigned long long>>;
50
    using BindingsMapType = HashMap<unsigned long long, GPUBindGroupLayoutBinding, WTF::IntHash<unsigned long long>, WTF::UnsignedWithZeroKeyHashTraits<unsigned long long>>;
51
    const BindingsMapType& bindingsMap() const { return m_bindingsMap; }
51
    const BindingsMapType& bindingsMap() const { return m_bindingsMap; }
- a/Source/WebCore/platform/graphics/gpu/GPUBindGroupLayoutBinding.h -59 lines
Lines 1-59 a/Source/WebCore/platform/graphics/gpu/GPUBindGroupLayoutBinding.h_sec1
1
/*
2
 * Copyright (C) 2018 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#pragma once
27
28
#if ENABLE(WEBGPU)
29
30
#include <wtf/RefCounted.h>
31
32
namespace WebCore {
33
34
using GPUShaderStageFlags = unsigned long;
35
36
class GPUShaderStageBit : public RefCounted<GPUShaderStageBit> {
37
public:
38
    static const GPUShaderStageFlags NONE = 0;
39
    static const GPUShaderStageFlags VERTEX = 1;
40
    static const GPUShaderStageFlags FRAGMENT = 2;
41
    static const GPUShaderStageFlags COMPUTE = 4;
42
};
43
44
struct GPUBindGroupLayoutBinding {
45
    enum class BindingType {
46
        UniformBuffer,
47
        Sampler,
48
        SampledTexture,
49
        StorageBuffer
50
    };
51
52
    unsigned long binding;
53
    GPUShaderStageFlags visibility;
54
    BindingType type;
55
};
56
57
} // namespace WebCore
58
59
#endif // ENABLE(WEBGPU)
- a/Source/WebCore/platform/graphics/gpu/GPUBindGroupLayoutDescriptor.h -43 lines
Lines 1-43 a/Source/WebCore/platform/graphics/gpu/GPUBindGroupLayoutDescriptor.h_sec1
1
/*
2
 * Copyright (C) 2018 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#pragma once
27
28
#if ENABLE(WEBGPU)
29
30
#include "GPUBindGroupLayoutBinding.h"
31
32
#include <wtf/Vector.h>
33
34
namespace WebCore {
35
36
struct GPUBindGroupLayoutDescriptor {
37
    Vector<GPUBindGroupLayoutBinding> bindings;
38
};
39
40
} // namespace WebCore
41
42
#endif // ENABLE(WEBGPU)
43
- a/Source/WebCore/platform/graphics/gpu/GPUCommandBuffer.h -4 / +13 lines
Lines 85-107 public: a/Source/WebCore/platform/graphics/gpu/GPUCommandBuffer.h_sec1
85
85
86
    PlatformCommandBuffer* platformCommandBuffer() const { return m_platformCommandBuffer.get(); }
86
    PlatformCommandBuffer* platformCommandBuffer() const { return m_platformCommandBuffer.get(); }
87
    const Vector<Ref<GPUBuffer>>& usedBuffers() const { return m_usedBuffers; }
87
    const Vector<Ref<GPUBuffer>>& usedBuffers() const { return m_usedBuffers; }
88
    const Vector<Ref<GPUTexture>>& usedTextures() const { return m_usedTextures; }
89
    bool isEncodingPass() const { return m_isEncodingPass; }
90
91
    void setIsEncodingPass(bool isEncoding) { m_isEncodingPass = isEncoding; }
88
#if USE(METAL)
92
#if USE(METAL)
89
    MTLBlitCommandEncoder *blitEncoder() const;
93
    ~GPUCommandBuffer();
94
    void endBlitEncoding();
90
#endif
95
#endif
91
96
92
    void copyBufferToBuffer(Ref<GPUBuffer>&&, unsigned long srcOffset, Ref<GPUBuffer>&&, unsigned long dstOffset, unsigned long size);
97
    void copyBufferToBuffer(Ref<GPUBuffer>&&, unsigned long srcOffset, Ref<GPUBuffer>&&, unsigned long dstOffset, unsigned long size);
93
    void copyBufferToTexture(const GPUBufferCopyView&, const GPUTextureCopyView&, const GPUExtent3D&);
98
    void copyBufferToTexture(GPUBufferCopyView&&, GPUTextureCopyView&&, const GPUExtent3D&);
94
    void copyTextureToBuffer(const GPUTextureCopyView&, const GPUBufferCopyView&, const GPUExtent3D&);
99
    void copyTextureToBuffer(GPUTextureCopyView&&, GPUBufferCopyView&&, const GPUExtent3D&);
95
    void copyTextureToTexture(const GPUTextureCopyView&, const GPUTextureCopyView&, const GPUExtent3D&);
100
    void copyTextureToTexture(GPUTextureCopyView&&, GPUTextureCopyView&&, const GPUExtent3D&);
96
101
97
    void useBuffer(Ref<GPUBuffer>&& buffer) { m_usedBuffers.append(WTFMove(buffer)); }
102
    void useBuffer(Ref<GPUBuffer>&& buffer) { m_usedBuffers.append(WTFMove(buffer)); }
103
    void useTexture(Ref<GPUTexture>&& texture) { m_usedTextures.append(WTFMove(texture)); }
98
104
99
private:
105
private:
100
    GPUCommandBuffer(PlatformCommandBufferSmartPtr&&);
106
    GPUCommandBuffer(PlatformCommandBufferSmartPtr&&);
101
107
102
    PlatformCommandBufferSmartPtr m_platformCommandBuffer;
108
    PlatformCommandBufferSmartPtr m_platformCommandBuffer;
103
    Vector<Ref<GPUBuffer>> m_usedBuffers;
109
    Vector<Ref<GPUBuffer>> m_usedBuffers;
110
    Vector<Ref<GPUTexture>> m_usedTextures;
111
    bool m_isEncodingPass = false;
104
#if USE(METAL)
112
#if USE(METAL)
113
    MTLBlitCommandEncoder *blitEncoder() const;
105
    mutable RetainPtr<MTLBlitCommandEncoder> m_blitEncoder;
114
    mutable RetainPtr<MTLBlitCommandEncoder> m_blitEncoder;
106
#endif
115
#endif
107
};
116
};
- a/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp -2 / +2 lines
Lines 54-62 RefPtr<GPUTexture> GPUDevice::tryCreateTexture(GPUTextureDescriptor&& descriptor a/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp_sec1
54
    return GPUTexture::tryCreate(*this, WTFMove(descriptor));
54
    return GPUTexture::tryCreate(*this, WTFMove(descriptor));
55
}
55
}
56
56
57
RefPtr<GPUBindGroupLayout> GPUDevice::tryCreateBindGroupLayout(GPUBindGroupLayoutDescriptor&& descriptor) const
57
RefPtr<GPUBindGroupLayout> GPUDevice::tryCreateBindGroupLayout(const GPUBindGroupLayoutDescriptor& descriptor) const
58
{
58
{
59
    return GPUBindGroupLayout::tryCreate(*this, WTFMove(descriptor));
59
    return GPUBindGroupLayout::tryCreate(*this, descriptor);
60
}
60
}
61
61
62
Ref<GPUPipelineLayout> GPUDevice::createPipelineLayout(GPUPipelineLayoutDescriptor&& descriptor) const
62
Ref<GPUPipelineLayout> GPUDevice::createPipelineLayout(GPUPipelineLayoutDescriptor&& descriptor) const
- a/Source/WebCore/platform/graphics/gpu/GPUDevice.h -1 / +1 lines
Lines 63-69 public: a/Source/WebCore/platform/graphics/gpu/GPUDevice.h_sec1
63
    RefPtr<GPUBuffer> tryCreateBuffer(GPUBufferDescriptor&&);
63
    RefPtr<GPUBuffer> tryCreateBuffer(GPUBufferDescriptor&&);
64
    RefPtr<GPUTexture> tryCreateTexture(GPUTextureDescriptor&&) const;
64
    RefPtr<GPUTexture> tryCreateTexture(GPUTextureDescriptor&&) const;
65
65
66
    RefPtr<GPUBindGroupLayout> tryCreateBindGroupLayout(GPUBindGroupLayoutDescriptor&&) const;
66
    RefPtr<GPUBindGroupLayout> tryCreateBindGroupLayout(const GPUBindGroupLayoutDescriptor&) const;
67
    Ref<GPUPipelineLayout> createPipelineLayout(GPUPipelineLayoutDescriptor&&) const;
67
    Ref<GPUPipelineLayout> createPipelineLayout(GPUPipelineLayoutDescriptor&&) const;
68
68
69
    RefPtr<GPUShaderModule> createShaderModule(GPUShaderModuleDescriptor&&) const;
69
    RefPtr<GPUShaderModule> createShaderModule(GPUShaderModuleDescriptor&&) const;
- a/Source/WebCore/platform/graphics/gpu/GPUPipelineLayout.cpp -1 / +1 lines
Lines 36-42 Ref<GPUPipelineLayout> GPUPipelineLayout::create(GPUPipelineLayoutDescriptor&& d a/Source/WebCore/platform/graphics/gpu/GPUPipelineLayout.cpp_sec1
36
}
36
}
37
37
38
GPUPipelineLayout::GPUPipelineLayout(GPUPipelineLayoutDescriptor&& descriptor)
38
GPUPipelineLayout::GPUPipelineLayout(GPUPipelineLayoutDescriptor&& descriptor)
39
    : m_bindGroupLayouts(descriptor.bindGroupLayouts)
39
    : m_bindGroupLayouts(WTFMove(descriptor.bindGroupLayouts))
40
{
40
{
41
}
41
}
42
42
- a/Source/WebCore/platform/graphics/gpu/GPUProgrammablePassEncoder.cpp +1 lines
Lines 35-40 namespace WebCore { a/Source/WebCore/platform/graphics/gpu/GPUProgrammablePassEncoder.cpp_sec1
35
GPUProgrammablePassEncoder::GPUProgrammablePassEncoder(Ref<GPUCommandBuffer>&& commandBuffer)
35
GPUProgrammablePassEncoder::GPUProgrammablePassEncoder(Ref<GPUCommandBuffer>&& commandBuffer)
36
    : m_commandBuffer(WTFMove(commandBuffer))
36
    : m_commandBuffer(WTFMove(commandBuffer))
37
{
37
{
38
    m_commandBuffer->setIsEncodingPass(true);
38
}
39
}
39
40
40
} // namespace WebCore
41
} // namespace WebCore
- a/Source/WebCore/platform/graphics/gpu/GPUProgrammablePassEncoder.h -8 / +8 lines
Lines 49-76 class GPUProgrammablePassEncoder : public RefCounted<GPUProgrammablePassEncoder> a/Source/WebCore/platform/graphics/gpu/GPUProgrammablePassEncoder.h_sec1
49
public:
49
public:
50
    virtual ~GPUProgrammablePassEncoder() = default;
50
    virtual ~GPUProgrammablePassEncoder() = default;
51
51
52
    void endPass();
52
    virtual void endPass();
53
    void setBindGroup(unsigned long, GPUBindGroup&);
53
    void setBindGroup(unsigned, GPUBindGroup&);
54
    virtual void setPipeline(Ref<GPURenderPipeline>&&) = 0;
54
    virtual void setPipeline(Ref<GPURenderPipeline>&&) = 0;
55
55
56
protected:
56
protected:
57
    GPUProgrammablePassEncoder(Ref<GPUCommandBuffer>&&);
57
    GPUProgrammablePassEncoder(Ref<GPUCommandBuffer>&&);
58
    virtual PlatformProgrammablePassEncoder* platformPassEncoder() const = 0;
59
58
60
    GPUCommandBuffer& commandBuffer() const { return m_commandBuffer.get(); }
59
    GPUCommandBuffer& commandBuffer() const { return m_commandBuffer.get(); }
60
    virtual PlatformProgrammablePassEncoder* platformPassEncoder() const = 0;
61
61
62
private:
62
private:
63
#if USE(METAL)
63
#if USE(METAL)
64
    void setResourceAsBufferOnEncoder(MTLArgumentEncoder *, const GPUBindingResource&, unsigned long, const char* const);
64
    void setResourceAsBufferOnEncoder(MTLArgumentEncoder *, const GPUBindingResource&, unsigned, const char* const);
65
    virtual void useResource(MTLResource *, unsigned long) = 0;
65
    void setResourceAsTextureOnEncoder(MTLArgumentEncoder *, const GPUBindingResource&, unsigned, const char* const);
66
    virtual void useResource(MTLResource *, unsigned) = 0;
66
67
67
    // Render command encoder methods.
68
    // Render command encoder methods.
68
    virtual void setVertexBuffer(MTLBuffer *, unsigned long, unsigned long) { }
69
    virtual void setVertexBuffer(MTLBuffer *, unsigned, unsigned) { }
69
    virtual void setFragmentBuffer(MTLBuffer *, unsigned long, unsigned long) { }
70
    virtual void setFragmentBuffer(MTLBuffer *, unsigned, unsigned) { }
70
#endif // USE(METAL)
71
#endif // USE(METAL)
71
72
72
    Ref<GPUCommandBuffer> m_commandBuffer;
73
    Ref<GPUCommandBuffer> m_commandBuffer;
73
    bool m_isEncoding { true };
74
};
74
};
75
75
76
} // namespace WebCore
76
} // namespace WebCore
- a/Source/WebCore/platform/graphics/gpu/GPUQueue.h -1 / +1 lines
Lines 48-54 public: a/Source/WebCore/platform/graphics/gpu/GPUQueue.h_sec1
48
48
49
    PlatformQueue* platformQueue() const { return m_platformQueue.get(); }
49
    PlatformQueue* platformQueue() const { return m_platformQueue.get(); }
50
50
51
    void submit(Vector<Ref<const GPUCommandBuffer>>&&);
51
    void submit(Vector<Ref<GPUCommandBuffer>>&&);
52
52
53
    String label() const;
53
    String label() const;
54
    void setLabel(const String&) const;
54
    void setLabel(const String&) const;
- a/Source/WebCore/platform/graphics/gpu/GPURenderPassEncoder.h -3 / +4 lines
Lines 51-56 class GPURenderPassEncoder : public GPUProgrammablePassEncoder { a/Source/WebCore/platform/graphics/gpu/GPURenderPassEncoder.h_sec1
51
public:
51
public:
52
    static RefPtr<GPURenderPassEncoder> tryCreate(Ref<GPUCommandBuffer>&&, GPURenderPassDescriptor&&);
52
    static RefPtr<GPURenderPassEncoder> tryCreate(Ref<GPUCommandBuffer>&&, GPURenderPassDescriptor&&);
53
53
54
    void endPass() final;
54
    void setPipeline(Ref<GPURenderPipeline>&&) final;
55
    void setPipeline(Ref<GPURenderPipeline>&&) final;
55
56
56
    void setVertexBuffers(unsigned long, Vector<Ref<GPUBuffer>>&&, Vector<unsigned long long>&&);
57
    void setVertexBuffers(unsigned long, Vector<Ref<GPUBuffer>>&&, Vector<unsigned long long>&&);
Lines 64-72 private: a/Source/WebCore/platform/graphics/gpu/GPURenderPassEncoder.h_sec2
64
65
65
#if USE(METAL)
66
#if USE(METAL)
66
    // GPUProgrammablePassEncoder
67
    // GPUProgrammablePassEncoder
67
    void useResource(MTLResource *, unsigned long usage) final;
68
    void useResource(MTLResource *, unsigned usage) final;
68
    void setVertexBuffer(MTLBuffer *, unsigned long offset, unsigned long index) final;
69
    void setVertexBuffer(MTLBuffer *, unsigned offset, unsigned index) final;
69
    void setFragmentBuffer(MTLBuffer *, unsigned long offset, unsigned long index) final;
70
    void setFragmentBuffer(MTLBuffer *, unsigned offset, unsigned index) final;
70
#endif // USE(METAL)
71
#endif // USE(METAL)
71
72
72
    PlatformRenderPassEncoderSmartPtr m_platformRenderPassEncoder;
73
    PlatformRenderPassEncoderSmartPtr m_platformRenderPassEncoder;
- a/Source/WebCore/platform/graphics/gpu/GPUTexture.h -1 / +3 lines
Lines 53-60 public: a/Source/WebCore/platform/graphics/gpu/GPUTexture.h_sec1
53
    bool isTransferSource() const { return m_usage.contains(GPUTextureUsage::Flags::TransferSource); }
53
    bool isTransferSource() const { return m_usage.contains(GPUTextureUsage::Flags::TransferSource); }
54
    bool isTransferDestination() const { return m_usage.contains(GPUTextureUsage::Flags::TransferDestination); }
54
    bool isTransferDestination() const { return m_usage.contains(GPUTextureUsage::Flags::TransferDestination); }
55
    bool isOutputAttachment() const { return m_usage.contains(GPUTextureUsage::Flags::OutputAttachment); }
55
    bool isOutputAttachment() const { return m_usage.contains(GPUTextureUsage::Flags::OutputAttachment); }
56
    bool isReadOnly() const { return m_usage.containsAny({ GPUTextureUsage::Flags::TransferSource, GPUTextureUsage::Flags::Sampled }); }
56
57
57
    RefPtr<GPUTexture> createDefaultTextureView();
58
    RefPtr<GPUTexture> tryCreateDefaultTextureView();
59
    void destroy() { m_platformTexture = nullptr; }
58
60
59
private:
61
private:
60
    explicit GPUTexture(PlatformTextureSmartPtr&&, OptionSet<GPUTextureUsage::Flags>);
62
    explicit GPUTexture(PlatformTextureSmartPtr&&, OptionSet<GPUTextureUsage::Flags>);
- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupLayoutMetal.mm -5 / +7 lines
Lines 45-51 static MTLDataType MTLDataTypeForBindingType(GPUBindGroupLayoutBinding::BindingT a/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupLayoutMetal.mm_sec1
45
    case GPUBindGroupLayoutBinding::BindingType::SampledTexture:
45
    case GPUBindGroupLayoutBinding::BindingType::SampledTexture:
46
        return MTLDataTypeTexture;
46
        return MTLDataTypeTexture;
47
    case GPUBindGroupLayoutBinding::BindingType::UniformBuffer:
47
    case GPUBindGroupLayoutBinding::BindingType::UniformBuffer:
48
    case GPUBindGroupLayoutBinding::BindingType::DynamicUniformBuffer:
48
    case GPUBindGroupLayoutBinding::BindingType::StorageBuffer:
49
    case GPUBindGroupLayoutBinding::BindingType::StorageBuffer:
50
    case GPUBindGroupLayoutBinding::BindingType::DynamicStorageBuffer:
49
        return MTLDataTypePointer;
51
        return MTLDataTypePointer;
50
    }
52
    }
51
}
53
}
Lines 85-91 static GPUBindGroupLayout::ArgumentEncoderBuffer tryCreateArgumentEncoderAndBuff a/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupLayoutMetal.mm_sec2
85
    return args;
87
    return args;
86
};
88
};
87
89
88
RefPtr<GPUBindGroupLayout> GPUBindGroupLayout::tryCreate(const GPUDevice& device, GPUBindGroupLayoutDescriptor&& descriptor)
90
RefPtr<GPUBindGroupLayout> GPUBindGroupLayout::tryCreate(const GPUDevice& device, const GPUBindGroupLayoutDescriptor& descriptor)
89
{
91
{
90
    if (!device.platformDevice()) {
92
    if (!device.platformDevice()) {
91
        LOG(WebGPU, "GPUBindGroupLayout::tryCreate(): Invalid MTLDevice!");
93
        LOG(WebGPU, "GPUBindGroupLayout::tryCreate(): Invalid MTLDevice!");
Lines 97-103 RefPtr<GPUBindGroupLayout> GPUBindGroupLayout::tryCreate(const GPUDevice& device a/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupLayoutMetal.mm_sec3
97
99
98
    for (const auto& binding : descriptor.bindings) {
100
    for (const auto& binding : descriptor.bindings) {
99
        if (!bindingsMap.add(binding.binding, binding)) {
101
        if (!bindingsMap.add(binding.binding, binding)) {
100
            LOG(WebGPU, "GPUBindGroupLayout::tryCreate(): Duplicate binding %lu found in WebGPUBindGroupLayoutDescriptor!", binding.binding);
102
            LOG(WebGPU, "GPUBindGroupLayout::tryCreate(): Duplicate binding %lu found in GPUBindGroupLayoutDescriptor!", binding.binding);
101
            return nullptr;
103
            return nullptr;
102
        }
104
        }
103
105
Lines 115-125 RefPtr<GPUBindGroupLayout> GPUBindGroupLayout::tryCreate(const GPUDevice& device a/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupLayoutMetal.mm_sec4
115
        mtlArgument.get().dataType = MTLDataTypeForBindingType(binding.type);
117
        mtlArgument.get().dataType = MTLDataTypeForBindingType(binding.type);
116
        mtlArgument.get().index = binding.binding;
118
        mtlArgument.get().index = binding.binding;
117
119
118
        if (binding.visibility & GPUShaderStageBit::VERTEX)
120
        if (binding.visibility & GPUShaderStageBit::Flags::Vertex)
119
            appendArgumentToArray(vertexArgsArray, mtlArgument);
121
            appendArgumentToArray(vertexArgsArray, mtlArgument);
120
        if (binding.visibility & GPUShaderStageBit::FRAGMENT)
122
        if (binding.visibility & GPUShaderStageBit::Flags::Fragment)
121
            appendArgumentToArray(fragmentArgsArray, mtlArgument);
123
            appendArgumentToArray(fragmentArgsArray, mtlArgument);
122
        if (binding.visibility & GPUShaderStageBit::COMPUTE)
124
        if (binding.visibility & GPUShaderStageBit::Flags::Compute)
123
            appendArgumentToArray(computeArgsArray, mtlArgument);
125
            appendArgumentToArray(computeArgsArray, mtlArgument);
124
    }
126
    }
125
127
- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm -6 / +26 lines
Lines 58-64 RefPtr<GPUCommandBuffer> GPUCommandBuffer::create(GPUDevice& device) a/Source/WebCore/platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm_sec1
58
58
59
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
59
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
60
60
61
    buffer = retainPtr([mtlQueue commandBuffer]);
61
    buffer = [mtlQueue commandBuffer];
62
62
63
    END_BLOCK_OBJC_EXCEPTIONS;
63
    END_BLOCK_OBJC_EXCEPTIONS;
64
64
Lines 75-85 GPUCommandBuffer::GPUCommandBuffer(RetainPtr<MTLCommandBuffer>&& buffer) a/Source/WebCore/platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm_sec2
75
{
75
{
76
}
76
}
77
77
78
GPUCommandBuffer::~GPUCommandBuffer()
79
{
80
    endBlitEncoding();
81
}
82
78
MTLBlitCommandEncoder *GPUCommandBuffer::blitEncoder() const
83
MTLBlitCommandEncoder *GPUCommandBuffer::blitEncoder() const
79
{
84
{
80
    return m_blitEncoder ? m_blitEncoder.get() : (m_blitEncoder = [m_platformCommandBuffer blitCommandEncoder]).get();
85
    return m_blitEncoder ? m_blitEncoder.get() : (m_blitEncoder = [m_platformCommandBuffer blitCommandEncoder]).get();
81
}
86
}
82
87
88
void GPUCommandBuffer::endBlitEncoding()
89
{
90
    if (!m_blitEncoder)
91
        return;
92
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
93
    [m_blitEncoder endEncoding];
94
    END_BLOCK_OBJC_EXCEPTIONS;
95
    m_blitEncoder = nullptr;
96
}
97
83
void GPUCommandBuffer::copyBufferToBuffer(Ref<GPUBuffer>&& src, unsigned long srcOffset, Ref<GPUBuffer>&& dst, unsigned long dstOffset, unsigned long size)
98
void GPUCommandBuffer::copyBufferToBuffer(Ref<GPUBuffer>&& src, unsigned long srcOffset, Ref<GPUBuffer>&& dst, unsigned long dstOffset, unsigned long size)
84
{
99
{
85
    if (!src->isTransferSource() || !dst->isTransferDestination()) {
100
    if (!src->isTransferSource() || !dst->isTransferDestination()) {
Lines 117-123 void GPUCommandBuffer::copyBufferToBuffer(Ref<GPUBuffer>&& src, unsigned long sr a/Source/WebCore/platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm_sec3
117
    useBuffer(WTFMove(dst));
132
    useBuffer(WTFMove(dst));
118
}
133
}
119
134
120
void GPUCommandBuffer::copyBufferToTexture(const GPUBufferCopyView& srcBuffer, const GPUTextureCopyView& dstTexture, const GPUExtent3D& size)
135
void GPUCommandBuffer::copyBufferToTexture(GPUBufferCopyView&& srcBuffer, GPUTextureCopyView&& dstTexture, const GPUExtent3D& size)
121
{
136
{
122
    if (!srcBuffer.buffer->isTransferSource() || !dstTexture.texture->isTransferDestination()) {
137
    if (!srcBuffer.buffer->isTransferSource() || !dstTexture.texture->isTransferDestination()) {
123
        LOG(WebGPU, "GPUComandBuffer::copyBufferToTexture(): Invalid operation!");
138
        LOG(WebGPU, "GPUComandBuffer::copyBufferToTexture(): Invalid operation!");
Lines 151-160 void GPUCommandBuffer::copyBufferToTexture(const GPUBufferCopyView& srcBuffer, c a/Source/WebCore/platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm_sec4
151
166
152
    END_BLOCK_OBJC_EXCEPTIONS;
167
    END_BLOCK_OBJC_EXCEPTIONS;
153
168
154
    useBuffer(srcBuffer.buffer.copyRef());
169
    useBuffer(WTFMove(srcBuffer.buffer));
170
    useTexture(WTFMove(dstTexture.texture));
155
}
171
}
156
172
157
void GPUCommandBuffer::copyTextureToBuffer(const GPUTextureCopyView& srcTexture, const GPUBufferCopyView& dstBuffer, const GPUExtent3D& size)
173
void GPUCommandBuffer::copyTextureToBuffer(GPUTextureCopyView&& srcTexture, GPUBufferCopyView&& dstBuffer, const GPUExtent3D& size)
158
{
174
{
159
    if (!srcTexture.texture->isTransferSource() || !dstBuffer.buffer->isTransferDestination()) {
175
    if (!srcTexture.texture->isTransferSource() || !dstBuffer.buffer->isTransferDestination()) {
160
        LOG(WebGPU, "GPUCommandBuffer::copyTextureToBuffer(): Invalid operation!");
176
        LOG(WebGPU, "GPUCommandBuffer::copyTextureToBuffer(): Invalid operation!");
Lines 178-187 void GPUCommandBuffer::copyTextureToBuffer(const GPUTextureCopyView& srcTexture, a/Source/WebCore/platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm_sec5
178
194
179
    END_BLOCK_OBJC_EXCEPTIONS;
195
    END_BLOCK_OBJC_EXCEPTIONS;
180
196
181
    useBuffer(dstBuffer.buffer.copyRef());
197
    useTexture(WTFMove(srcTexture.texture));
198
    useBuffer(WTFMove(dstBuffer.buffer));
182
}
199
}
183
200
184
void GPUCommandBuffer::copyTextureToTexture(const GPUTextureCopyView& src, const GPUTextureCopyView& dst, const GPUExtent3D& size)
201
void GPUCommandBuffer::copyTextureToTexture(GPUTextureCopyView&& src, GPUTextureCopyView&& dst, const GPUExtent3D& size)
185
{
202
{
186
    if (!src.texture->isTransferSource() || !dst.texture->isTransferDestination()) {
203
    if (!src.texture->isTransferSource() || !dst.texture->isTransferDestination()) {
187
        LOG(WebGPU, "GPUCommandBuffer::copyTextureToTexture(): Invalid operation!");
204
        LOG(WebGPU, "GPUCommandBuffer::copyTextureToTexture(): Invalid operation!");
Lines 204-209 void GPUCommandBuffer::copyTextureToTexture(const GPUTextureCopyView& src, const a/Source/WebCore/platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm_sec6
204
        destinationOrigin:MTLOriginMake(dst.origin.x, dst.origin.y, dst.origin.z)];
221
        destinationOrigin:MTLOriginMake(dst.origin.x, dst.origin.y, dst.origin.z)];
205
222
206
    END_BLOCK_OBJC_EXCEPTIONS;
223
    END_BLOCK_OBJC_EXCEPTIONS;
224
225
    useTexture(WTFMove(src.texture));
226
    useTexture(WTFMove(dst.texture));
207
}
227
}
208
228
209
} // namespace WebCore
229
} // namespace WebCore
- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUDeviceMetal.mm -3 / +3 lines
Lines 38-44 namespace WebCore { a/Source/WebCore/platform/graphics/gpu/cocoa/GPUDeviceMetal.mm_sec1
38
38
39
RefPtr<GPUDevice> GPUDevice::create(Optional<GPURequestAdapterOptions>&& options)
39
RefPtr<GPUDevice> GPUDevice::create(Optional<GPURequestAdapterOptions>&& options)
40
{
40
{
41
    PlatformDeviceSmartPtr devicePtr;
41
    RetainPtr<MTLDevice> devicePtr;
42
42
43
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
43
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
44
    
44
    
Lines 48-54 RefPtr<GPUDevice> GPUDevice::create(Optional<GPURequestAdapterOptions>&& options a/Source/WebCore/platform/graphics/gpu/cocoa/GPUDeviceMetal.mm_sec2
48
        
48
        
49
        for (id <MTLDevice> device : devices.get()) {
49
        for (id <MTLDevice> device : devices.get()) {
50
            if (device.lowPower) {
50
            if (device.lowPower) {
51
                devicePtr = retainPtr(device);
51
                devicePtr = device;
52
                break;
52
                break;
53
            }
53
            }
54
        }
54
        }
Lines 70-76 RefPtr<GPUDevice> GPUDevice::create(Optional<GPURequestAdapterOptions>&& options a/Source/WebCore/platform/graphics/gpu/cocoa/GPUDeviceMetal.mm_sec3
70
    return adoptRef(new GPUDevice(WTFMove(devicePtr)));
70
    return adoptRef(new GPUDevice(WTFMove(devicePtr)));
71
}
71
}
72
72
73
GPUDevice::GPUDevice(PlatformDeviceSmartPtr&& device)
73
GPUDevice::GPUDevice(RetainPtr<MTLDevice>&& device)
74
    : m_platformDevice(WTFMove(device))
74
    : m_platformDevice(WTFMove(device))
75
{
75
{
76
}
76
}
- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUProgrammablePassEncoderMetal.mm -38 / +82 lines
Lines 38-51 namespace WebCore { a/Source/WebCore/platform/graphics/gpu/cocoa/GPUProgrammablePassEncoderMetal.mm_sec1
38
38
39
void GPUProgrammablePassEncoder::endPass()
39
void GPUProgrammablePassEncoder::endPass()
40
{
40
{
41
    if (!m_isEncoding)
41
    ASSERT(platformPassEncoder());
42
        return;
43
42
43
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
44
    [platformPassEncoder() endEncoding];
44
    [platformPassEncoder() endEncoding];
45
    m_isEncoding = false;
45
    END_BLOCK_OBJC_EXCEPTIONS;
46
47
    m_commandBuffer->setIsEncodingPass(false);
46
}
48
}
47
49
48
void GPUProgrammablePassEncoder::setResourceAsBufferOnEncoder(MTLArgumentEncoder *argumentEncoder, const GPUBindingResource& resource, unsigned long index, const char* const functionName)
50
void GPUProgrammablePassEncoder::setBindGroup(unsigned index, GPUBindGroup& bindGroup)
51
{
52
    const char* const functionName = "GPUProgrammablePassEncoder::setBindGroup()";
53
54
    if (!platformPassEncoder()) {
55
        LOG(WebGPU, "%s: Invalid operation: Encoding is ended!");
56
        return;
57
    }
58
59
    const auto& vertexArgs = bindGroup.layout().vertexArguments();
60
    const auto& fragmentArgs = bindGroup.layout().fragmentArguments();
61
    // FIXME: Finish support for compute.
62
63
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
64
65
    if (vertexArgs.buffer)
66
        setVertexBuffer(vertexArgs.buffer.get(), 0, index);
67
    if (fragmentArgs.buffer)
68
        setFragmentBuffer(fragmentArgs.buffer.get(), 0, index);
69
70
    END_BLOCK_OBJC_EXCEPTIONS;
71
72
    // Set each resource on each MTLArgumentEncoder it should be visible on.
73
    const auto& bindingsMap = bindGroup.layout().bindingsMap();
74
    for (const auto& binding : bindGroup.bindings()) {
75
        auto iterator = bindingsMap.find(binding.binding);
76
        if (iterator == bindingsMap.end()) {
77
            LOG(WebGPU, "%s: GPUBindGroupBinding %lu not found in GPUBindGroupLayout!", functionName, binding.binding);
78
            return;
79
        }
80
        auto bindGroupLayoutBinding = iterator->value;
81
82
        switch (bindGroupLayoutBinding.type) {
83
        // FIXME: Support more resource types.
84
        case GPUBindGroupLayoutBinding::BindingType::UniformBuffer:
85
        case GPUBindGroupLayoutBinding::BindingType::StorageBuffer: {
86
            if (bindGroupLayoutBinding.visibility & GPUShaderStageBit::Flags::Vertex)
87
                setResourceAsBufferOnEncoder(vertexArgs.encoder.get(), binding.resource, binding.binding, functionName);
88
            if (bindGroupLayoutBinding.visibility & GPUShaderStageBit::Flags::Fragment)
89
                setResourceAsBufferOnEncoder(fragmentArgs.encoder.get(), binding.resource, binding.binding, functionName);
90
            break;
91
        }
92
        case GPUBindGroupLayoutBinding::BindingType::SampledTexture: {
93
            if (bindGroupLayoutBinding.visibility & GPUShaderStageBit::Flags::Vertex)
94
                setResourceAsTextureOnEncoder(vertexArgs.encoder.get(), binding.resource, binding.binding, functionName);
95
            if (bindGroupLayoutBinding.visibility & GPUShaderStageBit::Flags::Fragment)
96
                setResourceAsTextureOnEncoder(fragmentArgs.encoder.get(), binding.resource, binding.binding, functionName);
97
            break;
98
        }
99
        default:
100
            LOG(WebGPU, "%s: Resource type not yet implemented.", functionName);
101
            return;
102
        }
103
    }
104
}
105
106
void GPUProgrammablePassEncoder::setResourceAsBufferOnEncoder(MTLArgumentEncoder *argumentEncoder, const GPUBindingResource& resource, unsigned index, const char* const functionName)
49
{
107
{
50
#if LOG_DISABLED
108
#if LOG_DISABLED
51
    UNUSED_PARAM(functionName);
109
    UNUSED_PARAM(functionName);
Lines 79-129 void GPUProgrammablePassEncoder::setResourceAsBufferOnEncoder(MTLArgumentEncoder a/Source/WebCore/platform/graphics/gpu/cocoa/GPUProgrammablePassEncoderMetal.mm_sec2
79
    m_commandBuffer->useBuffer(bufferRef.copyRef());
137
    m_commandBuffer->useBuffer(bufferRef.copyRef());
80
}
138
}
81
139
82
void GPUProgrammablePassEncoder::setBindGroup(unsigned long index, GPUBindGroup& bindGroup)
140
void GPUProgrammablePassEncoder::setResourceAsTextureOnEncoder(MTLArgumentEncoder *argumentEncoder, const GPUBindingResource& resource, unsigned index, const char* const functionName)
83
{
141
{
84
    const char* const functionName = "GPUProgrammablePassEncoder::setBindGroup()";
85
#if LOG_DISABLED
142
#if LOG_DISABLED
86
    UNUSED_PARAM(functionName);
143
    UNUSED_PARAM(functionName);
87
#endif
144
#endif
145
    if (!argumentEncoder) {
146
        LOG(WebGPU, "%s: No argument encoder for requested stage found!", functionName);
147
        return;
148
    }
88
149
89
    const auto& vertexArgs = bindGroup.layout().vertexArguments();
150
    if (!WTF::holds_alternative<Ref<GPUTexture>>(resource)) {
90
    const auto& fragmentArgs = bindGroup.layout().fragmentArguments();
151
        LOG(WebGPU, "%s: Resource is not a texture type!", functionName);
91
    // FIXME: Finish support for compute.
152
        return;
153
    }
154
155
    auto& textureRef = WTF::get<Ref<GPUTexture>>(resource);
156
    auto mtlTexture = textureRef->platformTexture();
157
158
    if (!mtlTexture) {
159
        LOG(WebGPU, "%s: Invalid MTLTexture in GPUTextureView binding!", functionName);
160
        return;
161
    }
92
162
93
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
163
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
94
164
95
    if (vertexArgs.buffer)
165
    [argumentEncoder setTexture:mtlTexture atIndex:index];
96
        setVertexBuffer(vertexArgs.buffer.get(), 0, index);
166
    useResource(mtlTexture, textureRef->isReadOnly() ? MTLResourceUsageRead : MTLResourceUsageRead | MTLResourceUsageWrite);
97
    if (fragmentArgs.buffer)
98
        setFragmentBuffer(fragmentArgs.buffer.get(), 0, index);
99
167
100
    END_BLOCK_OBJC_EXCEPTIONS;
168
    END_BLOCK_OBJC_EXCEPTIONS;
101
169
102
    // Set each resource on each MTLArgumentEncoder it should be visible on.
170
    m_commandBuffer->useTexture(textureRef.copyRef());
103
    const auto& bindingsMap = bindGroup.layout().bindingsMap();
104
    for (const auto& binding : bindGroup.bindings()) {
105
        auto iterator = bindingsMap.find(binding.binding);
106
        if (iterator == bindingsMap.end()) {
107
            LOG(WebGPU, "%s: GPUBindGroupBinding %lu not found in GPUBindGroupLayout!", functionName, binding.binding);
108
            return;
109
        }
110
        auto bindGroupLayoutBinding = iterator->value;
111
112
        switch (bindGroupLayoutBinding.type) {
113
        // FIXME: Support more resource types.
114
        case GPUBindGroupLayoutBinding::BindingType::UniformBuffer:
115
        case GPUBindGroupLayoutBinding::BindingType::StorageBuffer: {
116
            if (bindGroupLayoutBinding.visibility & GPUShaderStageBit::VERTEX)
117
                setResourceAsBufferOnEncoder(vertexArgs.encoder.get(), binding.resource, binding.binding, functionName);
118
            if (bindGroupLayoutBinding.visibility & GPUShaderStageBit::FRAGMENT)
119
                setResourceAsBufferOnEncoder(fragmentArgs.encoder.get(), binding.resource, binding.binding, functionName);
120
            break;
121
        }
122
        default:
123
            LOG(WebGPU, "%s: Resource type not yet implemented.", functionName);
124
            return;
125
        }
126
    }
127
}
171
}
128
172
129
} // namespace WebCore
173
} // namespace WebCore
- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUQueueMetal.mm -3 / +9 lines
Lines 70-82 GPUQueue::GPUQueue(PlatformQueueSmartPtr&& queue) a/Source/WebCore/platform/graphics/gpu/cocoa/GPUQueueMetal.mm_sec1
70
{
70
{
71
}
71
}
72
72
73
void GPUQueue::submit(Vector<Ref<const GPUCommandBuffer>>&& commandBuffers)
73
void GPUQueue::submit(Vector<Ref<GPUCommandBuffer>>&& commandBuffers)
74
{
74
{
75
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
75
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
76
76
77
    for (auto& commandBuffer : commandBuffers) {
77
    for (auto& commandBuffer : commandBuffers) {
78
        if (commandBuffer->blitEncoder())
78
        commandBuffer->endBlitEncoding();
79
            [commandBuffer->blitEncoder() endEncoding];
80
        // Prevent any buffer mapping callbacks from executing until command buffer is complete.
79
        // Prevent any buffer mapping callbacks from executing until command buffer is complete.
81
        for (auto& buffer : commandBuffer->usedBuffers()) {
80
        for (auto& buffer : commandBuffer->usedBuffers()) {
82
            if (buffer->state() != GPUBuffer::State::Unmapped) {
81
            if (buffer->state() != GPUBuffer::State::Unmapped) {
Lines 85-90 void GPUQueue::submit(Vector<Ref<const GPUCommandBuffer>>&& commandBuffers) a/Source/WebCore/platform/graphics/gpu/cocoa/GPUQueueMetal.mm_sec2
85
            }
84
            }
86
            buffer->commandBufferCommitted(commandBuffer->platformCommandBuffer());
85
            buffer->commandBufferCommitted(commandBuffer->platformCommandBuffer());
87
        }
86
        }
87
        // Also ensure textures are still valid.
88
        for (auto& texture : commandBuffer->usedTextures()) {
89
            if (!texture->platformTexture()) {
90
                LOG(WebGPU, "GPUQueue::submit(): Invalid GPUTexture set on a GPUCommandBuffer!");
91
                return;
92
            }
93
        }
88
94
89
        [commandBuffer->platformCommandBuffer() commit];
95
        [commandBuffer->platformCommandBuffer() commit];
90
    }
96
    }
- a/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPassEncoderMetal.mm -6 / +57 lines
Lines 117-122 RefPtr<GPURenderPassEncoder> GPURenderPassEncoder::tryCreate(Ref<GPUCommandBuffe a/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPassEncoderMetal.mm_sec1
117
{
117
{
118
    const char* const functionName = "GPURenderPassEncoder::tryCreate()";
118
    const char* const functionName = "GPURenderPassEncoder::tryCreate()";
119
119
120
    // Only one command encoder may be active at a time.
121
    if (buffer->isEncodingPass()) {
122
        LOG(WebGPU, "%s: Existing pass encoder must be ended first!");
123
        return nullptr;
124
    }
125
120
    RetainPtr<MTLRenderPassDescriptor> mtlDescriptor;
126
    RetainPtr<MTLRenderPassDescriptor> mtlDescriptor;
121
127
122
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
128
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
Lines 137-147 RefPtr<GPURenderPassEncoder> GPURenderPassEncoder::tryCreate(Ref<GPUCommandBuffe a/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPassEncoderMetal.mm_sec2
137
        && !populateMtlDepthStencilAttachment(mtlDescriptor.get().depthAttachment, *descriptor.depthStencilAttachment, functionName))
143
        && !populateMtlDepthStencilAttachment(mtlDescriptor.get().depthAttachment, *descriptor.depthStencilAttachment, functionName))
138
        return nullptr;
144
        return nullptr;
139
145
146
    buffer->endBlitEncoding();
147
140
    RetainPtr<MTLRenderCommandEncoder> mtlEncoder;
148
    RetainPtr<MTLRenderCommandEncoder> mtlEncoder;
141
149
142
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
150
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
143
151
144
    mtlEncoder = retainPtr([buffer->platformCommandBuffer() renderCommandEncoderWithDescriptor:mtlDescriptor.get()]);
152
    mtlEncoder = [buffer->platformCommandBuffer() renderCommandEncoderWithDescriptor:mtlDescriptor.get()];
145
153
146
    END_BLOCK_OBJC_EXCEPTIONS;
154
    END_BLOCK_OBJC_EXCEPTIONS;
147
155
Lines 149-155 RefPtr<GPURenderPassEncoder> GPURenderPassEncoder::tryCreate(Ref<GPUCommandBuffe a/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPassEncoderMetal.mm_sec3
149
        LOG(WebGPU, "%s: Unable to create MTLRenderCommandEncoder!", functionName);
157
        LOG(WebGPU, "%s: Unable to create MTLRenderCommandEncoder!", functionName);
150
        return nullptr;
158
        return nullptr;
151
    }
159
    }
152
160
    
153
    return adoptRef(new GPURenderPassEncoder(WTFMove(buffer), WTFMove(mtlEncoder)));
161
    return adoptRef(new GPURenderPassEncoder(WTFMove(buffer), WTFMove(mtlEncoder)));
154
}
162
}
155
163
Lines 159-171 GPURenderPassEncoder::GPURenderPassEncoder(Ref<GPUCommandBuffer>&& commandBuffer a/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPassEncoderMetal.mm_sec4
159
{
167
{
160
}
168
}
161
169
162
PlatformProgrammablePassEncoder *GPURenderPassEncoder::platformPassEncoder() const
170
MTLCommandEncoder *GPURenderPassEncoder::platformPassEncoder() const
163
{
171
{
164
    return m_platformRenderPassEncoder.get();
172
    return m_platformRenderPassEncoder.get();
165
}
173
}
166
174
175
void GPURenderPassEncoder::endPass()
176
{
177
    if (!m_platformRenderPassEncoder)
178
        return;
179
    GPUProgrammablePassEncoder::endPass();
180
    m_platformRenderPassEncoder = nullptr;
181
}
182
167
void GPURenderPassEncoder::setPipeline(Ref<GPURenderPipeline>&& pipeline)
183
void GPURenderPassEncoder::setPipeline(Ref<GPURenderPipeline>&& pipeline)
168
{
184
{
185
    if (!m_platformRenderPassEncoder) {
186
        LOG(WebGPU, "GPURenderPassEncoder::setPipeline(): Invalid operation: Encoding is ended!");
187
        return;
188
    }
189
169
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
190
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
170
191
171
    if (pipeline->depthStencilState())
192
    if (pipeline->depthStencilState())
Lines 180-185 void GPURenderPassEncoder::setPipeline(Ref<GPURenderPipeline>&& pipeline) a/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPassEncoderMetal.mm_sec5
180
201
181
void GPURenderPassEncoder::setVertexBuffers(unsigned long index, Vector<Ref<GPUBuffer>>&& buffers, Vector<unsigned long long>&& offsets)
202
void GPURenderPassEncoder::setVertexBuffers(unsigned long index, Vector<Ref<GPUBuffer>>&& buffers, Vector<unsigned long long>&& offsets)
182
{
203
{
204
    if (!m_platformRenderPassEncoder) {
205
        LOG(WebGPU, "GPURenderPassEncoder::setVertexBuffers(): Invalid operation: Encoding is ended!");
206
        return;
207
    }
208
183
    ASSERT(buffers.size() && offsets.size() == buffers.size());
209
    ASSERT(buffers.size() && offsets.size() == buffers.size());
184
210
185
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
211
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
Lines 214-219 static MTLPrimitiveType primitiveTypeForGPUPrimitiveTopology(PrimitiveTopology t a/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPassEncoderMetal.mm_sec6
214
240
215
void GPURenderPassEncoder::draw(unsigned long vertexCount, unsigned long instanceCount, unsigned long firstVertex, unsigned long firstInstance)
241
void GPURenderPassEncoder::draw(unsigned long vertexCount, unsigned long instanceCount, unsigned long firstVertex, unsigned long firstInstance)
216
{
242
{
243
    if (!m_platformRenderPassEncoder) {
244
        LOG(WebGPU, "GPURenderPassEncoder::draw(): Invalid operation: Encoding is ended!");
245
        return;
246
    }
247
248
    if (!m_pipeline) {
249
        LOG(WebGPU, "GPURenderPassEncoder::draw(): No valid GPURenderPipeline found!");
250
        return;
251
    }
252
217
    [m_platformRenderPassEncoder 
253
    [m_platformRenderPassEncoder 
218
        drawPrimitives:primitiveTypeForGPUPrimitiveTopology(m_pipeline->primitiveTopology())
254
        drawPrimitives:primitiveTypeForGPUPrimitiveTopology(m_pipeline->primitiveTopology())
219
        vertexStart:firstVertex
255
        vertexStart:firstVertex
Lines 224-241 void GPURenderPassEncoder::draw(unsigned long vertexCount, unsigned long instanc a/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPassEncoderMetal.mm_sec7
224
260
225
#if USE(METAL)
261
#if USE(METAL)
226
262
227
void GPURenderPassEncoder::useResource(MTLResource *resource, unsigned long usage)
263
void GPURenderPassEncoder::useResource(MTLResource *resource, unsigned usage)
228
{
264
{
265
    if (!m_platformRenderPassEncoder) {
266
        LOG(WebGPU, "GPURenderPassEncoder: Invalid operation: Encoding is ended!");
267
        return;
268
    }
269
229
    [m_platformRenderPassEncoder useResource:resource usage:usage];
270
    [m_platformRenderPassEncoder useResource:resource usage:usage];
230
}
271
}
231
272
232
void GPURenderPassEncoder::setVertexBuffer(MTLBuffer *buffer, unsigned long offset, unsigned long index)
273
void GPURenderPassEncoder::setVertexBuffer(MTLBuffer *buffer, unsigned offset, unsigned index)
233
{
274
{
275
    if (!m_platformRenderPassEncoder) {
276
        LOG(WebGPU, "GPURenderPassEncoder: Invalid operation: Encoding is ended!");
277
        return;
278
    }
279
234
    [m_platformRenderPassEncoder setVertexBuffer:buffer offset:offset atIndex:index];
280
    [m_platformRenderPassEncoder setVertexBuffer:buffer offset:offset atIndex:index];
235
}
281
}
236
282
237
void GPURenderPassEncoder::setFragmentBuffer(MTLBuffer *buffer, unsigned long offset, unsigned long index)
283
void GPURenderPassEncoder::setFragmentBuffer(MTLBuffer *buffer, unsigned offset, unsigned index)
238
{
284
{
285
    if (!m_platformRenderPassEncoder) {
286
        LOG(WebGPU, "GPURenderPassEncoder: Invalid operation: Encoding is ended!");
287
        return;
288
    }
289
239
    [m_platformRenderPassEncoder setFragmentBuffer:buffer offset:offset atIndex:index];
290
    [m_platformRenderPassEncoder setFragmentBuffer:buffer offset:offset atIndex:index];
240
}
291
}
241
292
- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm -1 / +1 lines
Lines 108-114 RefPtr<GPUTexture> GPUSwapChain::getNextTexture() a/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm_sec1
108
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
108
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
109
109
110
    m_currentDrawable = retainPtr([m_platformSwapLayer nextDrawable]);
110
    m_currentDrawable = retainPtr([m_platformSwapLayer nextDrawable]);
111
    mtlTexture = retainPtr([m_currentDrawable texture]);
111
    mtlTexture = [m_currentDrawable texture];
112
112
113
    END_BLOCK_OBJC_EXCEPTIONS;
113
    END_BLOCK_OBJC_EXCEPTIONS;
114
114
- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUTextureMetal.mm -7 / +9 lines
Lines 82-99 static Optional<MTLTextureUsage> mtlTextureUsageForGPUTextureUsageFlags(OptionSe a/Source/WebCore/platform/graphics/gpu/cocoa/GPUTextureMetal.mm_sec1
82
    return MTLTextureUsageUnknown;
82
    return MTLTextureUsageUnknown;
83
}
83
}
84
84
85
#if !PLATFORM(MAC)
85
static MTLStorageMode storageModeForPixelFormatAndSampleCount(MTLPixelFormat format, unsigned long samples)
86
static MTLStorageMode storageModeForPixelFormatAndSampleCount(MTLPixelFormat format, unsigned long samples)
86
{
87
{
87
    // Depth, Stencil, DepthStencil, and Multisample textures must be allocated with the MTLStorageModePrivate resource option.
88
    // Depth, Stencil, DepthStencil, and Multisample textures must be allocated with the MTLStorageModePrivate resource option.
88
    if (format == MTLPixelFormatDepth32Float_Stencil8 || samples > 1)
89
    if (format == MTLPixelFormatDepth32Float_Stencil8 || samples > 1)
89
        return MTLStorageModePrivate;
90
        return MTLStorageModePrivate;
90
91
91
#if PLATFORM(MAC)
92
    return MTLStorageModeManaged;
93
#else
94
    return MTLStorageModeShared;
92
    return MTLStorageModeShared;
95
#endif
96
}
93
}
94
#endif
97
95
98
static RetainPtr<MTLTextureDescriptor> tryCreateMtlTextureDescriptor(const char* const functionName, const GPUTextureDescriptor& descriptor, OptionSet<GPUTextureUsage::Flags> usage)
96
static RetainPtr<MTLTextureDescriptor> tryCreateMtlTextureDescriptor(const char* const functionName, const GPUTextureDescriptor& descriptor, OptionSet<GPUTextureUsage::Flags> usage)
99
{
97
{
Lines 117-123 static RetainPtr<MTLTextureDescriptor> tryCreateMtlTextureDescriptor(const char* a/Source/WebCore/platform/graphics/gpu/cocoa/GPUTextureMetal.mm_sec2
117
    if (!mtlUsage)
115
    if (!mtlUsage)
118
        return nullptr;
116
        return nullptr;
119
117
118
#if PLATFORM(MAC)
119
    auto storageMode = MTLStorageModePrivate;
120
#else
120
    auto storageMode = storageModeForPixelFormatAndSampleCount(pixelFormat, descriptor.sampleCount);
121
    auto storageMode = storageModeForPixelFormatAndSampleCount(pixelFormat, descriptor.sampleCount);
122
#endif
121
123
122
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
124
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
123
125
Lines 168-185 RefPtr<GPUTexture> GPUTexture::tryCreate(const GPUDevice& device, const GPUTextu a/Source/WebCore/platform/graphics/gpu/cocoa/GPUTextureMetal.mm_sec3
168
    return adoptRef(new GPUTexture(WTFMove(mtlTexture), usage));
170
    return adoptRef(new GPUTexture(WTFMove(mtlTexture), usage));
169
}
171
}
170
172
171
Ref<GPUTexture> GPUTexture::create(PlatformTextureSmartPtr&& texture, OptionSet<GPUTextureUsage::Flags> usage)
173
Ref<GPUTexture> GPUTexture::create(RetainPtr<MTLTexture>&& texture, OptionSet<GPUTextureUsage::Flags> usage)
172
{
174
{
173
    return adoptRef(*new GPUTexture(WTFMove(texture), usage));
175
    return adoptRef(*new GPUTexture(WTFMove(texture), usage));
174
}
176
}
175
177
176
GPUTexture::GPUTexture(PlatformTextureSmartPtr&& texture, OptionSet<GPUTextureUsage::Flags> usage)
178
GPUTexture::GPUTexture(RetainPtr<MTLTexture>&& texture, OptionSet<GPUTextureUsage::Flags> usage)
177
    : m_platformTexture(WTFMove(texture))
179
    : m_platformTexture(WTFMove(texture))
178
    , m_usage(usage)
180
    , m_usage(usage)
179
{
181
{
180
}
182
}
181
183
182
RefPtr<GPUTexture> GPUTexture::createDefaultTextureView()
184
RefPtr<GPUTexture> GPUTexture::tryCreateDefaultTextureView()
183
{
185
{
184
    RetainPtr<MTLTexture> texture;
186
    RetainPtr<MTLTexture> texture;
185
187
- a/LayoutTests/ChangeLog +18 lines
Lines 1-3 a/LayoutTests/ChangeLog_sec1
1
2019-03-05  Justin Fan  <justin_fan@apple.com>
2
3
        [Web GPU] GPUTexture and GPUTextureView updates, and related GPUBindGroup updates
4
        https://bugs.webkit.org/show_bug.cgi?id=195347
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        * webgpu/blit-commands.html:
9
        * webgpu/resources/blue-checkered.png: Added.
10
        * webgpu/texture-triangle-strip-expected.html: Added. Draw a reference for blue-checkered.png with Canvas2D.
11
        * webgpu/texture-triangle-strip.html: Added. Draw blue-checkered.png as a texture on a Web GPU quad.
12
13
        Renaming updates, no change in behavior:
14
        * webgpu/bind-groups.html:
15
        * webgpu/buffer-resource-triangles.html:
16
        * webgpu/pipeline-layouts.html:
17
        * webgpu/render-pipelines.html:
18
1
2019-03-04  Justin Fan  <justin_fan@apple.com>
19
2019-03-04  Justin Fan  <justin_fan@apple.com>
2
20
3
        [Web GPU] Blitting function prototypes
21
        [Web GPU] Blitting function prototypes
- a/LayoutTests/webgpu/bind-groups.html -2 / +2 lines
Lines 13-20 promise_test(async () => { a/LayoutTests/webgpu/bind-groups.html_sec1
13
    // FIXME: Also test sampled texture bindings. 
13
    // FIXME: Also test sampled texture bindings. 
14
    const bufferLayoutBinding = {
14
    const bufferLayoutBinding = {
15
        binding: 1,
15
        binding: 1,
16
        visibility: WebGPUShaderStageBit.VERTEX,
16
        visibility: GPUShaderStageBit.VERTEX,
17
        type: "storageBuffer"
17
        type: "storage-buffer"
18
    };
18
    };
19
19
20
    const bindGroupLayout = device.createBindGroupLayout({ bindings: [bufferLayoutBinding] });
20
    const bindGroupLayout = device.createBindGroupLayout({ bindings: [bufferLayoutBinding] });
- a/LayoutTests/webgpu/blit-commands.html -1 / +5 lines
Lines 91-96 async function test(image) { a/LayoutTests/webgpu/blit-commands.html_sec1
91
    commandBuffer.copyTextureToTexture(textureViewA, textureViewB, textureSize);
91
    commandBuffer.copyTextureToTexture(textureViewA, textureViewB, textureSize);
92
    commandBuffer.copyTextureToBuffer(textureViewB, readBufferView, textureSize);
92
    commandBuffer.copyTextureToBuffer(textureViewB, readBufferView, textureSize);
93
    device.getQueue().submit([commandBuffer]);
93
    device.getQueue().submit([commandBuffer]);
94
    bufferA.destroy();
95
    bufferB.destroy();
96
    textureA.destroy();
97
    textureB.destroy();
94
98
95
    const resultContext = document.querySelector('canvas').getContext('2d');
99
    const resultContext = document.querySelector('canvas').getContext('2d');
96
100
Lines 100-106 async function test(image) { a/LayoutTests/webgpu/blit-commands.html_sec2
100
104
101
        resultContext.putImageData(resultImageData, 0, 0);
105
        resultContext.putImageData(resultImageData, 0, 0);
102
106
103
        readBuffer.unmap();
107
        readBuffer.destroy();
104
    });
108
    });
105
109
106
    if (window.testRunner)
110
    if (window.testRunner)
- a/LayoutTests/webgpu/buffer-resource-triangles.html -3 / +3 lines
Lines 72-82 const bindingNums = { a/LayoutTests/webgpu/buffer-resource-triangles.html_sec1
72
    G: 5
72
    G: 5
73
};
73
};
74
74
75
function createUniformBufferBindGroupLayout(bindNum, stage = WebGPUShaderStageBit.VERTEX) {
75
function createUniformBufferBindGroupLayout(bindNum, stage = GPUShaderStageBit.VERTEX) {
76
    return {
76
    return {
77
        binding: bindNum,
77
        binding: bindNum,
78
        visibility: stage,
78
        visibility: stage,
79
        type: "uniformBuffer"
79
        type: "uniform-buffer"
80
    };
80
    };
81
}
81
}
82
82
Lines 157-163 async function test() { a/LayoutTests/webgpu/buffer-resource-triangles.html_sec2
157
    const layoutUR = createUniformBufferBindGroupLayout(bindingNums.UR);
157
    const layoutUR = createUniformBufferBindGroupLayout(bindingNums.UR);
158
    const layoutLL = createUniformBufferBindGroupLayout(bindingNums.LL);
158
    const layoutLL = createUniformBufferBindGroupLayout(bindingNums.LL);
159
    const layoutLR = createUniformBufferBindGroupLayout(bindingNums.LR);
159
    const layoutLR = createUniformBufferBindGroupLayout(bindingNums.LR);
160
    const layoutG = createUniformBufferBindGroupLayout(bindingNums.G, WebGPUShaderStageBit.FRAGMENT);
160
    const layoutG = createUniformBufferBindGroupLayout(bindingNums.G, GPUShaderStageBit.FRAGMENT);
161
161
162
    // WebGPUBindGroupLayouts
162
    // WebGPUBindGroupLayouts
163
    const leftTriangleBGLayout = device.createBindGroupLayout({ bindings: [layoutUL, layoutUM, layoutLL, layoutG] });
163
    const leftTriangleBGLayout = device.createBindGroupLayout({ bindings: [layoutUL, layoutUM, layoutLL, layoutG] });
- a/LayoutTests/webgpu/pipeline-layouts.html -5 / +5 lines
Lines 9-24 a/LayoutTests/webgpu/pipeline-layouts.html_sec1
9
function createBindGroupLayoutBinding() {
9
function createBindGroupLayoutBinding() {
10
    return {
10
    return {
11
        binding: 0,
11
        binding: 0,
12
        visibility: WebGPUShaderStageBit.FRAGMENT | WebGPUShaderStageBit.VERTEX,
12
        visibility: GPUShaderStageBit.FRAGMENT | GPUShaderStageBit.VERTEX,
13
        type: "storageBuffer"
13
        type: "storage-buffer"
14
    };
14
    };
15
}
15
}
16
16
17
test(() => {
17
test(() => {
18
    const bindGroupLayoutDescriptor = { bindings: [createBindGroupLayoutBinding()] };
18
    const bindGroupLayoutDescriptor = { bindings: [createBindGroupLayoutBinding()] };
19
    assert_not_equals(bindGroupLayoutDescriptor.bindings[0].visibility & WebGPUShaderStageBit.FRAGMENT, 0);
19
    assert_not_equals(bindGroupLayoutDescriptor.bindings[0].visibility & GPUShaderStageBit.FRAGMENT, 0);
20
    assert_not_equals(bindGroupLayoutDescriptor.bindings[0].visibility & WebGPUShaderStageBit.VERTEX, 0);
20
    assert_not_equals(bindGroupLayoutDescriptor.bindings[0].visibility & GPUShaderStageBit.VERTEX, 0);
21
    assert_equals(bindGroupLayoutDescriptor.bindings[0].type, "storageBuffer");
21
    assert_equals(bindGroupLayoutDescriptor.bindings[0].type, "storage-buffer");
22
}, "Create a basic WebGPUBindGroupLayoutDescriptor."); 
22
}, "Create a basic WebGPUBindGroupLayoutDescriptor."); 
23
23
24
promise_test(async () => {
24
promise_test(async () => {
- a/LayoutTests/webgpu/render-pipelines.html -1 / +1 lines
Lines 43-49 promise_test(async () => { a/LayoutTests/webgpu/render-pipelines.html_sec1
43
    const device = await getBasicDevice();
43
    const device = await getBasicDevice();
44
    const shaderModule = device.createShaderModule({ code: shaderCode });
44
    const shaderModule = device.createShaderModule({ code: shaderCode });
45
45
46
    const layoutBinding = { binding: 0, visibility: WebGPUShaderStageBit.VERTEX, type: "storageBuffer" };
46
    const layoutBinding = { binding: 0, visibility: GPUShaderStageBit.VERTEX, type: "storage-buffer" };
47
    const bindGroupLayout = device.createBindGroupLayout({ bindings: [layoutBinding] });
47
    const bindGroupLayout = device.createBindGroupLayout({ bindings: [layoutBinding] });
48
    const pipelineLayout = device.createPipelineLayout({ bindGroupLayouts: [bindGroupLayout] });
48
    const pipelineLayout = device.createPipelineLayout({ bindGroupLayouts: [bindGroupLayout] });
49
49
- a/LayoutTests/webgpu/texture-triangle-strip-expected.html +29 lines
Line 0 a/LayoutTests/webgpu/texture-triangle-strip-expected.html_sec1
1
<!DOCTYPE html>
2
<meta charset="utf-8">
3
<title>HTML Reference File</title>
4
<p>Pass if square canvas below is a 4 by 4 blue/green checkerboard.</p>
5
<canvas width="400" height="400"></canvas>
6
<script>
7
const canvas = document.querySelector("canvas");
8
const context = canvas.getContext('2d');
9
10
context.fillStyle = 'rgb(0, 255, 0)';
11
context.fillRect(0, 0, canvas.width, canvas.height);
12
13
const numColumns = 4;
14
const numRows = 4;
15
context.beginPath();
16
context.fillStyle = 'rgb(0, 0, 255)';
17
for (let x = 0; x < numColumns; ++x) {
18
    for (let y = 0; y < numRows; ++y) {
19
        if (x % 2 == 0 && y % 2 == 0 || x % 2 == 1 && y % 2 == 1)
20
            context.rect(
21
                x * canvas.width / numColumns, 
22
                y * canvas.height / numRows, 
23
                canvas.width / numColumns, 
24
                canvas.height / numRows
25
                );
26
    }
27
}
28
context.fill();
29
</script>
- a/LayoutTests/webgpu/texture-triangle-strip.html +196 lines
Line 0 a/LayoutTests/webgpu/texture-triangle-strip.html_sec1
1
<!DOCTYPE html>
2
<meta charset="utf-8">
3
<title>WebGPU Hello Triangles</title>
4
<meta name="assert" content="WebGPU correctly renders a green canvas.">
5
<link rel="match" href="vertex-buffer-triangle-strip-expected.html">
6
<p>Pass if square canvas below is a 4 by 4 blue/green checkerboard.</p>
7
<canvas width="400" height="400"></canvas>
8
<script src="js/webgpu-functions.js"></script>
9
<script>
10
if (window.testRunner)
11
    testRunner.waitUntilDone();
12
13
const shaderCode = `
14
#include <metal_stdlib>
15
    
16
using namespace metal;
17
18
struct VertexIn
19
{
20
    float4 position [[attribute(0)]];
21
    float2 texCoords [[attribute(1)]];
22
};
23
24
struct VertexOut
25
{
26
    float4 position [[position]];
27
    float2 texCoords;
28
};
29
30
vertex VertexOut vertex_main(VertexIn vertexIn [[stage_in]])
31
{
32
    VertexOut vOut;
33
    vOut.position = vertexIn.position;
34
    vOut.texCoords = vertexIn.texCoords;
35
    return vOut;
36
}
37
38
struct Texture
39
{
40
    texture2d<float> image [[id(0)]];
41
};
42
43
fragment float4 fragment_main(VertexOut v [[stage_in]], const device Texture& t [[buffer(0)]])
44
{
45
    constexpr sampler s(coord::normalized, address::clamp_to_zero, filter::nearest);
46
    return t.image.sample(s, v.texCoords);
47
}
48
`
49
50
function createInputStateDescriptor() {
51
    return {
52
        indexFormat: WebGPUIndexFormat.UINT32,
53
        attributes: [{
54
            shaderLocation: 0,
55
            inputSlot: 0,
56
            offset: 0,
57
            format: WebGPUVertexFormat.FLOAT_R32_G32_B32_A32
58
        }, {
59
            shaderLocation: 1,
60
            inputSlot: 1,
61
            offset: 0,
62
            format: WebGPUVertexFormat.FLOAT_R32_G32
63
        }],
64
        inputs: [{
65
            inputSlot: 0,
66
            stride: 4 * 4,
67
            stepMode: WebGPUInputStepMode.VERTEX
68
        }, {
69
            inputSlot: 1,
70
            stride: 4 * 2,
71
            stepMode: WebGPUInputStepMode.VERTEX
72
        }]
73
    }
74
}
75
76
async function test() {
77
    const device = await getBasicDevice();
78
    const canvas = document.querySelector("canvas");
79
    const context = createBasicContext(canvas, device);
80
    // FIXME: Replace with non-MSL shaders.
81
    const shaderModule = device.createShaderModule({ code: shaderCode });
82
83
    const vertexArray = new Float32Array([
84
        // float4 xyzw
85
        -1, 1, 0, 1,
86
        -1, -1, 0, 1,
87
        1, 1, 0, 1, 
88
        1, -1, 0, 1
89
    ]);
90
    const vertexBuffer = device.createBuffer({ size: vertexArray.byteLength, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.TRANSFER_DST });
91
    vertexBuffer.setSubData(0, vertexArray.buffer);
92
93
    const textureCoordArray = new Float32Array([
94
        // float2 texCoords
95
        0, 0,
96
        0, 1,
97
        1, 0,
98
        1, 1
99
    ]);
100
    const textureCoordBuffer = device.createBuffer({ size: textureCoordArray.byteLength, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.TRANSFER_DST });
101
    textureCoordBuffer.setSubData(0, textureCoordArray.buffer);
102
103
    const inputStateDescriptor = createInputStateDescriptor();
104
105
    // Load texture image
106
    const image = new Image();
107
    const imageLoadPromise = new Promise(resolve => { 
108
        image.onload = () => resolve(); 
109
        image.src = "resources/blue-checkered.png";
110
    });
111
    await Promise.resolve(imageLoadPromise);
112
113
    // Convert image to data and fill GPUBuffer
114
    const canvas2d = document.createElement("canvas");
115
    canvas2d.width = image.width;
116
    canvas2d.height = image.height;
117
    const context2d = canvas2d.getContext("2d");
118
    context2d.drawImage(image, 0, 0);
119
    const imageData = context2d.getImageData(0, 0, image.width, image.height);
120
121
    const textureBufferDescriptor = {
122
        size: imageData.data.length,
123
        usage: GPUBufferUsage.TRANSFER_SRC | GPUBufferUsage.TRANSFER_DST
124
    };
125
    const textureBuffer = device.createBuffer(textureBufferDescriptor);
126
    textureBuffer.setSubData(0, imageData.data.buffer);
127
128
    // Create GPUTexture
129
    const textureSize = {
130
        width: image.width,
131
        height: image.height,
132
        depth: 1
133
    };
134
135
    const textureDescriptor = {
136
        size: { width: image.width, height: image.height, depth: 1 },
137
        arrayLayerCount: 1,
138
        mipLevelCount: 1,
139
        sampleCount: 1,
140
        dimension: "2d",
141
        format: "r8g8b8a8-unorm",
142
        usage: GPUTextureUsage.TRANSFER_DST | GPUTextureUsage.SAMPLED
143
    };
144
    const texture = device.createTexture(textureDescriptor);
145
146
    // Bind texture to pipeline
147
    const textureBindingNum = 0;
148
    const bindGroupLayoutDescriptor = {
149
        bindings: [{ binding: textureBindingNum, visibility: GPUShaderStageBit.FRAGMENT, type: "sampled-texture" }]
150
    };
151
    bindGroupLayout = device.createBindGroupLayout(bindGroupLayoutDescriptor);
152
    const pipelineLayout = device.createPipelineLayout({ bindGroupLayouts: [bindGroupLayout] });
153
154
    const bindGroupDescriptor = {
155
        layout: bindGroupLayout,
156
        bindings: [{ binding: textureBindingNum, resource: texture.createDefaultTextureView() }]
157
    };
158
    const bindGroup = device.createBindGroup(bindGroupDescriptor);
159
160
    // Pipeline and render
161
    const pipeline = createBasicPipeline(shaderModule, device, pipelineLayout, inputStateDescriptor);
162
    const commandBuffer = device.createCommandBuffer();
163
164
    const bufferCopyView = {
165
        buffer: textureBuffer,
166
        offset: 0,
167
        rowPitch: 0,
168
        imageHeight: 0
169
    };
170
    const textureCopyView = {
171
        texture: texture,
172
        mipLevel: 0,
173
        arrayLayer: 0,
174
        origin: { x: 0, y: 0, z: 0 }
175
    };
176
    commandBuffer.copyBufferToTexture(bufferCopyView, textureCopyView, textureSize);
177
    const passEncoder = beginBasicRenderPass(context, commandBuffer);
178
    passEncoder.setPipeline(pipeline);
179
    passEncoder.setBindGroup(0, bindGroup);
180
    passEncoder.setVertexBuffers(0, [vertexBuffer, textureCoordBuffer], [0, 0]);
181
    passEncoder.draw(4, 1, 0, 0);
182
    passEncoder.endPass();
183
184
    const queue = device.getQueue();
185
    queue.submit([commandBuffer]);
186
    vertexBuffer.destroy();
187
    textureCoordBuffer.destroy();
188
    texture.destroy();
189
    context.present();
190
191
    if (window.testRunner)
192
        testRunner.notifyDone();
193
}
194
195
test();
196
</script>

Return to Bug 195347