File: CommandEncoder.h

package info (click to toggle)
firefox 144.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,637,504 kB
  • sloc: cpp: 7,576,692; javascript: 6,430,831; ansic: 3,748,119; python: 1,398,978; xml: 628,810; asm: 438,679; java: 186,194; sh: 63,212; makefile: 19,159; objc: 13,086; perl: 12,986; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (147 lines) | stat: -rw-r--r-- 5,316 bytes parent folder | download | duplicates (3)
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/* -*- 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 "CanvasContext.h"
#include "ObjectModel.h"
#include "QuerySet.h"
#include "mozilla/RefPtr.h"
#include "mozilla/Span.h"
#include "mozilla/WeakPtr.h"
#include "mozilla/dom/TypedArray.h"
#include "mozilla/webgpu/WebGPUTypes.h"
#include "mozilla/webgpu/ffi/wgpu.h"
#include "nsTArrayForwardDeclare.h"
#include "nsWrapperCache.h"

namespace mozilla {
class ErrorResult;

namespace dom {
struct GPUComputePassDescriptor;
template <typename T>
class Sequence;
struct GPUCommandBufferDescriptor;
class GPUComputePipelineOrGPURenderPipeline;
class RangeEnforcedUnsignedLongSequenceOrGPUExtent3DDict;
struct GPUTexelCopyBufferInfo;
struct GPUTexelCopyTextureInfo;
struct GPUImageBitmapCopyView;
struct GPUTexelCopyBufferLayout;
struct GPURenderPassDescriptor;
using GPUExtent3D = RangeEnforcedUnsignedLongSequenceOrGPUExtent3DDict;
}  // namespace dom
namespace webgpu {

class BindGroup;
class Buffer;
class CanvasContext;
class CommandBuffer;
class ComputePassEncoder;
class Device;
class ExternalTexture;
class RenderPassEncoder;
class WebGPUChild;

enum class CommandEncoderState { Open, Locked, Ended };

class CommandEncoder final : public nsWrapperCache,
                             public ObjectBase,
                             public ChildOf<Device> {
 public:
  GPU_DECL_CYCLE_COLLECTION(CommandEncoder)
  GPU_DECL_JS_WRAP(CommandEncoder)

  CommandEncoder(Device* const aParent, RawId aId);

  static void ConvertTextureDataLayoutToFFI(
      const dom::GPUTexelCopyBufferLayout& aLayout,
      ffi::WGPUTexelCopyBufferLayout* aLayoutFFI);
  static void ConvertTextureCopyViewToFFI(
      const dom::GPUTexelCopyTextureInfo& aCopy,
      ffi::WGPUTexelCopyTextureInfo_TextureId* aViewFFI);

 private:
  virtual ~CommandEncoder();

  CommandEncoderState mState;

  CanvasContextArray mPresentationContexts;
  nsTArray<RefPtr<ExternalTexture>> mExternalTextures;

  void TrackPresentationContext(WeakPtr<CanvasContext> aTargetContext);

 public:
  const auto& GetDevice() const { return mParent; };

  CommandEncoderState GetState() const { return mState; };

  void EndComputePass(ffi::WGPURecordedComputePass& aPass,
                      CanvasContextArray& aCanvasContexts,
                      Span<RefPtr<ExternalTexture>> aExternalTextures);
  void EndRenderPass(ffi::WGPURecordedRenderPass& aPass,
                     CanvasContextArray& aCanvasContexts,
                     Span<RefPtr<ExternalTexture>> aExternalTextures);

  void CopyBufferToBuffer(const Buffer& aSource, const Buffer& aDestination,
                          const dom::Optional<BufferAddress>& aSize) {
    this->CopyBufferToBuffer(aSource, 0, aDestination, 0, aSize);
  }
  void CopyBufferToBuffer(const Buffer& aSource, BufferAddress aSourceOffset,
                          const Buffer& aDestination,
                          BufferAddress aDestinationOffset,
                          const dom::Optional<BufferAddress>& aSize);
  void CopyBufferToTexture(const dom::GPUTexelCopyBufferInfo& aSource,
                           const dom::GPUTexelCopyTextureInfo& aDestination,
                           const dom::GPUExtent3D& aCopySize);
  void CopyTextureToBuffer(const dom::GPUTexelCopyTextureInfo& aSource,
                           const dom::GPUTexelCopyBufferInfo& aDestination,
                           const dom::GPUExtent3D& aCopySize);
  void CopyTextureToTexture(const dom::GPUTexelCopyTextureInfo& aSource,
                            const dom::GPUTexelCopyTextureInfo& 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);
  void ResolveQuerySet(QuerySet& aQuerySet, uint32_t aFirstQuery,
                       uint32_t aQueryCount, webgpu::Buffer& aDestination,
                       uint64_t aDestinationOffset);
  already_AddRefed<CommandBuffer> Finish(
      const dom::GPUCommandBufferDescriptor& aDesc);
};

template <typename T>
void AssignPassTimestampWrites(const T& src,
                               ffi::WGPUPassTimestampWrites& dest) {
  if (src.mBeginningOfPassWriteIndex.WasPassed()) {
    dest.beginning_of_pass_write_index =
        &src.mBeginningOfPassWriteIndex.Value();
  } else {
    dest.beginning_of_pass_write_index = nullptr;
  }

  if (src.mEndOfPassWriteIndex.WasPassed()) {
    dest.end_of_pass_write_index = &src.mEndOfPassWriteIndex.Value();
  } else {
    dest.end_of_pass_write_index = nullptr;
  }

  dest.query_set = src.mQuerySet->GetId();
}

}  // namespace webgpu
}  // namespace mozilla

#endif  // GPU_CommandEncoder_H_