tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ComputePassEncoder.h (3113B)


      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/. */
      5 
      6 #ifndef GPU_ComputePassEncoder_H_
      7 #define GPU_ComputePassEncoder_H_
      8 
      9 #include "ObjectModel.h"
     10 #include "mozilla/dom/TypedArray.h"
     11 #include "mozilla/webgpu/CanvasContext.h"
     12 
     13 namespace mozilla {
     14 class ErrorResult;
     15 
     16 namespace dom {
     17 struct GPUComputePassDescriptor;
     18 }
     19 
     20 namespace webgpu {
     21 namespace ffi {
     22 struct WGPURecordedComputePass;
     23 }  // namespace ffi
     24 
     25 class BindGroup;
     26 class Buffer;
     27 class CommandEncoder;
     28 class ComputePipeline;
     29 
     30 struct ffiWGPUComputePassDeleter {
     31  void operator()(ffi::WGPURecordedComputePass*);
     32 };
     33 
     34 class ComputePassEncoder final : public nsWrapperCache,
     35                                 public ObjectBase,
     36                                 public ChildOf<CommandEncoder> {
     37 public:
     38  GPU_DECL_CYCLE_COLLECTION(ComputePassEncoder)
     39  GPU_DECL_JS_WRAP(ComputePassEncoder)
     40 
     41  ComputePassEncoder(CommandEncoder* const aParent, RawId aId,
     42                     const dom::GPUComputePassDescriptor& aDesc);
     43 
     44 private:
     45  virtual ~ComputePassEncoder();
     46 
     47  std::unique_ptr<ffi::WGPURecordedComputePass, ffiWGPUComputePassDeleter>
     48      mPass;
     49  // keep all the used objects alive while the pass is recorded
     50  nsTArray<RefPtr<const BindGroup>> mUsedBindGroups;
     51  nsTArray<RefPtr<const Buffer>> mUsedBuffers;
     52  nsTArray<RefPtr<const ComputePipeline>> mUsedPipelines;
     53 
     54  // The canvas contexts of any canvas textures used in bind groups of this
     55  // compute pass.
     56  CanvasContextArray mUsedCanvasContexts;
     57 
     58  // programmable pass encoder
     59 private:
     60  bool mValid = true;
     61 
     62  void SetBindGroup(uint32_t aSlot, BindGroup* const aBindGroup,
     63                    const uint32_t* aDynamicOffsets,
     64                    size_t aDynamicOffsetsLength);
     65 
     66 public:
     67  void Invalidate() { mValid = false; }
     68 
     69  void SetBindGroup(uint32_t aSlot, BindGroup* const aBindGroup,
     70                    const dom::Sequence<uint32_t>& aDynamicOffsets,
     71                    ErrorResult& aRv);
     72  void SetBindGroup(uint32_t aSlot, BindGroup* const aBindGroup,
     73                    const dom::Uint32Array& aDynamicOffsetsData,
     74                    uint64_t aDynamicOffsetsDataStart,
     75                    uint64_t aDynamicOffsetsDataLength, ErrorResult& aRv);
     76  // self
     77  void SetPipeline(const ComputePipeline& aPipeline);
     78 
     79  void DispatchWorkgroups(uint32_t workgroupCountX, uint32_t workgroupCountY,
     80                          uint32_t workgroupCountZ);
     81  void DispatchWorkgroupsIndirect(const Buffer& aIndirectBuffer,
     82                                  uint64_t aIndirectOffset);
     83 
     84  void PushDebugGroup(const nsAString& aString);
     85  void PopDebugGroup();
     86  void InsertDebugMarker(const nsAString& aString);
     87 
     88  void End();
     89 
     90  // helpers not defined by WebGPU
     91  mozilla::Span<const WeakPtr<CanvasContext>> GetCanvasContexts() const {
     92    return mUsedCanvasContexts;
     93  }
     94 };
     95 
     96 }  // namespace webgpu
     97 }  // namespace mozilla
     98 
     99 #endif  // GPU_ComputePassEncoder_H_