2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2018-06-13 20:43:48 +03:00
|
|
|
/* 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/. */
|
|
|
|
|
2019-10-02 19:46:03 +03:00
|
|
|
#ifndef GPU_BUFFER_H_
|
|
|
|
#define GPU_BUFFER_H_
|
2018-06-13 20:43:48 +03:00
|
|
|
|
2019-12-10 20:07:18 +03:00
|
|
|
#include "js/RootingAPI.h"
|
2018-06-13 20:43:48 +03:00
|
|
|
#include "mozilla/dom/Nullable.h"
|
2019-12-10 20:07:18 +03:00
|
|
|
#include "mozilla/webgpu/WebGPUTypes.h"
|
2018-06-13 20:43:48 +03:00
|
|
|
#include "ObjectModel.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
2019-12-10 20:07:18 +03:00
|
|
|
namespace ipc {
|
|
|
|
class Shmem;
|
|
|
|
} // namespace ipc
|
2018-06-13 20:43:48 +03:00
|
|
|
namespace webgpu {
|
|
|
|
|
|
|
|
class Device;
|
|
|
|
|
2019-10-02 19:46:03 +03:00
|
|
|
class Buffer final : public ObjectBase, public ChildOf<Device> {
|
2018-06-13 20:43:48 +03:00
|
|
|
public:
|
2019-10-02 19:46:03 +03:00
|
|
|
GPU_DECL_CYCLE_COLLECTION(Buffer)
|
|
|
|
GPU_DECL_JS_WRAP(Buffer)
|
2018-06-13 20:43:48 +03:00
|
|
|
|
2019-12-10 20:07:18 +03:00
|
|
|
struct Mapping final {
|
|
|
|
UniquePtr<ipc::Shmem> mShmem;
|
|
|
|
JS::Heap<JSObject*> mArrayBuffer;
|
2020-04-15 00:26:45 +03:00
|
|
|
const bool mWrite;
|
2019-12-10 20:07:18 +03:00
|
|
|
|
2020-04-15 00:26:45 +03:00
|
|
|
Mapping(ipc::Shmem&& aShmem, JSObject* aArrayBuffer, bool aWrite);
|
2019-12-10 20:07:18 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
Buffer(Device* const aParent, RawId aId, BufferAddress aSize);
|
2020-04-15 00:26:45 +03:00
|
|
|
void InitMapping(ipc::Shmem&& aShmem, JSObject* aArrayBuffer, bool aWrite);
|
2019-12-10 20:07:18 +03:00
|
|
|
|
2020-01-24 19:27:09 +03:00
|
|
|
const RawId mId;
|
|
|
|
|
2018-06-13 20:43:48 +03:00
|
|
|
private:
|
|
|
|
virtual ~Buffer();
|
2020-01-22 10:31:51 +03:00
|
|
|
void Cleanup();
|
2018-06-13 20:43:48 +03:00
|
|
|
|
2019-12-10 20:07:18 +03:00
|
|
|
// 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;
|
|
|
|
Maybe<Mapping> mMapping;
|
|
|
|
|
2018-06-13 20:43:48 +03:00
|
|
|
public:
|
2019-12-10 20:07:18 +03:00
|
|
|
already_AddRefed<dom::Promise> MapReadAsync(ErrorResult& aRv);
|
|
|
|
void Unmap(JSContext* aCx, ErrorResult& aRv);
|
2020-04-16 22:28:22 +03:00
|
|
|
void Destroy();
|
2018-06-13 20:43:48 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace webgpu
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2019-10-02 19:46:03 +03:00
|
|
|
#endif // GPU_BUFFER_H_
|