[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [42766] trunk/blender/intern/cycles: Cycles: avoid using float3 in kernel constant memory, just so we' re sure alignment

Brecht Van Lommel brechtvanlommel at pandora.be
Tue Dec 20 13:25:45 CET 2011


Revision: 42766
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42766
Author:   blendix
Date:     2011-12-20 12:25:45 +0000 (Tue, 20 Dec 2011)
Log Message:
-----------
Cycles: avoid using float3 in kernel constant memory, just so we're sure alignment
is working compatible between cpu and gpu.

Modified Paths:
--------------
    trunk/blender/intern/cycles/kernel/kernel_camera.h
    trunk/blender/intern/cycles/kernel/kernel_types.h
    trunk/blender/intern/cycles/render/camera.cpp
    trunk/blender/intern/cycles/render/nodes.cpp
    trunk/blender/intern/cycles/util/util_math.h

Modified: trunk/blender/intern/cycles/kernel/kernel_camera.h
===================================================================
--- trunk/blender/intern/cycles/kernel/kernel_camera.h	2011-12-20 12:25:37 UTC (rev 42765)
+++ trunk/blender/intern/cycles/kernel/kernel_camera.h	2011-12-20 12:25:45 UTC (rev 42766)
@@ -74,8 +74,8 @@
 	ray->dP.dx = make_float3(0.0f, 0.0f, 0.0f);
 	ray->dP.dy = make_float3(0.0f, 0.0f, 0.0f);
 
-	ray->dD.dx = normalize(Ddiff + kernel_data.cam.dx) - normalize(Ddiff);
-	ray->dD.dy = normalize(Ddiff + kernel_data.cam.dy) - normalize(Ddiff);
+	ray->dD.dx = normalize(Ddiff + float4_to_float3(kernel_data.cam.dx)) - normalize(Ddiff);
+	ray->dD.dy = normalize(Ddiff + float4_to_float3(kernel_data.cam.dy)) - normalize(Ddiff);
 #endif
 
 #ifdef __CAMERA_CLIPPING__
@@ -107,8 +107,8 @@
 
 #ifdef __RAY_DIFFERENTIALS__
 	/* ray differential */
-	ray->dP.dx = kernel_data.cam.dx;
-	ray->dP.dy = kernel_data.cam.dy;
+	ray->dP.dx = float4_to_float3(kernel_data.cam.dx);
+	ray->dP.dy = float4_to_float3(kernel_data.cam.dy);
 
 	ray->dD.dx = make_float3(0.0f, 0.0f, 0.0f);
 	ray->dD.dy = make_float3(0.0f, 0.0f, 0.0f);

Modified: trunk/blender/intern/cycles/kernel/kernel_types.h
===================================================================
--- trunk/blender/intern/cycles/kernel/kernel_types.h	2011-12-20 12:25:37 UTC (rev 42765)
+++ trunk/blender/intern/cycles/kernel/kernel_types.h	2011-12-20 12:25:45 UTC (rev 42766)
@@ -295,7 +295,11 @@
 #endif
 } ShaderData;
 
-/* Constrant Kernel Data */
+/* Constrant Kernel Data
+ *
+ * These structs are passed from CPU to various devices, and the struct layout
+ * must match exactly. Structs are padded to ensure 16 byte alignment, and we
+ * do not use float3 because its size may not be the same on all devices. */
 
 typedef struct KernelCamera {
 	/* type */
@@ -307,14 +311,8 @@
 	Transform rastertocamera;
 
 	/* differentials */
-	float3 dx;
-#ifndef WITH_OPENCL
-	float pad1;
-#endif
-	float3 dy;
-#ifndef WITH_OPENCL
-	float pad2;
-#endif
+	float4 dx;
+	float4 dy;
 
 	/* depth of field */
 	float aperturesize;
@@ -355,10 +353,6 @@
 typedef struct KernelSunSky {
 	/* sun direction in spherical and cartesian */
 	float theta, phi, pad3, pad4;
-	float3 dir;
-#ifndef WITH_OPENCL
-	float pad;
-#endif
 
 	/* perez function parameters */
 	float zenith_Y, zenith_x, zenith_y, pad2;

Modified: trunk/blender/intern/cycles/render/camera.cpp
===================================================================
--- trunk/blender/intern/cycles/render/camera.cpp	2011-12-20 12:25:37 UTC (rev 42765)
+++ trunk/blender/intern/cycles/render/camera.cpp	2011-12-20 12:25:45 UTC (rev 42766)
@@ -150,8 +150,8 @@
 	kcam->ortho = ortho;
 
 	/* store differentials */
-	kcam->dx = dx;
-	kcam->dy = dy;
+	kcam->dx = float3_to_float4(dx);
+	kcam->dy = float3_to_float4(dy);
 
 	/* clipping */
 	kcam->nearclip = nearclip;

Modified: trunk/blender/intern/cycles/render/nodes.cpp
===================================================================
--- trunk/blender/intern/cycles/render/nodes.cpp	2011-12-20 12:25:37 UTC (rev 42765)
+++ trunk/blender/intern/cycles/render/nodes.cpp	2011-12-20 12:25:45 UTC (rev 42766)
@@ -273,7 +273,6 @@
 
 	ksunsky->theta = theta;
 	ksunsky->phi = phi;
-	ksunsky->dir = dir;
 
 	float theta2 = theta*theta;
 	float theta3 = theta*theta*theta;

Modified: trunk/blender/intern/cycles/util/util_math.h
===================================================================
--- trunk/blender/intern/cycles/util/util_math.h	2011-12-20 12:25:37 UTC (rev 42765)
+++ trunk/blender/intern/cycles/util/util_math.h	2011-12-20 12:25:45 UTC (rev 42766)
@@ -536,6 +536,11 @@
 	return make_float3(a.x, a.y, a.z);
 }
 
+__device_inline float4 float3_to_float4(const float3 a)
+{
+	return make_float4(a.x, a.y, a.z, 1.0f);
+}
+
 #ifndef __KERNEL_GPU__
 
 __device_inline void print_float3(const char *label, const float3& a)




More information about the Bf-blender-cvs mailing list