diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2017-10-20 05:32:29 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2017-10-21 21:58:28 +0300 |
commit | 57a0cb797d60024357a3e3a64c1873844b0178bd (patch) | |
tree | 1f8ade576fbbc6cbbf7a41c51304ee8ae3fe95b6 /intern/cycles/device/device_memory.h | |
parent | 92ec4863c22f249a21a5b5224d91fcab5c602100 (diff) |
Code refactor: avoid some unnecessary device memory copying.
Diffstat (limited to 'intern/cycles/device/device_memory.h')
-rw-r--r-- | intern/cycles/device/device_memory.h | 36 |
1 files changed, 12 insertions, 24 deletions
diff --git a/intern/cycles/device/device_memory.h b/intern/cycles/device/device_memory.h index 20707ad04c9..eeeca61496e 100644 --- a/intern/cycles/device/device_memory.h +++ b/intern/cycles/device/device_memory.h @@ -270,31 +270,14 @@ public: return &data[0]; } - T *copy(T *ptr, size_t width, size_t height = 0, size_t depth = 0) + void steal_data(array<T>& from) { - T *mem = resize(width, height, depth); - if(mem != NULL) { - memcpy(mem, ptr, memory_size()); - } - return mem; - } - - void copy_at(T *ptr, size_t offset, size_t size) - { - if(size > 0) { - size_t mem_size = size*data_elements*datatype_size(data_type); - memcpy(&data[0] + offset, ptr, mem_size); - } - } - - void reference(T *ptr, size_t width, size_t height = 0, size_t depth = 0) - { - data.clear(); - data_size = width * ((height == 0)? 1: height) * ((depth == 0)? 1: depth); - data_pointer = (device_ptr)ptr; - data_width = width; - data_height = height; - data_depth = depth; + data.steal_data(from); + data_size = data.size(); + data_pointer = (data_size)? (device_ptr)&data[0]: 0; + data_width = data_size; + data_height = 0; + data_depth = 0; } void clear() @@ -318,6 +301,11 @@ public: return &data[0]; } + T& operator[](size_t i) + { + return data[i]; + } + private: array<T> data; }; |