[Bf-blender-cvs] [8d16869] master: Code cleanup: Add -Werror=float-conversion to Cycles

Campbell Barton noreply at git.blender.org
Fri May 2 23:32:27 CEST 2014


Commit: 8d16869d833ea2a2bd548c8f7b767dae582c78f2
Author: Campbell Barton
Date:   Sat May 3 07:22:14 2014 +1000
https://developer.blender.org/rB8d16869d833ea2a2bd548c8f7b767dae582c78f2

Code cleanup: Add -Werror=float-conversion to Cycles

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

M	intern/cycles/CMakeLists.txt
M	intern/cycles/SConscript
M	intern/cycles/blender/blender_camera.cpp
M	intern/cycles/blender/blender_util.h
M	intern/cycles/bvh/bvh_binning.cpp
M	intern/cycles/device/device_cuda.cpp
M	intern/cycles/device/device_opencl.cpp
M	intern/cycles/kernel/closure/bsdf_hair.h
M	intern/cycles/kernel/geom/geom_curve.h
M	intern/cycles/kernel/geom/geom_object.h
M	intern/cycles/kernel/kernel_volume.h
M	intern/cycles/kernel/svm/svm_mix.h
M	intern/cycles/kernel/svm/svm_sky.h
M	intern/cycles/kernel/svm/svm_wavelength.h
M	intern/cycles/kernel/svm/svm_wireframe.h
M	intern/cycles/render/blackbody.cpp
M	intern/cycles/render/camera.cpp
M	intern/cycles/render/integrator.cpp
M	intern/cycles/render/nodes.cpp
M	intern/cycles/render/sky_model.cpp
M	intern/cycles/subd/subd_split.cpp

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

diff --git a/intern/cycles/CMakeLists.txt b/intern/cycles/CMakeLists.txt
index 0d13c4b..50fd195 100644
--- a/intern/cycles/CMakeLists.txt
+++ b/intern/cycles/CMakeLists.txt
@@ -1,4 +1,3 @@
-
 # Standalone or with Blender
 if(NOT WITH_BLENDER AND WITH_CYCLES_STANDALONE)
 	set(CYCLES_INSTALL_PATH "")
@@ -127,6 +126,13 @@ include_directories(
 	${OPENEXR_INCLUDE_DIRS}
 )
 
+
+# Warnings
+if(CMAKE_COMPILER_IS_GNUCC)
+	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=float-conversion")
+endif()
+
+
 # Subdirectories
 
 if(WITH_CYCLES_BLENDER)
diff --git a/intern/cycles/SConscript b/intern/cycles/SConscript
index 1aa873c..893ad09 100644
--- a/intern/cycles/SConscript
+++ b/intern/cycles/SConscript
@@ -72,6 +72,10 @@ if env['OURPLATFORM'] in ('win32-vc', 'win64-vc'):
 else:
     cxxflags.append('-ffast-math'.split())
 
+# Warnings
+if env['C_COMPILER_ID'] == 'gcc':
+    cxxflags.append(['-Werror=float-conversion'])
+
 if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc', 'win64-mingw'):
     incs.append(env['BF_PTHREADS_INC'])
 
diff --git a/intern/cycles/blender/blender_camera.cpp b/intern/cycles/blender/blender_camera.cpp
index 6bbd410..1a85561 100644
--- a/intern/cycles/blender/blender_camera.cpp
+++ b/intern/cycles/blender/blender_camera.cpp
@@ -212,8 +212,8 @@ static void blender_camera_viewplane(BlenderCamera *bcam, int width, int height,
 	BoundBox2D *viewplane, float *aspectratio, float *sensor_size)
 {
 	/* dimensions */
-	float xratio = width*bcam->pixelaspect.x;
-	float yratio = height*bcam->pixelaspect.y;
+	float xratio = (float)width*bcam->pixelaspect.x;
+	float yratio = (float)height*bcam->pixelaspect.y;
 
 	/* compute x/y aspect and ratio */
 	float xaspect, yaspect;
@@ -288,8 +288,8 @@ static void blender_camera_sync(Camera *cam, BlenderCamera *bcam, int width, int
 
 	/* panorama sensor */
 	if (bcam->type == CAMERA_PANORAMA && bcam->panorama_type == PANORAMA_FISHEYE_EQUISOLID) {
-		float fit_xratio = bcam->full_width*bcam->pixelaspect.x;
-		float fit_yratio = bcam->full_height*bcam->pixelaspect.y;
+		float fit_xratio = (float)bcam->full_width*bcam->pixelaspect.x;
+		float fit_yratio = (float)bcam->full_height*bcam->pixelaspect.y;
 		bool horizontal_fit;
 		float sensor_size;
 
@@ -565,10 +565,10 @@ BufferParams BlenderSync::get_buffer_params(BL::RenderSettings b_render, BL::Sce
 
 	if(use_border) {
 		/* border render */
-		params.full_x = cam->border.left*width;
-		params.full_y = cam->border.bottom*height;
-		params.width = (int)(cam->border.right*width) - params.full_x;
-		params.height = (int)(cam->border.top*height) - params.full_y;
+		params.full_x = (int)(cam->border.left * (float)width);
+		params.full_y = (int)(cam->border.bottom * (float)height);
+		params.width = (int)(cam->border.right * (float)width) - params.full_x;
+		params.height = (int)(cam->border.top * (float)height) - params.full_y;
 
 		/* survive in case border goes out of view or becomes too small */
 		params.width = max(params.width, 1);
diff --git a/intern/cycles/blender/blender_util.h b/intern/cycles/blender/blender_util.h
index 2c83ee6..35e417d 100644
--- a/intern/cycles/blender/blender_util.h
+++ b/intern/cycles/blender/blender_util.h
@@ -57,7 +57,7 @@ static inline void colorramp_to_array(BL::ColorRamp ramp, float4 *data, int size
 	for(int i = 0; i < size; i++) {
 		float color[4];
 
-		ramp.evaluate(i/(float)(size-1), color);
+		ramp.evaluate((float)i/(float)(size-1), color);
 		data[i] = make_float4(color[0], color[1], color[2], color[3]);
 	}
 }
@@ -74,7 +74,7 @@ static inline void curvemapping_color_to_array(BL::CurveMapping cumap, float4 *d
 		BL::CurveMap mapI = cumap.curves[3];
 
 		for(int i = 0; i < size; i++) {
-			float t = i/(float)(size-1);
+			float t = (float)i/(float)(size-1);
 
 			data[i][0] = mapR.evaluate(mapI.evaluate(t));
 			data[i][1] = mapG.evaluate(mapI.evaluate(t));
@@ -83,7 +83,7 @@ static inline void curvemapping_color_to_array(BL::CurveMapping cumap, float4 *d
 	}
 	else {
 		for(int i = 0; i < size; i++) {
-			float t = i/(float)(size-1);
+			float t = (float)i/(float)(size-1);
 
 			data[i][0] = mapR.evaluate(t);
 			data[i][1] = mapG.evaluate(t);
diff --git a/intern/cycles/bvh/bvh_binning.cpp b/intern/cycles/bvh/bvh_binning.cpp
index 05a674a..bd37ffb 100644
--- a/intern/cycles/bvh/bvh_binning.cpp
+++ b/intern/cycles/bvh/bvh_binning.cpp
@@ -83,14 +83,14 @@ BVHObjectBinning::BVHObjectBinning(const BVHRange& job, BVHReference *prims)
 			int4 bin1 = get_bin(prim1.bounds());
 
 			/* increase bounds for bins for even primitive */
-			int b00 = extract<0>(bin0); bin_count[b00][0]++; bin_bounds[b00][0].grow(prim0.bounds());
-			int b01 = extract<1>(bin0); bin_count[b01][1]++; bin_bounds[b01][1].grow(prim0.bounds());
-			int b02 = extract<2>(bin0); bin_count[b02][2]++; bin_bounds[b02][2].grow(prim0.bounds());
+			int b00 = (int)extract<0>(bin0); bin_count[b00][0]++; bin_bounds[b00][0].grow(prim0.bounds());
+			int b01 = (int)extract<1>(bin0); bin_count[b01][1]++; bin_bounds[b01][1].grow(prim0.bounds());
+			int b02 = (int)extract<2>(bin0); bin_count[b02][2]++; bin_bounds[b02][2].grow(prim0.bounds());
 
 			/* increase bounds of bins for odd primitive */
-			int b10 = extract<0>(bin1); bin_count[b10][0]++; bin_bounds[b10][0].grow(prim1.bounds());
-			int b11 = extract<1>(bin1); bin_count[b11][1]++; bin_bounds[b11][1].grow(prim1.bounds());
-			int b12 = extract<2>(bin1); bin_count[b12][2]++; bin_bounds[b12][2].grow(prim1.bounds());
+			int b10 = (int)extract<0>(bin1); bin_count[b10][0]++; bin_bounds[b10][0].grow(prim1.bounds());
+			int b11 = (int)extract<1>(bin1); bin_count[b11][1]++; bin_bounds[b11][1].grow(prim1.bounds());
+			int b12 = (int)extract<2>(bin1); bin_count[b12][2]++; bin_bounds[b12][2].grow(prim1.bounds());
 		}
 
 		/* for uneven number of primitives */
@@ -100,9 +100,9 @@ BVHObjectBinning::BVHObjectBinning(const BVHRange& job, BVHReference *prims)
 			int4 bin0 = get_bin(prim0.bounds());
 
 			/* increase bounds of bins */
-			int b00 = extract<0>(bin0); bin_count[b00][0]++; bin_bounds[b00][0].grow(prim0.bounds());
-			int b01 = extract<1>(bin0); bin_count[b01][1]++; bin_bounds[b01][1].grow(prim0.bounds());
-			int b02 = extract<2>(bin0); bin_count[b02][2]++; bin_bounds[b02][2].grow(prim0.bounds());
+			int b00 = (int)extract<0>(bin0); bin_count[b00][0]++; bin_bounds[b00][0].grow(prim0.bounds());
+			int b01 = (int)extract<1>(bin0); bin_count[b01][1]++; bin_bounds[b01][1].grow(prim0.bounds());
+			int b02 = (int)extract<2>(bin0); bin_count[b02][2]++; bin_bounds[b02][2].grow(prim0.bounds());
 		}
 	}
 
diff --git a/intern/cycles/device/device_cuda.cpp b/intern/cycles/device/device_cuda.cpp
index 72453e8..48bde70 100644
--- a/intern/cycles/device/device_cuda.cpp
+++ b/intern/cycles/device/device_cuda.cpp
@@ -1036,7 +1036,7 @@ public:
 						float scaling_factor = (float)target_update_frequency / (float)msec;
 
 						/* sync at earliest next sample and probably later */
-						sync_sample = (sample + 1) + sync_sample * ceil(scaling_factor);
+						sync_sample = (sample + 1) + sync_sample * (int)ceil(scaling_factor);
 
 						sync_sample = min(end_sample - 1, sync_sample); // make sure we sync the last sample always
 
diff --git a/intern/cycles/device/device_opencl.cpp b/intern/cycles/device/device_opencl.cpp
index 9a5b261..3076272 100644
--- a/intern/cycles/device/device_opencl.cpp
+++ b/intern/cycles/device/device_opencl.cpp
@@ -932,7 +932,7 @@ public:
 			CL_DEVICE_MAX_WORK_ITEM_SIZES, sizeof(size_t)*3, max_work_items, NULL);
 	
 		/* try to divide evenly over 2 dimensions */
-		size_t sqrt_workgroup_size = max(sqrt((double)workgroup_size), 1.0);
+		size_t sqrt_workgroup_size = max((size_t)sqrt((double)workgroup_size), 1);
 		size_t local_size[2] = {sqrt_workgroup_size, sqrt_workgroup_size};
 
 		/* some implementations have max size 1 on 2nd dimension */
diff --git a/intern/cycles/kernel/closure/bsdf_hair.h b/intern/cycles/kernel/closure/bsdf_hair.h
index 163e7cc..26e1198 100644
--- a/intern/cycles/kernel/closure/bsdf_hair.h
+++ b/intern/cycles/kernel/closure/bsdf_hair.h
@@ -99,7 +99,7 @@ ccl_device float3 bsdf_hair_reflection_eval_reflect(const ShaderClosure *sc, con
 	float theta_h = (theta_i + theta_r) * 0.5f;
 	float t = theta_h - offset;
 
-	float phi_pdf = cos(phi_i * 0.5f) * 0.25f / roughness2;
+	float phi_pdf = cosf(phi_i * 0.5f) * 0.25f / roughness2;
 	float theta_pdf = roughness1 / (2 * (t*t + roughness1*roughness1) * (a_R - b_R)* costheta_i);
 	*pdf = phi_pdf * theta_pdf;
 
@@ -191,7 +191,7 @@ ccl_device int bsdf_hair_reflection_sample(const ShaderClosure *sc, float3 Ng, f
 
 	float phi = 2 * safe_asinf(1 - 2 * randv) * roughness2;
 
-	float phi_pdf = cos(phi * 0.5f) * 0.25f / roughness2;
+	float phi_pdf = cosf(phi * 0.5f) * 0.25f / roughness2;
 
 	float theta_pdf = roughness1 / (2 * (t*t + roughness1*roughness1) * (a_R - b_R)*costheta_i);
 
diff --git a/intern/cycles/kernel/geom/geom_curve.h b/intern/cycles/kernel/geom/geom_curve.h
index d1f8496..dbffcbc 100644
--- a/intern/cycles/kernel/geom/geom_curve.h
+++ b/intern/cycles/kernel/geom/geom_curve.h
@@ -167,7 +167,7 @@ ccl_device_inline void curvebounds(float *lower, float *upper, float *extremta,
 
 	if(halfdiscroot >= 0) {
 		float inv3p3 = (1.0f/3.0f)/p3;
-		halfdiscroot = sqrt(halfdiscroot);
+		halfdiscroot = sqrtf(halfdiscroot);
 		ta = (-p2 - halfdiscroot) * inv3p3;
 		tb = (-p2 + halfdiscroot) * inv3p3;
 	}
diff --git a/intern/cycles/kernel/geom/geom_object.h b/intern/cycles/kernel/geom/geom_object.h
index 431cd63..de800d7 100644
--- a/intern/cycles/kernel/geom/geom_object.h
+++ b/intern/cycles/kernel/geom/geom_object.h
@@ -364,7 +364,7 @@ ccl_device float3 particle_angular_velocity(KernelGlobals *kg, int particle)
 ccl_device_inline float3 bvh_clamp_direction(float3 dir)
 {
 	/* clamp absolute values by exp2f(-80.0f) to avoid division by zero when calculating inverse direction */
-	float ooeps = 8.271806E-25;
+	float ooeps = 8.271806E-25f;
 	return make_float3((fabsf(dir.x) > ooeps)? dir.x: copysignf(ooeps, dir.x),
 					   (fabsf(dir.y) > ooeps)? dir.y: copysignf(ooeps, dir.y),
 					   (fabsf(dir.z) > ooeps)? dir.z: copysignf(ooeps, dir.z));
diff --git a/intern/cycles/kernel/kernel_volume.h b/intern/cycles/kernel/k

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list