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/. */
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"
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
;
47 class GPUBufferOrGPUTexture
;
48 enum class GPUErrorFilter
: uint8_t;
49 enum class GPUFeatureName
: uint8_t;
53 enum class ResponseRejectReason
;
62 class BindGroupLayout
;
65 class ComputePipeline
;
70 class RenderBundleEncoder
;
74 class SupportedFeatures
;
75 class SupportedLimits
;
79 using MappingPromise
=
80 MozPromise
<BufferMapResult
, ipc::ResponseRejectReason
, true>;
82 class Device final
: public DOMEventTargetHelper
, public SupportsWeakPtr
{
84 NS_DECL_ISUPPORTS_INHERITED
85 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(Device
, DOMEventTargetHelper
)
86 GPU_DECL_JS_WRAP(Device
)
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
);
111 RefPtr
<WebGPUChild
> mBridge
;
114 RefPtr
<dom::Promise
> mLostPromise
;
115 RefPtr
<Queue
> mQueue
;
116 nsTHashSet
<nsCString
> mKnownWarnings
;
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
,
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
);
164 IMPL_EVENT_HANDLER(uncapturederror
)
167 } // namespace webgpu
168 } // namespace mozilla
170 #endif // GPU_DEVICE_H_