[Bf-blender-cvs] [14d1f5b89f9] cycles_refactor: Cycles: Refactored kernel particle structure from float4 array to an actual struct with named and typed members.

Stefan Werner noreply at git.blender.org
Mon Dec 4 13:15:18 CET 2017


Commit: 14d1f5b89f9fdbe5dd0c4c04b38efdbb5d5e29ba
Author: Stefan Werner
Date:   Mon Dec 4 12:59:29 2017 +0100
Branches: cycles_refactor
https://developer.blender.org/rB14d1f5b89f9fdbe5dd0c4c04b38efdbb5d5e29ba

Cycles: Refactored kernel particle structure from float4 array to an actual struct with named and typed members.

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

M	intern/cycles/kernel/geom/geom_object.h
M	intern/cycles/kernel/kernel_textures.h
M	intern/cycles/kernel/kernel_types.h
M	intern/cycles/render/particles.cpp
M	intern/cycles/render/scene.h

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

diff --git a/intern/cycles/kernel/geom/geom_object.h b/intern/cycles/kernel/geom/geom_object.h
index db7f2d278be..a5aa4138421 100644
--- a/intern/cycles/kernel/geom/geom_object.h
+++ b/intern/cycles/kernel/geom/geom_object.h
@@ -336,60 +336,42 @@ ccl_device int shader_pass_id(KernelGlobals *kg, const ShaderData *sd)
 
 ccl_device_inline float particle_index(KernelGlobals *kg, int particle)
 {
-	int offset = particle*PARTICLE_SIZE;
-	float4 f = kernel_tex_fetch(__particles, offset + 0);
-	return f.x;
+	return kernel_tex_fetch(__particles, particle).index;
 }
 
 ccl_device float particle_age(KernelGlobals *kg, int particle)
 {
-	int offset = particle*PARTICLE_SIZE;
-	float4 f = kernel_tex_fetch(__particles, offset + 0);
-	return f.y;
+	return kernel_tex_fetch(__particles, particle).age;
 }
 
 ccl_device float particle_lifetime(KernelGlobals *kg, int particle)
 {
-	int offset = particle*PARTICLE_SIZE;
-	float4 f = kernel_tex_fetch(__particles, offset + 0);
-	return f.z;
+	return kernel_tex_fetch(__particles, particle).lifetime;
 }
 
 ccl_device float particle_size(KernelGlobals *kg, int particle)
 {
-	int offset = particle*PARTICLE_SIZE;
-	float4 f = kernel_tex_fetch(__particles, offset + 0);
-	return f.w;
+	return kernel_tex_fetch(__particles, particle).size;
 }
 
 ccl_device float4 particle_rotation(KernelGlobals *kg, int particle)
 {
-	int offset = particle*PARTICLE_SIZE;
-	float4 f = kernel_tex_fetch(__particles, offset + 1);
-	return f;
+	return kernel_tex_fetch(__particles, particle).rotation;
 }
 
 ccl_device float3 particle_location(KernelGlobals *kg, int particle)
 {
-	int offset = particle*PARTICLE_SIZE;
-	float4 f = kernel_tex_fetch(__particles, offset + 2);
-	return make_float3(f.x, f.y, f.z);
+	return float4_to_float3(kernel_tex_fetch(__particles, particle).location);
 }
 
 ccl_device float3 particle_velocity(KernelGlobals *kg, int particle)
 {
-	int offset = particle*PARTICLE_SIZE;
-	float4 f2 = kernel_tex_fetch(__particles, offset + 2);
-	float4 f3 = kernel_tex_fetch(__particles, offset + 3);
-	return make_float3(f2.w, f3.x, f3.y);
+	return float4_to_float3(kernel_tex_fetch(__particles, particle).velocity);
 }
 
 ccl_device float3 particle_angular_velocity(KernelGlobals *kg, int particle)
 {
-	int offset = particle*PARTICLE_SIZE;
-	float4 f3 = kernel_tex_fetch(__particles, offset + 3);
-	float4 f4 = kernel_tex_fetch(__particles, offset + 4);
-	return make_float3(f3.z, f3.w, f4.x);
+	return float4_to_float3(kernel_tex_fetch(__particles, particle).angular_velocity);
 }
 
 /* Object intersection in BVH */
diff --git a/intern/cycles/kernel/kernel_textures.h b/intern/cycles/kernel/kernel_textures.h
index d5f8f6619ef..b555dcdd73c 100644
--- a/intern/cycles/kernel/kernel_textures.h
+++ b/intern/cycles/kernel/kernel_textures.h
@@ -65,7 +65,7 @@ KERNEL_TEX(float2, __light_background_marginal_cdf)
 KERNEL_TEX(float2, __light_background_conditional_cdf)
 
 /* particles */
-KERNEL_TEX(float4, __particles)
+KERNEL_TEX(KernelParticle, __particles)
 
 /* shaders */
 KERNEL_TEX(uint4, __svm_nodes)
diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h
index e9fee35d0a9..1262b1a73c4 100644
--- a/intern/cycles/kernel/kernel_types.h
+++ b/intern/cycles/kernel/kernel_types.h
@@ -39,7 +39,6 @@ CCL_NAMESPACE_BEGIN
 #define FILTER_TABLE_SIZE	1024
 #define RAMP_TABLE_SIZE		256
 #define SHUTTER_TABLE_SIZE		256
-#define PARTICLE_SIZE 		5
 #define SHADER_SIZE		5
 
 #define BSSRDF_MIN_RADIUS			1e-8f
@@ -1589,6 +1588,20 @@ typedef struct KernelLightDistribution
 	};
 } KernelLightDistribution;
 
+typedef struct KernelParticle
+{
+	int index;
+	float age;
+	float lifetime;
+	float size;
+	float4 rotation;
+	/* Only xyz are used of the following. 
+	 * float4 instead of float3 are used to ensure consistent padding/alignment across devices. */
+	float4 location;
+	float4 velocity;
+	float4 angular_velocity;
+} KernelParticle;
+
 CCL_NAMESPACE_END
 
 #endif /*  __KERNEL_TYPES_H__ */
diff --git a/intern/cycles/render/particles.cpp b/intern/cycles/render/particles.cpp
index 06ff45b09bd..1a20f436128 100644
--- a/intern/cycles/render/particles.cpp
+++ b/intern/cycles/render/particles.cpp
@@ -61,14 +61,10 @@ void ParticleSystemManager::device_update_particles(Device *, DeviceScene *dscen
 	for(size_t j = 0; j < scene->particle_systems.size(); j++)
 		num_particles += scene->particle_systems[j]->particles.size();
 	
-	float4 *particles = dscene->particles.alloc(PARTICLE_SIZE*num_particles);
+	KernelParticle *particles = dscene->particles.alloc(num_particles);
 	
 	/* dummy particle */
-	particles[0] = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
-	particles[1] = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
-	particles[2] = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
-	particles[3] = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
-	particles[4] = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
+	::memset(particles, 0, sizeof(KernelParticle));
 	
 	int i = 1;
 	for(size_t j = 0; j < scene->particle_systems.size(); j++) {
@@ -77,13 +73,15 @@ void ParticleSystemManager::device_update_particles(Device *, DeviceScene *dscen
 		for(size_t k = 0; k < psys->particles.size(); k++) {
 			/* pack in texture */
 			Particle& pa = psys->particles[k];
-			int offset = i*PARTICLE_SIZE;
 			
-			particles[offset] = make_float4(pa.index, pa.age, pa.lifetime, pa.size);
-			particles[offset+1] = pa.rotation;
-			particles[offset+2] = make_float4(pa.location.x, pa.location.y, pa.location.z, pa.velocity.x);
-			particles[offset+3] = make_float4(pa.velocity.y, pa.velocity.z, pa.angular_velocity.x, pa.angular_velocity.y);
-			particles[offset+4] = make_float4(pa.angular_velocity.z, 0.0f, 0.0f, 0.0f);
+			particles[i].index = pa.index;
+			particles[i].age = pa.age;
+			particles[i].lifetime = pa.lifetime;
+			particles[i].size = pa.size;
+			particles[i].rotation = pa.rotation;
+			particles[i].location = float3_to_float4(pa.location);
+			particles[i].velocity = float3_to_float4(pa.velocity);
+			particles[i].angular_velocity = float3_to_float4(pa.angular_velocity);
 			
 			i++;
 			
diff --git a/intern/cycles/render/scene.h b/intern/cycles/render/scene.h
index 5abb7173951..7d91e149d33 100644
--- a/intern/cycles/render/scene.h
+++ b/intern/cycles/render/scene.h
@@ -100,7 +100,7 @@ public:
 	device_vector<float2> light_background_conditional_cdf;
 
 	/* particles */
-	device_vector<float4> particles;
+	device_vector<KernelParticle> particles;
 
 	/* shaders */
 	device_vector<int4> svm_nodes;



More information about the Bf-blender-cvs mailing list