diff options
author | Stefan Werner <stewreo@gmail.com> | 2017-04-27 10:34:51 +0300 |
---|---|---|
committer | Stefan Werner <stewreo@gmail.com> | 2017-04-27 10:35:22 +0300 |
commit | ec25060a05e394560ec92388b347c45bd9eba0ed (patch) | |
tree | 86bef3c575358707945b35fe8c155848bb9465c8 /intern/cycles/kernel/kernels/cpu | |
parent | a6b9bd023b18d8fbf75da6b886312f1ba41302fd (diff) |
Unlimited number of textures for Cycles
This patch allows for an unlimited number of textures in Cycles where the hardware allows. It replaces a number static arrays with dynamic arrays and changes the way the flat_slot indices are calculated. Eventually, I'd like to get to a point where there are only flat slots left and textures off all kinds are stored in a single array.
Note that the arrays in DeviceScene are changed from containing device_vector<T> objects to device_vector<T>* pointers. Ideally, I'd like to store objects, but dynamic resizing of a std:vector in pre-C++11 calls the copy constructor, which for a good reason is not implemented for device_vector. Once we require C++11 for Cycles builds, we can implement a move constructor for device_vector and store objects again.
The limits for CUDA Fermi hardware still apply.
Reviewers: tod_baudais, InsigMathK, dingto, #cycles
Reviewed By: dingto, #cycles
Subscribers: dingto, smellslikedonkey
Differential Revision: https://developer.blender.org/D2650
Diffstat (limited to 'intern/cycles/kernel/kernels/cpu')
-rw-r--r-- | intern/cycles/kernel/kernels/cpu/kernel.cpp | 52 | ||||
-rw-r--r-- | intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h | 82 |
2 files changed, 80 insertions, 54 deletions
diff --git a/intern/cycles/kernel/kernels/cpu/kernel.cpp b/intern/cycles/kernel/kernels/cpu/kernel.cpp index 16992c681e6..db2de6836d3 100644 --- a/intern/cycles/kernel/kernels/cpu/kernel.cpp +++ b/intern/cycles/kernel/kernels/cpu/kernel.cpp @@ -95,9 +95,12 @@ void kernel_tex_copy(KernelGlobals *kg, else if(strstr(name, "__tex_image_float4")) { texture_image_float4 *tex = NULL; int id = atoi(name + strlen("__tex_image_float4_")); - int array_index = id; + int array_index = kernel_tex_index(id); - if(array_index >= 0 && array_index < TEX_NUM_FLOAT4_CPU) { + if(array_index >= 0) { + if(array_index >= kg->texture_float4_images.size()) { + kg->texture_float4_images.resize(array_index+1); + } tex = &kg->texture_float4_images[array_index]; } @@ -111,9 +114,12 @@ void kernel_tex_copy(KernelGlobals *kg, else if(strstr(name, "__tex_image_float")) { texture_image_float *tex = NULL; int id = atoi(name + strlen("__tex_image_float_")); - int array_index = id - TEX_START_FLOAT_CPU; - - if(array_index >= 0 && array_index < TEX_NUM_FLOAT_CPU) { + int array_index = kernel_tex_index(id); + + if(array_index >= 0) { + if(array_index >= kg->texture_float_images.size()) { + kg->texture_float_images.resize(array_index+1); + } tex = &kg->texture_float_images[array_index]; } @@ -127,9 +133,12 @@ void kernel_tex_copy(KernelGlobals *kg, else if(strstr(name, "__tex_image_byte4")) { texture_image_uchar4 *tex = NULL; int id = atoi(name + strlen("__tex_image_byte4_")); - int array_index = id - TEX_START_BYTE4_CPU; - - if(array_index >= 0 && array_index < TEX_NUM_BYTE4_CPU) { + int array_index = kernel_tex_index(id); + + if(array_index >= 0) { + if(array_index >= kg->texture_byte4_images.size()) { + kg->texture_byte4_images.resize(array_index+1); + } tex = &kg->texture_byte4_images[array_index]; } @@ -143,9 +152,12 @@ void kernel_tex_copy(KernelGlobals *kg, else if(strstr(name, "__tex_image_byte")) { texture_image_uchar *tex = NULL; int id = atoi(name + strlen("__tex_image_byte_")); - int array_index = id - TEX_START_BYTE_CPU; - - if(array_index >= 0 && array_index < TEX_NUM_BYTE_CPU) { + int array_index = kernel_tex_index(id); + + if(array_index >= 0) { + if(array_index >= kg->texture_byte_images.size()) { + kg->texture_byte_images.resize(array_index+1); + } tex = &kg->texture_byte_images[array_index]; } @@ -159,9 +171,12 @@ void kernel_tex_copy(KernelGlobals *kg, else if(strstr(name, "__tex_image_half4")) { texture_image_half4 *tex = NULL; int id = atoi(name + strlen("__tex_image_half4_")); - int array_index = id - TEX_START_HALF4_CPU; - - if(array_index >= 0 && array_index < TEX_NUM_HALF4_CPU) { + int array_index = kernel_tex_index(id); + + if(array_index >= 0) { + if(array_index >= kg->texture_half4_images.size()) { + kg->texture_half4_images.resize(array_index+1); + } tex = &kg->texture_half4_images[array_index]; } @@ -175,9 +190,12 @@ void kernel_tex_copy(KernelGlobals *kg, else if(strstr(name, "__tex_image_half")) { texture_image_half *tex = NULL; int id = atoi(name + strlen("__tex_image_half_")); - int array_index = id - TEX_START_HALF_CPU; - - if(array_index >= 0 && array_index < TEX_NUM_HALF_CPU) { + int array_index = kernel_tex_index(id); + + if(array_index >= 0) { + if(array_index >= kg->texture_half_images.size()) { + kg->texture_half_images.resize(array_index+1); + } tex = &kg->texture_half_images[array_index]; } diff --git a/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h b/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h index af68907a5c2..f6bb4c25012 100644 --- a/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h +++ b/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h @@ -23,51 +23,59 @@ CCL_NAMESPACE_BEGIN ccl_device float4 kernel_tex_image_interp_impl(KernelGlobals *kg, int tex, float x, float y) { - if(tex >= TEX_START_HALF_CPU) - return kg->texture_half_images[tex - TEX_START_HALF_CPU].interp(x, y); - else if(tex >= TEX_START_BYTE_CPU) - return kg->texture_byte_images[tex - TEX_START_BYTE_CPU].interp(x, y); - else if(tex >= TEX_START_FLOAT_CPU) - return kg->texture_float_images[tex - TEX_START_FLOAT_CPU].interp(x, y); - else if(tex >= TEX_START_HALF4_CPU) - return kg->texture_half4_images[tex - TEX_START_HALF4_CPU].interp(x, y); - else if(tex >= TEX_START_BYTE4_CPU) - return kg->texture_byte4_images[tex - TEX_START_BYTE4_CPU].interp(x, y); - else - return kg->texture_float4_images[tex].interp(x, y); + switch(kernel_tex_type(tex)) { + case IMAGE_DATA_TYPE_HALF: + return kg->texture_half_images[kernel_tex_index(tex)].interp(x, y); + case IMAGE_DATA_TYPE_BYTE: + return kg->texture_byte_images[kernel_tex_index(tex)].interp(x, y); + case IMAGE_DATA_TYPE_FLOAT: + return kg->texture_float_images[kernel_tex_index(tex)].interp(x, y); + case IMAGE_DATA_TYPE_HALF4: + return kg->texture_half4_images[kernel_tex_index(tex)].interp(x, y); + case IMAGE_DATA_TYPE_BYTE4: + return kg->texture_byte4_images[kernel_tex_index(tex)].interp(x, y); + case IMAGE_DATA_TYPE_FLOAT4: + default: + return kg->texture_float4_images[kernel_tex_index(tex)].interp(x, y); + } } ccl_device float4 kernel_tex_image_interp_3d_impl(KernelGlobals *kg, int tex, float x, float y, float z) { - if(tex >= TEX_START_HALF_CPU) - return kg->texture_half_images[tex - TEX_START_HALF_CPU].interp_3d(x, y, z); - else if(tex >= TEX_START_BYTE_CPU) - return kg->texture_byte_images[tex - TEX_START_BYTE_CPU].interp_3d(x, y, z); - else if(tex >= TEX_START_FLOAT_CPU) - return kg->texture_float_images[tex - TEX_START_FLOAT_CPU].interp_3d(x, y, z); - else if(tex >= TEX_START_HALF4_CPU) - return kg->texture_half4_images[tex - TEX_START_HALF4_CPU].interp_3d(x, y, z); - else if(tex >= TEX_START_BYTE4_CPU) - return kg->texture_byte4_images[tex - TEX_START_BYTE4_CPU].interp_3d(x, y, z); - else - return kg->texture_float4_images[tex].interp_3d(x, y, z); - + switch(kernel_tex_type(tex)) { + case IMAGE_DATA_TYPE_HALF: + return kg->texture_half_images[kernel_tex_index(tex)].interp_3d(x, y, z); + case IMAGE_DATA_TYPE_BYTE: + return kg->texture_byte_images[kernel_tex_index(tex)].interp_3d(x, y, z); + case IMAGE_DATA_TYPE_FLOAT: + return kg->texture_float_images[kernel_tex_index(tex)].interp_3d(x, y, z); + case IMAGE_DATA_TYPE_HALF4: + return kg->texture_half4_images[kernel_tex_index(tex)].interp_3d(x, y, z); + case IMAGE_DATA_TYPE_BYTE4: + return kg->texture_byte4_images[kernel_tex_index(tex)].interp_3d(x, y, z); + case IMAGE_DATA_TYPE_FLOAT4: + default: + return kg->texture_float4_images[kernel_tex_index(tex)].interp_3d(x, y, z); + } } ccl_device float4 kernel_tex_image_interp_3d_ex_impl(KernelGlobals *kg, int tex, float x, float y, float z, int interpolation) { - if(tex >= TEX_START_HALF_CPU) - return kg->texture_half_images[tex - TEX_START_HALF_CPU].interp_3d_ex(x, y, z, interpolation); - else if(tex >= TEX_START_BYTE_CPU) - return kg->texture_byte_images[tex - TEX_START_BYTE_CPU].interp_3d_ex(x, y, z, interpolation); - else if(tex >= TEX_START_FLOAT_CPU) - return kg->texture_float_images[tex - TEX_START_FLOAT_CPU].interp_3d_ex(x, y, z, interpolation); - else if(tex >= TEX_START_HALF4_CPU) - return kg->texture_half4_images[tex - TEX_START_HALF4_CPU].interp_3d_ex(x, y, z, interpolation); - else if(tex >= TEX_START_BYTE4_CPU) - return kg->texture_byte4_images[tex - TEX_START_BYTE4_CPU].interp_3d_ex(x, y, z, interpolation); - else - return kg->texture_float4_images[tex].interp_3d_ex(x, y, z, interpolation); + switch(kernel_tex_type(tex)) { + case IMAGE_DATA_TYPE_HALF: + return kg->texture_half_images[kernel_tex_index(tex)].interp_3d_ex(x, y, z, interpolation); + case IMAGE_DATA_TYPE_BYTE: + return kg->texture_byte_images[kernel_tex_index(tex)].interp_3d_ex(x, y, z, interpolation); + case IMAGE_DATA_TYPE_FLOAT: + return kg->texture_float_images[kernel_tex_index(tex)].interp_3d_ex(x, y, z, interpolation); + case IMAGE_DATA_TYPE_HALF4: + return kg->texture_half4_images[kernel_tex_index(tex)].interp_3d_ex(x, y, z, interpolation); + case IMAGE_DATA_TYPE_BYTE4: + return kg->texture_byte4_images[kernel_tex_index(tex)].interp_3d_ex(x, y, z, interpolation); + case IMAGE_DATA_TYPE_FLOAT4: + default: + return kg->texture_float4_images[kernel_tex_index(tex)].interp_3d_ex(x, y, z, interpolation); + } } CCL_NAMESPACE_END |