[Bf-blender-cvs] [c32377da988] master: Cycles: support move semantics for device_memory

Patrick Mours noreply at git.blender.org
Mon Aug 26 17:45:11 CEST 2019


Commit: c32377da9888cc004cb9216383a9f1383fcf5a03
Author: Patrick Mours
Date:   Mon Aug 26 17:41:44 2019 +0200
Branches: master
https://developer.blender.org/rBc32377da9888cc004cb9216383a9f1383fcf5a03

Cycles: support move semantics for device_memory

Ref D5363

===================================================================

M	intern/cycles/device/device_memory.cpp
M	intern/cycles/device/device_memory.h

===================================================================

diff --git a/intern/cycles/device/device_memory.cpp b/intern/cycles/device/device_memory.cpp
index 859535307f4..c8a71bf4b3b 100644
--- a/intern/cycles/device/device_memory.cpp
+++ b/intern/cycles/device/device_memory.cpp
@@ -44,6 +44,29 @@ device_memory::~device_memory()
 {
 }
 
+device_memory::device_memory(device_memory &&other)
+    : data_type(other.data_type),
+      data_elements(other.data_elements),
+      data_size(other.data_size),
+      device_size(other.device_size),
+      data_width(other.data_width),
+      data_height(other.data_height),
+      data_depth(other.data_depth),
+      type(other.type),
+      name(other.name),
+      interpolation(other.interpolation),
+      extension(other.extension),
+      device(other.device),
+      device_pointer(other.device_pointer),
+      host_pointer(other.host_pointer),
+      shared_pointer(other.shared_pointer)
+{
+  other.device_size = 0;
+  other.device_pointer = 0;
+  other.host_pointer = 0;
+  other.shared_pointer = 0;
+}
+
 void *device_memory::host_alloc(size_t size)
 {
   if (!size) {
diff --git a/intern/cycles/device/device_memory.h b/intern/cycles/device/device_memory.h
index f50184efba7..5b43ce8b0bc 100644
--- a/intern/cycles/device/device_memory.h
+++ b/intern/cycles/device/device_memory.h
@@ -229,8 +229,11 @@ class device_memory {
   device_memory(Device *device, const char *name, MemoryType type);
 
   /* No copying allowed. */
-  device_memory(const device_memory &);
-  device_memory &operator=(const device_memory &);
+  device_memory(const device_memory &) = delete;
+  device_memory &operator=(const device_memory &) = delete;
+
+  /* But moving is possible. */
+  device_memory(device_memory &&);
 
   /* Host allocation on the device. All host_pointer memory should be
    * allocated with these functions, for devices that support using
@@ -269,6 +272,11 @@ template<typename T> class device_only_memory : public device_memory {
     free();
   }
 
+  device_only_memory(device_only_memory &&other)
+      : device_memory(static_cast<device_memory &&>(other))
+  {
+  }
+
   void alloc_to_device(size_t num, bool shrink_to_fit = true)
   {
     size_t new_size = num;
@@ -327,6 +335,10 @@ template<typename T> class device_vector : public device_memory {
     free();
   }
 
+  device_vector(device_vector &&other) : device_memory(static_cast<device_memory &&>(other))
+  {
+  }
+
   /* Host memory allocation. */
   T *alloc(size_t width, size_t height = 0, size_t depth = 0)
   {



More information about the Bf-blender-cvs mailing list