Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHristo Gueorguiev <>2016-10-23 00:38:42 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2017-01-20 13:25:03 +0300
commite2dd5f15d95bb02986c73135a4f7452457fe9a23 (patch)
treeddc6cd7450797c8cbfed2fb9006fef42d56a0f03 /intern/cycles/kernel/svm
parent7bddb79f495ebed96c9798828715b355db10f641 (diff)
Cycles: OpenCL 3d textures support.
Note that volume rendering is not supported yet, this is a step towards that. Reviewed By: brecht Differential Revision: https://developer.blender.org/D2299
Diffstat (limited to 'intern/cycles/kernel/svm')
-rw-r--r--intern/cycles/kernel/svm/svm_image.h145
-rw-r--r--intern/cycles/kernel/svm/svm_voxel.h8
2 files changed, 7 insertions, 146 deletions
diff --git a/intern/cycles/kernel/svm/svm_image.h b/intern/cycles/kernel/svm/svm_image.h
index 378ce650129..9606064492e 100644
--- a/intern/cycles/kernel/svm/svm_image.h
+++ b/intern/cycles/kernel/svm/svm_image.h
@@ -29,147 +29,6 @@ CCL_NAMESPACE_BEGIN
# define TEX_NUM_FLOAT4_IMAGES TEX_NUM_FLOAT4_OPENCL
#endif
-#ifdef __KERNEL_OPENCL__
-
-/* For OpenCL all images are packed in a single array, and we do manual lookup
- * and interpolation. */
-
-ccl_device_inline float4 svm_image_texture_read(KernelGlobals *kg, int id, int offset)
-{
- /* Float4 */
- if(id < TEX_START_BYTE4_OPENCL) {
- return kernel_tex_fetch(__tex_image_float4_packed, offset);
- }
- /* Byte4 */
- else if(id < TEX_START_FLOAT_OPENCL) {
- uchar4 r = kernel_tex_fetch(__tex_image_byte4_packed, offset);
- float f = 1.0f/255.0f;
- return make_float4(r.x*f, r.y*f, r.z*f, r.w*f);
- }
- /* Float */
- else if(id < TEX_START_BYTE_OPENCL) {
- float f = kernel_tex_fetch(__tex_image_float_packed, offset);
- return make_float4(f, f, f, 1.0f);
- }
- /* Byte */
- else {
- uchar r = kernel_tex_fetch(__tex_image_byte_packed, offset);
- float f = r * (1.0f/255.0f);
- return make_float4(f, f, f, 1.0f);
- }
-}
-
-ccl_device_inline int svm_image_texture_wrap_periodic(int x, int width)
-{
- x %= width;
- if(x < 0)
- x += width;
- return x;
-}
-
-ccl_device_inline int svm_image_texture_wrap_clamp(int x, int width)
-{
- return clamp(x, 0, width-1);
-}
-
-ccl_device_inline float svm_image_texture_frac(float x, int *ix)
-{
- int i = float_to_int(x) - ((x < 0.0f)? 1: 0);
- *ix = i;
- return x - (float)i;
-}
-
-ccl_device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y, uint srgb, uint use_alpha)
-{
- uint4 info = kernel_tex_fetch(__tex_image_packed_info, id);
- uint width = info.x;
- uint height = info.y;
- uint offset = info.z;
-
- /* 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;
-
- float4 r;
- int ix, iy, nix, niy;
- if(interpolation == INTERPOLATION_CLOSEST) {
- svm_image_texture_frac(x*width, &ix);
- svm_image_texture_frac(y*height, &iy);
-
- if(extension == EXTENSION_REPEAT) {
- ix = svm_image_texture_wrap_periodic(ix, width);
- iy = svm_image_texture_wrap_periodic(iy, height);
- }
- else if(extension == EXTENSION_CLIP) {
- if(x < 0.0f || y < 0.0f || x > 1.0f || y > 1.0f)
- return make_float4(0.0f, 0.0f, 0.0f, 0.0f);
- }
- else { /* EXTENSION_EXTEND */
- ix = svm_image_texture_wrap_clamp(ix, width);
- iy = svm_image_texture_wrap_clamp(iy, height);
- }
-
- r = svm_image_texture_read(kg, id, offset + ix + iy*width);
- }
- else { /* INTERPOLATION_LINEAR */
- float tx = svm_image_texture_frac(x*width - 0.5f, &ix);
- float ty = svm_image_texture_frac(y*height - 0.5f, &iy);
-
- if(extension == EXTENSION_REPEAT) {
- ix = svm_image_texture_wrap_periodic(ix, width);
- iy = svm_image_texture_wrap_periodic(iy, height);
-
- nix = svm_image_texture_wrap_periodic(ix+1, width);
- niy = svm_image_texture_wrap_periodic(iy+1, height);
- }
- else {
- if(extension == EXTENSION_CLIP) {
- if(x < 0.0f || y < 0.0f || x > 1.0f || y > 1.0f) {
- return make_float4(0.0f, 0.0f, 0.0f, 0.0f);
- }
- }
- nix = svm_image_texture_wrap_clamp(ix+1, width);
- niy = svm_image_texture_wrap_clamp(iy+1, height);
- ix = svm_image_texture_wrap_clamp(ix, width);
- iy = svm_image_texture_wrap_clamp(iy, height);
- }
-
- r = (1.0f - ty)*(1.0f - tx)*svm_image_texture_read(kg, id, offset + ix + iy*width);
- r += (1.0f - ty)*tx*svm_image_texture_read(kg, id, offset + nix + iy*width);
- 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);
- }
-
- if(use_alpha && r.w != 1.0f && r.w != 0.0f) {
- float invw = 1.0f/r.w;
- r.x *= invw;
- r.y *= invw;
- r.z *= invw;
-
- if(id >= TEX_NUM_FLOAT4_IMAGES) {
- r.x = min(r.x, 1.0f);
- r.y = min(r.y, 1.0f);
- r.z = min(r.z, 1.0f);
- }
- }
-
- if(srgb) {
- r.x = color_srgb_to_scene_linear(r.x);
- r.y = color_srgb_to_scene_linear(r.y);
- r.z = color_srgb_to_scene_linear(r.z);
- }
-
- return r;
-}
-
-#else
-
ccl_device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y, uint srgb, uint use_alpha)
{
#ifdef __KERNEL_CPU__
@@ -180,6 +39,8 @@ ccl_device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y,
# else
float4 r = kernel_tex_image_interp(id, x, y);
# endif
+#elif defined(__KERNEL_OPENCL__)
+ float4 r = kernel_tex_image_interp(kg, id, x, y);
#else
float4 r;
@@ -339,8 +200,6 @@ ccl_device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y,
return r;
}
-#endif
-
/* Remap coordnate from 0..1 box to -1..-1 */
ccl_device_inline float3 texco_remap_square(float3 co)
{
diff --git a/intern/cycles/kernel/svm/svm_voxel.h b/intern/cycles/kernel/svm/svm_voxel.h
index f54f4e8e888..a8b3604a8a7 100644
--- a/intern/cycles/kernel/svm/svm_voxel.h
+++ b/intern/cycles/kernel/svm/svm_voxel.h
@@ -43,7 +43,7 @@ ccl_device void svm_node_tex_voxel(KernelGlobals *kg,
co = transform_point(&tfm, co);
}
float4 r;
-# if defined(__KERNEL_GPU__)
+# if defined(__KERNEL_CUDA__)
# if __CUDA_ARCH__ >= 300
CUtexObject tex = kernel_tex_fetch(__bindless_mapping, id);
if(id < 2048) /* TODO(dingto): Make this a variable */
@@ -55,9 +55,11 @@ ccl_device void svm_node_tex_voxel(KernelGlobals *kg,
# else /* __CUDA_ARCH__ >= 300 */
r = volume_image_texture_3d(id, co.x, co.y, co.z);
# endif
-# else /* __KERNEL_GPU__ */
+# elif defined(__KERNEL_OPENCL__)
+ r = kernel_tex_image_interp_3d(kg, id, co.x, co.y, co.z);
+# else
r = kernel_tex_image_interp_3d(id, co.x, co.y, co.z);
-# endif
+# endif /* __KERNEL_CUDA__ */
#else
float4 r = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
#endif