Add Create/ReleaseStagingBuffer to DynamicUploader

StagingBuffers need to be created and explicitly released outside of
the RingBuffer for CreateBufferMapped since the staging buffer must live
until the Buffer is Unmapped or Destroyed. This patch adds methods to the
DynamicUploaded for creating and tracking the release of StagingBuffers.

This patch also fixes SerialQueue for non-copy-constructible types.

Bug: dawn:7
Change-Id: I582c4d9cf452f808a8a7ab4164ff833087619a18
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/7720
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Austin Eng 2019-06-05 16:16:37 +00:00 committed by Commit Bot service account
parent b632bc58ed
commit 233ce73c50
3 changed files with 29 additions and 7 deletions

View File

@ -54,9 +54,9 @@ void SerialQueue<T>::Enqueue(const T& value, Serial serial) {
DAWN_ASSERT(this->Empty() || this->mStorage.back().first <= serial);
if (this->Empty() || this->mStorage.back().first < serial) {
this->mStorage.emplace_back(SerialPair(serial, {}));
this->mStorage.emplace_back(serial, std::vector<T>{});
}
this->mStorage.back().second.emplace_back(value);
this->mStorage.back().second.push_back(value);
}
template <typename T>
@ -64,23 +64,23 @@ void SerialQueue<T>::Enqueue(T&& value, Serial serial) {
DAWN_ASSERT(this->Empty() || this->mStorage.back().first <= serial);
if (this->Empty() || this->mStorage.back().first < serial) {
this->mStorage.emplace_back(SerialPair(serial, {}));
this->mStorage.emplace_back(serial, std::vector<T>{});
}
this->mStorage.back().second.emplace_back(value);
this->mStorage.back().second.push_back(std::move(value));
}
template <typename T>
void SerialQueue<T>::Enqueue(const std::vector<T>& values, Serial serial) {
DAWN_ASSERT(values.size() > 0);
DAWN_ASSERT(this->Empty() || this->mStorage.back().first <= serial);
this->mStorage.emplace_back(SerialPair(serial, {values}));
this->mStorage.emplace_back(serial, values);
}
template <typename T>
void SerialQueue<T>::Enqueue(std::vector<T>&& values, Serial serial) {
DAWN_ASSERT(values.size() > 0);
DAWN_ASSERT(this->Empty() || this->mStorage.back().first <= serial);
this->mStorage.emplace_back(SerialPair(serial, {values}));
this->mStorage.emplace_back(serial, values);
}
#endif // COMMON_SERIALQUEUE_H_

View File

@ -21,6 +21,19 @@ namespace dawn_native {
DynamicUploader::DynamicUploader(DeviceBase* device) : mDevice(device) {
}
ResultOrError<std::unique_ptr<StagingBufferBase>> DynamicUploader::CreateStagingBuffer(
size_t size) {
std::unique_ptr<StagingBufferBase> stagingBuffer;
DAWN_TRY_ASSIGN(stagingBuffer, mDevice->CreateStagingBuffer(size));
DAWN_TRY(stagingBuffer->Initialize());
return stagingBuffer;
}
void DynamicUploader::ReleaseStagingBuffer(std::unique_ptr<StagingBufferBase> stagingBuffer) {
mReleasedStagingBuffers.Enqueue(std::move(stagingBuffer),
mDevice->GetPendingCommandSerial());
}
MaybeError DynamicUploader::CreateAndAppendBuffer(size_t size) {
std::unique_ptr<RingBuffer> ringBuffer = std::make_unique<RingBuffer>(mDevice, size);
DAWN_TRY(ringBuffer->Initialize());
@ -69,6 +82,7 @@ namespace dawn_native {
mRingBuffers.erase(mRingBuffers.begin() + i);
}
}
mReleasedStagingBuffers.ClearUpTo(lastCompletedSerial);
}
RingBuffer* DynamicUploader::GetLargestBuffer() {

View File

@ -27,6 +27,13 @@ namespace dawn_native {
DynamicUploader(DeviceBase* device);
~DynamicUploader() = default;
// We add functions to Create/Release StagingBuffers to the DynamicUploader as there's
// currently no place to track the allocated staging buffers such that they're freed after
// pending coommands are finished. This should be changed when better resource allocation is
// implemented.
ResultOrError<std::unique_ptr<StagingBufferBase>> CreateStagingBuffer(size_t size);
void ReleaseStagingBuffer(std::unique_ptr<StagingBufferBase> stagingBuffer);
ResultOrError<UploadHandle> Allocate(uint32_t requiredSize, uint32_t alignment);
void Tick(Serial lastCompletedSerial);
@ -41,6 +48,7 @@ namespace dawn_native {
static constexpr size_t kBaseUploadBufferSize = 64000;
std::vector<std::unique_ptr<RingBuffer>> mRingBuffers;
SerialQueue<std::unique_ptr<StagingBufferBase>> mReleasedStagingBuffers;
DeviceBase* mDevice;
};
} // namespace dawn_native