diff --git a/libraries/gpu/src/gpu/Resource.cpp b/libraries/gpu/src/gpu/Resource.cpp index b4e989ff12..d78cc3c0d3 100644 --- a/libraries/gpu/src/gpu/Resource.cpp +++ b/libraries/gpu/src/gpu/Resource.cpp @@ -282,11 +282,6 @@ void Buffer::markDirty(Size offset, Size bytes) { _pages.markRegion(offset, bytes); } -void Buffer::applyUpdate(const Update& update) { - _renderPages = update.pages; - update.updateOperator(_renderSysmem); - } - Buffer::Update Buffer::getUpdate() const { static Update EMPTY_UPDATE; if (!_pages) { @@ -319,6 +314,21 @@ Buffer::Update Buffer::getUpdate() const { return result; } +void Buffer::applyUpdate(const Update& update) { + _renderPages = update.pages; + update.updateOperator(_renderSysmem); +} + +void Buffer::flush() { + _renderPages = _pages; + _renderSysmem.resize(_sysmem.getSize()); + auto dirtyPages = _pages.getMarkedPages(); + for (Size page : dirtyPages) { + Size offset = page * _pages._pageSize; + memcpy(_renderSysmem.editData() + offset, _sysmem.readData() + offset, _pages._pageSize); + } +} + Buffer::Size Buffer::setData(Size size, const Byte* data) { resize(size); setSubData(0, size, data); diff --git a/libraries/gpu/src/gpu/Resource.h b/libraries/gpu/src/gpu/Resource.h index 428a977113..d629775684 100644 --- a/libraries/gpu/src/gpu/Resource.h +++ b/libraries/gpu/src/gpu/Resource.h @@ -105,8 +105,6 @@ public: }; protected: - using Sysmem = gpu::Sysmem; - Resource() {} virtual ~Resource() {} @@ -135,7 +133,7 @@ struct PageManager { uint8 _flags{ 0 }; const Size _pageSize; - operator bool const() { + operator bool() const { return (*this)(DIRTY); } @@ -346,6 +344,11 @@ public: // Main thread operation to say that the buffer is ready to be used as a frame Update getUpdate() const; + // For use by the render thread to avoid the intermediate step of getUpdate/applyUpdate + void flush(); + + // FIXME don't maintain a second buffer continuously. We should be able to apply updates + // directly to the GL object and discard _renderSysmem and _renderPages mutable PageManager _renderPages; Sysmem _renderSysmem;