diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2017-10-21 02:09:59 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2017-10-24 02:25:19 +0300 |
commit | 070a668d04844610059aaedc80c49e9038fd1779 (patch) | |
tree | cad5c64972e45b4ee19cc8e11cdd9adedd7a2f08 /intern/cycles/device/device_memory.cpp | |
parent | aa8b4c5d8124c0379eeee9eacd1a0887a573d7d7 (diff) |
Code refactor: move more memory allocation logic into device API.
* Remove tex_* and pixels_* functions, replace by mem_*.
* Add MEM_TEXTURE and MEM_PIXELS as memory types recognized by devices.
* No longer create device_memory and call mem_* directly, always go
through device_only_memory, device_vector and device_pixels.
Diffstat (limited to 'intern/cycles/device/device_memory.cpp')
-rw-r--r-- | intern/cycles/device/device_memory.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/intern/cycles/device/device_memory.cpp b/intern/cycles/device/device_memory.cpp index 98fa638ef8e..9f4f60e7531 100644 --- a/intern/cycles/device/device_memory.cpp +++ b/intern/cycles/device/device_memory.cpp @@ -43,6 +43,68 @@ device_memory::~device_memory() { } +device_ptr device_memory::host_alloc(size_t size) +{ + if(!size) { + return 0; + } + + size_t alignment = device->mem_address_alignment(); + device_ptr ptr = (device_ptr)util_aligned_malloc(size, alignment); + + if(ptr) { + util_guarded_mem_alloc(size); + } + else { + throw std::bad_alloc(); + } + + return ptr; +} + +void device_memory::host_free(device_ptr ptr, size_t size) +{ + if(ptr) { + util_guarded_mem_free(size); + util_aligned_free((void*)ptr); + } +} + +void device_memory::device_alloc() +{ + assert(!device_pointer && type != MEM_TEXTURE); + device->mem_alloc(*this); +} + +void device_memory::device_free() +{ + if(device_pointer) { + device->mem_free(*this); + } +} + +void device_memory::device_copy_to() +{ + assert(type != MEM_PIXELS && type != MEM_WRITE_ONLY); + if(data_size) { + device->mem_copy_to(*this); + } +} + +void device_memory::device_copy_from(int y, int w, int h, int elem) +{ + assert(type != MEM_TEXTURE && type != MEM_READ_ONLY); + device->mem_copy_from(*this, y, w, h, elem); +} + +void device_memory::device_zero() +{ + assert(type != MEM_PIXELS && type != MEM_WRITE_ONLY); + if(data_size) { + device->mem_zero(*this); + } +} + /* Device Sub Ptr */ device_sub_ptr::device_sub_ptr(device_memory& mem, int offset, int size) |