From 2aa4a82499d4becd2284cdb482213d541b8804dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 16:29:10 +0200 Subject: Adding upstream version 86.0.1. Signed-off-by: Daniel Baumann --- dom/webgpu/Buffer.h | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 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..4b7537cc6d --- /dev/null +++ b/dom/webgpu/Buffer.h @@ -0,0 +1,71 @@ +/* -*- 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/ipc/Shmem.h" +#include "mozilla/webgpu/WebGPUTypes.h" +#include "ObjectModel.h" + +namespace mozilla { +namespace ipc { +class Shmem; +} // namespace ipc +namespace webgpu { + +class Device; + +struct MappedInfo { + ipc::Shmem mShmem; + // True if mapping is requested for writing. + bool mWritable = false; + // Populated by `GetMappedRange`. + nsTArray> mArrayBuffers; + + MappedInfo() = default; + MappedInfo(const MappedInfo&) = delete; + bool IsReady() const { return mShmem.IsReadable(); } +}; + +class Buffer final : public ObjectBase, public ChildOf { + public: + GPU_DECL_CYCLE_COLLECTION(Buffer) + GPU_DECL_JS_WRAP(Buffer) + + Buffer(Device* const aParent, RawId aId, BufferAddress aSize); + void SetMapped(ipc::Shmem&& aShmem, bool aWritable); + + const RawId mId; + + private: + virtual ~Buffer(); + void Cleanup(); + + // 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; + nsString mLabel; + // Information about the currently active mapping. + Maybe mMapped; + + public: + 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(); +}; + +} // namespace webgpu +} // namespace mozilla + +#endif // GPU_BUFFER_H_ -- cgit v1.2.3