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/Builder.h"
|
|
|
|
#include "dawn_native/Error.h"
|
|
|
|
#include "dawn_native/Forward.h"
|
|
|
|
#include "dawn_native/RefCounted.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
|
|
|
|
2018-07-24 14:45:45 +00:00
|
|
|
namespace dawn_native {
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2018-07-18 09:38:11 +00:00
|
|
|
static constexpr dawn::BufferUsageBit kReadOnlyBufferUsages =
|
|
|
|
dawn::BufferUsageBit::MapRead | dawn::BufferUsageBit::TransferSrc |
|
|
|
|
dawn::BufferUsageBit::Index | dawn::BufferUsageBit::Vertex | dawn::BufferUsageBit::Uniform;
|
2018-07-05 14:29:12 +00:00
|
|
|
|
2018-07-18 09:38:11 +00:00
|
|
|
static constexpr dawn::BufferUsageBit kWritableBufferUsages =
|
|
|
|
dawn::BufferUsageBit::MapWrite | dawn::BufferUsageBit::TransferDst |
|
|
|
|
dawn::BufferUsageBit::Storage;
|
2018-07-05 14:29:12 +00:00
|
|
|
|
2017-04-20 18:38:20 +00:00
|
|
|
class BufferBase : public RefCounted {
|
2017-11-24 18:59:42 +00:00
|
|
|
public:
|
|
|
|
BufferBase(BufferBuilder* builder);
|
|
|
|
~BufferBase();
|
|
|
|
|
|
|
|
uint32_t GetSize() const;
|
2018-07-18 09:38:11 +00:00
|
|
|
dawn::BufferUsageBit GetAllowedUsage() const;
|
2017-11-24 18:59:42 +00:00
|
|
|
|
2017-12-04 23:06:02 +00:00
|
|
|
DeviceBase* GetDevice() const;
|
2017-11-24 18:59:42 +00:00
|
|
|
|
2018-07-18 13:20:28 +00:00
|
|
|
// Dawn API
|
2017-11-24 18:59:42 +00:00
|
|
|
BufferViewBuilder* CreateBufferViewBuilder();
|
2018-02-04 16:07:02 +00:00
|
|
|
void SetSubData(uint32_t start, uint32_t count, const uint8_t* data);
|
2017-11-24 18:59:42 +00:00
|
|
|
void MapReadAsync(uint32_t start,
|
|
|
|
uint32_t size,
|
2018-07-18 13:12:52 +00:00
|
|
|
dawnBufferMapReadCallback callback,
|
|
|
|
dawnCallbackUserdata userdata);
|
2018-03-21 00:56:39 +00:00
|
|
|
void MapWriteAsync(uint32_t start,
|
|
|
|
uint32_t size,
|
2018-07-18 13:12:52 +00:00
|
|
|
dawnBufferMapWriteCallback callback,
|
|
|
|
dawnCallbackUserdata userdata);
|
2017-11-24 18:59:42 +00:00
|
|
|
void Unmap();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void CallMapReadCallback(uint32_t serial,
|
2018-07-18 13:12:52 +00:00
|
|
|
dawnBufferMapAsyncStatus status,
|
2017-11-24 18:59:42 +00:00
|
|
|
const void* pointer);
|
2018-07-18 13:12:52 +00:00
|
|
|
void CallMapWriteCallback(uint32_t serial, dawnBufferMapAsyncStatus status, void* pointer);
|
2017-11-24 18:59:42 +00:00
|
|
|
|
|
|
|
private:
|
2018-02-04 16:07:02 +00:00
|
|
|
virtual void SetSubDataImpl(uint32_t start, uint32_t count, const uint8_t* data) = 0;
|
2017-11-24 18:59:42 +00:00
|
|
|
virtual void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t size) = 0;
|
2018-03-21 00:56:39 +00:00
|
|
|
virtual void MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t size) = 0;
|
2017-11-24 18:59:42 +00:00
|
|
|
virtual void UnmapImpl() = 0;
|
|
|
|
|
2018-07-18 19:20:07 +00:00
|
|
|
MaybeError ValidateSetSubData(uint32_t start, uint32_t count) const;
|
|
|
|
MaybeError ValidateMap(uint32_t start,
|
|
|
|
uint32_t size,
|
|
|
|
dawn::BufferUsageBit requiredUsage) const;
|
|
|
|
MaybeError ValidateUnmap() const;
|
2018-03-21 00:56:39 +00:00
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
DeviceBase* mDevice;
|
|
|
|
uint32_t mSize;
|
2018-07-18 09:38:11 +00:00
|
|
|
dawn::BufferUsageBit mAllowedUsage = dawn::BufferUsageBit::None;
|
2017-11-24 18:59:42 +00:00
|
|
|
|
2018-07-18 13:12:52 +00:00
|
|
|
dawnBufferMapReadCallback mMapReadCallback = nullptr;
|
|
|
|
dawnBufferMapWriteCallback mMapWriteCallback = nullptr;
|
|
|
|
dawnCallbackUserdata mMapUserdata = 0;
|
2018-03-21 00:56:39 +00:00
|
|
|
uint32_t mMapSerial = 0;
|
2017-11-24 18:59:42 +00:00
|
|
|
|
|
|
|
bool mIsMapped = false;
|
2017-04-20 18:38:20 +00:00
|
|
|
};
|
|
|
|
|
2017-05-08 13:17:44 +00:00
|
|
|
class BufferBuilder : public Builder<BufferBase> {
|
2017-11-24 18:59:42 +00:00
|
|
|
public:
|
|
|
|
BufferBuilder(DeviceBase* device);
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2018-07-18 13:20:28 +00:00
|
|
|
// Dawn API
|
2018-07-18 09:38:11 +00:00
|
|
|
void SetAllowedUsage(dawn::BufferUsageBit usage);
|
|
|
|
void SetInitialUsage(dawn::BufferUsageBit usage);
|
2017-11-24 18:59:42 +00:00
|
|
|
void SetSize(uint32_t size);
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
private:
|
|
|
|
friend class BufferBase;
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
BufferBase* GetResultImpl() override;
|
2017-05-08 13:17:44 +00:00
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
uint32_t mSize;
|
2018-07-18 09:38:11 +00:00
|
|
|
dawn::BufferUsageBit mAllowedUsage = dawn::BufferUsageBit::None;
|
|
|
|
dawn::BufferUsageBit mCurrentUsage = dawn::BufferUsageBit::None;
|
2017-11-24 18:59:42 +00:00
|
|
|
int mPropertiesSet = 0;
|
2017-04-20 18:38:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class BufferViewBase : public RefCounted {
|
2017-11-24 18:59:42 +00:00
|
|
|
public:
|
|
|
|
BufferViewBase(BufferViewBuilder* builder);
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
BufferBase* GetBuffer();
|
|
|
|
uint32_t GetSize() const;
|
|
|
|
uint32_t GetOffset() const;
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
private:
|
|
|
|
Ref<BufferBase> mBuffer;
|
|
|
|
uint32_t mSize;
|
|
|
|
uint32_t mOffset;
|
2017-04-20 18:38:20 +00:00
|
|
|
};
|
|
|
|
|
2017-05-08 13:17:44 +00:00
|
|
|
class BufferViewBuilder : public Builder<BufferViewBase> {
|
2017-11-24 18:59:42 +00:00
|
|
|
public:
|
|
|
|
BufferViewBuilder(DeviceBase* device, BufferBase* buffer);
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2018-07-18 13:20:28 +00:00
|
|
|
// Dawn API
|
2017-11-24 18:59:42 +00:00
|
|
|
void SetExtent(uint32_t offset, uint32_t size);
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
private:
|
|
|
|
friend class BufferViewBase;
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
BufferViewBase* GetResultImpl() override;
|
2017-05-08 13:17:44 +00:00
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
Ref<BufferBase> mBuffer;
|
|
|
|
uint32_t mOffset = 0;
|
|
|
|
uint32_t mSize = 0;
|
|
|
|
int mPropertiesSet = 0;
|
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_
|