[Bf-blender-cvs] [f383c926b43] master: Cycles: De-duplicate bit magic for decoding image options in OpenCL kernel

Sergey Sharybin noreply at git.blender.org
Fri Apr 28 15:20:54 CEST 2017


Commit: f383c926b43e832d1c4e2bf5cd00812a88f0c059
Author: Sergey Sharybin
Date:   Fri Apr 28 15:20:34 2017 +0200
Branches: master
https://developer.blender.org/rBf383c926b43e832d1c4e2bf5cd00812a88f0c059

Cycles: De-duplicate bit magic for decoding image options in OpenCL kernel

===================================================================

M	intern/cycles/kernel/kernel_image_opencl.h

===================================================================

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;
 }




More information about the Bf-blender-cvs mailing list