[Bf-blender-cvs] [7096529] master: Fix T38501: blender crashes right after adding image texture to material in cycles

Sv. Lockal noreply at git.blender.org
Mon Feb 10 14:25:23 CET 2014


Commit: 7096529704989286f30d645fae54e40c8335ec5e
Author: Sv. Lockal
Date:   Mon Feb 10 17:19:26 2014 +0400
https://developer.blender.org/rB7096529704989286f30d645fae54e40c8335ec5e

Fix T38501: blender crashes right after adding image texture to material
in cycles

Also fix very similar problem in half-float SSE conversion.

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

M	intern/cycles/kernel/kernel_film.h
M	intern/cycles/kernel/svm/svm_image.h

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

diff --git a/intern/cycles/kernel/kernel_film.h b/intern/cycles/kernel/kernel_film.h
index b411866..cbd875e 100644
--- a/intern/cycles/kernel/kernel_film.h
+++ b/intern/cycles/kernel/kernel_film.h
@@ -75,17 +75,15 @@ ccl_device void kernel_film_convert_to_half_float(KernelGlobals *kg,
 
 	float exposure = kernel_data.film.exposure;
 
-	if(exposure == 1.0f) {
-		float4_store_half(out, in, sample_scale);
-	}
-	else {
-		float4 rgba = *in;
-		rgba.x *= exposure;
-		rgba.y *= exposure;
-		rgba.z *= exposure;
+	ccl_align(16) float4 rgba_in = *in;
 
-		float4_store_half(out, &rgba, sample_scale);
+	if(exposure != 1.0f) {
+		rgba_in.x *= exposure;
+		rgba_in.y *= exposure;
+		rgba_in.z *= exposure;
 	}
+
+	float4_store_half(out, &rgba_in, sample_scale);
 }
 
 CCL_NAMESPACE_END
diff --git a/intern/cycles/kernel/svm/svm_image.h b/intern/cycles/kernel/svm/svm_image.h
index 2687e03..6dd4430 100644
--- a/intern/cycles/kernel/svm/svm_image.h
+++ b/intern/cycles/kernel/svm/svm_image.h
@@ -112,10 +112,8 @@ ccl_device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y,
 
 ccl_device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y, uint srgb, uint use_alpha)
 {
-#if defined(__KERNEL_CPU__) && defined(__KERNEL_SSE2__)
-	union { float4 rgba; __m128 m128; } r = { kernel_tex_image_interp(id, x, y) };
-#elif defined(__KERNEL_CPU__)
-	float4 r = kernel_tex_image_interp(id, x, y);
+#ifdef __KERNEL_CPU__
+	ccl_align(16) float4 r = kernel_tex_image_interp(id, x, y);
 #else
 	float4 r;
 
@@ -236,21 +234,20 @@ ccl_device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y,
 #endif
 
 #ifdef __KERNEL_SSE2__
-	if(use_alpha && r.rgba.w != 1.0f && r.rgba.w != 0.0f) {
-		float alpha = r.rgba.w;
-		r.m128 = _mm_div_ps(r.m128, _mm_set1_ps(alpha));
+	__m128 &r_m128 = (__m128&)r;
+	if(use_alpha && r.w != 1.0f && r.w != 0.0f) {
+		float alpha = r.w;
+		r_m128 = _mm_div_ps(r_m128, _mm_set1_ps(alpha));
 		if(id >= TEX_NUM_FLOAT_IMAGES)
-			r.m128 = _mm_min_ps(r.m128, _mm_set1_ps(1.0f));
-		r.rgba.w = alpha;
+			r_m128 = _mm_min_ps(r_m128, _mm_set1_ps(1.0f));
+		r.w = alpha;
 	}
 
 	if(srgb) {
-		float alpha = r.rgba.w;
-		r.m128 = color_srgb_to_scene_linear(r.m128);
-		r.rgba.w = alpha;
+		float alpha = r.w;
+		r_m128 = color_srgb_to_scene_linear(r_m128);
+		r.w = alpha;
 	}
-
-	return r.rgba;
 #else
 	if(use_alpha && r.w != 1.0f && r.w != 0.0f) {
 		float invw = 1.0f/r.w;
@@ -270,9 +267,9 @@ ccl_device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y,
 		r.y = color_srgb_to_scene_linear(r.y);
 		r.z = color_srgb_to_scene_linear(r.z);
 	}
+#endif
 
 	return r;
-#endif
 }
 
 #endif




More information about the Bf-blender-cvs mailing list