From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:22:09 +0200 Subject: Adding upstream version 110.0.1. Signed-off-by: Daniel Baumann --- dom/webgpu/Buffer.h | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 dom/webgpu/Buffer.h (limited to 'dom/webgpu/Buffer.h') diff --git a/dom/webgpu/Buffer.h b/dom/webgpu/Buffer.h new file mode 100644 index 0000000000..3f77ab8381 --- /dev/null +++ b/dom/webgpu/Buffer.h @@ -0,0 +1,90 @@ +/* -*- 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_BUFFER_H_ +#define GPU_BUFFER_H_ + +#include "js/RootingAPI.h" +#include "mozilla/dom/Nullable.h" +#include "mozilla/webgpu/WebGPUTypes.h" +#include "nsTArray.h" +#include "ObjectModel.h" +#include "mozilla/ipc/RawShmem.h" +#include + +namespace mozilla { +class ErrorResult; + +namespace dom { +struct GPUBufferDescriptor; +template +class Optional; +} // namespace dom + +namespace webgpu { + +class Device; + +struct MappedInfo { + // True if mapping is requested for writing. + bool mWritable = false; + // Populated by `GetMappedRange`. + nsTArray> mArrayBuffers; + BufferAddress mOffset; + BufferAddress mSize; + MappedInfo() = default; + MappedInfo(const MappedInfo&) = delete; +}; + +class Buffer final : public ObjectBase, public ChildOf { + public: + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(Buffer) + NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(Buffer) + GPU_DECL_JS_WRAP(Buffer) + + static already_AddRefed Create(Device* aDevice, RawId aDeviceId, + const dom::GPUBufferDescriptor& aDesc, + ErrorResult& aRv); + + already_AddRefed MapAsync(uint32_t aMode, uint64_t aOffset, + const dom::Optional& aSize, + ErrorResult& aRv); + void GetMappedRange(JSContext* aCx, uint64_t aOffset, + const dom::Optional& aSize, + JS::Rooted* aObject, ErrorResult& aRv); + void Unmap(JSContext* aCx, ErrorResult& aRv); + void Destroy(JSContext* aCx, ErrorResult& aRv); + + const RawId mId; + + private: + Buffer(Device* const aParent, RawId aId, BufferAddress aSize, uint32_t aUsage, + ipc::WritableSharedMemoryMapping&& aShmem); + virtual ~Buffer(); + Device& GetDevice() { return *mParent; } + void Drop(); + void UnmapArrayBuffers(JSContext* aCx, ErrorResult& aRv); + void RejectMapRequest(dom::Promise* aPromise, nsACString& message); + void AbortMapRequest(); + void SetMapped(BufferAddress aOffset, BufferAddress aSize, bool aWritable); + + // Note: we can't map a buffer with the size that don't fit into `size_t` + // (which may be smaller than `BufferAddress`), but general not all buffers + // are mapped. + const BufferAddress mSize; + const uint32_t mUsage; + nsString mLabel; + // Information about the currently active mapping. + Maybe mMapped; + RefPtr mMapRequest; + // mShmem does not point to a shared memory segment if the buffer is not + // mappable. + std::shared_ptr mShmem; +}; + +} // namespace webgpu +} // namespace mozilla + +#endif // GPU_BUFFER_H_ -- cgit v1.2.3