]> git.tdb.fi Git - libs/gl.git/commitdiff
Make Buffer::AsyncTransfer default-constructible and move-assignable
authorMikko Rasa <tdb@tdb.fi>
Mon, 27 Dec 2021 21:26:25 +0000 (23:26 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 27 Dec 2021 21:59:34 +0000 (23:59 +0200)
source/backends/opengl/buffer_backend.cpp
source/backends/vulkan/buffer_backend.cpp
source/core/buffer.cpp
source/core/buffer.h

index c59540834615c61062ccd81ad33428fe90c764c4..dc081b1c76517852a5b832a8918b06b7896b8990 100644 (file)
@@ -135,12 +135,12 @@ void OpenGLBuffer::unbind_scratch()
 
 void Buffer::AsyncTransfer::allocate()
 {
-       dest_addr = buffer.map();
+       dest_addr = buffer->map();
 }
 
 void Buffer::AsyncTransfer::finalize()
 {
-       buffer.unmap();
+       buffer->unmap();
 }
 
 } // namespace GL
index aaf415703db8158e5cba7cacd4b6d93ee294f769..750c926bf2e90c0ff5feacd7a299febaa3a453ba 100644 (file)
@@ -110,15 +110,15 @@ void VulkanBuffer::set_vulkan_object_name() const
 
 void Buffer::AsyncTransfer::allocate()
 {
-       if(buffer.can_map())
-               dest_addr = static_cast<char *>(buffer.map())+offset;
+       if(buffer->can_map())
+               dest_addr = static_cast<char *>(buffer->map())+offset;
        else
        {
-               Buffer &buf = buffer;
+               Buffer &buf = *buffer;
                size_t off = offset;
                size_t sz = size;
 
-               dest_addr = buffer.device.get_transfer_queue().prepare_transfer(&buffer, false, size,
+               dest_addr = buf.device.get_transfer_queue().prepare_transfer(buffer, false, size,
                        [&buf, off, sz](){
                                buf.device.get_synchronizer().write_buffer(buf.handle, off, sz);
                        },
@@ -136,13 +136,13 @@ void Buffer::AsyncTransfer::allocate()
 
 void Buffer::AsyncTransfer::finalize()
 {
-       if(buffer.can_map())
+       if(buffer->can_map())
        {
-               buffer.unmap();
-               buffer.device.get_synchronizer().write_buffer(buffer.handle, offset, size, true);
+               buffer->unmap();
+               buffer->device.get_synchronizer().write_buffer(buffer->handle, offset, size, true);
        }
        else
-               buffer.device.get_transfer_queue().finalize_transfer(dest_addr);
+               buffer->device.get_transfer_queue().finalize_transfer(dest_addr);
 }
 
 } // namespace GL
index b6f2e44b9e55555bebcfa08b80bf1ffeadb4a3c5..d5fc29d11635830042b1b065905c818c1d3ac79d 100644 (file)
@@ -76,7 +76,7 @@ bool Buffer::unmap()
 
 
 Buffer::AsyncTransfer::AsyncTransfer(Buffer &b, size_t o, size_t s):
-       buffer(b),
+       buffer(&b),
        offset(o),
        size(s),
        dest_addr(0)
@@ -93,6 +93,21 @@ Buffer::AsyncTransfer::AsyncTransfer(AsyncTransfer &&other):
        other.dest_addr = 0;
 }
 
+Buffer::AsyncTransfer &Buffer::AsyncTransfer::operator=(AsyncTransfer &&other)
+{
+       if(dest_addr)
+               finalize();
+
+       buffer = other.buffer;
+       offset = other.offset;
+       size = other.size;
+       dest_addr = other.dest_addr;
+
+       other.dest_addr = 0;
+
+       return *this;
+}
+
 Buffer::AsyncTransfer::~AsyncTransfer()
 {
        if(dest_addr)
index 66eb8d41fc44e76c91eddc4865b2a2f1dcb43c9d..9b1293615832a615318cf0212400c08b3af10961 100644 (file)
@@ -49,14 +49,16 @@ public:
                friend class Buffer;
 
        private:
-               Buffer &buffer;
+               Buffer *buffer = 0;
                std::size_t offset = 0;
                std::size_t size = 0;
                void *dest_addr = 0;
 
                AsyncTransfer(Buffer &, std::size_t, std::size_t);
        public:
+               AsyncTransfer() = default;
                AsyncTransfer(AsyncTransfer &&);
+               AsyncTransfer &operator=(AsyncTransfer &&);
                ~AsyncTransfer();
 
        private: