diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2017-10-06 22:47:41 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2017-10-07 15:53:14 +0300 |
commit | 23098cda9936d785988b689ee69e58e900f17cb2 (patch) | |
tree | ed49843e81afbe9c38707324f37bf7e14b234a9b /intern/cycles/device/opencl | |
parent | d013b56dde47580d1907e3a994bc49cfaaa9f90c (diff) |
Code refactor: make texture code more consistent between devices.
* Use common TextureInfo struct for all devices, except CUDA fermi.
* Move image sampling code to kernels/*/kernel_*_image.h files.
* Use arrays for data textures on Fermi too, so device_vector<Struct> works.
Diffstat (limited to 'intern/cycles/device/opencl')
-rw-r--r-- | intern/cycles/device/opencl/opencl.h | 11 | ||||
-rw-r--r-- | intern/cycles/device/opencl/opencl_base.cpp | 53 | ||||
-rw-r--r-- | intern/cycles/device/opencl/opencl_split.cpp | 10 |
3 files changed, 23 insertions, 51 deletions
diff --git a/intern/cycles/device/opencl/opencl.h b/intern/cycles/device/opencl/opencl.h index 26bf4a9af5b..bd956e29083 100644 --- a/intern/cycles/device/opencl/opencl.h +++ b/intern/cycles/device/opencl/opencl.h @@ -545,15 +545,10 @@ private: MemoryManager memory_manager; friend class MemoryManager; - struct tex_info_t { - uint buffer, padding; - cl_ulong offset; - uint width, height, depth, options; - }; - static_assert_align(tex_info_t, 16); + static_assert_align(TextureInfo, 16); - vector<tex_info_t> texture_descriptors; - device_memory texture_descriptors_buffer; + vector<TextureInfo> texture_info; + device_memory texture_info_buffer; struct Texture { Texture() {} diff --git a/intern/cycles/device/opencl/opencl_base.cpp b/intern/cycles/device/opencl/opencl_base.cpp index 3db3efd1103..486ef89d22e 100644 --- a/intern/cycles/device/opencl/opencl_base.cpp +++ b/intern/cycles/device/opencl/opencl_base.cpp @@ -136,11 +136,11 @@ OpenCLDeviceBase::OpenCLDeviceBase(DeviceInfo& info, Stats &stats, bool backgrou return; } - /* Allocate this right away so that texture_descriptors_buffer is placed at offset 0 in the device memory buffers */ - texture_descriptors.resize(1); - texture_descriptors_buffer.resize(1); - texture_descriptors_buffer.data_pointer = (device_ptr)&texture_descriptors[0]; - memory_manager.alloc("texture_descriptors", texture_descriptors_buffer); + /* Allocate this right away so that texture_info_buffer is placed at offset 0 in the device memory buffers */ + texture_info.resize(1); + texture_info_buffer.resize(1); + texture_info_buffer.data_pointer = (device_ptr)&texture_info[0]; + memory_manager.alloc("texture_info", texture_info_buffer); fprintf(stderr, "Device init success\n"); device_initialized = true; @@ -625,7 +625,7 @@ void OpenCLDeviceBase::flush_texture_buffers() vector<texture_slot_t> texture_slots; -#define KERNEL_TEX(type, ttype, name) \ +#define KERNEL_TEX(type, name) \ if(textures.find(#name) != textures.end()) { \ texture_slots.push_back(texture_slot_t(#name, num_slots)); \ } \ @@ -647,55 +647,38 @@ void OpenCLDeviceBase::flush_texture_buffers() } /* Realloc texture descriptors buffer. */ - memory_manager.free(texture_descriptors_buffer); + memory_manager.free(texture_info_buffer); - texture_descriptors.resize(num_slots); - texture_descriptors_buffer.resize(num_slots * sizeof(tex_info_t)); - texture_descriptors_buffer.data_pointer = (device_ptr)&texture_descriptors[0]; + texture_info.resize(num_slots); + texture_info_buffer.resize(num_slots * sizeof(TextureInfo)); + texture_info_buffer.data_pointer = (device_ptr)&texture_info[0]; - memory_manager.alloc("texture_descriptors", texture_descriptors_buffer); + memory_manager.alloc("texture_info", texture_info_buffer); /* Fill in descriptors */ foreach(texture_slot_t& slot, texture_slots) { Texture& tex = textures[slot.name]; - tex_info_t& info = texture_descriptors[slot.slot]; + TextureInfo& info = texture_info[slot.slot]; MemoryManager::BufferDescriptor desc = memory_manager.get_descriptor(slot.name); - info.offset = desc.offset; - info.buffer = desc.device_buffer; + info.data = desc.offset; + info.cl_buffer = desc.device_buffer; if(string_startswith(slot.name, "__tex_image")) { info.width = tex.mem->data_width; info.height = tex.mem->data_height; info.depth = tex.mem->data_depth; - info.options = 0; - - if(tex.interpolation == INTERPOLATION_CLOSEST) { - info.options |= (1 << 0); - } - - switch(tex.extension) { - case EXTENSION_REPEAT: - info.options |= (1 << 1); - break; - case EXTENSION_EXTEND: - info.options |= (1 << 2); - break; - case EXTENSION_CLIP: - info.options |= (1 << 3); - break; - default: - break; - } + info.interpolation = tex.interpolation; + info.extension = tex.extension; } } /* Force write of descriptors. */ - memory_manager.free(texture_descriptors_buffer); - memory_manager.alloc("texture_descriptors", texture_descriptors_buffer); + memory_manager.free(texture_info_buffer); + memory_manager.alloc("texture_info", texture_info_buffer); } void OpenCLDeviceBase::film_convert(DeviceTask& task, device_ptr buffer, device_ptr rgba_byte, device_ptr rgba_half) diff --git a/intern/cycles/device/opencl/opencl_split.cpp b/intern/cycles/device/opencl/opencl_split.cpp index 976cc9df46d..b4e9419ebbd 100644 --- a/intern/cycles/device/opencl/opencl_split.cpp +++ b/intern/cycles/device/opencl/opencl_split.cpp @@ -117,14 +117,8 @@ public: ccl_constant KernelData *data; ccl_global char *buffers[8]; - typedef struct _tex_info_t { - uint buffer, padding; - uint64_t offset; - uint width, height, depth, options; - } _tex_info_t; - -#define KERNEL_TEX(type, ttype, name) \ - _tex_info_t name; +#define KERNEL_TEX(type, name) \ + TextureInfo name; #include "kernel/kernel_textures.h" #undef KERNEL_TEX |