1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
/* -*- 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_CommandEncoder_H_
#define GPU_CommandEncoder_H_
#include "mozilla/dom/TypedArray.h"
#include "mozilla/WeakPtr.h"
#include "mozilla/webgpu/WebGPUTypes.h"
#include "nsWrapperCache.h"
#include "ObjectModel.h"
namespace mozilla {
class ErrorResult;
namespace dom {
struct GPUComputePassDescriptor;
template <typename T>
class Sequence;
struct GPUCommandBufferDescriptor;
class GPUComputePipelineOrGPURenderPipeline;
class RangeEnforcedUnsignedLongSequenceOrGPUExtent3DDict;
struct GPUImageCopyBuffer;
struct GPUImageCopyTexture;
struct GPUImageBitmapCopyView;
struct GPUImageDataLayout;
struct GPURenderPassDescriptor;
using GPUExtent3D = RangeEnforcedUnsignedLongSequenceOrGPUExtent3DDict;
} // namespace dom
namespace webgpu {
namespace ffi {
struct WGPUComputePass;
struct WGPURecordedRenderPass;
struct WGPUImageDataLayout;
struct WGPUImageCopyTexture_TextureId;
struct WGPUExtent3d;
} // namespace ffi
class BindGroup;
class Buffer;
class CanvasContext;
class CommandBuffer;
class ComputePassEncoder;
class Device;
class RenderPassEncoder;
class CommandEncoder final : public ObjectBase, public ChildOf<Device> {
public:
GPU_DECL_CYCLE_COLLECTION(CommandEncoder)
GPU_DECL_JS_WRAP(CommandEncoder)
CommandEncoder(Device* const aParent, WebGPUChild* const aBridge, RawId aId);
const RawId mId;
static void ConvertTextureDataLayoutToFFI(
const dom::GPUImageDataLayout& aLayout,
ffi::WGPUImageDataLayout* aLayoutFFI);
static void ConvertTextureCopyViewToFFI(
const dom::GPUImageCopyTexture& aCopy,
ffi::WGPUImageCopyTexture_TextureId* aViewFFI);
private:
~CommandEncoder();
void Cleanup();
RefPtr<WebGPUChild> mBridge;
nsTArray<WeakPtr<CanvasContext>> mPresentationContexts;
void TrackPresentationContext(CanvasContext* aTargetContext);
public:
const auto& GetDevice() const { return mParent; };
void EndComputePass(ffi::WGPURecordedComputePass& aPass);
void EndRenderPass(ffi::WGPURecordedRenderPass& aPass);
void CopyBufferToBuffer(const Buffer& aSource, BufferAddress aSourceOffset,
const Buffer& aDestination,
BufferAddress aDestinationOffset,
BufferAddress aSize);
void CopyBufferToTexture(const dom::GPUImageCopyBuffer& aSource,
const dom::GPUImageCopyTexture& aDestination,
const dom::GPUExtent3D& aCopySize);
void CopyTextureToBuffer(const dom::GPUImageCopyTexture& aSource,
const dom::GPUImageCopyBuffer& aDestination,
const dom::GPUExtent3D& aCopySize);
void CopyTextureToTexture(const dom::GPUImageCopyTexture& aSource,
const dom::GPUImageCopyTexture& aDestination,
const dom::GPUExtent3D& aCopySize);
void ClearBuffer(const Buffer& aBuffer, const uint64_t aOffset,
const dom::Optional<uint64_t>& aSize);
void PushDebugGroup(const nsAString& aString);
void PopDebugGroup();
void InsertDebugMarker(const nsAString& aString);
already_AddRefed<ComputePassEncoder> BeginComputePass(
const dom::GPUComputePassDescriptor& aDesc);
already_AddRefed<RenderPassEncoder> BeginRenderPass(
const dom::GPURenderPassDescriptor& aDesc);
already_AddRefed<CommandBuffer> Finish(
const dom::GPUCommandBufferDescriptor& aDesc);
};
} // namespace webgpu
} // namespace mozilla
#endif // GPU_CommandEncoder_H_
|