Bug 1581710 - Update WebGPU IDL bindings r=jgilbert,bzbarsky

This mostly updates the bindings to the current state.
No actual logic backing them yet.

*Note*: the IDL does *not* need to be checked for matching the upstream spec precisely at this stage. The upstream is evolving, we just need to update in order to start integrating the implementation. What needs to be checked is - how C++ represents the IDL, esp with regards to derived classes, events, and hierarchies.

The trickiest points, arguably, are:
  - WebGPU -> GPU prefix change
  - the goop for interfaces that are not final

Differential Revision: https://phabricator.services.mozilla.com/D46166

--HG--
rename : dom/webgpu/InputState.cpp => dom/webgpu/DeviceLostInfo.cpp
rename : dom/webgpu/Fence.h => dom/webgpu/DeviceLostInfo.h
rename : dom/webgpu/BlendState.cpp => dom/webgpu/OutOfMemoryError.cpp
rename : dom/webgpu/LogEntry.h => dom/webgpu/OutOfMemoryError.h
rename : dom/webgpu/BindGroup.h => dom/webgpu/ProgrammablePassEncoder.cpp
rename : dom/webgpu/BlendState.cpp => dom/webgpu/RenderBundle.cpp
rename : dom/webgpu/BlendState.h => dom/webgpu/RenderBundle.h
rename : dom/webgpu/AttachmentState.cpp => dom/webgpu/ValidationError.cpp
rename : dom/webgpu/AttachmentState.h => dom/webgpu/ValidationError.h
extra : moz-landing-system : lando
This commit is contained in:
Dzmitry Malyshau 2019-10-02 16:46:03 +00:00
parent 20983ff87e
commit b91906eeac
78 changed files with 1604 additions and 1232 deletions

View File

@ -105,6 +105,8 @@
#include "mozilla/DetailedPromise.h"
#include "mozilla/Unused.h"
#include "mozilla/webgpu/Instance.h"
namespace mozilla {
namespace dom {
@ -157,6 +159,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Navigator)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mServiceWorkerContainer)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaCapabilities)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAddonManager)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWebGpu)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaKeySystemAccessManager)
@ -227,7 +230,10 @@ void Navigator::Invalidate() {
}
mMediaCapabilities = nullptr;
mAddonManager = nullptr;
mWebGpu = nullptr;
}
void Navigator::GetUserAgent(nsAString& aUserAgent, CallerType aCallerType,
@ -1847,6 +1853,13 @@ AddonManager* Navigator::GetMozAddonManager(ErrorResult& aRv) {
return mAddonManager;
}
webgpu::Instance* Navigator::Gpu() {
if (!mWebGpu) {
mWebGpu = webgpu::Instance::Create(GetWindow()->AsGlobal());
}
return mWebGpu;
}
/* static */
bool Navigator::Webdriver() {
return Preferences::GetBool("marionette.enabled", false);

View File

@ -42,6 +42,9 @@ class DOMRequest;
class CredentialsContainer;
class Clipboard;
} // namespace dom
namespace webgpu {
class Instance;
} // namespace webgpu
} // namespace mozilla
//*****************************************************************************
@ -199,6 +202,7 @@ class Navigator final : public nsISupports, public nsWrapperCache {
mozilla::dom::CredentialsContainer* Credentials();
dom::Clipboard* Clipboard();
webgpu::Instance* Gpu();
static bool Webdriver();
@ -271,6 +275,7 @@ class Navigator final : public nsISupports, public nsWrapperCache {
RefPtr<StorageManager> mStorageManager;
RefPtr<dom::MediaCapabilities> mMediaCapabilities;
RefPtr<AddonManager> mAddonManager;
RefPtr<webgpu::Instance> mWebGpu;
};
} // namespace dom

View File

@ -1306,132 +1306,143 @@ DOMInterfaces = {
# WebGPU
'WebGPU': {
'GPU': {
'nativeType': 'mozilla::webgpu::Instance',
},
'WebGPUAdapter': {
'GPUAdapter': {
'nativeType': 'mozilla::webgpu::Adapter',
},
'WebGPUAttachmentState': {
'nativeType': 'mozilla::webgpu::AttachmentState',
},
'WebGPUBindGroup': {
'GPUBindGroup': {
'nativeType': 'mozilla::webgpu::BindGroup',
},
'WebGPUBindGroupLayout': {
'GPUBindGroupLayout': {
'nativeType': 'mozilla::webgpu::BindGroupLayout',
},
'WebGPUBlendState': {
'nativeType': 'mozilla::webgpu::BlendState',
},
'WebGPUBuffer': {
'GPUBuffer': {
'nativeType': 'mozilla::webgpu::Buffer',
},
'WebGPUCommandBuffer': {
'GPUCanvasContext': {
'nativeType': 'mozilla::webgpu::CanvasContext',
},
'GPUCommandBuffer': {
'nativeType': 'mozilla::webgpu::CommandBuffer',
},
'WebGPUCommandEncoder': {
'GPUCommandEncoder': {
'nativeType': 'mozilla::webgpu::CommandEncoder',
},
'WebGPUComputePipeline': {
'GPUComputePassEncoder': {
'nativeType': 'mozilla::webgpu::ComputePassEncoder',
},
'GPUComputePipeline': {
'nativeType': 'mozilla::webgpu::ComputePipeline',
},
'WebGPUDepthStencilState': {
'nativeType': 'mozilla::webgpu::DepthStencilState',
},
'WebGPUDevice': {
'GPUDevice': {
'nativeType': 'mozilla::webgpu::Device',
},
'WebGPUFence': {
'GPUDeviceLostInfo': {
'nativeType': 'mozilla::webgpu::DeviceLostInfo',
},
'GPUFence': {
'nativeType': 'mozilla::webgpu::Fence',
},
'WebGPUInputState': {
'nativeType': 'mozilla::webgpu::InputState',
'GPUOutOfMemoryError': {
'nativeType': 'mozilla::webgpu::OutOfMemoryError',
},
'WebGPULogEntry': {
'nativeType': 'mozilla::webgpu::LogEntry',
},
'WebGPUPipelineLayout': {
'GPUPipelineLayout': {
'nativeType': 'mozilla::webgpu::PipelineLayout',
},
'WebGPUQueue': {
'GPUProgrammablePassEncoder': {
'nativeType': 'mozilla::webgpu::ProgrammablePassEncoder',
},
'GPUQueue': {
'nativeType': 'mozilla::webgpu::Queue',
},
'WebGPURenderPipeline': {
'GPURenderBundle': {
'nativeType': 'mozilla::webgpu::RenderBundle',
},
'GPURenderBundleEncoder': {
'nativeType': 'mozilla::webgpu::RenderBundleEncoder',
},
'GPURenderEncoderBase': {
'nativeType': 'mozilla::webgpu::RenderEncoderBase',
},
'GPURenderPassEncoder': {
'nativeType': 'mozilla::webgpu::RenderPassEncoder',
},
'GPURenderPipeline': {
'nativeType': 'mozilla::webgpu::RenderPipeline',
},
'WebGPUSampler': {
'GPUSampler': {
'nativeType': 'mozilla::webgpu::Sampler',
},
'WebGPUShaderModule': {
'GPUShaderModule': {
'nativeType': 'mozilla::webgpu::ShaderModule',
},
'WebGPUSwapChain': {
'GPUSwapChain': {
'nativeType': 'mozilla::webgpu::SwapChain',
},
'WebGPUTexture': {
'GPUTexture': {
'nativeType': 'mozilla::webgpu::Texture',
},
'WebGPUTextureView': {
'GPUTextureView': {
'nativeType': 'mozilla::webgpu::TextureView',
},
'GPUValidationError': {
'nativeType': 'mozilla::webgpu::ValidationError',
},
'WebGPUBindingType': {
'GPUBindingType': {
'concrete': False,
},
'WebGPUBlendFactor': {
'GPUBlendFactor': {
'concrete': False,
},
'WebGPUBlendOperation': {
'GPUBlendOperation': {
'concrete': False,
},
'WebGPUBufferUsage': {
'GPUBufferUsage': {
'concrete': False,
},
'WebGPUColorWriteBits': {
'GPUColorWrite': {
'concrete': False,
},
'WebGPUCompareFunction': {
'GPUCompareFunction': {
'concrete': False,
},
'WebGPUFilterMode': {
'GPUFilterMode': {
'concrete': False,
},
'WebGPUIndexFormat': {
'GPUIndexFormat': {
'concrete': False,
},
'WebGPUInputStepMode': {
'GPUInputStepMode': {
'concrete': False,
},
'WebGPULoadOp': {
'GPULoadOp': {
'concrete': False,
},
'WebGPUPrimitiveTopology': {
'GPUPrimitiveTopology': {
'concrete': False,
},
'WebGPUShaderStage': {
'GPUShaderStage': {
'concrete': False,
},
'WebGPUShaderStageBit': {
'GPUStencilOperation': {
'concrete': False,
},
'WebGPUStencilOperation': {
'GPUStoreOp': {
'concrete': False,
},
'WebGPUStoreOp': {
'GPUTextureDimension': {
'concrete': False,
},
'WebGPUTextureDimension': {
'GPUTextureFormat': {
'concrete': False,
},
'WebGPUTextureFormat': {
'GPUTextureUsage': {
'concrete': False,
},
'WebGPUTextureUsage': {
'concrete': False,
},
'WebGPUVertexFormat': {
'GPUVertexFormat': {
'concrete': False,
},

View File

@ -148,6 +148,8 @@ const kEventConstructors = {
return new GamepadButtonEvent(aName, aProps);
},
},
GPUUncapturedErrorEvent: { create: null, //TODO: constructor test
},
HashChangeEvent: { create (aName, aProps) {
return new HashChangeEvent(aName, aProps);
},

View File

@ -3,28 +3,18 @@
* 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 "mozilla/dom/WebGPUBinding.h"
#include "Adapter.h"
#include "Instance.h"
#include "mozilla/dom/WebGPUBinding.h"
namespace mozilla {
namespace webgpu {
GPU_IMPL_CYCLE_COLLECTION(Adapter, mParent)
GPU_IMPL_JS_WRAP(Adapter)
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<Device> Adapter::CreateDevice(
const dom::WebGPUDeviceDescriptor& desc) const {
MOZ_CRASH("todo");
}
WEBGPU_IMPL_GOOP_0(Adapter)
} // namespace webgpu
} // namespace mozilla

View File

@ -3,8 +3,8 @@
* 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_
#ifndef GPU_Adapter_H_
#define GPU_Adapter_H_
#include "mozilla/AlreadyAddRefed.h"
#include "nsString.h"
@ -12,18 +12,20 @@
namespace mozilla {
namespace dom {
struct WebGPUDeviceDescriptor;
struct WebGPUExtensions;
struct WebGPUFeatures;
class Promise;
struct GPUDeviceDescriptor;
struct GPUExtensions;
struct GPUFeatures;
} // namespace dom
namespace webgpu {
class Device;
class Instance;
class Adapter final : public ChildOf<Instance> {
class Adapter final : public ObjectBase, public ChildOf<Instance> {
public:
WEBGPU_DECL_GOOP(Adapter)
GPU_DECL_CYCLE_COLLECTION(Adapter)
GPU_DECL_JS_WRAP(Adapter)
const nsString mName;
@ -33,14 +35,9 @@ class Adapter final : public ChildOf<Instance> {
public:
void GetName(nsString& out) const { out = mName; }
void Extensions(dom::WebGPUExtensions& out) const;
void Features(dom::WebGPUFeatures& out) const;
already_AddRefed<Device> CreateDevice(
const dom::WebGPUDeviceDescriptor& desc) const;
};
} // namespace webgpu
} // namespace mozilla
#endif // WEBGPU_Adapter_H_
#endif // GPU_Adapter_H_

View File

@ -3,17 +3,18 @@
* 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 "mozilla/dom/WebGPUBinding.h"
#include "BindGroup.h"
#include "Device.h"
#include "mozilla/dom/WebGPUBinding.h"
namespace mozilla {
namespace webgpu {
BindGroup::~BindGroup() = default;
WEBGPU_IMPL_GOOP_0(BindGroup)
GPU_IMPL_CYCLE_COLLECTION(BindGroup, mParent)
GPU_IMPL_JS_WRAP(BindGroup)
} // namespace webgpu
} // namespace mozilla

View File

@ -3,8 +3,8 @@
* 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_
#ifndef GPU_BindGroup_H_
#define GPU_BindGroup_H_
#include "nsWrapperCache.h"
#include "ObjectModel.h"
@ -14,9 +14,10 @@ namespace webgpu {
class Device;
class BindGroup final : public ChildOf<Device> {
class BindGroup final : public ObjectBase, public ChildOf<Device> {
public:
WEBGPU_DECL_GOOP(BindGroup)
GPU_DECL_CYCLE_COLLECTION(BindGroup)
GPU_DECL_JS_WRAP(BindGroup)
private:
BindGroup() = delete;
@ -26,4 +27,4 @@ class BindGroup final : public ChildOf<Device> {
} // namespace webgpu
} // namespace mozilla
#endif // WEBGPU_BindGroup_H_
#endif // GPU_BindGroup_H_

View File

@ -3,17 +3,18 @@
* 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 "mozilla/dom/WebGPUBinding.h"
#include "BindGroupLayout.h"
#include "Device.h"
#include "mozilla/dom/WebGPUBinding.h"
namespace mozilla {
namespace webgpu {
BindGroupLayout::~BindGroupLayout() = default;
WEBGPU_IMPL_GOOP_0(BindGroupLayout)
GPU_IMPL_CYCLE_COLLECTION(BindGroupLayout, mParent)
GPU_IMPL_JS_WRAP(BindGroupLayout)
} // namespace webgpu
} // namespace mozilla

View File

@ -3,8 +3,8 @@
* 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_
#ifndef GPU_BindGroupLayout_H_
#define GPU_BindGroupLayout_H_
#include "nsWrapperCache.h"
#include "ObjectModel.h"
@ -14,9 +14,10 @@ namespace webgpu {
class Device;
class BindGroupLayout final : public ChildOf<Device> {
class BindGroupLayout final : public ObjectBase, public ChildOf<Device> {
public:
WEBGPU_DECL_GOOP(BindGroupLayout)
GPU_DECL_CYCLE_COLLECTION(BindGroupLayout)
GPU_DECL_JS_WRAP(BindGroupLayout)
private:
BindGroupLayout() = delete;
@ -26,4 +27,4 @@ class BindGroupLayout final : public ChildOf<Device> {
} // namespace webgpu
} // namespace mozilla
#endif // WEBGPU_BindGroupLayout_H_
#endif // GPU_BindGroupLayout_H_

View File

@ -3,50 +3,21 @@
* 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 "mozilla/dom/WebGPUBinding.h"
#include "Buffer.h"
#include "nsWrapperCache.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
}
GPU_IMPL_CYCLE_COLLECTION(Buffer, mParent)
GPU_IMPL_JS_WRAP(Buffer)
Buffer::~Buffer() {
mMapping = nullptr;
mozilla::DropJSObjects(this);
}
Buffer::Buffer(Device* const parent) : ChildOf(parent) {}
void Buffer::GetMapping(JSContext*, JS::MutableHandle<JSObject*> out) const {
out.set(mMapping);
}
void Buffer::Unmap() const { MOZ_CRASH("todo"); }
JSObject* webgpu::Buffer::WrapObject(JSContext* cx,
JS::Handle<JSObject*> 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)
Buffer::~Buffer() = default;
} // namespace webgpu
} // namespace mozilla

View File

@ -3,8 +3,8 @@
* 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_
#ifndef GPU_BUFFER_H_
#define GPU_BUFFER_H_
#include "mozilla/dom/Nullable.h"
#include "mozilla/dom/TypedArray.h"
@ -15,22 +15,19 @@ namespace webgpu {
class Device;
class Buffer final : public ChildOf<Device> {
class Buffer final : public ObjectBase, public ChildOf<Device> {
public:
JS::Heap<JSObject*> mMapping;
WEBGPU_DECL_GOOP(Buffer)
GPU_DECL_CYCLE_COLLECTION(Buffer)
GPU_DECL_JS_WRAP(Buffer)
private:
explicit Buffer(Device* parent);
virtual ~Buffer();
public:
void GetMapping(JSContext* cx, JS::MutableHandle<JSObject*> out) const;
void Unmap() const;
};
} // namespace webgpu
} // namespace mozilla
#endif // WEBGPU_BUFFER_H_
#endif // GPU_BUFFER_H_

View File

@ -0,0 +1,35 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 "mozilla/dom/WebGPUBinding.h"
#include "CanvasContext.h"
namespace mozilla {
namespace webgpu {
CanvasContext::~CanvasContext() = default;
JSObject* CanvasContext::WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) {
return dom::GPUCanvasContext_Binding::Wrap(aCx, this, aGivenProto);
}
NS_IMPL_CYCLE_COLLECTING_ADDREF(CanvasContext)
NS_IMPL_CYCLE_COLLECTING_RELEASE(CanvasContext)
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(CanvasContext)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CanvasContext)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsICanvasRenderingContextInternal)
// NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
// If the exact way we cast to nsISupports here ever changes, fix our
// ToSupports() method.
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports,
nsICanvasRenderingContextInternal)
NS_INTERFACE_MAP_END
} // namespace webgpu
} // namespace mozilla

View File

@ -0,0 +1,87 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 GPU_CanvasContext_H_
#define GPU_CanvasContext_H_
#include "nsICanvasRenderingContextInternal.h"
#include "nsWrapperCache.h"
#include "ObjectModel.h"
#include "SwapChain.h"
namespace mozilla {
namespace dom {
class Promise;
}
namespace webgpu {
class Device;
class SwapChain;
class CanvasContext final : public nsICanvasRenderingContextInternal,
public nsWrapperCache {
private:
virtual ~CanvasContext();
public:
CanvasContext() = delete;
JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
// nsISupports interface + CC
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(CanvasContext)
public:
// nsICanvasRenderingContextInternal
int32_t GetWidth() override { return 0; }
int32_t GetHeight() override { return 0; }
NS_IMETHOD SetDimensions(int32_t aWidth, int32_t aHeight) override {
return NS_OK;
}
NS_IMETHOD InitializeWithDrawTarget(
nsIDocShell* aShell, NotNull<gfx::DrawTarget*> aTarget) override {
return NS_OK;
}
mozilla::UniquePtr<uint8_t[]> GetImageBuffer(int32_t* aFormat) override {
MOZ_CRASH("todo");
}
NS_IMETHOD GetInputStream(const char* aMimeType,
const nsAString& aEncoderOptions,
nsIInputStream** aStream) override {
*aStream = nullptr;
return NS_OK;
}
already_AddRefed<mozilla::gfx::SourceSurface> GetSurfaceSnapshot(
gfxAlphaType* aOutAlphaType) override {
return nullptr;
}
void SetOpaqueValueFromOpaqueAttr(bool aOpaqueAttrValue) override {}
bool GetIsOpaque() override { return true; }
NS_IMETHOD Reset() override { return NS_OK; }
already_AddRefed<Layer> GetCanvasLayer(nsDisplayListBuilder* aBuilder,
Layer* aOldLayer,
LayerManager* aManager) override {
return nullptr;
}
void MarkContextClean() override {}
NS_IMETHOD Redraw(const gfxRect& aDirty) override { return NS_OK; }
NS_IMETHOD SetIsIPC(bool aIsIPC) override { return NS_OK; }
void DidRefresh() override {}
void MarkContextCleanForFrameCapture() override {}
bool IsContextCleanForFrameCapture() override { return false; }
};
} // namespace webgpu
} // namespace mozilla
#endif // GPU_CanvasContext_H_

View File

@ -3,17 +3,18 @@
* 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 "mozilla/dom/WebGPUBinding.h"
#include "CommandBuffer.h"
#include "Device.h"
#include "mozilla/dom/WebGPUBinding.h"
namespace mozilla {
namespace webgpu {
CommandBuffer::~CommandBuffer() = default;
WEBGPU_IMPL_GOOP_0(CommandBuffer)
GPU_IMPL_CYCLE_COLLECTION(CommandBuffer, mParent)
GPU_IMPL_JS_WRAP(CommandBuffer)
} // namespace webgpu
} // namespace mozilla

View File

@ -3,8 +3,8 @@
* 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_
#ifndef GPU_CommandBuffer_H_
#define GPU_CommandBuffer_H_
#include "nsWrapperCache.h"
#include "ObjectModel.h"
@ -14,9 +14,10 @@ namespace webgpu {
class Device;
class CommandBuffer final : public ChildOf<Device> {
class CommandBuffer final : public ObjectBase, public ChildOf<Device> {
public:
WEBGPU_DECL_GOOP(CommandBuffer)
GPU_DECL_CYCLE_COLLECTION(CommandBuffer)
GPU_DECL_JS_WRAP(CommandBuffer)
private:
CommandBuffer() = delete;
@ -26,4 +27,4 @@ class CommandBuffer final : public ChildOf<Device> {
} // namespace webgpu
} // namespace mozilla
#endif // WEBGPU_CommandBuffer_H_
#endif // GPU_CommandBuffer_H_

View File

@ -3,106 +3,18 @@
* 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 "mozilla/dom/WebGPUBinding.h"
#include "CommandEncoder.h"
#include "Device.h"
#include "mozilla/dom/WebGPUBinding.h"
namespace mozilla {
namespace webgpu {
CommandEncoder::~CommandEncoder() = default;
already_AddRefed<CommandBuffer> 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<OwningNonNull<Buffer>>& buffers,
const dom::Sequence<uint32_t>& 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)
GPU_IMPL_CYCLE_COLLECTION(CommandEncoder, mParent)
GPU_IMPL_JS_WRAP(CommandEncoder)
} // namespace webgpu
} // namespace mozilla

View File

@ -3,8 +3,8 @@
* 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_
#ifndef GPU_CommandEncoder_H_
#define GPU_CommandEncoder_H_
#include "mozilla/dom/TypedArray.h"
#include "nsWrapperCache.h"
@ -14,70 +14,34 @@ namespace mozilla {
namespace dom {
template <typename T>
class Sequence;
class WebGPUComputePipelineOrWebGPURenderPipeline;
struct WebGPURenderPassDescriptor;
class GPUComputePipelineOrGPURenderPipeline;
class UnsignedLongSequenceOrGPUExtent3DDict;
struct GPUBufferCopyView;
struct GPUCommandBufferDescriptor;
struct GPUImageBitmapCopyView;
struct GPURenderPassDescriptor;
struct GPUTextureCopyView;
} // namespace dom
namespace webgpu {
class BindGroup;
class Buffer;
class CommandBuffer;
class ComputePassEncoder;
class Device;
class RenderPassEncoder;
class CommandEncoder final : public ChildOf<Device> {
class CommandEncoder final : public ObjectBase, public ChildOf<Device> {
public:
WEBGPU_DECL_GOOP(CommandEncoder)
GPU_DECL_CYCLE_COLLECTION(CommandEncoder)
GPU_DECL_JS_WRAP(CommandEncoder)
private:
CommandEncoder() = delete;
virtual ~CommandEncoder();
public:
already_AddRefed<CommandBuffer> 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<OwningNonNull<Buffer>>& buffers,
const dom::Sequence<uint32_t>& 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_
#endif // GPU_CommandEncoder_H_

View File

@ -0,0 +1,23 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 "ComputePassEncoder.h"
namespace mozilla {
namespace webgpu {
NS_IMPL_CYCLE_COLLECTION_INHERITED(ComputePassEncoder, ProgrammablePassEncoder,
mParent)
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(ComputePassEncoder,
ProgrammablePassEncoder)
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(ComputePassEncoder,
ProgrammablePassEncoder)
NS_IMPL_CYCLE_COLLECTION_TRACE_END
GPU_IMPL_JS_WRAP(ComputePassEncoder)
ComputePassEncoder::~ComputePassEncoder() = default;
} // namespace webgpu
} // namespace mozilla

View File

@ -0,0 +1,39 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 GPU_ComputePassEncoder_H_
#define GPU_ComputePassEncoder_H_
#include "mozilla/dom/TypedArray.h"
#include "ObjectModel.h"
#include "ProgrammablePassEncoder.h"
namespace mozilla {
namespace webgpu {
class Buffer;
class CommandEncoder;
class ComputePipeline;
class ComputePassEncoder final : public ProgrammablePassEncoder,
public ChildOf<CommandEncoder> {
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(
ComputePassEncoder, ProgrammablePassEncoder)
GPU_DECL_JS_WRAP(ComputePassEncoder)
ComputePassEncoder() = delete;
private:
virtual ~ComputePassEncoder();
public:
};
} // namespace webgpu
} // namespace mozilla
#endif // GPU_ComputePassEncoder_H_

View File

@ -6,14 +6,14 @@
#include "ComputePipeline.h"
#include "Device.h"
#include "mozilla/dom/WebGPUBinding.h"
namespace mozilla {
namespace webgpu {
ComputePipeline::~ComputePipeline() = default;
WEBGPU_IMPL_GOOP_0(ComputePipeline)
GPU_IMPL_CYCLE_COLLECTION(ComputePipeline, mParent)
GPU_IMPL_JS_WRAP(ComputePipeline)
} // namespace webgpu
} // namespace mozilla

View File

@ -3,8 +3,8 @@
* 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_
#ifndef GPU_ComputePipeline_H_
#define GPU_ComputePipeline_H_
#include "nsWrapperCache.h"
#include "ObjectModel.h"
@ -14,9 +14,10 @@ namespace webgpu {
class Device;
class ComputePipeline final : public ChildOf<Device> {
class ComputePipeline final : public ObjectBase, public ChildOf<Device> {
public:
WEBGPU_DECL_GOOP(ComputePipeline)
GPU_DECL_CYCLE_COLLECTION(ComputePipeline)
GPU_DECL_JS_WRAP(ComputePipeline)
private:
ComputePipeline() = delete;
@ -26,4 +27,4 @@ class ComputePipeline final : public ChildOf<Device> {
} // namespace webgpu
} // namespace mozilla
#endif // WEBGPU_ComputePipeline_H_
#endif // GPU_ComputePipeline_H_

View File

@ -3,108 +3,24 @@
* 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 "mozilla/dom/WebGPUBinding.h"
#include "Device.h"
#include "Adapter.h"
#include "mozilla/dom/WebGPUBinding.h"
namespace mozilla {
namespace webgpu {
NS_IMPL_CYCLE_COLLECTION_INHERITED(Device, DOMEventTargetHelper)
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(Device, DOMEventTargetHelper)
GPU_IMPL_JS_WRAP(Device)
Device::Device(nsIGlobalObject* aGlobal) : DOMEventTargetHelper(aGlobal) {}
Device::~Device() = default;
already_AddRefed<webgpu::Adapter> 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<Buffer> Device::CreateBuffer(
const dom::WebGPUBufferDescriptor& desc) const {
MOZ_CRASH("todo");
}
already_AddRefed<Texture> Device::CreateTexture(
const dom::WebGPUTextureDescriptor& desc) const {
MOZ_CRASH("todo");
}
already_AddRefed<Sampler> Device::CreateSampler(
const dom::WebGPUSamplerDescriptor& desc) const {
MOZ_CRASH("todo");
}
already_AddRefed<BindGroupLayout> Device::CreateBindGroupLayout(
const dom::WebGPUBindGroupLayoutDescriptor& desc) const {
MOZ_CRASH("todo");
}
already_AddRefed<PipelineLayout> Device::CreatePipelineLayout(
const dom::WebGPUPipelineLayoutDescriptor& desc) const {
MOZ_CRASH("todo");
}
already_AddRefed<BindGroup> Device::CreateBindGroup(
const dom::WebGPUBindGroupDescriptor& desc) const {
MOZ_CRASH("todo");
}
already_AddRefed<BlendState> Device::CreateBlendState(
const dom::WebGPUBlendStateDescriptor& desc) const {
MOZ_CRASH("todo");
}
already_AddRefed<DepthStencilState> Device::CreateDepthStencilState(
const dom::WebGPUDepthStencilStateDescriptor& desc) const {
MOZ_CRASH("todo");
}
already_AddRefed<InputState> Device::CreateInputState(
const dom::WebGPUInputStateDescriptor& desc) const {
MOZ_CRASH("todo");
}
already_AddRefed<ShaderModule> Device::CreateShaderModule(
const dom::WebGPUShaderModuleDescriptor& desc) const {
MOZ_CRASH("todo");
}
already_AddRefed<AttachmentState> Device::CreateAttachmentState(
const dom::WebGPUAttachmentStateDescriptor& desc) const {
MOZ_CRASH("todo");
}
already_AddRefed<ComputePipeline> Device::CreateComputePipeline(
const dom::WebGPUComputePipelineDescriptor& desc) const {
MOZ_CRASH("todo");
}
already_AddRefed<RenderPipeline> Device::CreateRenderPipeline(
const dom::WebGPURenderPipelineDescriptor& desc) const {
MOZ_CRASH("todo");
}
already_AddRefed<CommandEncoder> Device::CreateCommandEncoder(
const dom::WebGPUCommandEncoderDescriptor& desc) const {
MOZ_CRASH("todo");
}
already_AddRefed<Queue> Device::GetQueue() const { MOZ_CRASH("todo"); }
RefPtr<dom::WebGPULogCallback> Device::OnLog() const { MOZ_CRASH("todo"); }
void Device::SetOnLog(const dom::WebGPULogCallback& callback) const {
MOZ_CRASH("todo");
}
already_AddRefed<dom::Promise> Device::GetObjectStatus(
const dom::WebGPUBufferOrWebGPUTexture& obj) const {
MOZ_CRASH("todo");
}
WEBGPU_IMPL_GOOP_0(Device)
void Device::GetLabel(nsAString& aValue) const { aValue = mLabel; }
void Device::SetLabel(const nsAString& aLabel) { mLabel = aLabel; }
} // namespace webgpu
} // namespace mozilla

View File

@ -3,114 +3,81 @@
* 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_
#ifndef GPU_DEVICE_H_
#define GPU_DEVICE_H_
#include "mozilla/RefPtr.h"
#include "ObjectModel.h"
#include "mozilla/DOMEventTargetHelper.h"
namespace mozilla {
namespace dom {
struct WebGPUExtensions;
struct WebGPUFeatures;
struct WebGPULimits;
struct GPUExtensions;
struct GPUFeatures;
struct GPULimits;
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;
struct GPUBufferDescriptor;
struct GPUTextureDescriptor;
struct GPUSamplerDescriptor;
struct GPUBindGroupLayoutDescriptor;
struct GPUPipelineLayoutDescriptor;
struct GPUBindGroupDescriptor;
struct GPUBlendStateDescriptor;
struct GPUDepthStencilStateDescriptor;
struct GPUInputStateDescriptor;
struct GPUShaderModuleDescriptor;
struct GPUAttachmentStateDescriptor;
struct GPUComputePipelineDescriptor;
struct GPURenderBundleEncoderDescriptor;
struct GPURenderPipelineDescriptor;
struct GPUCommandEncoderDescriptor;
class EventHandlerNonNull;
class Promise;
class WebGPUBufferOrWebGPUTexture;
class WebGPULogCallback;
class GPUBufferOrGPUTexture;
enum class GPUErrorFilter : uint8_t;
class GPULogCallback;
} // 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 RenderBundleEncoder;
class RenderPipeline;
class Sampler;
class ShaderModule;
class Texture;
class Device final : public ChildOf<Adapter> {
class Device final : public DOMEventTargetHelper {
public:
WEBGPU_DECL_GOOP(Device)
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(Device, DOMEventTargetHelper)
GPU_DECL_JS_WRAP(Device)
explicit Device(nsIGlobalObject* aGlobal);
private:
Device() = delete;
virtual ~Device();
nsString mLabel;
public:
already_AddRefed<webgpu::Adapter> Adapter() const;
void GetLabel(nsAString& aValue) const;
void SetLabel(const nsAString& aLabel);
void Extensions(dom::WebGPUExtensions& out) const;
void Features(dom::WebGPUFeatures& out) const;
void Limits(dom::WebGPULimits& out) const;
already_AddRefed<Buffer> CreateBuffer(
const dom::WebGPUBufferDescriptor& desc) const;
already_AddRefed<Texture> CreateTexture(
const dom::WebGPUTextureDescriptor& desc) const;
already_AddRefed<Sampler> CreateSampler(
const dom::WebGPUSamplerDescriptor& desc) const;
already_AddRefed<BindGroupLayout> CreateBindGroupLayout(
const dom::WebGPUBindGroupLayoutDescriptor& desc) const;
already_AddRefed<PipelineLayout> CreatePipelineLayout(
const dom::WebGPUPipelineLayoutDescriptor& desc) const;
already_AddRefed<BindGroup> CreateBindGroup(
const dom::WebGPUBindGroupDescriptor& desc) const;
already_AddRefed<BlendState> CreateBlendState(
const dom::WebGPUBlendStateDescriptor& desc) const;
already_AddRefed<DepthStencilState> CreateDepthStencilState(
const dom::WebGPUDepthStencilStateDescriptor& desc) const;
already_AddRefed<InputState> CreateInputState(
const dom::WebGPUInputStateDescriptor& desc) const;
already_AddRefed<ShaderModule> CreateShaderModule(
const dom::WebGPUShaderModuleDescriptor& desc) const;
already_AddRefed<AttachmentState> CreateAttachmentState(
const dom::WebGPUAttachmentStateDescriptor& desc) const;
already_AddRefed<ComputePipeline> CreateComputePipeline(
const dom::WebGPUComputePipelineDescriptor& desc) const;
already_AddRefed<RenderPipeline> CreateRenderPipeline(
const dom::WebGPURenderPipelineDescriptor& desc) const;
already_AddRefed<CommandEncoder> CreateCommandEncoder(
const dom::WebGPUCommandEncoderDescriptor& desc) const;
already_AddRefed<Queue> GetQueue() const;
RefPtr<dom::WebGPULogCallback> OnLog() const;
void SetOnLog(const dom::WebGPULogCallback& callback) const;
already_AddRefed<dom::Promise> GetObjectStatus(
const dom::WebGPUBufferOrWebGPUTexture& obj) const;
// IMPL_EVENT_HANDLER(uncapturederror)
};
} // namespace webgpu
} // namespace mozilla
#endif // WEBGPU_DEVICE_H_
#endif // GPU_DEVICE_H_

View File

@ -3,17 +3,15 @@
* 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"
#include "DeviceLostInfo.h"
namespace mozilla {
namespace webgpu {
BlendState::~BlendState() = default;
GPU_IMPL_CYCLE_COLLECTION(DeviceLostInfo, mParent)
GPU_IMPL_JS_WRAP(DeviceLostInfo)
WEBGPU_IMPL_GOOP_0(BlendState)
DeviceLostInfo::~DeviceLostInfo() = default;
} // namespace webgpu
} // namespace mozilla

View File

@ -3,27 +3,30 @@
* 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_
#ifndef GPU_DeviceLostInfo_H_
#define GPU_DeviceLostInfo_H_
#include "nsWrapperCache.h"
#include "ObjectModel.h"
namespace mozilla {
namespace webgpu {
class Device;
class InputState final : public ChildOf<Device> {
class DeviceLostInfo final : public nsWrapperCache, public ChildOf<Device> {
public:
WEBGPU_DECL_GOOP(InputState)
GPU_DECL_CYCLE_COLLECTION(DeviceLostInfo)
GPU_DECL_JS_WRAP(DeviceLostInfo)
private:
InputState() = delete;
virtual ~InputState();
DeviceLostInfo() = delete;
virtual ~DeviceLostInfo();
public:
void GetMessage(nsAString& aValue) const {}
};
} // namespace webgpu
} // namespace mozilla
#endif // WEBGPU_InputState_H_
#endif // GPU_DeviceLostInfo_H_

View File

@ -5,7 +5,6 @@
#include "Fence.h"
#include "Device.h"
#include "mozilla/dom/WebGPUBinding.h"
namespace mozilla {
@ -13,11 +12,8 @@ namespace webgpu {
Fence::~Fence() = default;
bool Fence::Wait(const double milliseconds) const { MOZ_CRASH("todo"); }
already_AddRefed<dom::Promise> Fence::Promise() const { MOZ_CRASH("todo"); }
WEBGPU_IMPL_GOOP_0(Fence)
GPU_IMPL_CYCLE_COLLECTION(Fence, mParent)
GPU_IMPL_JS_WRAP(Fence)
} // namespace webgpu
} // namespace mozilla

View File

@ -3,8 +3,8 @@
* 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_
#ifndef GPU_Fence_H_
#define GPU_Fence_H_
#include "nsWrapperCache.h"
#include "ObjectModel.h"
@ -17,20 +17,19 @@ namespace webgpu {
class Device;
class Fence final : public ChildOf<Device> {
class Fence final : public ObjectBase, public ChildOf<Device> {
public:
WEBGPU_DECL_GOOP(Fence)
GPU_DECL_CYCLE_COLLECTION(Fence)
GPU_DECL_JS_WRAP(Fence)
private:
Fence() = delete;
virtual ~Fence();
public:
bool Wait(double milliseconds) const;
already_AddRefed<dom::Promise> Promise() const;
};
} // namespace webgpu
} // namespace mozilla
#endif // WEBGPU_Fence_H_
#endif // GPU_Fence_H_

View File

@ -7,12 +7,13 @@
#include "Adapter.h"
#include "InstanceProvider.h"
#include "mozilla/dom/WebGPUBinding.h"
#include "nsIGlobalObject.h"
namespace mozilla {
namespace webgpu {
GPU_IMPL_CYCLE_COLLECTION(Instance, mParent)
/*static*/
RefPtr<Instance> Instance::Create(nsIGlobalObject* parent) {
return new Instance(parent);
@ -22,32 +23,10 @@ Instance::Instance(nsIGlobalObject* parent) : mParent(parent) {}
Instance::~Instance() = default;
already_AddRefed<Adapter> Instance::GetAdapter(
const dom::WebGPUAdapterDescriptor& desc) const {
MOZ_CRASH("todo");
}
template <typename T>
void ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& callback,
const nsCOMPtr<T>& field, const char* name,
uint32_t flags) {
CycleCollectionNoteChild(callback, field.get(), name, flags);
}
template <typename T>
void ImplCycleCollectionUnlink(const nsCOMPtr<T>& field) {
const auto mut = const_cast<nsCOMPtr<T>*>(&field);
*mut = nullptr;
}
JSObject* Instance::WrapObject(JSContext* cx,
JS::Handle<JSObject*> givenProto) {
return dom::WebGPU_Binding::Wrap(cx, this, givenProto);
return dom::GPU_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

View File

@ -3,8 +3,8 @@
* 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_
#ifndef GPU_INSTANCE_H_
#define GPU_INSTANCE_H_
#include "mozilla/AlreadyAddRefed.h"
#include "mozilla/RefPtr.h"
@ -13,7 +13,8 @@
namespace mozilla {
namespace dom {
struct WebGPUAdapterDescriptor;
class Promise;
struct GPURequestAdapterOptions;
} // namespace dom
namespace webgpu {
@ -22,9 +23,10 @@ class InstanceProvider;
class Instance final : public nsWrapperCache {
public:
WEBGPU_DECL_GOOP(Instance)
GPU_DECL_CYCLE_COLLECTION(Instance)
GPU_DECL_JS_WRAP(Instance)
const nsCOMPtr<nsIGlobalObject> mParent;
nsCOMPtr<nsIGlobalObject> mParent;
static RefPtr<Instance> Create(nsIGlobalObject* parent);
@ -34,12 +36,9 @@ class Instance final : public nsWrapperCache {
public:
nsIGlobalObject* GetParentObject() const { return mParent.get(); }
already_AddRefed<Adapter> GetAdapter(
const dom::WebGPUAdapterDescriptor& desc) const;
};
} // namespace webgpu
} // namespace mozilla
#endif // WEBGPU_INSTANCE_H_
#endif // GPU_INSTANCE_H_

View File

@ -6,7 +6,6 @@
#include "InstanceProvider.h"
#include "Instance.h"
#include "mozilla/dom/WebGPUBinding.h"
namespace mozilla {
namespace webgpu {

View File

@ -3,8 +3,8 @@
* 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_
#ifndef GPU_INSTANCE_PROVIDER_H_
#define GPU_INSTANCE_PROVIDER_H_
#include "mozilla/AlreadyAddRefed.h"
#include "mozilla/Maybe.h"
@ -52,4 +52,4 @@ void ImplCycleCollectionUnlink(Maybe<T>& field) {
} // namespace webgpu
} // namespace mozilla
#endif // WEBGPU_INSTANCE_PROVIDER_H_
#endif // GPU_INSTANCE_PROVIDER_H_

View File

@ -1,27 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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

View File

@ -7,6 +7,7 @@
#include "Adapter.h"
#include "Device.h"
#include "CommandEncoder.h"
#include "Instance.h"
namespace mozilla {
@ -23,7 +24,11 @@ nsIGlobalObject* ChildOf<T>::GetParentObject() const {
return mParent->GetParentObject();
}
void ObjectBase::GetLabel(nsAString& aValue) const { aValue = mLabel; }
void ObjectBase::SetLabel(const nsAString& aLabel) { mLabel = aLabel; }
template class ChildOf<Adapter>;
template class ChildOf<CommandEncoder>;
template class ChildOf<Device>;
template class ChildOf<Instance>;

View File

@ -3,10 +3,11 @@
* 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_
#ifndef GPU_OBJECT_MODEL_H_
#define GPU_OBJECT_MODEL_H_
#include "nsWrapperCache.h"
#include "nsString.h"
class nsIGlobalObject;
@ -14,7 +15,7 @@ namespace mozilla {
namespace webgpu {
template <typename T>
class ChildOf : public nsWrapperCache {
class ChildOf {
public:
const RefPtr<T> mParent;
@ -27,29 +28,38 @@ class ChildOf : public nsWrapperCache {
nsIGlobalObject* GetParentObject() const;
};
class ObjectBase : public nsWrapperCache {
private:
nsString mLabel;
protected:
virtual ~ObjectBase() = default;
public:
void GetLabel(nsAString& aValue) const;
void SetLabel(const nsAString& aLabel);
};
} // namespace webgpu
} // namespace mozilla
#define WEBGPU_DECL_GOOP(T) \
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(T) \
#define GPU_DECL_JS_WRAP(T) \
JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) \
override;
#define GPU_DECL_CYCLE_COLLECTION(T) \
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(T) \
virtual JSObject* WrapObject(JSContext* cx, \
JS::Handle<JSObject*> givenProto) override;
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(T)
#define WEBGPU_IMPL_GOOP_INTERNAL(T) \
#define GPU_IMPL_JS_WRAP(T) \
JSObject* T::WrapObject(JSContext* cx, JS::Handle<JSObject*> 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)
return dom::GPU##T##_Binding::Wrap(cx, this, givenProto); \
}
#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)
#define GPU_IMPL_CYCLE_COLLECTION(T, ...) \
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(T, AddRef) \
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(T, Release) \
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(T, __VA_ARGS__)
template <typename T>
void ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& callback,
@ -64,4 +74,4 @@ void ImplCycleCollectionUnlink(const RefPtr<T>& field) {
ImplCycleCollectionUnlink(*mutPtr);
}
#endif // WEBGPU_OBJECT_MODEL_H_
#endif // GPU_OBJECT_MODEL_H_

View File

@ -3,17 +3,16 @@
* 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 "OutOfMemoryError.h"
#include "Device.h"
#include "mozilla/dom/WebGPUBinding.h"
namespace mozilla {
namespace webgpu {
InputState::~InputState() = default;
GPU_IMPL_CYCLE_COLLECTION(OutOfMemoryError, mParent)
GPU_IMPL_JS_WRAP(OutOfMemoryError)
WEBGPU_IMPL_GOOP_0(InputState)
OutOfMemoryError::~OutOfMemoryError() = default;
} // namespace webgpu
} // namespace mozilla

View File

@ -3,35 +3,32 @@
* 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_
#ifndef GPU_OutOfMemoryError_H_
#define GPU_OutOfMemoryError_H_
#include "nsWrapperCache.h"
#include "ObjectModel.h"
namespace mozilla {
namespace dom {
enum class WebGPULogEntryType : uint8_t;
class GlobalObject;
} // namespace dom
namespace webgpu {
class Device;
class LogEntry final : public ChildOf<Device> {
class OutOfMemoryError final : public nsWrapperCache, public ChildOf<Device> {
public:
WEBGPU_DECL_GOOP(LogEntry)
GPU_DECL_CYCLE_COLLECTION(OutOfMemoryError)
GPU_DECL_JS_WRAP(OutOfMemoryError)
OutOfMemoryError() = delete;
private:
LogEntry() = delete;
virtual ~LogEntry();
virtual ~OutOfMemoryError();
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_
#endif // GPU_OutOfMemoryError_H_

View File

@ -3,17 +3,18 @@
* 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 "mozilla/dom/WebGPUBinding.h"
#include "PipelineLayout.h"
#include "Device.h"
#include "mozilla/dom/WebGPUBinding.h"
namespace mozilla {
namespace webgpu {
PipelineLayout::~PipelineLayout() = default;
WEBGPU_IMPL_GOOP_0(PipelineLayout)
GPU_IMPL_CYCLE_COLLECTION(PipelineLayout, mParent)
GPU_IMPL_JS_WRAP(PipelineLayout)
} // namespace webgpu
} // namespace mozilla

View File

@ -3,8 +3,8 @@
* 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_
#ifndef GPU_PipelineLayout_H_
#define GPU_PipelineLayout_H_
#include "nsWrapperCache.h"
#include "ObjectModel.h"
@ -14,9 +14,10 @@ namespace webgpu {
class Device;
class PipelineLayout final : public ChildOf<Device> {
class PipelineLayout final : public ObjectBase, public ChildOf<Device> {
public:
WEBGPU_DECL_GOOP(PipelineLayout)
GPU_DECL_CYCLE_COLLECTION(PipelineLayout)
GPU_DECL_JS_WRAP(PipelineLayout)
private:
PipelineLayout() = delete;
@ -26,4 +27,4 @@ class PipelineLayout final : public ChildOf<Device> {
} // namespace webgpu
} // namespace mozilla
#endif // WEBGPU_PipelineLayout_H_
#endif // GPU_PipelineLayout_H_

View File

@ -3,27 +3,18 @@
* 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"
#include "ProgrammablePassEncoder.h"
namespace mozilla {
namespace webgpu {
class Device;
class BlendState final : public ChildOf<Device> {
public:
WEBGPU_DECL_GOOP(BlendState)
private:
BlendState() = delete;
virtual ~BlendState();
};
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(ProgrammablePassEncoder)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ProgrammablePassEncoder)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(ProgrammablePassEncoder)
NS_IMPL_CYCLE_COLLECTING_RELEASE(ProgrammablePassEncoder)
} // namespace webgpu
} // namespace mozilla
#endif // WEBGPU_BlendState_H_

View File

@ -0,0 +1,41 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 GPU_ProgrammablePassEncoder_H_
#define GPU_ProgrammablePassEncoder_H_
#include "mozilla/dom/TypedArray.h"
#include "ObjectModel.h"
namespace mozilla {
namespace dom {
template <typename T>
class Sequence;
template <typename T>
class Optional;
} // namespace dom
namespace webgpu {
class BindGroup;
class CommandEncoder;
class ProgrammablePassEncoder : public nsISupports, public ObjectBase {
public:
// Note: here and in derived classes, there is no need for SCRIPT_HOLDER if
// it doesn't hold any JS::Value or JSObject members. That way, we could be
// using a simpler `NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED` macro.
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ProgrammablePassEncoder)
ProgrammablePassEncoder() = delete;
protected:
virtual ~ProgrammablePassEncoder() = default;
};
} // namespace webgpu
} // namespace mozilla
#endif // GPU_ProgrammablePassEncoder_H_

View File

@ -3,24 +3,16 @@
* 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"
#include "Queue.h"
namespace mozilla {
namespace webgpu {
Queue::~Queue() = default;
void Queue::Submit(
const dom::Sequence<OwningNonNull<CommandBuffer>>& buffers) const {
MOZ_CRASH("todo");
}
already_AddRefed<Fence> Queue::InsertFence() const { MOZ_CRASH("todo"); }
WEBGPU_IMPL_GOOP_0(Queue)
GPU_IMPL_CYCLE_COLLECTION(Queue, mParent)
GPU_IMPL_JS_WRAP(Queue)
} // namespace webgpu
} // namespace mozilla

View File

@ -3,38 +3,32 @@
* 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_
#ifndef GPU_Queue_H_
#define GPU_Queue_H_
#include "nsWrapperCache.h"
#include "ObjectModel.h"
namespace mozilla {
namespace dom {
template <typename T>
class Sequence;
} // namespace dom
namespace webgpu {
class CommandBuffer;
class Device;
class Fence;
class Queue final : public ChildOf<Device> {
class Queue final : public ObjectBase, public ChildOf<Device> {
public:
WEBGPU_DECL_GOOP(Queue)
GPU_DECL_CYCLE_COLLECTION(Queue)
GPU_DECL_JS_WRAP(Queue)
private:
Queue() = delete;
virtual ~Queue();
public:
void Submit(const dom::Sequence<OwningNonNull<CommandBuffer>>& buffers) const;
already_AddRefed<Fence> InsertFence() const;
};
} // namespace webgpu
} // namespace mozilla
#endif // WEBGPU_Queue_H_
#endif // GPU_Queue_H_

View File

@ -3,17 +3,18 @@
* 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 "mozilla/dom/WebGPUBinding.h"
#include "RenderBundle.h"
#include "Device.h"
#include "mozilla/dom/WebGPUBinding.h"
namespace mozilla {
namespace webgpu {
AttachmentState::~AttachmentState() = default;
RenderBundle::~RenderBundle() = default;
WEBGPU_IMPL_GOOP_0(AttachmentState)
GPU_IMPL_CYCLE_COLLECTION(RenderBundle, mParent)
GPU_IMPL_JS_WRAP(RenderBundle)
} // namespace webgpu
} // namespace mozilla

View File

@ -3,8 +3,8 @@
* 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_
#ifndef GPU_RenderBundle_H_
#define GPU_RenderBundle_H_
#include "nsWrapperCache.h"
#include "ObjectModel.h"
@ -14,16 +14,17 @@ namespace webgpu {
class Device;
class DepthStencilState final : public ChildOf<Device> {
class RenderBundle final : public ObjectBase, public ChildOf<Device> {
public:
WEBGPU_DECL_GOOP(DepthStencilState)
GPU_DECL_CYCLE_COLLECTION(RenderBundle)
GPU_DECL_JS_WRAP(RenderBundle)
private:
DepthStencilState() = delete;
virtual ~DepthStencilState();
RenderBundle() = delete;
virtual ~RenderBundle();
};
} // namespace webgpu
} // namespace mozilla
#endif // WEBGPU_DepthStencilState_H_
#endif // GPU_RenderBundle_H_

View File

@ -0,0 +1,24 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 "mozilla/dom/WebGPUBinding.h"
#include "RenderBundleEncoder.h"
#include "RenderBundle.h"
namespace mozilla {
namespace webgpu {
NS_IMPL_CYCLE_COLLECTION_INHERITED(RenderBundleEncoder, RenderEncoderBase,
mParent)
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(RenderBundleEncoder,
RenderEncoderBase)
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(RenderBundleEncoder,
RenderEncoderBase)
NS_IMPL_CYCLE_COLLECTION_TRACE_END
GPU_IMPL_JS_WRAP(RenderBundleEncoder)
} // namespace webgpu
} // namespace mozilla

View File

@ -0,0 +1,37 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 GPU_RenderBundleEncoder_H_
#define GPU_RenderBundleEncoder_H_
#include "ObjectModel.h"
#include "RenderEncoderBase.h"
namespace mozilla {
namespace webgpu {
class Device;
class RenderBundle;
class RenderBundleEncoder final : public RenderEncoderBase,
public ChildOf<Device> {
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(RenderBundleEncoder,
RenderEncoderBase)
GPU_DECL_JS_WRAP(RenderBundleEncoder)
RenderBundleEncoder() = delete;
private:
virtual ~RenderBundleEncoder() = default;
public:
};
} // namespace webgpu
} // namespace mozilla
#endif // GPU_RenderBundleEncoder_H_

View File

@ -0,0 +1,23 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 "RenderEncoderBase.h"
#include "RenderPipeline.h"
namespace mozilla {
namespace webgpu {
NS_IMPL_CYCLE_COLLECTION_INHERITED(RenderEncoderBase, ProgrammablePassEncoder)
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(RenderEncoderBase,
ProgrammablePassEncoder)
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(RenderEncoderBase,
ProgrammablePassEncoder)
NS_IMPL_CYCLE_COLLECTION_TRACE_END
RenderEncoderBase::~RenderEncoderBase() = default;
} // namespace webgpu
} // namespace mozilla

View File

@ -0,0 +1,35 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 GPU_RenderEncoderBase_H_
#define GPU_RenderEncoderBase_H_
#include "mozilla/dom/TypedArray.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "ProgrammablePassEncoder.h"
namespace mozilla {
namespace webgpu {
class Buffer;
class ComputePipeline;
class RenderEncoderBase : public ProgrammablePassEncoder {
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(
RenderEncoderBase, ProgrammablePassEncoder)
RenderEncoderBase() = delete;
protected:
virtual ~RenderEncoderBase();
public:
};
} // namespace webgpu
} // namespace mozilla
#endif // GPU_RenderEncoderBase_H_

View File

@ -0,0 +1,25 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 "mozilla/dom/WebGPUBinding.h"
#include "RenderPassEncoder.h"
#include "CommandEncoder.h"
namespace mozilla {
namespace webgpu {
NS_IMPL_CYCLE_COLLECTION_INHERITED(RenderPassEncoder, RenderEncoderBase,
mParent)
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(RenderPassEncoder,
RenderEncoderBase)
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(RenderPassEncoder,
RenderEncoderBase)
NS_IMPL_CYCLE_COLLECTION_TRACE_END
GPU_IMPL_JS_WRAP(RenderPassEncoder)
RenderPassEncoder::~RenderPassEncoder() = default;
} // namespace webgpu
} // namespace mozilla

View File

@ -0,0 +1,46 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 GPU_RenderPassEncoder_H_
#define GPU_RenderPassEncoder_H_
#include "ObjectModel.h"
#include "RenderEncoderBase.h"
namespace mozilla {
namespace dom {
class DoubleSequenceOrGPUColorDict;
template <typename T>
class Sequence;
namespace binding_detail {
template <typename T>
class AutoSequence;
} // namespace binding_detail
} // namespace dom
namespace webgpu {
class CommandEncoder;
class RenderBundle;
class RenderPassEncoder final : public RenderEncoderBase,
public ChildOf<CommandEncoder> {
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(RenderPassEncoder,
RenderEncoderBase)
GPU_DECL_JS_WRAP(RenderPassEncoder)
RenderPassEncoder() = delete;
protected:
virtual ~RenderPassEncoder();
public:
};
} // namespace webgpu
} // namespace mozilla
#endif // GPU_RenderPassEncoder_H_

View File

@ -6,14 +6,14 @@
#include "RenderPipeline.h"
#include "Device.h"
#include "mozilla/dom/WebGPUBinding.h"
namespace mozilla {
namespace webgpu {
RenderPipeline::~RenderPipeline() = default;
WEBGPU_IMPL_GOOP_0(RenderPipeline)
GPU_IMPL_CYCLE_COLLECTION(RenderPipeline, mParent)
GPU_IMPL_JS_WRAP(RenderPipeline)
} // namespace webgpu
} // namespace mozilla

View File

@ -3,8 +3,8 @@
* 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_
#ifndef GPU_RenderPipeline_H_
#define GPU_RenderPipeline_H_
#include "nsWrapperCache.h"
#include "ObjectModel.h"
@ -14,9 +14,10 @@ namespace webgpu {
class Device;
class RenderPipeline final : public ChildOf<Device> {
class RenderPipeline final : public ObjectBase, public ChildOf<Device> {
public:
WEBGPU_DECL_GOOP(RenderPipeline)
GPU_DECL_CYCLE_COLLECTION(RenderPipeline)
GPU_DECL_JS_WRAP(RenderPipeline)
private:
RenderPipeline() = delete;
@ -26,4 +27,4 @@ class RenderPipeline final : public ChildOf<Device> {
} // namespace webgpu
} // namespace mozilla
#endif // WEBGPU_RenderPipeline_H_
#endif // GPU_RenderPipeline_H_

View File

@ -3,17 +3,18 @@
* 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 "mozilla/dom/WebGPUBinding.h"
#include "Sampler.h"
#include "Device.h"
#include "mozilla/dom/WebGPUBinding.h"
namespace mozilla {
namespace webgpu {
Sampler::~Sampler() = default;
WEBGPU_IMPL_GOOP_0(Sampler)
GPU_IMPL_CYCLE_COLLECTION(Sampler, mParent)
GPU_IMPL_JS_WRAP(Sampler)
} // namespace webgpu
} // namespace mozilla

View File

@ -3,8 +3,8 @@
* 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_
#ifndef GPU_SAMPLER_H_
#define GPU_SAMPLER_H_
#include "nsWrapperCache.h"
#include "ObjectModel.h"
@ -14,9 +14,10 @@ namespace webgpu {
class Device;
class Sampler final : public ChildOf<Device> {
class Sampler final : public ObjectBase, public ChildOf<Device> {
public:
WEBGPU_DECL_GOOP(Sampler)
GPU_DECL_CYCLE_COLLECTION(Sampler)
GPU_DECL_JS_WRAP(Sampler)
private:
Sampler() = delete;
@ -26,4 +27,4 @@ class Sampler final : public ChildOf<Device> {
} // namespace webgpu
} // namespace mozilla
#endif // WEBGPU_SAMPLER_H_
#endif // GPU_SAMPLER_H_

View File

@ -3,17 +3,18 @@
* 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 "mozilla/dom/WebGPUBinding.h"
#include "ShaderModule.h"
#include "Device.h"
#include "mozilla/dom/WebGPUBinding.h"
namespace mozilla {
namespace webgpu {
ShaderModule::~ShaderModule() = default;
WEBGPU_IMPL_GOOP_0(ShaderModule)
GPU_IMPL_CYCLE_COLLECTION(ShaderModule, mParent)
GPU_IMPL_JS_WRAP(ShaderModule)
} // namespace webgpu
} // namespace mozilla

View File

@ -3,8 +3,8 @@
* 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_
#ifndef GPU_ShaderModule_H_
#define GPU_ShaderModule_H_
#include "nsWrapperCache.h"
#include "ObjectModel.h"
@ -14,9 +14,10 @@ namespace webgpu {
class Device;
class ShaderModule final : public ChildOf<Device> {
class ShaderModule final : public ObjectBase, public ChildOf<Device> {
public:
WEBGPU_DECL_GOOP(ShaderModule)
GPU_DECL_CYCLE_COLLECTION(ShaderModule)
GPU_DECL_JS_WRAP(ShaderModule)
private:
ShaderModule() = delete;
@ -26,4 +27,4 @@ class ShaderModule final : public ChildOf<Device> {
} // namespace webgpu
} // namespace mozilla
#endif // WEBGPU_ShaderModule_H_
#endif // GPU_ShaderModule_H_

View File

@ -5,25 +5,13 @@
#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<Texture> SwapChain::GetNextTexture() const {
MOZ_CRASH("todo");
}
void SwapChain::Present() const { MOZ_CRASH("todo"); }
WEBGPU_IMPL_GOOP_0(SwapChain)
GPU_IMPL_CYCLE_COLLECTION(SwapChain, mParent)
GPU_IMPL_JS_WRAP(SwapChain)
} // namespace webgpu
} // namespace mozilla

View File

@ -3,37 +3,31 @@
* 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_
#ifndef GPU_SwapChain_H_
#define GPU_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<Device> {
class SwapChain final : public ObjectBase, public ChildOf<Device> {
public:
WEBGPU_DECL_GOOP(SwapChain)
GPU_DECL_CYCLE_COLLECTION(SwapChain)
GPU_DECL_JS_WRAP(SwapChain)
private:
SwapChain() = delete;
virtual ~SwapChain();
public:
void Configure(const dom::WebGPUSwapChainDescriptor& desc) const;
already_AddRefed<Texture> GetNextTexture() const;
void Present() const;
};
} // namespace webgpu
} // namespace mozilla
#endif // WEBGPU_SwapChain_H_
#endif // GPU_SwapChain_H_

View File

@ -5,8 +5,6 @@
#include "Texture.h"
#include "Device.h"
#include "mozilla/dom/WebGPUBinding.h"
#include "TextureView.h"
namespace mozilla {
@ -14,12 +12,8 @@ namespace webgpu {
Texture::~Texture() = default;
already_AddRefed<TextureView> Texture::CreateTextureView(
const dom::WebGPUTextureViewDescriptor& desc) const {
MOZ_CRASH("todo");
}
WEBGPU_IMPL_GOOP_0(Texture)
GPU_IMPL_CYCLE_COLLECTION(Texture, mParent)
GPU_IMPL_JS_WRAP(Texture)
} // namespace webgpu
} // namespace mozilla

View File

@ -3,15 +3,15 @@
* 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_
#ifndef GPU_Texture_H_
#define GPU_Texture_H_
#include "nsWrapperCache.h"
#include "ObjectModel.h"
namespace mozilla {
namespace dom {
struct WebGPUTextureViewDescriptor;
struct GPUTextureViewDescriptor;
} // namespace dom
namespace webgpu {
@ -19,20 +19,19 @@ namespace webgpu {
class Device;
class TextureView;
class Texture final : public ChildOf<Device> {
class Texture final : public ObjectBase, public ChildOf<Device> {
public:
WEBGPU_DECL_GOOP(Texture)
GPU_DECL_CYCLE_COLLECTION(Texture)
GPU_DECL_JS_WRAP(Texture)
private:
Texture() = delete;
virtual ~Texture();
public:
already_AddRefed<TextureView> CreateTextureView(
const dom::WebGPUTextureViewDescriptor&) const;
};
} // namespace webgpu
} // namespace mozilla
#endif // WEBGPU_Texture_H_
#endif // GPU_Texture_H_

View File

@ -6,14 +6,14 @@
#include "TextureView.h"
#include "Device.h"
#include "mozilla/dom/WebGPUBinding.h"
namespace mozilla {
namespace webgpu {
TextureView::~TextureView() = default;
WEBGPU_IMPL_GOOP_0(TextureView)
GPU_IMPL_CYCLE_COLLECTION(TextureView, mParent)
GPU_IMPL_JS_WRAP(TextureView)
} // namespace webgpu
} // namespace mozilla

View File

@ -3,8 +3,8 @@
* 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_
#ifndef GPU_TextureView_H_
#define GPU_TextureView_H_
#include "nsWrapperCache.h"
#include "ObjectModel.h"
@ -14,9 +14,10 @@ namespace webgpu {
class Device;
class TextureView final : public ChildOf<Device> {
class TextureView final : public ObjectBase, public ChildOf<Device> {
public:
WEBGPU_DECL_GOOP(TextureView)
GPU_DECL_CYCLE_COLLECTION(TextureView)
GPU_DECL_JS_WRAP(TextureView)
private:
TextureView() = delete;
@ -26,4 +27,4 @@ class TextureView final : public ChildOf<Device> {
} // namespace webgpu
} // namespace mozilla
#endif // WEBGPU_TEXTURE_VIEW_H_
#endif // GPU_TextureView_H_

View File

@ -3,17 +3,16 @@
* 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 "ValidationError.h"
#include "Device.h"
#include "mozilla/dom/WebGPUBinding.h"
namespace mozilla {
namespace webgpu {
DepthStencilState::~DepthStencilState() = default;
GPU_IMPL_CYCLE_COLLECTION(ValidationError, mParent)
GPU_IMPL_JS_WRAP(ValidationError)
WEBGPU_IMPL_GOOP_0(DepthStencilState)
ValidationError::~ValidationError() = default;
} // namespace webgpu
} // namespace mozilla

View File

@ -3,27 +3,27 @@
* 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_
#ifndef GPU_ValidationError_H_
#define GPU_ValidationError_H_
#include "nsWrapperCache.h"
#include "ObjectModel.h"
namespace mozilla {
namespace webgpu {
class Device;
class AttachmentState final : public ChildOf<Device> {
class ValidationError final : public nsWrapperCache, public ChildOf<Device> {
public:
WEBGPU_DECL_GOOP(AttachmentState)
GPU_DECL_CYCLE_COLLECTION(ValidationError)
GPU_DECL_JS_WRAP(ValidationError)
ValidationError() = delete;
private:
AttachmentState() = delete;
virtual ~AttachmentState();
virtual ~ValidationError();
};
} // namespace webgpu
} // namespace mozilla
#endif // WEBGPU_AttachmentState_H_
#endif // GPU_ValidationError_H_

View File

@ -9,8 +9,7 @@
<script>
ok(!SpecialPowers.getBoolPref('dom.webgpu.enable'), 'Pref should be disabled.');
ok(window.WebGPU === undefined, 'window.WebGPU === undefined');
ok(window.webgpu === undefined, 'window.webgpu === undefined');
ok(navigator.gpu === undefined, 'navigator.gpu === undefined');
</script>
</body>

View File

@ -9,8 +9,7 @@
<script>
ok(SpecialPowers.getBoolPref('dom.webgpu.enable'), 'Pref should be enabled.');
ok(window.WebGPU !== undefined, 'window.WebGPU !== undefined');
ok(window.webgpu !== undefined, 'window.webgpu !== undefined');
ok(navigator.gpu !== undefined, 'navigator.gpu !== undefined');
</script>
</body>

View File

@ -14,36 +14,37 @@ MOCHITEST_MANIFESTS += [
h_and_cpp = [
'Adapter',
'AttachmentState',
'BindGroup',
'BindGroupLayout',
'BlendState',
'Buffer',
'CanvasContext',
'CommandBuffer',
'CommandEncoder',
'ComputePassEncoder',
'ComputePipeline',
'DepthStencilState',
'Device',
'DeviceLostInfo',
'Fence',
'InputState',
'Instance',
'InstanceProvider',
'LogEntry',
'ObjectModel',
'OutOfMemoryError',
'PipelineLayout',
'ProgrammablePassEncoder',
'Queue',
'RenderBundle',
'RenderBundleEncoder',
'RenderEncoderBase',
'RenderPassEncoder',
'RenderPipeline',
'Sampler',
'ShaderModule',
'SwapChain',
'Texture',
'TextureView',
'ValidationError',
]
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'

View File

@ -0,0 +1,21 @@
/* -*- 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://gpuweb.github.io/gpuweb/
*/
[
Pref="dom.webgpu.enable",
Exposed=Window,
]
interface GPUUncapturedErrorEvent : Event {
constructor(DOMString type, GPUUncapturedErrorEventInit gpuUncapturedErrorEventInitDict);
readonly attribute GPUError error;
};
dictionary GPUUncapturedErrorEventInit : EventInit {
required GPUError error;
};

View File

@ -39,6 +39,7 @@ Navigator includes NavigatorStorageUtils;
Navigator includes NavigatorConcurrentHardware;
Navigator includes NavigatorStorage;
Navigator includes NavigatorAutomationInformation;
Navigator includes GPUProvider;
interface mixin NavigatorID {
// WebKit/Blink/Trident/Presto support this (hardcoded "Mozilla").

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +0,0 @@
/* -*- 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;
};

View File

@ -602,8 +602,6 @@ partial interface Window {
readonly attribute IntlUtils intlUtils;
};
Window includes WebGPUProvider;
partial interface Window {
[SameObject, Pref="dom.visualviewport.enabled", Replaceable]
readonly attribute VisualViewport visualViewport;

View File

@ -931,7 +931,6 @@ WEBIDL_FILES = [
'WebGL2RenderingContext.webidl',
'WebGLRenderingContext.webidl',
'WebGPU.webidl',
'WebGPUExtras.webidl',
'WebSocket.webidl',
'WheelEvent.webidl',
'WidevineCDMManifest.webidl',
@ -1047,6 +1046,7 @@ GENERATED_EVENTS_WEBIDL_FILES = [
'GamepadAxisMoveEvent.webidl',
'GamepadButtonEvent.webidl',
'GamepadEvent.webidl',
'GPUUncapturedErrorEvent.webidl',
'HashChangeEvent.webidl',
'HiddenPluginEvent.webidl',
'ImageCaptureErrorEvent.webidl',

View File

@ -26,13 +26,15 @@
#include "mozilla/dom/Navigator.h"
#include "mozilla/webgpu/Instance.h"
namespace mozilla {
namespace dom {
using namespace workerinternals;
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(WorkerNavigator, mStorageManager,
mConnection, mMediaCapabilities);
mConnection, mMediaCapabilities, mWebGpu);
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WorkerNavigator, AddRef)
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WorkerNavigator, Release)
@ -209,5 +211,18 @@ dom::MediaCapabilities* WorkerNavigator::MediaCapabilities() {
return mMediaCapabilities;
}
webgpu::Instance* WorkerNavigator::Gpu() {
if (!mWebGpu) {
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
MOZ_ASSERT(workerPrivate);
nsIGlobalObject* global = workerPrivate->GlobalScope();
MOZ_ASSERT(global);
mWebGpu = webgpu::Instance::Create(global);
}
return mWebGpu;
}
} // namespace dom
} // namespace mozilla

View File

@ -15,6 +15,9 @@
#include "mozilla/dom/workerinternals/RuntimeService.h"
namespace mozilla {
namespace webgpu {
class Instance;
} // namespace webgpu
namespace dom {
class Promise;
class StorageManager;
@ -31,6 +34,8 @@ class WorkerNavigator final : public nsWrapperCache {
NavigatorProperties mProperties;
RefPtr<StorageManager> mStorageManager;
RefPtr<network::Connection> mConnection;
RefPtr<dom::MediaCapabilities> mMediaCapabilities;
RefPtr<webgpu::Instance> mWebGpu;
bool mOnline;
WorkerNavigator(const NavigatorProperties& aProperties, bool aOnline);
@ -92,8 +97,7 @@ class WorkerNavigator final : public nsWrapperCache {
dom::MediaCapabilities* MediaCapabilities();
private:
RefPtr<dom::MediaCapabilities> mMediaCapabilities;
webgpu::Instance* Gpu();
};
} // namespace dom

View File

@ -49,6 +49,11 @@ worker.onmessage = function(event) {
return;
}
if (args.name === "gpu") {
is(typeof navigator.gpu, typeof args.value, "gpu type matches");
return;
}
is(
navigator[args.name],
args.value,

View File

@ -2564,7 +2564,7 @@
# Is support for the Web GPU API enabled?
- name: dom.webgpu.enable
type: bool
type: RelaxedAtomicBool
value: false
mirror: always