2018-07-18 09:40:26 +00:00
|
|
|
// Copyright 2017 The Dawn Authors
|
2017-04-20 18:38:20 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2018-07-24 14:42:33 +00:00
|
|
|
#ifndef DAWNNATIVE_BUFFER_H_
|
|
|
|
#define DAWNNATIVE_BUFFER_H_
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2018-07-24 11:53:51 +00:00
|
|
|
#include "dawn_native/Error.h"
|
|
|
|
#include "dawn_native/Forward.h"
|
2018-10-15 12:54:30 +00:00
|
|
|
#include "dawn_native/ObjectBase.h"
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2018-07-25 15:03:23 +00:00
|
|
|
#include "dawn_native/dawn_platform.h"
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2019-07-19 21:51:09 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2018-07-24 14:45:45 +00:00
|
|
|
namespace dawn_native {
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2018-08-22 13:37:29 +00:00
|
|
|
MaybeError ValidateBufferDescriptor(DeviceBase* device, const BufferDescriptor* descriptor);
|
|
|
|
|
2019-08-27 08:21:39 +00:00
|
|
|
static constexpr dawn::BufferUsage kReadOnlyBufferUsages =
|
|
|
|
dawn::BufferUsage::MapRead | dawn::BufferUsage::CopySrc | dawn::BufferUsage::Index |
|
|
|
|
dawn::BufferUsage::Vertex | dawn::BufferUsage::Uniform;
|
2018-07-05 14:29:12 +00:00
|
|
|
|
2019-08-27 08:21:39 +00:00
|
|
|
static constexpr dawn::BufferUsage kWritableBufferUsages =
|
|
|
|
dawn::BufferUsage::MapWrite | dawn::BufferUsage::CopyDst | dawn::BufferUsage::Storage;
|
2018-07-05 14:29:12 +00:00
|
|
|
|
2018-10-15 12:54:30 +00:00
|
|
|
class BufferBase : public ObjectBase {
|
2019-02-13 21:26:48 +00:00
|
|
|
enum class BufferState {
|
|
|
|
Unmapped,
|
|
|
|
Mapped,
|
|
|
|
Destroyed,
|
|
|
|
};
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
public:
|
2018-08-22 13:37:29 +00:00
|
|
|
BufferBase(DeviceBase* device, const BufferDescriptor* descriptor);
|
2017-11-24 18:59:42 +00:00
|
|
|
~BufferBase();
|
|
|
|
|
2019-02-13 13:09:18 +00:00
|
|
|
static BufferBase* MakeError(DeviceBase* device);
|
2019-05-15 18:55:22 +00:00
|
|
|
static BufferBase* MakeErrorMapped(DeviceBase* device,
|
|
|
|
uint64_t size,
|
|
|
|
uint8_t** mappedPointer);
|
2019-02-13 13:09:18 +00:00
|
|
|
|
2019-06-05 18:35:31 +00:00
|
|
|
uint64_t GetSize() const;
|
2019-08-27 08:21:39 +00:00
|
|
|
dawn::BufferUsage GetUsage() const;
|
2017-11-24 18:59:42 +00:00
|
|
|
|
2019-05-15 18:55:22 +00:00
|
|
|
MaybeError MapAtCreation(uint8_t** mappedPointer);
|
|
|
|
|
2018-11-07 10:02:43 +00:00
|
|
|
MaybeError ValidateCanUseInSubmitNow() const;
|
|
|
|
|
2018-07-18 13:20:28 +00:00
|
|
|
// Dawn API
|
2019-06-06 16:19:15 +00:00
|
|
|
void SetSubData(uint32_t start, uint32_t count, const void* data);
|
2019-05-29 13:03:50 +00:00
|
|
|
void MapReadAsync(DawnBufferMapReadCallback callback, void* userdata);
|
|
|
|
void MapWriteAsync(DawnBufferMapWriteCallback callback, void* userdata);
|
2017-11-24 18:59:42 +00:00
|
|
|
void Unmap();
|
2019-02-13 21:26:48 +00:00
|
|
|
void Destroy();
|
2017-11-24 18:59:42 +00:00
|
|
|
|
|
|
|
protected:
|
2019-02-13 13:09:18 +00:00
|
|
|
BufferBase(DeviceBase* device, ObjectBase::ErrorTag tag);
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
void CallMapReadCallback(uint32_t serial,
|
2019-03-11 16:52:42 +00:00
|
|
|
DawnBufferMapAsyncStatus status,
|
2019-02-14 19:31:17 +00:00
|
|
|
const void* pointer,
|
|
|
|
uint32_t dataLength);
|
|
|
|
void CallMapWriteCallback(uint32_t serial,
|
2019-03-11 16:52:42 +00:00
|
|
|
DawnBufferMapAsyncStatus status,
|
2019-02-14 19:31:17 +00:00
|
|
|
void* pointer,
|
|
|
|
uint32_t dataLength);
|
2017-11-24 18:59:42 +00:00
|
|
|
|
2019-04-01 19:49:04 +00:00
|
|
|
void DestroyInternal();
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
private:
|
2019-05-15 18:55:22 +00:00
|
|
|
virtual MaybeError MapAtCreationImpl(uint8_t** mappedPointer) = 0;
|
2019-06-06 16:19:15 +00:00
|
|
|
virtual MaybeError SetSubDataImpl(uint32_t start, uint32_t count, const void* data);
|
2019-07-23 00:04:59 +00:00
|
|
|
virtual MaybeError MapReadAsyncImpl(uint32_t serial) = 0;
|
|
|
|
virtual MaybeError MapWriteAsyncImpl(uint32_t serial) = 0;
|
2017-11-24 18:59:42 +00:00
|
|
|
virtual void UnmapImpl() = 0;
|
2019-03-11 17:05:22 +00:00
|
|
|
virtual void DestroyImpl() = 0;
|
2017-11-24 18:59:42 +00:00
|
|
|
|
2019-06-05 18:35:31 +00:00
|
|
|
virtual bool IsMapWritable() const = 0;
|
|
|
|
MaybeError CopyFromStagingBuffer();
|
|
|
|
|
2018-07-18 19:20:07 +00:00
|
|
|
MaybeError ValidateSetSubData(uint32_t start, uint32_t count) const;
|
2019-08-27 08:21:39 +00:00
|
|
|
MaybeError ValidateMap(dawn::BufferUsage requiredUsage) const;
|
2018-07-18 19:20:07 +00:00
|
|
|
MaybeError ValidateUnmap() const;
|
2019-02-13 21:26:48 +00:00
|
|
|
MaybeError ValidateDestroy() const;
|
2018-03-21 00:56:39 +00:00
|
|
|
|
2019-04-05 20:51:29 +00:00
|
|
|
uint64_t mSize = 0;
|
2019-08-27 08:21:39 +00:00
|
|
|
dawn::BufferUsage mUsage = dawn::BufferUsage::None;
|
2017-11-24 18:59:42 +00:00
|
|
|
|
2019-03-11 16:52:42 +00:00
|
|
|
DawnBufferMapReadCallback mMapReadCallback = nullptr;
|
|
|
|
DawnBufferMapWriteCallback mMapWriteCallback = nullptr;
|
2019-05-29 13:03:50 +00:00
|
|
|
void* mMapUserdata = 0;
|
2018-03-21 00:56:39 +00:00
|
|
|
uint32_t mMapSerial = 0;
|
2017-11-24 18:59:42 +00:00
|
|
|
|
2019-06-05 18:35:31 +00:00
|
|
|
std::unique_ptr<StagingBufferBase> mStagingBuffer;
|
|
|
|
|
2019-02-13 21:26:48 +00:00
|
|
|
BufferState mState;
|
2017-04-20 18:38:20 +00:00
|
|
|
};
|
|
|
|
|
2018-07-24 14:45:45 +00:00
|
|
|
} // namespace dawn_native
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2018-07-24 14:42:33 +00:00
|
|
|
#endif // DAWNNATIVE_BUFFER_H_
|