diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-04-28 16:20:34 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-04-28 16:20:34 +0300 |
commit | f383c926b43e832d1c4e2bf5cd00812a88f0c059 (patch) | |
tree | e532f7bb5f0e9e1a2ea9ec01581a908d40598699 | |
parent | f8d0b27d9d426c9998f8422cefac72584506a348 (diff) |
Cycles: De-duplicate bit magic for decoding image options in OpenCL kernel
-rw-r--r-- | intern/cycles/kernel/kernel_image_opencl.h | 51 |
1 files changed, 23 insertions, 28 deletions
diff --git a/intern/cycles/kernel/kernel_image_opencl.h b/intern/cycles/kernel/kernel_image_opencl.h index ddf56f119a8..795f2e3149f 100644 --- a/intern/cycles/kernel/kernel_image_opencl.h +++ b/intern/cycles/kernel/kernel_image_opencl.h @@ -64,26 +64,34 @@ ccl_device_inline float svm_image_texture_frac(float x, int *ix) return x - (float)i; } -ccl_device float4 kernel_tex_image_interp(KernelGlobals *kg, int id, float x, float y) +ccl_device_inline uint kernel_decode_image_interpolation(uint4 info) { - uint4 info = kernel_tex_fetch(__tex_image_packed_info, id*2); - uint width = info.x; - uint height = info.y; - uint offset = info.z; + return (info.w & (1 << 0)) ? INTERPOLATION_CLOSEST : INTERPOLATION_LINEAR; +} - /* Image Options */ - uint interpolation = (info.w & (1 << 0)) ? INTERPOLATION_CLOSEST : INTERPOLATION_LINEAR; - uint extension; +ccl_device_inline uint kernel_decode_image_extension(uint4 info) +{ if(info.w & (1 << 1)) { - extension = EXTENSION_REPEAT; + return EXTENSION_REPEAT; } else if(info.w & (1 << 2)) { - extension = EXTENSION_EXTEND; + return EXTENSION_EXTEND; } else { - extension = EXTENSION_CLIP; + return EXTENSION_CLIP; } +} +ccl_device float4 kernel_tex_image_interp(KernelGlobals *kg, int id, float x, float y) +{ + uint4 info = kernel_tex_fetch(__tex_image_packed_info, id*2); + uint width = info.x; + uint height = info.y; + uint offset = info.z; + /* Decode image options. */ + uint interpolation = kernel_decode_image_interpolation(info); + uint extension = kernel_decode_image_extension(info); + /* Actual sampling. */ float4 r; int ix, iy, nix, niy; if(interpolation == INTERPOLATION_CLOSEST) { @@ -136,7 +144,6 @@ ccl_device float4 kernel_tex_image_interp(KernelGlobals *kg, int id, float x, fl r += ty*(1.0f - tx)*svm_image_texture_read(kg, id, offset + ix + niy*width); r += ty*tx*svm_image_texture_read(kg, id, offset + nix + niy*width); } - return r; } @@ -148,20 +155,10 @@ ccl_device float4 kernel_tex_image_interp_3d(KernelGlobals *kg, int id, float x, uint height = info.y; uint offset = info.z; uint depth = kernel_tex_fetch(__tex_image_packed_info, id*2+1).x; - - /* Image Options */ - uint interpolation = (info.w & (1 << 0)) ? INTERPOLATION_CLOSEST : INTERPOLATION_LINEAR; - uint extension; - if(info.w & (1 << 1)) { - extension = EXTENSION_REPEAT; - } - else if(info.w & (1 << 2)) { - extension = EXTENSION_EXTEND; - } - else { - extension = EXTENSION_CLIP; - } - + /* Decode image options. */ + uint interpolation = kernel_decode_image_interpolation(info); + uint extension = kernel_decode_image_extension(info); + /* Actual sampling. */ float4 r; int ix, iy, iz, nix, niy, niz; if(interpolation == INTERPOLATION_CLOSEST) { @@ -232,8 +229,6 @@ ccl_device float4 kernel_tex_image_interp_3d(KernelGlobals *kg, int id, float x, r += tz*(1.0f - ty)*tx*svm_image_texture_read(kg, id, offset + nix + iy*width + niz*width*height); r += tz*ty*(1.0f - tx)*svm_image_texture_read(kg, id, offset + ix + niy*width + niz*width*height); r += tz*ty*tx*svm_image_texture_read(kg, id, offset + nix + niy*width + niz*width*height); - } - return r; } |