diff options
Diffstat (limited to 'intern/cycles/device/device_memory.cpp')
-rw-r--r-- | intern/cycles/device/device_memory.cpp | 96 |
1 files changed, 91 insertions, 5 deletions
diff --git a/intern/cycles/device/device_memory.cpp b/intern/cycles/device/device_memory.cpp index f22b91f3fa1..3c4f68cfc77 100644 --- a/intern/cycles/device/device_memory.cpp +++ b/intern/cycles/device/device_memory.cpp @@ -31,9 +31,6 @@ device_memory::device_memory(Device *device, const char *name, MemoryType type) data_depth(0), type(type), name(name), - image_data_type(IMAGE_DATA_NUM_TYPES), - interpolation(INTERPOLATION_NONE), - extension(EXTENSION_REPEAT), device(device), device_pointer(0), host_pointer(0), @@ -77,7 +74,7 @@ void device_memory::host_free() void device_memory::device_alloc() { - assert(!device_pointer && type != MEM_TEXTURE); + assert(!device_pointer && type != MEM_TEXTURE && type != MEM_GLOBAL); device->mem_alloc(*this); } @@ -97,7 +94,7 @@ void device_memory::device_copy_to() void device_memory::device_copy_from(int y, int w, int h, int elem) { - assert(type != MEM_TEXTURE && type != MEM_READ_ONLY); + assert(type != MEM_TEXTURE && type != MEM_READ_ONLY && type != MEM_GLOBAL); device->mem_copy_from(*this, y, w, h, elem); } @@ -140,4 +137,93 @@ device_sub_ptr::~device_sub_ptr() device->mem_free_sub_ptr(ptr); } +/* Device Texture */ + +device_texture::device_texture(Device *device, + const char *name, + const uint slot, + ImageDataType image_data_type, + InterpolationType interpolation, + ExtensionType extension) + : device_memory(device, name, MEM_TEXTURE), slot(slot) +{ + switch (image_data_type) { + case IMAGE_DATA_TYPE_FLOAT4: + data_type = TYPE_FLOAT; + data_elements = 4; + break; + case IMAGE_DATA_TYPE_FLOAT: + data_type = TYPE_FLOAT; + data_elements = 1; + break; + case IMAGE_DATA_TYPE_BYTE4: + data_type = TYPE_UCHAR; + data_elements = 4; + break; + case IMAGE_DATA_TYPE_BYTE: + data_type = TYPE_UCHAR; + data_elements = 1; + break; + case IMAGE_DATA_TYPE_HALF4: + data_type = TYPE_HALF; + data_elements = 4; + break; + case IMAGE_DATA_TYPE_HALF: + data_type = TYPE_HALF; + data_elements = 1; + break; + case IMAGE_DATA_TYPE_USHORT4: + data_type = TYPE_UINT16; + data_elements = 4; + break; + case IMAGE_DATA_TYPE_USHORT: + data_type = TYPE_UINT16; + data_elements = 1; + break; + case IMAGE_DATA_NUM_TYPES: + assert(0); + return; + } + + memset(&info, 0, sizeof(info)); + info.data_type = image_data_type; + info.interpolation = interpolation; + info.extension = extension; +} + +device_texture::~device_texture() +{ + device_free(); + host_free(); +} + +/* Host memory allocation. */ +void *device_texture::alloc(const size_t width, const size_t height, const size_t depth) +{ + const size_t new_size = size(width, height, depth); + + if (new_size != data_size) { + device_free(); + host_free(); + host_pointer = host_alloc(data_elements * datatype_size(data_type) * new_size); + assert(device_pointer == 0); + } + + data_size = new_size; + data_width = width; + data_height = height; + data_depth = depth; + + info.width = width; + info.height = height; + info.depth = depth; + + return host_pointer; +} + +void device_texture::copy_to_device() +{ + device_copy_to(); +} + CCL_NAMESPACE_END |