diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /dom/webgpu/CommandEncoder.h | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream/115.8.0esr.tar.xz firefox-esr-upstream/115.8.0esr.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/webgpu/CommandEncoder.h')
-rw-r--r-- | dom/webgpu/CommandEncoder.h | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/dom/webgpu/CommandEncoder.h b/dom/webgpu/CommandEncoder.h new file mode 100644 index 0000000000..fc58b7ee35 --- /dev/null +++ b/dom/webgpu/CommandEncoder.h @@ -0,0 +1,107 @@ +/* -*- 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 WGPURenderPass; +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>> mTargetContexts; + + public: + const auto& GetDevice() const { return mParent; }; + + void EndComputePass(ffi::WGPUComputePass& aPass, ErrorResult& aRv); + void EndRenderPass(ffi::WGPURenderPass& aPass, ErrorResult& aRv); + + 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 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_ |