tor-browser

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

RenderBundleEncoder.h (3839B)


      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_RenderBundleEncoder_H_
      7 #define GPU_RenderBundleEncoder_H_
      8 
      9 #include "CanvasContext.h"
     10 #include "ObjectModel.h"
     11 #include "mozilla/dom/TypedArray.h"
     12 
     13 namespace mozilla::dom {
     14 struct GPURenderBundleEncoderDescriptor;
     15 struct GPURenderBundleDescriptor;
     16 enum class GPUIndexFormat : uint8_t;
     17 }  // namespace mozilla::dom
     18 
     19 namespace mozilla::webgpu {
     20 class BindGroup;
     21 class Buffer;
     22 class RenderPipeline;
     23 
     24 namespace ffi {
     25 struct WGPURenderBundleEncoder;
     26 }  // namespace ffi
     27 
     28 class Device;
     29 class RenderBundle;
     30 
     31 struct ffiWGPURenderBundleEncoderDeleter {
     32  void operator()(ffi::WGPURenderBundleEncoder*);
     33 };
     34 
     35 class RenderBundleEncoder final : public nsWrapperCache,
     36                                  public ObjectBase,
     37                                  public ChildOf<Device> {
     38 public:
     39  GPU_DECL_CYCLE_COLLECTION(RenderBundleEncoder)
     40  GPU_DECL_JS_WRAP(RenderBundleEncoder)
     41 
     42  RenderBundleEncoder(Device* const aParent, RawId aId,
     43                      const dom::GPURenderBundleEncoderDescriptor& aDesc);
     44 
     45 private:
     46  virtual ~RenderBundleEncoder();
     47 
     48  std::unique_ptr<ffi::WGPURenderBundleEncoder,
     49                  ffiWGPURenderBundleEncoderDeleter>
     50      mEncoder;
     51  // keep all the used objects alive while the encoder is finished
     52  nsTArray<RefPtr<const BindGroup>> mUsedBindGroups;
     53  nsTArray<RefPtr<const Buffer>> mUsedBuffers;
     54  nsTArray<RefPtr<const RenderPipeline>> mUsedPipelines;
     55 
     56  // The canvas contexts of any canvas textures used in bind groups of this
     57  // render bundle.
     58  CanvasContextArray mUsedCanvasContexts;
     59 
     60  // programmable pass encoder
     61 private:
     62  bool mValid = true;
     63 
     64  void SetBindGroup(uint32_t aSlot, BindGroup* const aBindGroup,
     65                    const uint32_t* aDynamicOffsets,
     66                    size_t aDynamicOffsetsLength);
     67 
     68 public:
     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  // render encoder base
     77  void SetPipeline(const RenderPipeline& aPipeline);
     78  void SetIndexBuffer(const Buffer& aBuffer,
     79                      const dom::GPUIndexFormat& aIndexFormat, uint64_t aOffset,
     80                      const dom::Optional<uint64_t>& aSize);
     81  void SetVertexBuffer(uint32_t aSlot, const Buffer& aBuffer, uint64_t aOffset,
     82                       const dom::Optional<uint64_t>& aSize);
     83  void Draw(uint32_t aVertexCount, uint32_t aInstanceCount,
     84            uint32_t aFirstVertex, uint32_t aFirstInstance);
     85  void DrawIndexed(uint32_t aIndexCount, uint32_t aInstanceCount,
     86                   uint32_t aFirstIndex, int32_t aBaseVertex,
     87                   uint32_t aFirstInstance);
     88  void DrawIndirect(const Buffer& aIndirectBuffer, uint64_t aIndirectOffset);
     89  void DrawIndexedIndirect(const Buffer& aIndirectBuffer,
     90                           uint64_t aIndirectOffset);
     91 
     92  void PushDebugGroup(const nsAString& aString);
     93  void PopDebugGroup();
     94  void InsertDebugMarker(const nsAString& aString);
     95 
     96  // self
     97  already_AddRefed<RenderBundle> Finish(
     98      const dom::GPURenderBundleDescriptor& aDesc);
     99 
    100  // helpers not defined by WebGPU
    101  mozilla::Span<const WeakPtr<CanvasContext>> GetCanvasContexts() const {
    102    return mUsedCanvasContexts;
    103  }
    104 };
    105 
    106 }  // namespace mozilla::webgpu
    107 
    108 #endif  // GPU_RenderBundleEncoder_H_