Skip to content

Commit 60342c9

Browse files
committed
Support GPUAutoLayoutMode
https://bugs.webkit.org/show_bug.cgi?id=248706 <rdar://101404965> Reviewed by Dean Jackson. Allow layout: "auto" to be specified in place of creating a pipeline layout. This is needed to support running some WebGPU existing samples, e.g., the ones located at https://austin-eng.com/webgpu-samples/ * Source/WebCore/CMakeLists.txt: * Source/WebCore/DerivedSources-input.xcfilelist: * Source/WebCore/DerivedSources-output.xcfilelist: * Source/WebCore/DerivedSources.make: * Source/WebCore/Headers.cmake: * Source/WebCore/Modules/WebGPU/GPUAutoLayoutMode.h: Copied from Source/WebCore/Modules/WebGPU/GPUShaderModuleCompilationHint.idl. * Source/WebCore/Modules/WebGPU/GPUAutoLayoutMode.idl: Copied from Source/WebCore/Modules/WebGPU/GPUPipelineDescriptorBase.idl. Add files. * Source/WebCore/Modules/WebGPU/GPUComputePipelineDescriptor.h: (WebCore::GPUComputePipelineDescriptor::convertToBacking const): * Source/WebCore/Modules/WebGPU/GPUDevice.cpp: (WebCore::GPUDevice::GPUDevice): (WebCore::m_queue): (WebCore::m_autoPipelineLayout): (WebCore::GPUDevice::createShaderModule): (WebCore::GPUDevice::createComputePipeline): (WebCore::GPUDevice::createRenderPipeline): (WebCore::GPUDevice::createComputePipelineAsync): (WebCore::GPUDevice::createRenderPipelineAsync): Support auto pipeline layouts by passing an empty pipeline layout. * Source/WebCore/Modules/WebGPU/GPUDevice.h: (WebCore::GPUDevice::GPUDevice): Deleted. (WebCore::GPUDevice::m_queue): Deleted. Moved to cpp file. * Source/WebCore/Modules/WebGPU/GPUPipelineDescriptorBase.h: (WebCore::convertPipelineLayoutToBacking): (WebCore::GPUPipelineDescriptorBase::convertToBacking const): * Source/WebCore/Modules/WebGPU/GPUPipelineDescriptorBase.idl: * Source/WebCore/Modules/WebGPU/GPURenderPipelineDescriptor.h: (WebCore::GPURenderPipelineDescriptor::convertToBacking const): * Source/WebCore/Modules/WebGPU/GPUShaderModuleCompilationHint.h: (WebCore::GPUShaderModuleCompilationHint::convertToBacking const): * Source/WebCore/Modules/WebGPU/GPUShaderModuleCompilationHint.idl: * Source/WebCore/Modules/WebGPU/GPUShaderModuleDescriptor.h: (WebCore::GPUShaderModuleDescriptor::convertToBacking const): Pass the auto layout to convertToBacking(), so we can fall back to that one if needed. * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Websites/webkit.org/demos/webgpu/hello-cube-auto-layout.html: Added. * Websites/webkit.org/demos/webgpu/scripts/hello-cube-auto-layout.js: Added. (async helloCube.frameUpdate): (async helloCube): Example using layout: "auto" in the call to createRenderPipeline and the shader hint, which are both supported in the specification. Canonical link: https://commits.webkit.org/257537@main
1 parent 240f2f8 commit 60342c9

20 files changed

+410
-27
lines changed

Source/WebCore/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,6 +1571,7 @@ list(APPEND WebCore_NON_SVG_IDL_FILES
15711571
Modules/WebGPU/GPU.idl
15721572
Modules/WebGPU/GPUAdapter.idl
15731573
Modules/WebGPU/GPUAddressMode.idl
1574+
Modules/WebGPU/GPUAutoLayoutMode.idl
15741575
Modules/WebGPU/GPUBindGroup.idl
15751576
Modules/WebGPU/GPUBindGroupDescriptor.idl
15761577
Modules/WebGPU/GPUBindGroupEntry.idl

Source/WebCore/DerivedSources-input.xcfilelist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ $(PROJECT_DIR)/DerivedSources.make
3737
$(PROJECT_DIR)/Modules/WebGPU/GPU.idl
3838
$(PROJECT_DIR)/Modules/WebGPU/GPUAdapter.idl
3939
$(PROJECT_DIR)/Modules/WebGPU/GPUAddressMode.idl
40+
$(PROJECT_DIR)/Modules/WebGPU/GPUAutoLayoutMode.idl
4041
$(PROJECT_DIR)/Modules/WebGPU/GPUBindGroup.idl
4142
$(PROJECT_DIR)/Modules/WebGPU/GPUBindGroupDescriptor.idl
4243
$(PROJECT_DIR)/Modules/WebGPU/GPUBindGroupEntry.idl

Source/WebCore/DerivedSources-output.xcfilelist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,8 @@ $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUAdapter.cpp
973973
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUAdapter.h
974974
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUAddressMode.cpp
975975
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUAddressMode.h
976+
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUAutoLayoutMode.cpp
977+
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUAutoLayoutMode.h
976978
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUBindGroup.cpp
977979
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUBindGroup.h
978980
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUBindGroupDescriptor.cpp

Source/WebCore/DerivedSources.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ JS_BINDING_IDLS := \
6060
$(WebCore)/Modules/WebGPU/GPU.idl \
6161
$(WebCore)/Modules/WebGPU/GPUAdapter.idl \
6262
$(WebCore)/Modules/WebGPU/GPUAddressMode.idl \
63+
$(WebCore)/Modules/WebGPU/GPUAutoLayoutMode.idl \
6364
$(WebCore)/Modules/WebGPU/GPUBindGroup.idl \
6465
$(WebCore)/Modules/WebGPU/GPUBindGroupDescriptor.idl \
6566
$(WebCore)/Modules/WebGPU/GPUBindGroupEntry.idl \

Source/WebCore/Headers.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
22
Modules/WebGPU/GPU.h
33
Modules/WebGPU/GPUAdapter.h
44
Modules/WebGPU/GPUAddressMode.h
5+
Modules/WebGPU/GPUAutoLayoutMode.h
56
Modules/WebGPU/GPUBindGroup.h
67
Modules/WebGPU/GPUBindGroupDescriptor.h
78
Modules/WebGPU/GPUBindGroupEntry.h
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (C) 2022 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+
namespace WebCore {
29+
30+
enum class GPUAutoLayoutMode : uint8_t {
31+
Auto
32+
};
33+
34+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (C) 2022 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+
// https://gpuweb.github.io/gpuweb/#enumdef-gpuautolayoutmode
27+
28+
[
29+
EnabledBySetting=WebGPU
30+
]
31+
enum GPUAutoLayoutMode {
32+
"auto"
33+
};

Source/WebCore/Modules/WebGPU/GPUComputePipelineDescriptor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
namespace WebCore {
3333

3434
struct GPUComputePipelineDescriptor : public GPUPipelineDescriptorBase {
35-
PAL::WebGPU::ComputePipelineDescriptor convertToBacking() const
35+
PAL::WebGPU::ComputePipelineDescriptor convertToBacking(const Ref<GPUPipelineLayout>& autoLayout) const
3636
{
3737
return {
3838
{
3939
{ label },
40-
layout ? &layout->backing() : nullptr,
40+
&convertPipelineLayoutToBacking(layout, autoLayout),
4141
},
4242
compute.convertToBacking()
4343
};

Source/WebCore/Modules/WebGPU/GPUDevice.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ namespace WebCore {
6868

6969
WTF_MAKE_ISO_ALLOCATED_IMPL(GPUDevice);
7070

71+
GPUDevice::GPUDevice(ScriptExecutionContext* scriptExecutionContext, Ref<PAL::WebGPU::Device>&& backing)
72+
: ActiveDOMObject { scriptExecutionContext }
73+
, m_backing(WTFMove(backing))
74+
, m_queue(GPUQueue::create(Ref { m_backing->queue() }))
75+
, m_autoPipelineLayout(createPipelineLayout({ { "autoLayout"_s, }, { } }))
76+
{
77+
}
78+
7179
GPUDevice::~GPUDevice() = default;
7280

7381
String GPUDevice::label() const
@@ -173,29 +181,29 @@ Ref<GPUBindGroup> GPUDevice::createBindGroup(const GPUBindGroupDescriptor& bindG
173181

174182
Ref<GPUShaderModule> GPUDevice::createShaderModule(const GPUShaderModuleDescriptor& shaderModuleDescriptor)
175183
{
176-
return GPUShaderModule::create(m_backing->createShaderModule(shaderModuleDescriptor.convertToBacking()));
184+
return GPUShaderModule::create(m_backing->createShaderModule(shaderModuleDescriptor.convertToBacking(m_autoPipelineLayout)));
177185
}
178186

179187
Ref<GPUComputePipeline> GPUDevice::createComputePipeline(const GPUComputePipelineDescriptor& computePipelineDescriptor)
180188
{
181-
return GPUComputePipeline::create(m_backing->createComputePipeline(computePipelineDescriptor.convertToBacking()));
189+
return GPUComputePipeline::create(m_backing->createComputePipeline(computePipelineDescriptor.convertToBacking(m_autoPipelineLayout)));
182190
}
183191

184192
Ref<GPURenderPipeline> GPUDevice::createRenderPipeline(const GPURenderPipelineDescriptor& renderPipelineDescriptor)
185193
{
186-
return GPURenderPipeline::create(m_backing->createRenderPipeline(renderPipelineDescriptor.convertToBacking()));
194+
return GPURenderPipeline::create(m_backing->createRenderPipeline(renderPipelineDescriptor.convertToBacking(m_autoPipelineLayout)));
187195
}
188196

189197
void GPUDevice::createComputePipelineAsync(const GPUComputePipelineDescriptor& computePipelineDescriptor, CreateComputePipelineAsyncPromise&& promise)
190198
{
191-
m_backing->createComputePipelineAsync(computePipelineDescriptor.convertToBacking(), [promise = WTFMove(promise)] (Ref<PAL::WebGPU::ComputePipeline>&& computePipeline) mutable {
199+
m_backing->createComputePipelineAsync(computePipelineDescriptor.convertToBacking(m_autoPipelineLayout), [promise = WTFMove(promise)] (Ref<PAL::WebGPU::ComputePipeline>&& computePipeline) mutable {
192200
promise.resolve(GPUComputePipeline::create(WTFMove(computePipeline)));
193201
});
194202
}
195203

196204
void GPUDevice::createRenderPipelineAsync(const GPURenderPipelineDescriptor& renderPipelineDescriptor, CreateRenderPipelineAsyncPromise&& promise)
197205
{
198-
m_backing->createRenderPipelineAsync(renderPipelineDescriptor.convertToBacking(), [promise = WTFMove(promise)] (Ref<PAL::WebGPU::RenderPipeline>&& renderPipeline) mutable {
206+
m_backing->createRenderPipelineAsync(renderPipelineDescriptor.convertToBacking(m_autoPipelineLayout), [promise = WTFMove(promise)] (Ref<PAL::WebGPU::RenderPipeline>&& renderPipeline) mutable {
199207
promise.resolve(GPURenderPipeline::create(WTFMove(renderPipeline)));
200208
});
201209
}

Source/WebCore/Modules/WebGPU/GPUDevice.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,7 @@ class GPUDevice : public RefCounted<GPUDevice>, public ActiveDOMObject, public E
138138
using RefCounted::deref;
139139

140140
private:
141-
GPUDevice(ScriptExecutionContext* scriptExecutionContext, Ref<PAL::WebGPU::Device>&& backing)
142-
: ActiveDOMObject { scriptExecutionContext }
143-
, m_backing(WTFMove(backing))
144-
, m_queue(GPUQueue::create(Ref { m_backing->queue() }))
145-
{
146-
}
141+
GPUDevice(ScriptExecutionContext*, Ref<PAL::WebGPU::Device>&&);
147142

148143
// ActiveDOMObject.
149144
// FIXME: We probably need to override more methods to make this work properly.
@@ -158,6 +153,7 @@ class GPUDevice : public RefCounted<GPUDevice>, public ActiveDOMObject, public E
158153
LostPromise m_lostPromise;
159154
Ref<PAL::WebGPU::Device> m_backing;
160155
Ref<GPUQueue> m_queue;
156+
Ref<GPUPipelineLayout> m_autoPipelineLayout;
161157
};
162158

163159
}

0 commit comments

Comments
 (0)