From a574f2ae1fcaedfa1bfe4f0439c885e9d5b57898 Mon Sep 17 00:00:00 2001 From: Jeff Gilbert Date: Wed, 13 Jun 2018 10:43:48 -0700 Subject: [PATCH] Bug 1469376 - Initial stubs for WebGPU sketch API. - r=kvark,qdot MozReview-Commit-ID: 3MZLQDNpHBk --HG-- extra : rebase_source : 4495aae52f283286ecafcc3217811d306097b9b6 --- .eslintignore | 1 + dom/base/nsGlobalWindowInner.cpp | 5 + dom/base/nsGlobalWindowInner.h | 2 + dom/bindings/Bindings.conf | 133 +++++ dom/bindings/moz.build | 3 + dom/moz.build | 1 + dom/webgpu/Adapter.cpp | 37 ++ dom/webgpu/Adapter.h | 49 ++ dom/webgpu/AttachmentState.cpp | 19 + dom/webgpu/AttachmentState.h | 31 + dom/webgpu/BindGroup.cpp | 19 + dom/webgpu/BindGroup.h | 31 + dom/webgpu/BindGroupLayout.cpp | 19 + dom/webgpu/BindGroupLayout.h | 31 + dom/webgpu/BlendState.cpp | 19 + dom/webgpu/BlendState.h | 31 + dom/webgpu/Buffer.cpp | 62 ++ dom/webgpu/Buffer.h | 38 ++ dom/webgpu/CommandBuffer.cpp | 19 + dom/webgpu/CommandBuffer.h | 31 + dom/webgpu/CommandEncoder.cpp | 147 +++++ dom/webgpu/CommandEncoder.h | 83 +++ dom/webgpu/ComputePipeline.cpp | 19 + dom/webgpu/ComputePipeline.h | 31 + dom/webgpu/DepthStencilState.cpp | 19 + dom/webgpu/DepthStencilState.h | 31 + dom/webgpu/Device.cpp | 153 +++++ dom/webgpu/Device.h | 103 ++++ dom/webgpu/Fence.cpp | 31 + dom/webgpu/Fence.h | 38 ++ dom/webgpu/InputState.cpp | 19 + dom/webgpu/InputState.h | 31 + dom/webgpu/Instance.cpp | 63 ++ dom/webgpu/Instance.h | 46 ++ dom/webgpu/InstanceProvider.cpp | 47 ++ dom/webgpu/InstanceProvider.h | 60 ++ dom/webgpu/LogEntry.cpp | 37 ++ dom/webgpu/LogEntry.h | 39 ++ dom/webgpu/ObjectModel.cpp | 35 ++ dom/webgpu/ObjectModel.h | 73 +++ dom/webgpu/PipelineLayout.cpp | 19 + dom/webgpu/PipelineLayout.h | 31 + dom/webgpu/Queue.cpp | 31 + dom/webgpu/Queue.h | 41 ++ dom/webgpu/RenderPipeline.cpp | 19 + dom/webgpu/RenderPipeline.h | 31 + dom/webgpu/Sampler.cpp | 19 + dom/webgpu/Sampler.h | 31 + dom/webgpu/ShaderModule.cpp | 19 + dom/webgpu/ShaderModule.h | 31 + dom/webgpu/SwapChain.cpp | 37 ++ dom/webgpu/SwapChain.h | 41 ++ dom/webgpu/Texture.cpp | 26 + dom/webgpu/Texture.h | 39 ++ dom/webgpu/TextureView.cpp | 19 + dom/webgpu/TextureView.h | 31 + dom/webgpu/mochitest/mochitest-no-pref.ini | 5 + dom/webgpu/mochitest/mochitest.ini | 6 + dom/webgpu/mochitest/test_disabled.html | 18 + dom/webgpu/mochitest/test_enabled.html | 18 + dom/webgpu/moz.build | 49 ++ dom/webidl/WebGPU.webidl | 639 +++++++++++++++++++++ dom/webidl/WebGPUExtras.webidl | 14 + dom/webidl/Window.webidl | 2 + dom/webidl/moz.build | 5 + modules/libpref/init/all.js | 2 + 66 files changed, 2909 insertions(+) create mode 100644 dom/webgpu/Adapter.cpp create mode 100644 dom/webgpu/Adapter.h create mode 100644 dom/webgpu/AttachmentState.cpp create mode 100644 dom/webgpu/AttachmentState.h create mode 100644 dom/webgpu/BindGroup.cpp create mode 100644 dom/webgpu/BindGroup.h create mode 100644 dom/webgpu/BindGroupLayout.cpp create mode 100644 dom/webgpu/BindGroupLayout.h create mode 100644 dom/webgpu/BlendState.cpp create mode 100644 dom/webgpu/BlendState.h create mode 100644 dom/webgpu/Buffer.cpp create mode 100644 dom/webgpu/Buffer.h create mode 100644 dom/webgpu/CommandBuffer.cpp create mode 100644 dom/webgpu/CommandBuffer.h create mode 100644 dom/webgpu/CommandEncoder.cpp create mode 100644 dom/webgpu/CommandEncoder.h create mode 100644 dom/webgpu/ComputePipeline.cpp create mode 100644 dom/webgpu/ComputePipeline.h create mode 100644 dom/webgpu/DepthStencilState.cpp create mode 100644 dom/webgpu/DepthStencilState.h create mode 100644 dom/webgpu/Device.cpp create mode 100644 dom/webgpu/Device.h create mode 100644 dom/webgpu/Fence.cpp create mode 100644 dom/webgpu/Fence.h create mode 100644 dom/webgpu/InputState.cpp create mode 100644 dom/webgpu/InputState.h create mode 100644 dom/webgpu/Instance.cpp create mode 100644 dom/webgpu/Instance.h create mode 100644 dom/webgpu/InstanceProvider.cpp create mode 100644 dom/webgpu/InstanceProvider.h create mode 100644 dom/webgpu/LogEntry.cpp create mode 100644 dom/webgpu/LogEntry.h create mode 100644 dom/webgpu/ObjectModel.cpp create mode 100644 dom/webgpu/ObjectModel.h create mode 100644 dom/webgpu/PipelineLayout.cpp create mode 100644 dom/webgpu/PipelineLayout.h create mode 100644 dom/webgpu/Queue.cpp create mode 100644 dom/webgpu/Queue.h create mode 100644 dom/webgpu/RenderPipeline.cpp create mode 100644 dom/webgpu/RenderPipeline.h create mode 100644 dom/webgpu/Sampler.cpp create mode 100644 dom/webgpu/Sampler.h create mode 100644 dom/webgpu/ShaderModule.cpp create mode 100644 dom/webgpu/ShaderModule.h create mode 100644 dom/webgpu/SwapChain.cpp create mode 100644 dom/webgpu/SwapChain.h create mode 100644 dom/webgpu/Texture.cpp create mode 100644 dom/webgpu/Texture.h create mode 100644 dom/webgpu/TextureView.cpp create mode 100644 dom/webgpu/TextureView.h create mode 100644 dom/webgpu/mochitest/mochitest-no-pref.ini create mode 100644 dom/webgpu/mochitest/mochitest.ini create mode 100644 dom/webgpu/mochitest/test_disabled.html create mode 100644 dom/webgpu/mochitest/test_enabled.html create mode 100644 dom/webgpu/moz.build create mode 100644 dom/webidl/WebGPU.webidl create mode 100644 dom/webidl/WebGPUExtras.webidl diff --git a/.eslintignore b/.eslintignore index be60a648b6cf..da5b7db6d088 100644 --- a/.eslintignore +++ b/.eslintignore @@ -263,6 +263,7 @@ dom/url/** dom/vr/** dom/webauthn/** dom/webbrowserpersist/** +dom/webgpu/** dom/webidl/** dom/websocket/** dom/workers/** diff --git a/dom/base/nsGlobalWindowInner.cpp b/dom/base/nsGlobalWindowInner.cpp index a7ba4063e1c9..6ad3ad9b2d82 100644 --- a/dom/base/nsGlobalWindowInner.cpp +++ b/dom/base/nsGlobalWindowInner.cpp @@ -886,6 +886,7 @@ public: nsGlobalWindowInner::nsGlobalWindowInner(nsGlobalWindowOuter *aOuterWindow) : nsPIDOMWindowInner(aOuterWindow->AsOuter()), + mozilla::webgpu::InstanceProvider(this), mIdleFuzzFactor(0), mIdleCallbackIndex(-1), mCurrentlyIdle(false), @@ -1479,6 +1480,8 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindowInner) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentFlushedResolvers[i]->mCallback); } + static_cast(tmp)->CcTraverse(cb); + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindowInner) @@ -1582,6 +1585,8 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindowInner) } tmp->mDocumentFlushedResolvers.Clear(); + static_cast(tmp)->CcUnlink(); + NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER NS_IMPL_CYCLE_COLLECTION_UNLINK_END diff --git a/dom/base/nsGlobalWindowInner.h b/dom/base/nsGlobalWindowInner.h index 84dcd83e7627..be4363f00609 100644 --- a/dom/base/nsGlobalWindowInner.h +++ b/dom/base/nsGlobalWindowInner.h @@ -45,6 +45,7 @@ #include "mozilla/GuardObjects.h" #include "mozilla/LinkedList.h" #include "mozilla/TimeStamp.h" +#include "mozilla/webgpu/InstanceProvider.h" #include "nsWrapperCacheInlines.h" #include "nsIIdleObserver.h" #include "nsIDocument.h" @@ -217,6 +218,7 @@ class nsGlobalWindowInner final , public nsIInterfaceRequestor , public PRCListStr , public nsAPostRefreshObserver + , public mozilla::webgpu::InstanceProvider { public: typedef mozilla::TimeStamp TimeStamp; diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index fb1811e83758..0fed3d9c792b 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -1297,6 +1297,139 @@ DOMInterfaces = { 'headerFile': 'WebGLVertexArray.h' }, +# WebGPU + +'WebGPU': { + 'nativeType': 'mozilla::webgpu::Instance', +}, +'WebGPUAdapter': { + 'nativeType': 'mozilla::webgpu::Adapter', +}, +'WebGPUAttachmentState': { + 'nativeType': 'mozilla::webgpu::AttachmentState', +}, +'WebGPUBindGroup': { + 'nativeType': 'mozilla::webgpu::BindGroup', +}, +'WebGPUBindGroupLayout': { + 'nativeType': 'mozilla::webgpu::BindGroupLayout', +}, +'WebGPUBlendState': { + 'nativeType': 'mozilla::webgpu::BlendState', +}, +'WebGPUBuffer': { + 'nativeType': 'mozilla::webgpu::Buffer', +}, +'WebGPUCommandBuffer': { + 'nativeType': 'mozilla::webgpu::CommandBuffer', +}, +'WebGPUCommandEncoder': { + 'nativeType': 'mozilla::webgpu::CommandEncoder', +}, +'WebGPUComputePipeline': { + 'nativeType': 'mozilla::webgpu::ComputePipeline', +}, +'WebGPUDepthStencilState': { + 'nativeType': 'mozilla::webgpu::DepthStencilState', +}, +'WebGPUDevice': { + 'nativeType': 'mozilla::webgpu::Device', +}, +'WebGPUFence': { + 'nativeType': 'mozilla::webgpu::Fence', +}, +'WebGPUInputState': { + 'nativeType': 'mozilla::webgpu::InputState', +}, +'WebGPULogEntry': { + 'nativeType': 'mozilla::webgpu::LogEntry', +}, +'WebGPUPipelineLayout': { + 'nativeType': 'mozilla::webgpu::PipelineLayout', +}, +'WebGPUQueue': { + 'nativeType': 'mozilla::webgpu::Queue', +}, +'WebGPURenderPipeline': { + 'nativeType': 'mozilla::webgpu::RenderPipeline', +}, +'WebGPUSampler': { + 'nativeType': 'mozilla::webgpu::Sampler', +}, +'WebGPUShaderModule': { + 'nativeType': 'mozilla::webgpu::ShaderModule', +}, +'WebGPUSwapChain': { + 'nativeType': 'mozilla::webgpu::SwapChain', +}, +'WebGPUTexture': { + 'nativeType': 'mozilla::webgpu::Texture', +}, +'WebGPUTextureView': { + 'nativeType': 'mozilla::webgpu::TextureView', +}, + + +'WebGPUBindingType': { + 'concrete': False, +}, +'WebGPUBlendFactor': { + 'concrete': False, +}, +'WebGPUBlendOperation': { + 'concrete': False, +}, +'WebGPUBufferUsage': { + 'concrete': False, +}, +'WebGPUColorWriteBits': { + 'concrete': False, +}, +'WebGPUCompareFunction': { + 'concrete': False, +}, +'WebGPUFilterMode': { + 'concrete': False, +}, +'WebGPUIndexFormat': { + 'concrete': False, +}, +'WebGPUInputStepMode': { + 'concrete': False, +}, +'WebGPULoadOp': { + 'concrete': False, +}, +'WebGPUPrimitiveTopology': { + 'concrete': False, +}, +'WebGPUShaderStage': { + 'concrete': False, +}, +'WebGPUShaderStageBit': { + 'concrete': False, +}, +'WebGPUStencilOperation': { + 'concrete': False, +}, +'WebGPUStoreOp': { + 'concrete': False, +}, +'WebGPUTextureDimension': { + 'concrete': False, +}, +'WebGPUTextureFormat': { + 'concrete': False, +}, +'WebGPUTextureUsage': { + 'concrete': False, +}, +'WebGPUVertexFormat': { + 'concrete': False, +}, + +# WebRTC + 'WebrtcGlobalInformation': { 'nativeType': 'mozilla::dom::WebrtcGlobalInformation', 'headerFile': 'WebrtcGlobalInformation.h', diff --git a/dom/bindings/moz.build b/dom/bindings/moz.build index 309285f11280..5ddb9db44375 100644 --- a/dom/bindings/moz.build +++ b/dom/bindings/moz.build @@ -7,6 +7,9 @@ with Files("**"): BUG_COMPONENT = ("Core", "DOM") +if CONFIG['CC_TYPE'] == 'msvc': + CXXFLAGS += ['-bigobj'] + TEST_DIRS += ['test'] XPIDL_SOURCES += [ diff --git a/dom/moz.build b/dom/moz.build index 4493c851ef34..e0a02b07ba90 100644 --- a/dom/moz.build +++ b/dom/moz.build @@ -39,6 +39,7 @@ DIRS += [ 'browser-element', 'cache', 'canvas', + 'webgpu', 'chrome-webidl', 'clients', 'commandhandler', diff --git a/dom/webgpu/Adapter.cpp b/dom/webgpu/Adapter.cpp new file mode 100644 index 000000000000..cc10a7921713 --- /dev/null +++ b/dom/webgpu/Adapter.cpp @@ -0,0 +1,37 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "Adapter.h" + +#include "Instance.h" +#include "mozilla/dom/WebGPUBinding.h" + +namespace mozilla { +namespace webgpu { + +Adapter::~Adapter() = default; + +void +Adapter::Extensions(dom::WebGPUExtensions& out) const +{ + MOZ_CRASH("todo"); +} + +void +Adapter::Features(dom::WebGPUFeatures& out) const +{ + MOZ_CRASH("todo"); +} + +already_AddRefed +Adapter::CreateDevice(const dom::WebGPUDeviceDescriptor& desc) const +{ + MOZ_CRASH("todo"); +} + +WEBGPU_IMPL_GOOP_0(Adapter) + +} // namespace webgpu +} // namespace mozilla diff --git a/dom/webgpu/Adapter.h b/dom/webgpu/Adapter.h new file mode 100644 index 000000000000..c6c2104bae2b --- /dev/null +++ b/dom/webgpu/Adapter.h @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WEBGPU_Adapter_H_ +#define WEBGPU_Adapter_H_ + +#include "mozilla/AlreadyAddRefed.h" +#include "nsString.h" +#include "ObjectModel.h" + +namespace mozilla { +namespace dom { +struct WebGPUDeviceDescriptor; +struct WebGPUExtensions; +struct WebGPUFeatures; +} // namespace dom + +namespace webgpu { +class Device; +class Instance; + +class Adapter final + : public ChildOf +{ +public: + WEBGPU_DECL_GOOP(Adapter) + + const nsString mName; + +private: + Adapter() = delete; + virtual ~Adapter(); + +public: + void GetName(nsString& out) const { + out = mName; + } + + void Extensions(dom::WebGPUExtensions& out) const; + void Features(dom::WebGPUFeatures& out) const; + already_AddRefed CreateDevice(const dom::WebGPUDeviceDescriptor& desc) const; +}; + +} // namespace webgpu +} // namespace mozilla + +#endif // WEBGPU_Adapter_H_ diff --git a/dom/webgpu/AttachmentState.cpp b/dom/webgpu/AttachmentState.cpp new file mode 100644 index 000000000000..6acf4f8b37b1 --- /dev/null +++ b/dom/webgpu/AttachmentState.cpp @@ -0,0 +1,19 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "AttachmentState.h" + +#include "Device.h" +#include "mozilla/dom/WebGPUBinding.h" + +namespace mozilla { +namespace webgpu { + +AttachmentState::~AttachmentState() = default; + +WEBGPU_IMPL_GOOP_0(AttachmentState) + +} // namespace webgpu +} // namespace mozilla diff --git a/dom/webgpu/AttachmentState.h b/dom/webgpu/AttachmentState.h new file mode 100644 index 000000000000..556972af8b58 --- /dev/null +++ b/dom/webgpu/AttachmentState.h @@ -0,0 +1,31 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WEBGPU_AttachmentState_H_ +#define WEBGPU_AttachmentState_H_ + +#include "nsWrapperCache.h" +#include "ObjectModel.h" + +namespace mozilla { +namespace webgpu { + +class Device; + +class AttachmentState final + : public ChildOf +{ +public: + WEBGPU_DECL_GOOP(AttachmentState) + +private: + AttachmentState() = delete; + virtual ~AttachmentState(); +}; + +} // namespace webgpu +} // namespace mozilla + +#endif // WEBGPU_AttachmentState_H_ diff --git a/dom/webgpu/BindGroup.cpp b/dom/webgpu/BindGroup.cpp new file mode 100644 index 000000000000..32c48a52c4f9 --- /dev/null +++ b/dom/webgpu/BindGroup.cpp @@ -0,0 +1,19 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "BindGroup.h" + +#include "Device.h" +#include "mozilla/dom/WebGPUBinding.h" + +namespace mozilla { +namespace webgpu { + +BindGroup::~BindGroup() = default; + +WEBGPU_IMPL_GOOP_0(BindGroup) + +} // namespace webgpu +} // namespace mozilla diff --git a/dom/webgpu/BindGroup.h b/dom/webgpu/BindGroup.h new file mode 100644 index 000000000000..66f88fc45108 --- /dev/null +++ b/dom/webgpu/BindGroup.h @@ -0,0 +1,31 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WEBGPU_BindGroup_H_ +#define WEBGPU_BindGroup_H_ + +#include "nsWrapperCache.h" +#include "ObjectModel.h" + +namespace mozilla { +namespace webgpu { + +class Device; + +class BindGroup final + : public ChildOf +{ +public: + WEBGPU_DECL_GOOP(BindGroup) + +private: + BindGroup() = delete; + virtual ~BindGroup(); +}; + +} // namespace webgpu +} // namespace mozilla + +#endif // WEBGPU_BindGroup_H_ diff --git a/dom/webgpu/BindGroupLayout.cpp b/dom/webgpu/BindGroupLayout.cpp new file mode 100644 index 000000000000..6c4c40d5b401 --- /dev/null +++ b/dom/webgpu/BindGroupLayout.cpp @@ -0,0 +1,19 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "BindGroupLayout.h" + +#include "Device.h" +#include "mozilla/dom/WebGPUBinding.h" + +namespace mozilla { +namespace webgpu { + +BindGroupLayout::~BindGroupLayout() = default; + +WEBGPU_IMPL_GOOP_0(BindGroupLayout) + +} // namespace webgpu +} // namespace mozilla diff --git a/dom/webgpu/BindGroupLayout.h b/dom/webgpu/BindGroupLayout.h new file mode 100644 index 000000000000..b84663f360cb --- /dev/null +++ b/dom/webgpu/BindGroupLayout.h @@ -0,0 +1,31 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WEBGPU_BindGroupLayout_H_ +#define WEBGPU_BindGroupLayout_H_ + +#include "nsWrapperCache.h" +#include "ObjectModel.h" + +namespace mozilla { +namespace webgpu { + +class Device; + +class BindGroupLayout final + : public ChildOf +{ +public: + WEBGPU_DECL_GOOP(BindGroupLayout) + +private: + BindGroupLayout() = delete; + virtual ~BindGroupLayout(); +}; + +} // namespace webgpu +} // namespace mozilla + +#endif // WEBGPU_BindGroupLayout_H_ diff --git a/dom/webgpu/BlendState.cpp b/dom/webgpu/BlendState.cpp new file mode 100644 index 000000000000..c098131ac488 --- /dev/null +++ b/dom/webgpu/BlendState.cpp @@ -0,0 +1,19 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "BlendState.h" + +#include "Device.h" +#include "mozilla/dom/WebGPUBinding.h" + +namespace mozilla { +namespace webgpu { + +BlendState::~BlendState() = default; + +WEBGPU_IMPL_GOOP_0(BlendState) + +} // namespace webgpu +} // namespace mozilla diff --git a/dom/webgpu/BlendState.h b/dom/webgpu/BlendState.h new file mode 100644 index 000000000000..ec570f773b8d --- /dev/null +++ b/dom/webgpu/BlendState.h @@ -0,0 +1,31 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WEBGPU_BlendState_H_ +#define WEBGPU_BlendState_H_ + +#include "nsWrapperCache.h" +#include "ObjectModel.h" + +namespace mozilla { +namespace webgpu { + +class Device; + +class BlendState final + : public ChildOf +{ +public: + WEBGPU_DECL_GOOP(BlendState) + +private: + BlendState() = delete; + virtual ~BlendState(); +}; + +} // namespace webgpu +} // namespace mozilla + +#endif // WEBGPU_BlendState_H_ diff --git a/dom/webgpu/Buffer.cpp b/dom/webgpu/Buffer.cpp new file mode 100644 index 000000000000..4ed902f081ae --- /dev/null +++ b/dom/webgpu/Buffer.cpp @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "Buffer.h" + +#include "Device.h" +#include "mozilla/dom/WebGPUBinding.h" + +namespace mozilla { +namespace webgpu { + +Buffer::Buffer(Device* const parent) + : ChildOf(parent) +{ + mozilla::HoldJSObjects(this); // Mimed from PushSubscriptionOptions +} + +Buffer::~Buffer() +{ + mMapping = nullptr; + mozilla::DropJSObjects(this); +} + +void +Buffer::GetMapping(JSContext*, JS::MutableHandle out) const +{ + out.set(mMapping); +} + +void +Buffer::Unmap() const +{ + MOZ_CRASH("todo"); +} + +JSObject* +webgpu::Buffer::WrapObject(JSContext* cx, JS::Handle givenProto) +{ + return dom::WebGPUBuffer_Binding::Wrap(cx, this, givenProto); +} + +NS_IMPL_CYCLE_COLLECTION_CLASS(Buffer) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Buffer) + NS_IMPL_CYCLE_COLLECTION_UNLINK(mParent) + NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER + tmp->mMapping = nullptr; +NS_IMPL_CYCLE_COLLECTION_UNLINK_END +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Buffer) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParent) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END +NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(Buffer) + NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER + NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mMapping) +NS_IMPL_CYCLE_COLLECTION_TRACE_END + +NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(Buffer, AddRef) +NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(Buffer, Release) + +} // namespace webgpu +} // namespace mozilla diff --git a/dom/webgpu/Buffer.h b/dom/webgpu/Buffer.h new file mode 100644 index 000000000000..f07c0460f8df --- /dev/null +++ b/dom/webgpu/Buffer.h @@ -0,0 +1,38 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WEBGPU_BUFFER_H_ +#define WEBGPU_BUFFER_H_ + +#include "mozilla/dom/Nullable.h" +#include "mozilla/dom/TypedArray.h" +#include "ObjectModel.h" + +namespace mozilla { +namespace webgpu { + +class Device; + +class Buffer final + : public ChildOf +{ +public: + JS::Heap mMapping; + + WEBGPU_DECL_GOOP(Buffer) + +private: + explicit Buffer(Device* parent); + virtual ~Buffer(); + +public: + void GetMapping(JSContext* cx, JS::MutableHandle out) const; + void Unmap() const; +}; + +} // namespace webgpu +} // namespace mozilla + +#endif // WEBGPU_BUFFER_H_ diff --git a/dom/webgpu/CommandBuffer.cpp b/dom/webgpu/CommandBuffer.cpp new file mode 100644 index 000000000000..48b066bce53b --- /dev/null +++ b/dom/webgpu/CommandBuffer.cpp @@ -0,0 +1,19 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "CommandBuffer.h" + +#include "Device.h" +#include "mozilla/dom/WebGPUBinding.h" + +namespace mozilla { +namespace webgpu { + +CommandBuffer::~CommandBuffer() = default; + +WEBGPU_IMPL_GOOP_0(CommandBuffer) + +} // namespace webgpu +} // namespace mozilla diff --git a/dom/webgpu/CommandBuffer.h b/dom/webgpu/CommandBuffer.h new file mode 100644 index 000000000000..4f5314d4b8b3 --- /dev/null +++ b/dom/webgpu/CommandBuffer.h @@ -0,0 +1,31 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WEBGPU_CommandBuffer_H_ +#define WEBGPU_CommandBuffer_H_ + +#include "nsWrapperCache.h" +#include "ObjectModel.h" + +namespace mozilla { +namespace webgpu { + +class Device; + +class CommandBuffer final + : public ChildOf +{ +public: + WEBGPU_DECL_GOOP(CommandBuffer) + +private: + CommandBuffer() = delete; + virtual ~CommandBuffer(); +}; + +} // namespace webgpu +} // namespace mozilla + +#endif // WEBGPU_CommandBuffer_H_ diff --git a/dom/webgpu/CommandEncoder.cpp b/dom/webgpu/CommandEncoder.cpp new file mode 100644 index 000000000000..1c93a27eaf7e --- /dev/null +++ b/dom/webgpu/CommandEncoder.cpp @@ -0,0 +1,147 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "CommandEncoder.h" + +#include "Device.h" +#include "mozilla/dom/WebGPUBinding.h" + +namespace mozilla { +namespace webgpu { + +CommandEncoder::~CommandEncoder() = default; + +already_AddRefed +CommandEncoder::FinishEncoding() const +{ + MOZ_CRASH("todo"); +} + +void +CommandEncoder::CopyBufferToBuffer(const Buffer& src, const uint32_t srcOffset, + const Buffer& dst, const uint32_t dstOffset, + const uint32_t size) const +{ + MOZ_CRASH("todo"); +} + +void +CommandEncoder::CopyBufferToTexture() const +{ + MOZ_CRASH("todo"); +} + +void +CommandEncoder::CopyTextureToBuffer() const +{ + MOZ_CRASH("todo"); +} + +void +CommandEncoder::CopyTextureToTexture() const +{ + MOZ_CRASH("todo"); +} + +void +CommandEncoder::Blit() const +{ + MOZ_CRASH("todo"); +} + +void +CommandEncoder::TransitionBuffer(const Buffer& b, const uint32_t flags) const +{ + MOZ_CRASH("todo"); +} + +void +CommandEncoder::SetPushConstants(const uint32_t stageFlags, const uint32_t offset, + const uint32_t count, const dom::ArrayBuffer& data) const +{ + MOZ_CRASH("todo"); +} + +void +CommandEncoder::SetBindGroup(const uint32_t index, const BindGroup& bindGroup) const +{ + MOZ_CRASH("todo"); +} + +void +CommandEncoder::SetPipeline(const dom::WebGPUComputePipelineOrWebGPURenderPipeline& pipeline) const +{ + MOZ_CRASH("todo"); +} + +void +CommandEncoder::BeginComputePass() const +{ + MOZ_CRASH("todo"); +} +void +CommandEncoder::EndComputePass() const +{ + MOZ_CRASH("todo"); +} + +void +CommandEncoder::Dispatch(const uint32_t x, const uint32_t y, const uint32_t z) const +{ + MOZ_CRASH("todo"); +} + +void +CommandEncoder::BeginRenderPass(const dom::WebGPURenderPassDescriptor& desc) const +{ + MOZ_CRASH("todo"); +} + +void +CommandEncoder::EndRenderPass() const +{ + MOZ_CRASH("todo"); +} + +void +CommandEncoder::SetBlendColor(const float r, const float g, const float b, + const float a) const +{ + MOZ_CRASH("todo"); +} + +void +CommandEncoder::SetIndexBuffer(const Buffer& buffer, const uint32_t offset) const +{ + MOZ_CRASH("todo"); +} + +void +CommandEncoder::SetVertexBuffers(const uint32_t startSlot, + const dom::Sequence>& buffers, + const dom::Sequence& offsets) const +{ + MOZ_CRASH("todo"); +} + +void +CommandEncoder::Draw(const uint32_t vertexCount, const uint32_t instanceCount, + const uint32_t firstVertex, const uint32_t firstInstance) const +{ + MOZ_CRASH("todo"); +} + +void +CommandEncoder::DrawIndexed(const uint32_t indexCount, const uint32_t instanceCount, + const uint32_t firstIndex, const uint32_t firstInstance, + const uint32_t firstVertex) const +{ + MOZ_CRASH("todo"); +} + +WEBGPU_IMPL_GOOP_0(CommandEncoder) + +} // namespace webgpu +} // namespace mozilla diff --git a/dom/webgpu/CommandEncoder.h b/dom/webgpu/CommandEncoder.h new file mode 100644 index 000000000000..0fe7f6d6c4d4 --- /dev/null +++ b/dom/webgpu/CommandEncoder.h @@ -0,0 +1,83 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WEBGPU_CommandEncoder_H_ +#define WEBGPU_CommandEncoder_H_ + +#include "mozilla/dom/TypedArray.h" +#include "nsWrapperCache.h" +#include "ObjectModel.h" + +namespace mozilla { +namespace dom { +template class Sequence; +class WebGPUComputePipelineOrWebGPURenderPipeline; +struct WebGPURenderPassDescriptor; +} // namespace dom +namespace webgpu { + +class BindGroup; +class Buffer; +class CommandBuffer; +class Device; + +class CommandEncoder final + : public ChildOf +{ +public: + WEBGPU_DECL_GOOP(CommandEncoder) + +private: + CommandEncoder() = delete; + virtual ~CommandEncoder(); + +public: + already_AddRefed FinishEncoding() const; + + // Commands allowed outside of "passes" + void CopyBufferToBuffer(const Buffer& src, uint32_t srcOffset, const Buffer& dst, + uint32_t dstOffset, uint32_t size) const; + // TODO figure out all the arguments required for these + void CopyBufferToTexture() const; + void CopyTextureToBuffer() const; + void CopyTextureToTexture() const; + void Blit() const; + + void TransitionBuffer(const Buffer& b, uint32_t flags) const; + + // Allowed in both compute and render passes + void SetPushConstants(uint32_t stageFlags, + uint32_t offset, + uint32_t count, + const dom::ArrayBuffer& data) const; + void SetBindGroup(uint32_t index, const BindGroup& bindGroup) const; + void SetPipeline(const dom::WebGPUComputePipelineOrWebGPURenderPipeline& pipeline) const; + + // Compute pass commands + void BeginComputePass() const; + void EndComputePass() const; + + void Dispatch(uint32_t x, uint32_t y, uint32_t z) const; + + // Render pass commands + void BeginRenderPass(const dom::WebGPURenderPassDescriptor& desc) const; + void EndRenderPass() const; + + void SetBlendColor(float r, float g, float b, float a) const; + void SetIndexBuffer(const Buffer& buffer, uint32_t offset) const; + void SetVertexBuffers(uint32_t startSlot, + const dom::Sequence>& buffers, + const dom::Sequence& offsets) const; + + void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, + uint32_t firstInstance) const; + void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, + uint32_t firstInstance, uint32_t firstVertex) const; +}; + +} // namespace webgpu +} // namespace mozilla + +#endif // WEBGPU_CommandEncoder_H_ diff --git a/dom/webgpu/ComputePipeline.cpp b/dom/webgpu/ComputePipeline.cpp new file mode 100644 index 000000000000..4db908956f20 --- /dev/null +++ b/dom/webgpu/ComputePipeline.cpp @@ -0,0 +1,19 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "ComputePipeline.h" + +#include "Device.h" +#include "mozilla/dom/WebGPUBinding.h" + +namespace mozilla { +namespace webgpu { + +ComputePipeline::~ComputePipeline() = default; + +WEBGPU_IMPL_GOOP_0(ComputePipeline) + +} // namespace webgpu +} // namespace mozilla diff --git a/dom/webgpu/ComputePipeline.h b/dom/webgpu/ComputePipeline.h new file mode 100644 index 000000000000..8bb7d914fa63 --- /dev/null +++ b/dom/webgpu/ComputePipeline.h @@ -0,0 +1,31 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WEBGPU_ComputePipeline_H_ +#define WEBGPU_ComputePipeline_H_ + +#include "nsWrapperCache.h" +#include "ObjectModel.h" + +namespace mozilla { +namespace webgpu { + +class Device; + +class ComputePipeline final + : public ChildOf +{ +public: + WEBGPU_DECL_GOOP(ComputePipeline) + +private: + ComputePipeline() = delete; + virtual ~ComputePipeline(); +}; + +} // namespace webgpu +} // namespace mozilla + +#endif // WEBGPU_ComputePipeline_H_ diff --git a/dom/webgpu/DepthStencilState.cpp b/dom/webgpu/DepthStencilState.cpp new file mode 100644 index 000000000000..2e59e737562e --- /dev/null +++ b/dom/webgpu/DepthStencilState.cpp @@ -0,0 +1,19 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "DepthStencilState.h" + +#include "Device.h" +#include "mozilla/dom/WebGPUBinding.h" + +namespace mozilla { +namespace webgpu { + +DepthStencilState::~DepthStencilState() = default; + +WEBGPU_IMPL_GOOP_0(DepthStencilState) + +} // namespace webgpu +} // namespace mozilla diff --git a/dom/webgpu/DepthStencilState.h b/dom/webgpu/DepthStencilState.h new file mode 100644 index 000000000000..1ceda2d5c0e4 --- /dev/null +++ b/dom/webgpu/DepthStencilState.h @@ -0,0 +1,31 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WEBGPU_DepthStencilState_H_ +#define WEBGPU_DepthStencilState_H_ + +#include "nsWrapperCache.h" +#include "ObjectModel.h" + +namespace mozilla { +namespace webgpu { + +class Device; + +class DepthStencilState final + : public ChildOf +{ +public: + WEBGPU_DECL_GOOP(DepthStencilState) + +private: + DepthStencilState() = delete; + virtual ~DepthStencilState(); +}; + +} // namespace webgpu +} // namespace mozilla + +#endif // WEBGPU_DepthStencilState_H_ diff --git a/dom/webgpu/Device.cpp b/dom/webgpu/Device.cpp new file mode 100644 index 000000000000..90059e19d8e4 --- /dev/null +++ b/dom/webgpu/Device.cpp @@ -0,0 +1,153 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "Device.h" + +#include "Adapter.h" +#include "mozilla/dom/WebGPUBinding.h" + +namespace mozilla { +namespace webgpu { + +Device::~Device() = default; + +already_AddRefed +Device::Adapter() const +{ + MOZ_CRASH("todo"); +} + +void +Device::Extensions(dom::WebGPUExtensions& out) const +{ + MOZ_CRASH("todo"); +} + +void +Device::Features(dom::WebGPUFeatures& out) const +{ + MOZ_CRASH("todo"); +} + +void +Device::Limits(dom::WebGPULimits& out) const +{ + MOZ_CRASH("todo"); +} + +already_AddRefed +Device::CreateBuffer(const dom::WebGPUBufferDescriptor& desc) const +{ + MOZ_CRASH("todo"); +} + +already_AddRefed +Device::CreateTexture(const dom::WebGPUTextureDescriptor& desc) const +{ + MOZ_CRASH("todo"); +} + +already_AddRefed +Device::CreateSampler(const dom::WebGPUSamplerDescriptor& desc) const +{ + MOZ_CRASH("todo"); +} + + +already_AddRefed +Device::CreateBindGroupLayout(const dom::WebGPUBindGroupLayoutDescriptor& desc) const +{ + MOZ_CRASH("todo"); +} + +already_AddRefed +Device::CreatePipelineLayout(const dom::WebGPUPipelineLayoutDescriptor& desc) const +{ + MOZ_CRASH("todo"); +} + +already_AddRefed +Device::CreateBindGroup(const dom::WebGPUBindGroupDescriptor& desc) const +{ + MOZ_CRASH("todo"); +} + + +already_AddRefed +Device::CreateBlendState(const dom::WebGPUBlendStateDescriptor& desc) const +{ + MOZ_CRASH("todo"); +} + +already_AddRefed +Device::CreateDepthStencilState(const dom::WebGPUDepthStencilStateDescriptor& desc) const +{ + MOZ_CRASH("todo"); +} + +already_AddRefed +Device::CreateInputState(const dom::WebGPUInputStateDescriptor& desc) const +{ + MOZ_CRASH("todo"); +} + +already_AddRefed +Device::CreateShaderModule(const dom::WebGPUShaderModuleDescriptor& desc) const +{ + MOZ_CRASH("todo"); +} + +already_AddRefed +Device::CreateAttachmentState(const dom::WebGPUAttachmentStateDescriptor& desc) const +{ + MOZ_CRASH("todo"); +} + +already_AddRefed +Device::CreateComputePipeline(const dom::WebGPUComputePipelineDescriptor& desc) const +{ + MOZ_CRASH("todo"); +} + +already_AddRefed +Device::CreateRenderPipeline(const dom::WebGPURenderPipelineDescriptor& desc) const +{ + MOZ_CRASH("todo"); +} + +already_AddRefed +Device::CreateCommandEncoder(const dom::WebGPUCommandEncoderDescriptor& desc) const +{ + MOZ_CRASH("todo"); +} + +already_AddRefed +Device::GetQueue() const +{ + MOZ_CRASH("todo"); +} + +RefPtr +Device::OnLog() const +{ + MOZ_CRASH("todo"); +} + +void +Device::SetOnLog(const dom::WebGPULogCallback& callback) const +{ + MOZ_CRASH("todo"); +} + +already_AddRefed +Device::GetObjectStatus(const dom::WebGPUBufferOrWebGPUTexture& obj) const +{ + MOZ_CRASH("todo"); +} + +WEBGPU_IMPL_GOOP_0(Device) + +} // namespace webgpu +} // namespace mozilla diff --git a/dom/webgpu/Device.h b/dom/webgpu/Device.h new file mode 100644 index 000000000000..c18d602c44ba --- /dev/null +++ b/dom/webgpu/Device.h @@ -0,0 +1,103 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WEBGPU_DEVICE_H_ +#define WEBGPU_DEVICE_H_ + +#include "mozilla/RefPtr.h" +#include "ObjectModel.h" + +namespace mozilla { +namespace dom { +struct WebGPUExtensions; +struct WebGPUFeatures; +struct WebGPULimits; + +struct WebGPUBufferDescriptor; +struct WebGPUTextureDescriptor; +struct WebGPUSamplerDescriptor; +struct WebGPUBindGroupLayoutDescriptor; +struct WebGPUPipelineLayoutDescriptor; +struct WebGPUBindGroupDescriptor; +struct WebGPUBlendStateDescriptor; +struct WebGPUDepthStencilStateDescriptor; +struct WebGPUInputStateDescriptor; +struct WebGPUShaderModuleDescriptor; +struct WebGPUAttachmentStateDescriptor; +struct WebGPUComputePipelineDescriptor; +struct WebGPURenderPipelineDescriptor; +struct WebGPUCommandEncoderDescriptor; + +class Promise; +class WebGPUBufferOrWebGPUTexture; +class WebGPULogCallback; +} // namespace dom + +namespace webgpu { +class Adapter; +class AttachmentState; +class BindGroup; +class BindGroupLayout; +class BlendState; +class Buffer; +class CommandEncoder; +class ComputePipeline; +class DepthStencilState; +class Fence; +class InputState; +class PipelineLayout; +class Queue; +class RenderPipeline; +class Sampler; +class ShaderModule; +class Texture; + +class Device final + : public ChildOf +{ +public: + WEBGPU_DECL_GOOP(Device) + +private: + Device() = delete; + virtual ~Device(); + +public: + already_AddRefed Adapter() const; + + void Extensions(dom::WebGPUExtensions& out) const; + void Features(dom::WebGPUFeatures& out) const; + void Limits(dom::WebGPULimits& out) const; + + already_AddRefed CreateBuffer(const dom::WebGPUBufferDescriptor& desc) const; + already_AddRefed CreateTexture(const dom::WebGPUTextureDescriptor& desc) const; + already_AddRefed CreateSampler(const dom::WebGPUSamplerDescriptor& desc) const; + + already_AddRefed CreateBindGroupLayout(const dom::WebGPUBindGroupLayoutDescriptor& desc) const; + already_AddRefed CreatePipelineLayout(const dom::WebGPUPipelineLayoutDescriptor& desc) const; + already_AddRefed CreateBindGroup(const dom::WebGPUBindGroupDescriptor& desc) const; + + already_AddRefed CreateBlendState(const dom::WebGPUBlendStateDescriptor& desc) const; + already_AddRefed CreateDepthStencilState(const dom::WebGPUDepthStencilStateDescriptor& desc) const; + already_AddRefed CreateInputState(const dom::WebGPUInputStateDescriptor& desc) const; + already_AddRefed CreateShaderModule(const dom::WebGPUShaderModuleDescriptor& desc) const; + already_AddRefed CreateAttachmentState(const dom::WebGPUAttachmentStateDescriptor& desc) const; + already_AddRefed CreateComputePipeline(const dom::WebGPUComputePipelineDescriptor& desc) const; + already_AddRefed CreateRenderPipeline(const dom::WebGPURenderPipelineDescriptor& desc) const; + + already_AddRefed CreateCommandEncoder(const dom::WebGPUCommandEncoderDescriptor& desc) const; + + already_AddRefed GetQueue() const; + + RefPtr OnLog() const; + void SetOnLog(const dom::WebGPULogCallback& callback) const; + + already_AddRefed GetObjectStatus(const dom::WebGPUBufferOrWebGPUTexture& obj) const; +}; + +} // namespace webgpu +} // namespace mozilla + +#endif // WEBGPU_DEVICE_H_ diff --git a/dom/webgpu/Fence.cpp b/dom/webgpu/Fence.cpp new file mode 100644 index 000000000000..4ec6801f29dc --- /dev/null +++ b/dom/webgpu/Fence.cpp @@ -0,0 +1,31 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "Fence.h" + +#include "Device.h" +#include "mozilla/dom/WebGPUBinding.h" + +namespace mozilla { +namespace webgpu { + +Fence::~Fence() = default; + +bool +Fence::Wait(const double milliseconds) const +{ + MOZ_CRASH("todo"); +} + +already_AddRefed +Fence::Promise() const +{ + MOZ_CRASH("todo"); +} + +WEBGPU_IMPL_GOOP_0(Fence) + +} // namespace webgpu +} // namespace mozilla diff --git a/dom/webgpu/Fence.h b/dom/webgpu/Fence.h new file mode 100644 index 000000000000..2041af4fec91 --- /dev/null +++ b/dom/webgpu/Fence.h @@ -0,0 +1,38 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WEBGPU_Fence_H_ +#define WEBGPU_Fence_H_ + +#include "nsWrapperCache.h" +#include "ObjectModel.h" + +namespace mozilla { +namespace dom { +class Promise; +} // namespace dom +namespace webgpu { + +class Device; + +class Fence final + : public ChildOf +{ +public: + WEBGPU_DECL_GOOP(Fence) + +private: + Fence() = delete; + virtual ~Fence(); + +public: + bool Wait(double milliseconds) const; + already_AddRefed Promise() const; +}; + +} // namespace webgpu +} // namespace mozilla + +#endif // WEBGPU_Fence_H_ diff --git a/dom/webgpu/InputState.cpp b/dom/webgpu/InputState.cpp new file mode 100644 index 000000000000..79347494024d --- /dev/null +++ b/dom/webgpu/InputState.cpp @@ -0,0 +1,19 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "InputState.h" + +#include "Device.h" +#include "mozilla/dom/WebGPUBinding.h" + +namespace mozilla { +namespace webgpu { + +InputState::~InputState() = default; + +WEBGPU_IMPL_GOOP_0(InputState) + +} // namespace webgpu +} // namespace mozilla diff --git a/dom/webgpu/InputState.h b/dom/webgpu/InputState.h new file mode 100644 index 000000000000..4b8ae36b8b80 --- /dev/null +++ b/dom/webgpu/InputState.h @@ -0,0 +1,31 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WEBGPU_InputState_H_ +#define WEBGPU_InputState_H_ + +#include "nsWrapperCache.h" +#include "ObjectModel.h" + +namespace mozilla { +namespace webgpu { + +class Device; + +class InputState final + : public ChildOf +{ +public: + WEBGPU_DECL_GOOP(InputState) + +private: + InputState() = delete; + virtual ~InputState(); +}; + +} // namespace webgpu +} // namespace mozilla + +#endif // WEBGPU_InputState_H_ diff --git a/dom/webgpu/Instance.cpp b/dom/webgpu/Instance.cpp new file mode 100644 index 000000000000..ba7b4359190d --- /dev/null +++ b/dom/webgpu/Instance.cpp @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "Instance.h" + +#include "Adapter.h" +#include "InstanceProvider.h" +#include "mozilla/dom/WebGPUBinding.h" +#include "nsIGlobalObject.h" + +namespace mozilla { +namespace webgpu { + +/*static*/ RefPtr +Instance::Create(nsIGlobalObject* parent) +{ + return new Instance(parent); +} + +Instance::Instance(nsIGlobalObject* parent) + : mParent(parent) +{ +} + +Instance::~Instance() = default; + +already_AddRefed +Instance::GetAdapter(const dom::WebGPUAdapterDescriptor& desc) const +{ + MOZ_CRASH("todo"); +} + +template +void +ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& callback, + const nsCOMPtr& field, + const char* name, uint32_t flags) +{ + CycleCollectionNoteChild(callback, field.get(), name, flags); +} + +template +void +ImplCycleCollectionUnlink(const nsCOMPtr& field) +{ + const auto mut = const_cast*>(&field); + *mut = nullptr; +} + +JSObject* +Instance::WrapObject(JSContext* cx, JS::Handle givenProto) +{ + return dom::WebGPU_Binding::Wrap(cx, this, givenProto); +} +NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(Instance, AddRef) +NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(Instance, Release) + +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Instance, mParent) + +} // namespace webgpu +} // namespace mozilla diff --git a/dom/webgpu/Instance.h b/dom/webgpu/Instance.h new file mode 100644 index 000000000000..a2fce8e8d1e2 --- /dev/null +++ b/dom/webgpu/Instance.h @@ -0,0 +1,46 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WEBGPU_INSTANCE_H_ +#define WEBGPU_INSTANCE_H_ + +#include "mozilla/AlreadyAddRefed.h" +#include "mozilla/RefPtr.h" +#include "nsCOMPtr.h" +#include "ObjectModel.h" + +namespace mozilla { +namespace dom { +struct WebGPUAdapterDescriptor; +} // namespace dom + +namespace webgpu { +class Adapter; +class InstanceProvider; + +class Instance final + : public nsWrapperCache +{ +public: + WEBGPU_DECL_GOOP(Instance) + + const nsCOMPtr mParent; + + static RefPtr Create(nsIGlobalObject* parent); + +private: + explicit Instance(nsIGlobalObject* parent); + virtual ~Instance(); + +public: + nsIGlobalObject* GetParentObject() const { return mParent.get(); } + + already_AddRefed GetAdapter(const dom::WebGPUAdapterDescriptor& desc) const; +}; + +} // namespace webgpu +} // namespace mozilla + +#endif // WEBGPU_INSTANCE_H_ diff --git a/dom/webgpu/InstanceProvider.cpp b/dom/webgpu/InstanceProvider.cpp new file mode 100644 index 000000000000..d9a2296954d3 --- /dev/null +++ b/dom/webgpu/InstanceProvider.cpp @@ -0,0 +1,47 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "InstanceProvider.h" + +#include "Instance.h" +#include "mozilla/dom/WebGPUBinding.h" + +namespace mozilla { +namespace webgpu { + +InstanceProvider::InstanceProvider(nsIGlobalObject* const global) + : mGlobal(global) +{ } + +InstanceProvider::~InstanceProvider() = default; + +already_AddRefed +InstanceProvider::Webgpu() const +{ + if (!mInstance) { + const auto inst = Instance::Create(mGlobal); + mInstance = Some(inst); + } + auto ret = mInstance.value(); + return ret.forget(); +} + +void +InstanceProvider::CcTraverse(nsCycleCollectionTraversalCallback& callback) const +{ + if (mInstance) { + CycleCollectionNoteChild(callback, mInstance.ref().get(), + "webgpu::InstanceProvider::mInstance", 0); + } +} + +void +InstanceProvider::CcUnlink() +{ + mInstance = Some(nullptr); +} + +} // namespace webgpu +} // namespace mozilla diff --git a/dom/webgpu/InstanceProvider.h b/dom/webgpu/InstanceProvider.h new file mode 100644 index 000000000000..ba246eb2a8b9 --- /dev/null +++ b/dom/webgpu/InstanceProvider.h @@ -0,0 +1,60 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WEBGPU_INSTANCE_PROVIDER_H_ +#define WEBGPU_INSTANCE_PROVIDER_H_ + +#include "mozilla/AlreadyAddRefed.h" +#include "mozilla/Maybe.h" +#include "mozilla/RefPtr.h" + +class nsCycleCollectionTraversalCallback; +class nsIGlobalObject; + +namespace mozilla { +namespace webgpu { +class Instance; + +class InstanceProvider +{ +private: + nsIGlobalObject* const mGlobal; + mutable Maybe> mInstance; + +protected: + explicit InstanceProvider(nsIGlobalObject* global); + virtual ~InstanceProvider(); + +public: + already_AddRefed Webgpu() const; + + nsIGlobalObject* GetParentObject() const { return mGlobal; } + + void CcTraverse(nsCycleCollectionTraversalCallback&) const; + void CcUnlink(); +}; + +template +void +ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& callback, + const Maybe& field, + const char* name, uint32_t flags) +{ + if (field) { + CycleCollectionNoteChild(callback, field.value(), name, flags); + } +} + +template +void +ImplCycleCollectionUnlink(Maybe& field) +{ + field = Nothing(); +} + +} // namespace webgpu +} // namespace mozilla + +#endif // WEBGPU_INSTANCE_PROVIDER_H_ diff --git a/dom/webgpu/LogEntry.cpp b/dom/webgpu/LogEntry.cpp new file mode 100644 index 000000000000..c0085a826f5c --- /dev/null +++ b/dom/webgpu/LogEntry.cpp @@ -0,0 +1,37 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "LogEntry.h" + +#include "Device.h" +#include "mozilla/dom/WebGPUBinding.h" + +namespace mozilla { +namespace webgpu { + +LogEntry::~LogEntry() = default; + +dom::WebGPULogEntryType +LogEntry::Type() const +{ + MOZ_CRASH("todo"); +} + +void +LogEntry::GetObj(JSContext* cx, JS::MutableHandleValue out) const +{ + MOZ_CRASH("todo"); +} + +void +LogEntry::GetReason(nsString& out) const +{ + MOZ_CRASH("todo"); +} + +WEBGPU_IMPL_GOOP_0(LogEntry) + +} // namespace webgpu +} // namespace mozilla diff --git a/dom/webgpu/LogEntry.h b/dom/webgpu/LogEntry.h new file mode 100644 index 000000000000..ce6e2d62c0b0 --- /dev/null +++ b/dom/webgpu/LogEntry.h @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WEBGPU_LogEntry_H_ +#define WEBGPU_LogEntry_H_ + +#include "nsWrapperCache.h" +#include "ObjectModel.h" + +namespace mozilla { +namespace dom { +enum class WebGPULogEntryType : uint8_t; +} // namespace dom +namespace webgpu { + +class Device; + +class LogEntry final + : public ChildOf +{ +public: + WEBGPU_DECL_GOOP(LogEntry) + +private: + LogEntry() = delete; + virtual ~LogEntry(); + +public: + dom::WebGPULogEntryType Type() const; + void GetObj(JSContext* cx, JS::MutableHandleValue out) const; + void GetReason(nsString& out) const; +}; + +} // namespace webgpu +} // namespace mozilla + +#endif // WEBGPU_LogEntry_H_ diff --git a/dom/webgpu/ObjectModel.cpp b/dom/webgpu/ObjectModel.cpp new file mode 100644 index 000000000000..d7ed94e32111 --- /dev/null +++ b/dom/webgpu/ObjectModel.cpp @@ -0,0 +1,35 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "ObjectModel.h" + +#include "Adapter.h" +#include "Device.h" +#include "Instance.h" + +namespace mozilla { +namespace webgpu { + +template +ChildOf::ChildOf(T* const parent) + : mParent(parent) +{ } + +template +ChildOf::~ChildOf() = default; + +template +nsIGlobalObject* +ChildOf::GetParentObject() const +{ + return mParent->GetParentObject(); +} + +template class ChildOf; +template class ChildOf; +template class ChildOf; + +} // namespace webgpu +} // namespace mozilla diff --git a/dom/webgpu/ObjectModel.h b/dom/webgpu/ObjectModel.h new file mode 100644 index 000000000000..f243a8a1e024 --- /dev/null +++ b/dom/webgpu/ObjectModel.h @@ -0,0 +1,73 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WEBGPU_OBJECT_MODEL_H_ +#define WEBGPU_OBJECT_MODEL_H_ + +#include "nsWrapperCache.h" + +class nsIGlobalObject; + +namespace mozilla { +namespace webgpu { + +template +class ChildOf + : public nsWrapperCache +{ +public: + const RefPtr mParent; + + explicit ChildOf(T* parent = nullptr); // TODO: This can't be nullptr eventually. +protected: + virtual ~ChildOf(); + +public: + nsIGlobalObject* GetParentObject() const; +}; + +} // namespace webgpu +} // namespace mozilla + +#define WEBGPU_DECL_GOOP(T) \ + NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(T) \ + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(T) \ + virtual JSObject* WrapObject(JSContext* cx, JS::Handle givenProto) override; + +#define WEBGPU_IMPL_GOOP_INTERNAL(T) \ + JSObject* \ + T::WrapObject(JSContext* cx, JS::Handle givenProto) \ + { \ + return dom::WebGPU ## T ## _Binding::Wrap(cx, this, givenProto); \ + } \ + NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(T, AddRef) \ + NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(T, Release) + +#define WEBGPU_IMPL_GOOP(T,...) \ + WEBGPU_IMPL_GOOP_INTERNAL(T) \ + NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(T, mParent, __VA_ARGS__) + +#define WEBGPU_IMPL_GOOP_0(T) \ + WEBGPU_IMPL_GOOP_INTERNAL(T) \ + NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(T, mParent) + +template +void +ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& callback, + const RefPtr& field, + const char* name, uint32_t flags) +{ + CycleCollectionNoteChild(callback, field.get(), name, flags); +} + +template +void +ImplCycleCollectionUnlink(const RefPtr& field) +{ + const auto mutPtr = const_cast< RefPtr* >(&field); + ImplCycleCollectionUnlink(*mutPtr); +} + +#endif // WEBGPU_OBJECT_MODEL_H_ diff --git a/dom/webgpu/PipelineLayout.cpp b/dom/webgpu/PipelineLayout.cpp new file mode 100644 index 000000000000..0078b571da52 --- /dev/null +++ b/dom/webgpu/PipelineLayout.cpp @@ -0,0 +1,19 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "PipelineLayout.h" + +#include "Device.h" +#include "mozilla/dom/WebGPUBinding.h" + +namespace mozilla { +namespace webgpu { + +PipelineLayout::~PipelineLayout() = default; + +WEBGPU_IMPL_GOOP_0(PipelineLayout) + +} // namespace webgpu +} // namespace mozilla diff --git a/dom/webgpu/PipelineLayout.h b/dom/webgpu/PipelineLayout.h new file mode 100644 index 000000000000..5ce90c013410 --- /dev/null +++ b/dom/webgpu/PipelineLayout.h @@ -0,0 +1,31 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WEBGPU_PipelineLayout_H_ +#define WEBGPU_PipelineLayout_H_ + +#include "nsWrapperCache.h" +#include "ObjectModel.h" + +namespace mozilla { +namespace webgpu { + +class Device; + +class PipelineLayout final + : public ChildOf +{ +public: + WEBGPU_DECL_GOOP(PipelineLayout) + +private: + PipelineLayout() = delete; + virtual ~PipelineLayout(); +}; + +} // namespace webgpu +} // namespace mozilla + +#endif // WEBGPU_PipelineLayout_H_ diff --git a/dom/webgpu/Queue.cpp b/dom/webgpu/Queue.cpp new file mode 100644 index 000000000000..1ead2bdde36e --- /dev/null +++ b/dom/webgpu/Queue.cpp @@ -0,0 +1,31 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "Queue.h" + +#include "Device.h" +#include "mozilla/dom/WebGPUBinding.h" + +namespace mozilla { +namespace webgpu { + +Queue::~Queue() = default; + +void +Queue::Submit(const dom::Sequence>& buffers) const +{ + MOZ_CRASH("todo"); +} + +already_AddRefed +Queue::InsertFence() const +{ + MOZ_CRASH("todo"); +} + +WEBGPU_IMPL_GOOP_0(Queue) + +} // namespace webgpu +} // namespace mozilla diff --git a/dom/webgpu/Queue.h b/dom/webgpu/Queue.h new file mode 100644 index 000000000000..d0e38ae56752 --- /dev/null +++ b/dom/webgpu/Queue.h @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WEBGPU_Queue_H_ +#define WEBGPU_Queue_H_ + +#include "nsWrapperCache.h" +#include "ObjectModel.h" + +namespace mozilla { +namespace dom { +template class Sequence; +} // namespace dom + +namespace webgpu { + +class CommandBuffer; +class Device; +class Fence; + +class Queue final + : public ChildOf +{ +public: + WEBGPU_DECL_GOOP(Queue) + +private: + Queue() = delete; + virtual ~Queue(); + +public: + void Submit(const dom::Sequence>& buffers) const; + already_AddRefed InsertFence() const; +}; + +} // namespace webgpu +} // namespace mozilla + +#endif // WEBGPU_Queue_H_ diff --git a/dom/webgpu/RenderPipeline.cpp b/dom/webgpu/RenderPipeline.cpp new file mode 100644 index 000000000000..e8fe1df2b10a --- /dev/null +++ b/dom/webgpu/RenderPipeline.cpp @@ -0,0 +1,19 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "RenderPipeline.h" + +#include "Device.h" +#include "mozilla/dom/WebGPUBinding.h" + +namespace mozilla { +namespace webgpu { + +RenderPipeline::~RenderPipeline() = default; + +WEBGPU_IMPL_GOOP_0(RenderPipeline) + +} // namespace webgpu +} // namespace mozilla diff --git a/dom/webgpu/RenderPipeline.h b/dom/webgpu/RenderPipeline.h new file mode 100644 index 000000000000..ffec0e805867 --- /dev/null +++ b/dom/webgpu/RenderPipeline.h @@ -0,0 +1,31 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WEBGPU_RenderPipeline_H_ +#define WEBGPU_RenderPipeline_H_ + +#include "nsWrapperCache.h" +#include "ObjectModel.h" + +namespace mozilla { +namespace webgpu { + +class Device; + +class RenderPipeline final + : public ChildOf +{ +public: + WEBGPU_DECL_GOOP(RenderPipeline) + +private: + RenderPipeline() = delete; + virtual ~RenderPipeline(); +}; + +} // namespace webgpu +} // namespace mozilla + +#endif // WEBGPU_RenderPipeline_H_ diff --git a/dom/webgpu/Sampler.cpp b/dom/webgpu/Sampler.cpp new file mode 100644 index 000000000000..0b6251f70447 --- /dev/null +++ b/dom/webgpu/Sampler.cpp @@ -0,0 +1,19 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "Sampler.h" + +#include "Device.h" +#include "mozilla/dom/WebGPUBinding.h" + +namespace mozilla { +namespace webgpu { + +Sampler::~Sampler() = default; + +WEBGPU_IMPL_GOOP_0(Sampler) + +} // namespace webgpu +} // namespace mozilla diff --git a/dom/webgpu/Sampler.h b/dom/webgpu/Sampler.h new file mode 100644 index 000000000000..fb9d22179564 --- /dev/null +++ b/dom/webgpu/Sampler.h @@ -0,0 +1,31 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WEBGPU_SAMPLER_H_ +#define WEBGPU_SAMPLER_H_ + +#include "nsWrapperCache.h" +#include "ObjectModel.h" + +namespace mozilla { +namespace webgpu { + +class Device; + +class Sampler final + : public ChildOf +{ +public: + WEBGPU_DECL_GOOP(Sampler) + +private: + Sampler() = delete; + virtual ~Sampler(); +}; + +} // namespace webgpu +} // namespace mozilla + +#endif // WEBGPU_SAMPLER_H_ diff --git a/dom/webgpu/ShaderModule.cpp b/dom/webgpu/ShaderModule.cpp new file mode 100644 index 000000000000..d674e0cfc0ed --- /dev/null +++ b/dom/webgpu/ShaderModule.cpp @@ -0,0 +1,19 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "ShaderModule.h" + +#include "Device.h" +#include "mozilla/dom/WebGPUBinding.h" + +namespace mozilla { +namespace webgpu { + +ShaderModule::~ShaderModule() = default; + +WEBGPU_IMPL_GOOP_0(ShaderModule) + +} // namespace webgpu +} // namespace mozilla diff --git a/dom/webgpu/ShaderModule.h b/dom/webgpu/ShaderModule.h new file mode 100644 index 000000000000..8c5b58c4a9a1 --- /dev/null +++ b/dom/webgpu/ShaderModule.h @@ -0,0 +1,31 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WEBGPU_ShaderModule_H_ +#define WEBGPU_ShaderModule_H_ + +#include "nsWrapperCache.h" +#include "ObjectModel.h" + +namespace mozilla { +namespace webgpu { + +class Device; + +class ShaderModule final + : public ChildOf +{ +public: + WEBGPU_DECL_GOOP(ShaderModule) + +private: + ShaderModule() = delete; + virtual ~ShaderModule(); +}; + +} // namespace webgpu +} // namespace mozilla + +#endif // WEBGPU_ShaderModule_H_ diff --git a/dom/webgpu/SwapChain.cpp b/dom/webgpu/SwapChain.cpp new file mode 100644 index 000000000000..2f9c547464e7 --- /dev/null +++ b/dom/webgpu/SwapChain.cpp @@ -0,0 +1,37 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "SwapChain.h" + +#include "Device.h" +#include "mozilla/dom/WebGPUBinding.h" + +namespace mozilla { +namespace webgpu { + +SwapChain::~SwapChain() = default; + +void +SwapChain::Configure(const dom::WebGPUSwapChainDescriptor& desc) const +{ + MOZ_CRASH("todo"); +} + +already_AddRefed +SwapChain::GetNextTexture() const +{ + MOZ_CRASH("todo"); +} + +void +SwapChain::Present() const +{ + MOZ_CRASH("todo"); +} + +WEBGPU_IMPL_GOOP_0(SwapChain) + +} // namespace webgpu +} // namespace mozilla diff --git a/dom/webgpu/SwapChain.h b/dom/webgpu/SwapChain.h new file mode 100644 index 000000000000..1c2b7e5ce9cc --- /dev/null +++ b/dom/webgpu/SwapChain.h @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WEBGPU_SwapChain_H_ +#define WEBGPU_SwapChain_H_ + +#include "nsWrapperCache.h" +#include "ObjectModel.h" + +namespace mozilla { +namespace dom { +struct WebGPUSwapChainDescriptor; +} // namespace dom + +namespace webgpu { + +class Device; +class Texture; + +class SwapChain final + : public ChildOf +{ +public: + WEBGPU_DECL_GOOP(SwapChain) + +private: + SwapChain() = delete; + virtual ~SwapChain(); + +public: + void Configure(const dom::WebGPUSwapChainDescriptor& desc) const; + already_AddRefed GetNextTexture() const; + void Present() const; +}; + +} // namespace webgpu +} // namespace mozilla + +#endif // WEBGPU_SwapChain_H_ diff --git a/dom/webgpu/Texture.cpp b/dom/webgpu/Texture.cpp new file mode 100644 index 000000000000..072811fd9b5c --- /dev/null +++ b/dom/webgpu/Texture.cpp @@ -0,0 +1,26 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "Texture.h" + +#include "Device.h" +#include "mozilla/dom/WebGPUBinding.h" +#include "TextureView.h" + +namespace mozilla { +namespace webgpu { + +Texture::~Texture() = default; + +already_AddRefed +Texture::CreateTextureView(const dom::WebGPUTextureViewDescriptor& desc) const +{ + MOZ_CRASH("todo"); +} + +WEBGPU_IMPL_GOOP_0(Texture) + +} // namespace webgpu +} // namespace mozilla diff --git a/dom/webgpu/Texture.h b/dom/webgpu/Texture.h new file mode 100644 index 000000000000..002266029b8d --- /dev/null +++ b/dom/webgpu/Texture.h @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WEBGPU_Texture_H_ +#define WEBGPU_Texture_H_ + +#include "nsWrapperCache.h" +#include "ObjectModel.h" + +namespace mozilla { +namespace dom { +struct WebGPUTextureViewDescriptor; +} // namespace dom + +namespace webgpu { + +class Device; +class TextureView; + +class Texture final + : public ChildOf +{ +public: + WEBGPU_DECL_GOOP(Texture) + +private: + Texture() = delete; + virtual ~Texture(); + +public: + already_AddRefed CreateTextureView(const dom::WebGPUTextureViewDescriptor&) const; +}; + +} // namespace webgpu +} // namespace mozilla + +#endif // WEBGPU_Texture_H_ diff --git a/dom/webgpu/TextureView.cpp b/dom/webgpu/TextureView.cpp new file mode 100644 index 000000000000..913beb7f79ef --- /dev/null +++ b/dom/webgpu/TextureView.cpp @@ -0,0 +1,19 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "TextureView.h" + +#include "Device.h" +#include "mozilla/dom/WebGPUBinding.h" + +namespace mozilla { +namespace webgpu { + +TextureView::~TextureView() = default; + +WEBGPU_IMPL_GOOP_0(TextureView) + +} // namespace webgpu +} // namespace mozilla diff --git a/dom/webgpu/TextureView.h b/dom/webgpu/TextureView.h new file mode 100644 index 000000000000..687321d4e168 --- /dev/null +++ b/dom/webgpu/TextureView.h @@ -0,0 +1,31 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WEBGPU_TEXTURE_VIEW_H_ +#define WEBGPU_TEXTURE_VIEW_H_ + +#include "nsWrapperCache.h" +#include "ObjectModel.h" + +namespace mozilla { +namespace webgpu { + +class Device; + +class TextureView final + : public ChildOf +{ +public: + WEBGPU_DECL_GOOP(TextureView) + +private: + TextureView() = delete; + virtual ~TextureView(); +}; + +} // namespace webgpu +} // namespace mozilla + +#endif // WEBGPU_TEXTURE_VIEW_H_ diff --git a/dom/webgpu/mochitest/mochitest-no-pref.ini b/dom/webgpu/mochitest/mochitest-no-pref.ini new file mode 100644 index 000000000000..6eaa5f60293b --- /dev/null +++ b/dom/webgpu/mochitest/mochitest-no-pref.ini @@ -0,0 +1,5 @@ +[DEFAULT] +subsuite = webgl1-core + +[test_disabled.html] + diff --git a/dom/webgpu/mochitest/mochitest.ini b/dom/webgpu/mochitest/mochitest.ini new file mode 100644 index 000000000000..0002429da42a --- /dev/null +++ b/dom/webgpu/mochitest/mochitest.ini @@ -0,0 +1,6 @@ +[DEFAULT] +subsuite = webgl1-core +prefs = dom.webgpu.enable=true + +[test_enabled.html] + diff --git a/dom/webgpu/mochitest/test_disabled.html b/dom/webgpu/mochitest/test_disabled.html new file mode 100644 index 000000000000..94927cab016e --- /dev/null +++ b/dom/webgpu/mochitest/test_disabled.html @@ -0,0 +1,18 @@ + + + + + + + + + + + + diff --git a/dom/webgpu/mochitest/test_enabled.html b/dom/webgpu/mochitest/test_enabled.html new file mode 100644 index 000000000000..9d5ab7c0aa18 --- /dev/null +++ b/dom/webgpu/mochitest/test_enabled.html @@ -0,0 +1,18 @@ + + + + + + + + + + + + diff --git a/dom/webgpu/moz.build b/dom/webgpu/moz.build new file mode 100644 index 000000000000..d63a85000acf --- /dev/null +++ b/dom/webgpu/moz.build @@ -0,0 +1,49 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +with Files('**'): + BUG_COMPONENT = ('Core', 'Canvas: WebGL') + +MOCHITEST_MANIFESTS += [ + 'mochitest/mochitest-no-pref.ini', + 'mochitest/mochitest.ini', +] + +h_and_cpp = [ + 'Adapter', + 'AttachmentState', + 'BindGroup', + 'BindGroupLayout', + 'BlendState', + 'Buffer', + 'CommandBuffer', + 'CommandEncoder', + 'ComputePipeline', + 'DepthStencilState', + 'Device', + 'Fence', + 'InputState', + 'Instance', + 'InstanceProvider', + 'LogEntry', + 'ObjectModel', + 'PipelineLayout', + 'Queue', + 'RenderPipeline', + 'Sampler', + 'ShaderModule', + 'SwapChain', + 'Texture', + 'TextureView', +] +EXPORTS.mozilla.webgpu += [x + '.h' for x in h_and_cpp] +UNIFIED_SOURCES += [x + '.cpp' for x in h_and_cpp] + +EXPORTS.mozilla.webgpu += [ +# 'ObjectModel.h', +] + +FINAL_LIBRARY = 'xul' diff --git a/dom/webidl/WebGPU.webidl b/dom/webidl/WebGPU.webidl new file mode 100644 index 000000000000..1da99854bded --- /dev/null +++ b/dom/webidl/WebGPU.webidl @@ -0,0 +1,639 @@ +/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is + * https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl + */ + +typedef unsigned long u32; +typedef unsigned long long u64; + +// **************************************************************************** +// ERROR HANDLING +// **************************************************************************** + +enum WebGPULogEntryType { + "device-lost", + "validation-error", + "recoverable-out-of-memory", +}; + +[Pref="dom.webgpu.enable"] +interface WebGPULogEntry { + readonly attribute WebGPULogEntryType type; + readonly attribute any obj; + readonly attribute DOMString? reason; +}; + +enum WebGPUObjectStatus { + "valid", + "out-of-memory", + "invalid", +}; + +typedef (WebGPUBuffer or WebGPUTexture) WebGPUStatusable; + +callback WebGPULogCallback = void (WebGPULogEntry error); + +// **************************************************************************** +// SHADER RESOURCES (buffer, textures, texture views, samples) +// **************************************************************************** + +// Buffer +typedef u32 WebGPUBufferUsageFlags; +[Pref="dom.webgpu.enable"] +interface WebGPUBufferUsage { + const u32 NONE = 0; + const u32 MAP_READ = 1; + const u32 MAP_WRITE = 2; + const u32 TRANSFER_SRC = 4; + const u32 TRANSFER_DST = 8; + const u32 INDEX = 16; + const u32 VERTEX = 32; + const u32 UNIFORM = 64; + const u32 STORAGE = 128; +}; + +dictionary WebGPUBufferDescriptor { + u32 size; + WebGPUBufferUsageFlags usage; +}; + +[Pref="dom.webgpu.enable"] +interface WebGPUBuffer { + readonly attribute ArrayBuffer? mapping; + void unmap(); +}; + +// Texture view +dictionary WebGPUTextureViewDescriptor { + // TODO Investigate what goes in there. +}; + +[Pref="dom.webgpu.enable"] +interface WebGPUTextureView { +}; + +// Texture +typedef u32 WebGPUTextureDimensionEnum; +[Pref="dom.webgpu.enable"] +interface WebGPUTextureDimension { + const u32 e1D = 0; + const u32 e2D = 1; + const u32 e3D = 2; + // TODO other dimensions (cube, arrays) +}; + +typedef u32 WebGPUTextureFormatEnum; +[Pref="dom.webgpu.enable"] +interface WebGPUTextureFormat { + const u32 R8_G8_B8_A8_UNORM = 0; + const u32 R8_G8_B8_A8_UINT = 1; + const u32 B8_G8_R8_A8_UNORM = 2; + const u32 D32_FLOAT_S8_UINT = 3; + // TODO other formats +}; + +typedef u32 WebGPUTextureUsageFlags; +[Pref="dom.webgpu.enable"] +interface WebGPUTextureUsage { + const u32 NONE = 0; + const u32 TRANSFER_SRC = 1; + const u32 TRANSFER_DST = 2; + const u32 SAMPLED = 4; + const u32 STORAGE = 8; + const u32 OUTPUT_ATTACHMENT = 16; + const u32 PRESENT = 32; +}; + +dictionary WebGPUTextureDescriptor { + u32 width; + u32 height; + u32 depth; + u32 arraySize; + WebGPUTextureDimensionEnum dimension; + WebGPUTextureFormatEnum format; + WebGPUTextureUsageFlags usage; +}; + +[Pref="dom.webgpu.enable"] +interface WebGPUTexture { + WebGPUTextureView createTextureView(optional WebGPUTextureViewDescriptor desc); +}; + +// Sampler +typedef u32 WebGPUFilterModeEnum; +[Pref="dom.webgpu.enable"] +interface WebGPUFilterMode { + const u32 NEAREST = 0; + const u32 LINEAR = 1; +}; + +dictionary WebGPUSamplerDescriptor { + WebGPUFilterModeEnum magFilter; + WebGPUFilterModeEnum minFilter; + WebGPUFilterModeEnum mipmapFilter; +}; + +[Pref="dom.webgpu.enable"] +interface WebGPUSampler { +}; + +// **************************************************************************** +// BINDING MODEL (bindgroup layout, bindgroup) +// **************************************************************************** + +// BindGroupLayout +typedef u32 WebGPUShaderStageFlags; +[Pref="dom.webgpu.enable"] +interface WebGPUShaderStageBit { + const u32 NONE = 0; + const u32 VERTEX = 1; + const u32 FRAGMENT = 2; + const u32 COMPUTE = 4; +}; + +typedef u32 WebGPUBindingTypeEnum; +[Pref="dom.webgpu.enable"] +interface WebGPUBindingType { + const u32 UNIFORM_BUFFER = 0; + const u32 SAMPLER = 1; + const u32 SAMPLED_TEXTURE = 2; + const u32 STORAGE_BUFFER = 3; + // TODO other binding types (storage images, ...) +}; + +dictionary WebGPUBindGroupBinding { + WebGPUShaderStageFlags visibility; + WebGPUBindingTypeEnum type; + u32 start; + u32 count; +}; + +dictionary WebGPUBindGroupLayoutDescriptor { + sequence bindingTypes; +}; + +[Pref="dom.webgpu.enable"] +interface WebGPUBindGroupLayout { +}; + +// PipelineLayout +dictionary WebGPUPipelineLayoutDescriptor { + sequence bindGroupLayouts; +}; + +[Pref="dom.webgpu.enable"] +interface WebGPUPipelineLayout { +}; + +// BindGroup +/* Moved to WebGPUExtras.webidl for now. +dictionary WebGPUBufferBinding { + WebGPUBuffer buffer; + u32 offset; + u32 size; +}; +*/ + +typedef (WebGPUSampler or WebGPUTextureView or WebGPUBufferBinding) WebGPUBindingResource; + +dictionary WebGPUBinding { + sequence resources; + u32 start; + u32 count; +}; + +dictionary WebGPUBindGroupDescriptor { + WebGPUBindGroupLayout layout; + sequence bindings; +}; + +[Pref="dom.webgpu.enable"] +interface WebGPUBindGroup { +}; + +// **************************************************************************** +// PIPELINE CREATION (blend state, DS state, ..., pipelines) +// **************************************************************************** + +// BlendState +typedef u32 WebGPUBlendFactorEnum; +[Pref="dom.webgpu.enable"] +interface WebGPUBlendFactor { + const u32 ZERO = 0; + const u32 ONE = 1; + const u32 SRC_COLOR = 2; + const u32 ONE_MINUS_SRC_COLOR = 3; + const u32 SRC_ALPHA = 4; + const u32 ONE_MINUS_SRC_ALPHA = 5; + const u32 DST_COLOR = 6; + const u32 ONE_MINUS_DST_COLOR = 7; + const u32 DST_ALPHA = 8; + const u32 ONE_MINUS_DST_ALPHA = 9; + const u32 SRC_ALPHA_SATURATED = 10; + const u32 BLEND_COLOR = 11; + const u32 ONE_MINUS_BLEND_COLOR = 12; +}; + +typedef u32 WebGPUBlendOperationEnum; +[Pref="dom.webgpu.enable"] +interface WebGPUBlendOperation { + const u32 ADD = 0; + const u32 SUBTRACT = 1; + const u32 REVERSE_SUBTRACT = 2; + const u32 MIN = 3; + const u32 MAX = 4; +}; + +typedef u32 WebGPUColorWriteFlags; +[Pref="dom.webgpu.enable"] +interface WebGPUColorWriteBits { + const u32 NONE = 0; + const u32 RED = 1; + const u32 GREEN = 2; + const u32 BLUE = 4; + const u32 ALPHA = 8; + const u32 ALL = 15; +}; + +dictionary WebGPUBlendDescriptor { + WebGPUBlendFactorEnum srcFactor; + WebGPUBlendFactorEnum dstFactor; + WebGPUBlendOperationEnum operation; +}; + +dictionary WebGPUBlendStateDescriptor { + boolean blendEnabled; + WebGPUBlendDescriptor alpha; + WebGPUBlendDescriptor color; + WebGPUColorWriteFlags writeMask; +}; + +[Pref="dom.webgpu.enable"] +interface WebGPUBlendState { +}; + +// DepthStencilState +typedef u32 WebGPUCompareFunctionEnum; +[Pref="dom.webgpu.enable"] +interface WebGPUCompareFunction { + const u32 NEVER = 0; + const u32 LESS = 1; + const u32 LESS_EQUAL = 2; + const u32 GREATER = 3; + const u32 GREATER_EQUAL = 4; + const u32 EQUAL = 5; + const u32 NOT_EQUAL = 6; + const u32 ALWAYS = 7; +}; + +typedef u32 WebGPUStencilOperationEnum; +[Pref="dom.webgpu.enable"] +interface WebGPUStencilOperation { + const u32 KEEP = 0; + const u32 ZERO = 1; + const u32 REPLACE = 2; + const u32 INVERT = 3; + const u32 INCREMENT_CLAMP = 4; + const u32 DECREMENT_CLAMP = 5; + const u32 INCREMENT_WRAP = 6; + const u32 DECREMENT_WRAP = 7; +}; + +dictionary WebGPUStencilStateFaceDescriptor { + WebGPUCompareFunctionEnum compare; + WebGPUStencilOperationEnum stencilFailOp; + WebGPUStencilOperationEnum depthFailOp; + WebGPUStencilOperationEnum passOp; +}; + +dictionary WebGPUDepthStencilStateDescriptor { + boolean depthWriteEnabled; + WebGPUCompareFunctionEnum depthCompare; + + WebGPUStencilStateFaceDescriptor front; + WebGPUStencilStateFaceDescriptor back; + + u32 stencilReadMask; + u32 stencilWriteMask; +}; + +[Pref="dom.webgpu.enable"] +interface WebGPUDepthStencilState { +}; + +// InputState +typedef u32 WebGPUIndexFormatEnum; +[Pref="dom.webgpu.enable"] +interface WebGPUIndexFormat { + const u32 UINT16 = 0; + const u32 UINT32 = 1; +}; + +typedef u32 WebGPUVertexFormatEnum; +[Pref="dom.webgpu.enable"] +interface WebGPUVertexFormat { + const u32 FLOAT_R32_G32_B32_A32 = 0; + const u32 FLOAT_R32_G32_B32 = 1; + const u32 FLOAT_R32_G32 = 2; + const u32 FLOAT_R32 = 3; + // TODO other vertex formats +}; + +typedef u32 WebGPUInputStepModeEnum; +[Pref="dom.webgpu.enable"] +interface WebGPUInputStepMode { + const u32 VERTEX = 0; + const u32 INSTANCE = 1; +}; + +dictionary WebGPUVertexAttributeDescriptor { + u32 shaderLocation; + u32 inputSlot; + u32 offset; + WebGPUVertexFormatEnum format; +}; + +dictionary WebGPUVertexInputDescriptor { + u32 inputSlot; + u32 stride; + WebGPUInputStepModeEnum stepMode; +}; + +dictionary WebGPUInputStateDescriptor { + WebGPUIndexFormatEnum indexFormat; + + sequence attributes; + sequence inputs; +}; + +[Pref="dom.webgpu.enable"] +interface WebGPUInputState { +}; + +// ShaderModule +dictionary WebGPUShaderModuleDescriptor { + required ArrayBuffer code; +}; + +[Pref="dom.webgpu.enable"] +interface WebGPUShaderModule { +}; + +// AttachmentState +dictionary WebGPUAttachmentStateDescriptor { + sequence formats; + // TODO other stuff like sample count etc. +}; + +[Pref="dom.webgpu.enable"] +interface WebGPUAttachmentState { +}; + +// Common stuff for ComputePipeline and RenderPipeline +typedef u32 WebGPUShaderStageEnum; +[Pref="dom.webgpu.enable"] +interface WebGPUShaderStage { + const u32 VERTEX = 0; + const u32 FRAGMENT = 1; + const u32 COMPUTE = 2; +}; + +dictionary WebGPUPipelineStageDescriptor { + required WebGPUShaderModule shaderModule; + required WebGPUShaderStageEnum stage; + required DOMString entryPoint; + // TODO other stuff like specialization constants? +}; + +dictionary WebGPUPipelineDescriptorBase { + required WebGPUPipelineLayout layout; + sequence stages; +}; + +// ComputePipeline +dictionary WebGPUComputePipelineDescriptor : WebGPUPipelineDescriptorBase { +}; + +[Pref="dom.webgpu.enable"] +interface WebGPUComputePipeline { +}; + +// WebGPURenderPipeline +typedef u32 WebGPUPrimitiveTopologyEnum; +[Pref="dom.webgpu.enable"] +interface WebGPUPrimitiveTopology { + const u32 POINT_LIST = 0; + const u32 LINE_LIST = 1; + const u32 LINE_STRIP = 2; + const u32 TRIANGLE_LIST = 3; + const u32 TRIANGLE_STRIP = 4; +}; + +dictionary WebGPURenderPipelineDescriptor : WebGPUPipelineDescriptorBase { + WebGPUPrimitiveTopologyEnum primitiveTopology; + sequence blendState; + WebGPUDepthStencilState depthStencilState; + WebGPUInputState inputState; + WebGPUAttachmentState attachmentState; + // TODO other properties +}; + +[Pref="dom.webgpu.enable"] +interface WebGPURenderPipeline { +}; +// **************************************************************************** +// COMMAND RECORDING (Command buffer and all relevant structures) +// **************************************************************************** + +typedef u32 WebGPULoadOpEnum; +[Pref="dom.webgpu.enable"] +interface WebGPULoadOp { + const u32 CLEAR = 0; + const u32 LOAD = 1; +}; + +typedef u32 WebGPUStoreOpEnum; +[Pref="dom.webgpu.enable"] +interface WebGPUStoreOp { + const u32 STORE = 0; +}; + +dictionary WebGPURenderPassAttachmentDescriptor { + WebGPUTextureView attachment; + WebGPULoadOpEnum loadOp; + WebGPUStoreOpEnum storeOp; +}; + +dictionary WebGPURenderPassDescriptor { + sequence colorAttachments; + WebGPURenderPassAttachmentDescriptor depthStencilAttachment; +}; + +[Pref="dom.webgpu.enable"] +interface WebGPUCommandBuffer { +}; + +dictionary WebGPUCommandEncoderDescriptor { +}; + +[Pref="dom.webgpu.enable"] +interface WebGPUCommandEncoder { + WebGPUCommandBuffer finishEncoding(); + + // Commands allowed outside of "passes" + void copyBufferToBuffer(WebGPUBuffer src, + u32 srcOffset, + WebGPUBuffer dst, + u32 dstOffset, + u32 size); + // TODO figure out all the arguments required for these + void copyBufferToTexture(); + void copyTextureToBuffer(); + void copyTextureToTexture(); + void blit(); + + void transitionBuffer(WebGPUBuffer b, WebGPUBufferUsageFlags f); + + // Allowed in both compute and render passes + void setPushConstants(WebGPUShaderStageFlags stage, + u32 offset, + u32 count, + ArrayBuffer data); + void setBindGroup(u32 index, WebGPUBindGroup bindGroup); + void setPipeline((WebGPUComputePipeline or WebGPURenderPipeline) pipeline); + + // Compute pass commands + void beginComputePass(); + void endComputePass(); + + void dispatch(u32 x, u32 y, u32 z); + + // Render pass commands + void beginRenderPass(optional WebGPURenderPassDescriptor descriptor); + void endRenderPass(); + + void setBlendColor(float r, float g, float b, float a); + void setIndexBuffer(WebGPUBuffer buffer, u32 offset); + void setVertexBuffers(u32 startSlot, sequence buffers, sequence offsets); + + void draw(u32 vertexCount, u32 instanceCount, u32 firstVertex, u32 firstInstance); + void drawIndexed(u32 indexCount, u32 instanceCount, u32 firstIndex, u32 firstInstance, u32 firstVertex); + + // TODO add missing commands +}; + +// **************************************************************************** +// OTHER (Fence, Queue SwapChain, Device) +// **************************************************************************** + +// Fence +[Pref="dom.webgpu.enable"] +interface WebGPUFence { + boolean wait(double milliseconds); + readonly attribute Promise promise; +}; + +// Queue +[Pref="dom.webgpu.enable"] +interface WebGPUQueue { + void submit(sequence buffers); + WebGPUFence insertFence(); +}; + +// SwapChain / RenderingContext +dictionary WebGPUSwapChainDescriptor { + WebGPUTextureUsageFlags usage; + WebGPUTextureFormatEnum format; + u32 width; + u32 height; +}; + +[Pref="dom.webgpu.enable"] +interface WebGPUSwapChain { + void configure(optional WebGPUSwapChainDescriptor descriptor); + WebGPUTexture getNextTexture(); + void present(); +}; + +//[Pref="dom.webgpu.enable"] +//interface WebGPURenderingContext : WebGPUSwapChain { +//}; + +// WebGPU "namespace" used for device creation +dictionary WebGPUExtensions { + boolean anisotropicFiltering; + boolean logicOp; // Previously a "Feature". +}; + +dictionary WebGPULimits { + u32 maxBindGroups; +}; + +// Device +[Pref="dom.webgpu.enable"] +interface WebGPUDevice { + readonly attribute WebGPUAdapter adapter; + WebGPUExtensions extensions(); + WebGPULimits limits(); + + WebGPUBuffer createBuffer(optional WebGPUBufferDescriptor descriptor); + WebGPUTexture createTexture(optional WebGPUTextureDescriptor descriptor); + WebGPUSampler createSampler(optional WebGPUSamplerDescriptor descriptor); + + WebGPUBindGroupLayout createBindGroupLayout(optional WebGPUBindGroupLayoutDescriptor descriptor); + WebGPUPipelineLayout createPipelineLayout(optional WebGPUPipelineLayoutDescriptor descriptor); + WebGPUBindGroup createBindGroup(optional WebGPUBindGroupDescriptor descriptor); + + WebGPUBlendState createBlendState(optional WebGPUBlendStateDescriptor descriptor); + WebGPUDepthStencilState createDepthStencilState(optional WebGPUDepthStencilStateDescriptor descriptor); + WebGPUInputState createInputState(optional WebGPUInputStateDescriptor descriptor); + WebGPUShaderModule createShaderModule(WebGPUShaderModuleDescriptor descriptor); + WebGPUAttachmentState createAttachmentState(optional WebGPUAttachmentStateDescriptor descriptor); + WebGPUComputePipeline createComputePipeline(WebGPUComputePipelineDescriptor descriptor); + WebGPURenderPipeline createRenderPipeline(WebGPURenderPipelineDescriptor descriptor); + + WebGPUCommandEncoder createCommandEncoder(optional WebGPUCommandEncoderDescriptor descriptor); + + WebGPUQueue getQueue(); + + attribute WebGPULogCallback onLog; + Promise getObjectStatus(WebGPUStatusable obj); +}; + +dictionary WebGPUDeviceDescriptor { + WebGPUExtensions extensions; + //WebGPULimits limits; Don't expose higher limits for now. + + // TODO are other things configurable like queues? +}; + +[Pref="dom.webgpu.enable"] +interface WebGPUAdapter { + readonly attribute DOMString name; + WebGPUExtensions extensions(); + //WebGPULimits limits(); Don't expose higher limits for now. + + WebGPUDevice createDevice(optional WebGPUDeviceDescriptor descriptor); +}; + +enum WebGPUPowerPreference { "default", "low-power", "high-performance" }; + +dictionary WebGPUAdapterDescriptor { + WebGPUPowerPreference powerPreference; +}; + +[Pref="dom.webgpu.enable"] +interface WebGPU { + WebGPUAdapter getAdapter(optional WebGPUAdapterDescriptor desc); +}; + +// Add a "webgpu" member to Window that contains the global instance of a "WebGPU" +[NoInterfaceObject] +interface WebGPUProvider { + [SameObject, Replaceable, Pref="dom.webgpu.enable"] readonly attribute WebGPU webgpu; +}; +//Window includes WebGPUProvider; diff --git a/dom/webidl/WebGPUExtras.webidl b/dom/webidl/WebGPUExtras.webidl new file mode 100644 index 000000000000..ad38d509b893 --- /dev/null +++ b/dom/webidl/WebGPUExtras.webidl @@ -0,0 +1,14 @@ +/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Some parts of WebGPU.webidl need to be pulled into a different file due to a codegen + * bug/missing support. + */ + +dictionary WebGPUBufferBinding { + WebGPUBuffer buffer; + u32 offset; + u32 size; +}; diff --git a/dom/webidl/Window.webidl b/dom/webidl/Window.webidl index 7688d110b851..3e075b839a88 100644 --- a/dom/webidl/Window.webidl +++ b/dom/webidl/Window.webidl @@ -563,3 +563,5 @@ partial interface Window { [Throws, Func="IsChromeOrXBL"] readonly attribute IntlUtils intlUtils; }; + +Window implements WebGPUProvider; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index 7929a2995e29..4f5a944324cd 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -328,6 +328,9 @@ with Files("WebAuthentication.webidl"): with Files("WebGL*"): BUG_COMPONENT = ("Core", "Canvas: WebGL") +with Files("WebGPU*"): + BUG_COMPONENT = ("Core", "Canvas: WebGL") + with Files("WebKitCSSMatrix.webidl"): BUG_COMPONENT = ("Core", "DOM: CSS Object Model") @@ -922,6 +925,8 @@ WEBIDL_FILES = [ 'WebComponents.webidl', 'WebGL2RenderingContext.webidl', 'WebGLRenderingContext.webidl', + 'WebGPU.webidl', + 'WebGPUExtras.webidl', 'WebKitCSSMatrix.webidl', 'WebSocket.webidl', 'WheelEvent.webidl', diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 7e74090786b4..4efc1e2df640 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -4716,6 +4716,8 @@ pref("webgl.dxgl.enabled", true); pref("webgl.dxgl.needs-finish", false); #endif +pref("dom.webgpu.enable", false); + pref("gfx.offscreencanvas.enabled", false); // sendbuffer of 0 means use OS default, sendbuffer unset means use