Bug 1812353 - Update GPUSupportedLimits in webgpu.webidl. r=webgpu-reviewers,webidl...
[gecko.git] / dom / webgpu / Device.h
blob96cc560931385bda5e841ae9ae9fcdc09dfa1830
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef GPU_DEVICE_H_
7 #define GPU_DEVICE_H_
9 #include "ObjectModel.h"
10 #include "nsTHashSet.h"
11 #include "mozilla/MozPromise.h"
12 #include "mozilla/RefPtr.h"
13 #include "mozilla/WeakPtr.h"
14 #include "mozilla/webgpu/WebGPUTypes.h"
15 #include "mozilla/webgpu/PWebGPUTypes.h"
16 #include "mozilla/webrender/WebRenderAPI.h"
17 #include "mozilla/DOMEventTargetHelper.h"
19 namespace mozilla {
20 namespace dom {
21 struct GPUExtensions;
22 struct GPUFeatures;
23 struct GPULimits;
24 struct GPUExtent3DDict;
26 struct GPUBufferDescriptor;
27 struct GPUTextureDescriptor;
28 struct GPUSamplerDescriptor;
29 struct GPUBindGroupLayoutDescriptor;
30 struct GPUPipelineLayoutDescriptor;
31 struct GPUBindGroupDescriptor;
32 struct GPUBlendStateDescriptor;
33 struct GPUDepthStencilStateDescriptor;
34 struct GPUInputStateDescriptor;
35 struct GPUShaderModuleDescriptor;
36 struct GPUAttachmentStateDescriptor;
37 struct GPUComputePipelineDescriptor;
38 struct GPURenderBundleEncoderDescriptor;
39 struct GPURenderPipelineDescriptor;
40 struct GPUCommandEncoderDescriptor;
41 struct GPUCanvasConfiguration;
43 class EventHandlerNonNull;
44 class Promise;
45 template <typename T>
46 class Sequence;
47 class GPUBufferOrGPUTexture;
48 enum class GPUErrorFilter : uint8_t;
49 enum class GPUFeatureName : uint8_t;
50 class GPULogCallback;
51 } // namespace dom
52 namespace ipc {
53 enum class ResponseRejectReason;
54 } // namespace ipc
56 namespace webgpu {
57 namespace ffi {
58 struct WGPULimits;
60 class Adapter;
61 class BindGroup;
62 class BindGroupLayout;
63 class Buffer;
64 class CommandEncoder;
65 class ComputePipeline;
66 class Fence;
67 class InputState;
68 class PipelineLayout;
69 class Queue;
70 class RenderBundleEncoder;
71 class RenderPipeline;
72 class Sampler;
73 class ShaderModule;
74 class SupportedFeatures;
75 class SupportedLimits;
76 class Texture;
77 class WebGPUChild;
79 using MappingPromise =
80 MozPromise<BufferMapResult, ipc::ResponseRejectReason, true>;
82 class Device final : public DOMEventTargetHelper, public SupportsWeakPtr {
83 public:
84 NS_DECL_ISUPPORTS_INHERITED
85 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(Device, DOMEventTargetHelper)
86 GPU_DECL_JS_WRAP(Device)
88 const RawId mId;
89 RefPtr<SupportedFeatures> mFeatures;
90 RefPtr<SupportedLimits> mLimits;
92 explicit Device(Adapter* const aParent, RawId aId, const ffi::WGPULimits&);
94 RefPtr<WebGPUChild> GetBridge();
95 already_AddRefed<Texture> InitSwapChain(
96 const dom::GPUCanvasConfiguration& aDesc,
97 const layers::RemoteTextureOwnerId aOwnerId, gfx::SurfaceFormat aFormat,
98 gfx::IntSize aCanvasSize);
99 bool CheckNewWarning(const nsACString& aMessage);
101 void CleanupUnregisteredInParent();
103 void GenerateError(const nsCString& aMessage);
105 bool IsLost() const;
107 private:
108 ~Device();
109 void Cleanup();
111 RefPtr<WebGPUChild> mBridge;
112 bool mValid = true;
113 nsString mLabel;
114 RefPtr<dom::Promise> mLostPromise;
115 RefPtr<Queue> mQueue;
116 nsTHashSet<nsCString> mKnownWarnings;
118 public:
119 void GetLabel(nsAString& aValue) const;
120 void SetLabel(const nsAString& aLabel);
121 dom::Promise* GetLost(ErrorResult& aRv);
122 dom::Promise* MaybeGetLost() const { return mLostPromise; }
124 const RefPtr<SupportedFeatures>& Features() const { return mFeatures; }
125 const RefPtr<SupportedLimits>& Limits() const { return mLimits; }
126 const RefPtr<Queue>& GetQueue() const { return mQueue; }
128 already_AddRefed<Buffer> CreateBuffer(const dom::GPUBufferDescriptor& aDesc,
129 ErrorResult& aRv);
131 already_AddRefed<Texture> CreateTexture(
132 const dom::GPUTextureDescriptor& aDesc);
133 already_AddRefed<Sampler> CreateSampler(
134 const dom::GPUSamplerDescriptor& aDesc);
136 already_AddRefed<CommandEncoder> CreateCommandEncoder(
137 const dom::GPUCommandEncoderDescriptor& aDesc);
138 already_AddRefed<RenderBundleEncoder> CreateRenderBundleEncoder(
139 const dom::GPURenderBundleEncoderDescriptor& aDesc);
141 already_AddRefed<BindGroupLayout> CreateBindGroupLayout(
142 const dom::GPUBindGroupLayoutDescriptor& aDesc);
143 already_AddRefed<PipelineLayout> CreatePipelineLayout(
144 const dom::GPUPipelineLayoutDescriptor& aDesc);
145 already_AddRefed<BindGroup> CreateBindGroup(
146 const dom::GPUBindGroupDescriptor& aDesc);
148 MOZ_CAN_RUN_SCRIPT already_AddRefed<ShaderModule> CreateShaderModule(
149 JSContext* aCx, const dom::GPUShaderModuleDescriptor& aDesc);
150 already_AddRefed<ComputePipeline> CreateComputePipeline(
151 const dom::GPUComputePipelineDescriptor& aDesc);
152 already_AddRefed<RenderPipeline> CreateRenderPipeline(
153 const dom::GPURenderPipelineDescriptor& aDesc);
154 already_AddRefed<dom::Promise> CreateComputePipelineAsync(
155 const dom::GPUComputePipelineDescriptor& aDesc, ErrorResult& aRv);
156 already_AddRefed<dom::Promise> CreateRenderPipelineAsync(
157 const dom::GPURenderPipelineDescriptor& aDesc, ErrorResult& aRv);
159 void PushErrorScope(const dom::GPUErrorFilter& aFilter);
160 already_AddRefed<dom::Promise> PopErrorScope(ErrorResult& aRv);
162 void Destroy();
164 IMPL_EVENT_HANDLER(uncapturederror)
167 } // namespace webgpu
168 } // namespace mozilla
170 #endif // GPU_DEVICE_H_