From 02b4873ab088e0d5a6f475fcbc116d30f29d1920 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Wed, 3 Aug 2016 08:14:30 -0700 Subject: [PATCH] Use move constructor for building buffer shadow updates --- libraries/gpu/src/gpu/Batch.cpp | 4 ++-- libraries/gpu/src/gpu/Frame.cpp | 6 ++---- libraries/gpu/src/gpu/Resource.cpp | 18 ++++++++++++++++-- libraries/gpu/src/gpu/Resource.h | 6 +++--- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/libraries/gpu/src/gpu/Batch.cpp b/libraries/gpu/src/gpu/Batch.cpp index 1848f9a18b..d0193024e4 100644 --- a/libraries/gpu/src/gpu/Batch.cpp +++ b/libraries/gpu/src/gpu/Batch.cpp @@ -636,7 +636,7 @@ void Batch::finish(BufferUpdates& updates) { if (!buffer || !buffer->isDirty()) { continue; } - updates.push_back({ buffer, buffer->getUpdate() }); + updates.emplace_back(buffer->getUpdate()); } } @@ -645,7 +645,7 @@ void Batch::finish(BufferUpdates& updates) { if (!buffer || !buffer->isDirty()) { continue; } - updates.push_back({ buffer, buffer->getUpdate() }); + updates.emplace_back(buffer->getUpdate()); } } diff --git a/libraries/gpu/src/gpu/Frame.cpp b/libraries/gpu/src/gpu/Frame.cpp index dbefa46c7a..b30fe4705a 100644 --- a/libraries/gpu/src/gpu/Frame.cpp +++ b/libraries/gpu/src/gpu/Frame.cpp @@ -34,10 +34,8 @@ void Frame::finish() { } void Frame::preRender() { - for (auto& bufferUpdate : bufferUpdates) { - const BufferPointer& buffer = bufferUpdate.first; - const Buffer::Update& update = bufferUpdate.second; - buffer->applyUpdate(update); + for (auto& update : bufferUpdates) { + update.apply(); } bufferUpdates.clear(); } diff --git a/libraries/gpu/src/gpu/Resource.cpp b/libraries/gpu/src/gpu/Resource.cpp index 4558dd1311..b23956e50a 100644 --- a/libraries/gpu/src/gpu/Resource.cpp +++ b/libraries/gpu/src/gpu/Resource.cpp @@ -410,6 +410,22 @@ void Buffer::markDirty(Size offset, Size bytes) { _pages.markRegion(offset, bytes); } +extern bool isRenderThread(); + +Buffer::Update::Update(const Update& other) : + buffer(other.buffer), + updateNumber(other.updateNumber), + size(other.size), + dirtyPages(other.dirtyPages), + dirtyData(other.dirtyData) { } + +Buffer::Update::Update(Update&& other) : + buffer(other.buffer), + updateNumber(other.updateNumber), + size(other.size), + dirtyPages(std::move(other.dirtyPages)), + dirtyData(std::move(other.dirtyData)) { } + Buffer::Update::Update(const Buffer& parent) : buffer(parent) { const auto pageSize = buffer._pages._pageSize; updateNumber = ++buffer._getUpdateCount; @@ -426,8 +442,6 @@ Buffer::Update::Update(const Buffer& parent) : buffer(parent) { } } -extern bool isRenderThread(); - void Buffer::Update::apply() const { // Make sure we're loaded in order ++buffer._applyUpdateCount; diff --git a/libraries/gpu/src/gpu/Resource.h b/libraries/gpu/src/gpu/Resource.h index 1fd02018bd..96d7b9d2aa 100644 --- a/libraries/gpu/src/gpu/Resource.h +++ b/libraries/gpu/src/gpu/Resource.h @@ -159,12 +159,13 @@ public: class Update { public: Update(const Buffer& buffer); + Update(const Update& other); + Update(Update&& other); void apply() const; private: const Buffer& buffer; size_t updateNumber; - //PageManager pages; Size size; PageManager::Pages dirtyPages; std::vector dirtyData; @@ -284,8 +285,7 @@ public: friend class Frame; }; -using BufferUpdate = std::pair; -using BufferUpdates = std::vector; +using BufferUpdates = std::vector; typedef std::shared_ptr BufferPointer; typedef std::vector< BufferPointer > Buffers;