[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43136] trunk/blender/intern/cycles: Cycles: device code refactoring, no functional changes.

Brecht Van Lommel brechtvanlommel at pandora.be
Wed Jan 4 19:06:45 CET 2012


Revision: 43136
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43136
Author:   blendix
Date:     2012-01-04 18:06:32 +0000 (Wed, 04 Jan 2012)
Log Message:
-----------
Cycles: device code refactoring, no functional changes.

Modified Paths:
--------------
    trunk/blender/intern/cycles/app/cycles_server.cpp
    trunk/blender/intern/cycles/app/cycles_test.cpp
    trunk/blender/intern/cycles/blender/blender_sync.cpp
    trunk/blender/intern/cycles/device/device.cpp
    trunk/blender/intern/cycles/device/device.h
    trunk/blender/intern/cycles/device/device_cpu.cpp
    trunk/blender/intern/cycles/device/device_cuda.cpp
    trunk/blender/intern/cycles/device/device_intern.h
    trunk/blender/intern/cycles/device/device_memory.h
    trunk/blender/intern/cycles/device/device_multi.cpp
    trunk/blender/intern/cycles/device/device_network.cpp
    trunk/blender/intern/cycles/device/device_opencl.cpp
    trunk/blender/intern/cycles/render/buffers.cpp
    trunk/blender/intern/cycles/render/session.cpp
    trunk/blender/intern/cycles/render/session.h
    trunk/blender/intern/cycles/render/tile.cpp

Modified: trunk/blender/intern/cycles/app/cycles_server.cpp
===================================================================
--- trunk/blender/intern/cycles/app/cycles_server.cpp	2012-01-04 17:33:47 UTC (rev 43135)
+++ trunk/blender/intern/cycles/app/cycles_server.cpp	2012-01-04 18:06:32 UTC (rev 43136)
@@ -34,8 +34,9 @@
 	/* device types */
 	string devices = "";
 	string devicename = "cpu";
+	bool list = false;
 
-	vector<DeviceType> types = Device::available_types();
+	vector<DeviceType>& types = Device::available_types();
 
 	foreach(DeviceType type, types) {
 		if(devices != "")
@@ -49,6 +50,7 @@
 
 	ap.options ("Usage: cycles_server [options]",
 		"--device %s", &devicename, ("Devices to use: " + devices).c_str(),
+		"--list-devices", &list, "List information about all available devices",
 		NULL);
 
 	if(ap.parse(argc, argv) < 0) {
@@ -56,11 +58,34 @@
 		ap.usage();
 		exit(EXIT_FAILURE);
 	}
+	else if(list) {
+		vector<DeviceInfo>& devices = Device::available_devices();
 
-	DeviceType dtype = Device::type_from_string(devicename.c_str());
+		printf("Devices:\n");
 
+		foreach(DeviceInfo& info, devices) {
+			printf("    %s%s\n",
+				info.description.c_str(),
+				(info.display_device)? " (display)": "");
+		}
+
+		exit(EXIT_SUCCESS);
+	}
+
+	/* find matching device */
+	DeviceType device_type = Device::type_from_string(devicename.c_str());
+	vector<DeviceInfo>& devices = Device::available_devices();
+	DeviceInfo device_info;
+
+	foreach(DeviceInfo& device, devices) {
+		if(device_type == device.type) {
+			device_info = device;
+			break;
+		}
+	}
+
 	while(1) {
-		Device *device = Device::create(dtype);
+		Device *device = Device::create(device_info);
 		printf("Cycles Server with device: %s\n", device->description().c_str());
 		device->server_run();
 		delete device;

Modified: trunk/blender/intern/cycles/app/cycles_test.cpp
===================================================================
--- trunk/blender/intern/cycles/app/cycles_test.cpp	2012-01-04 17:33:47 UTC (rev 43135)
+++ trunk/blender/intern/cycles/app/cycles_test.cpp	2012-01-04 18:06:32 UTC (rev 43136)
@@ -203,17 +203,18 @@
 	options.session = NULL;
 	options.quiet = false;
 
-	/* devices */
-	string devices = "";
+	/* device names */
+	string device_names = "";
 	string devicename = "cpu";
+	bool list = false;
 
-	vector<DeviceType> types = Device::available_types();
+	vector<DeviceType>& types = Device::available_types();
 
 	foreach(DeviceType type, types) {
-		if(devices != "")
-			devices += ", ";
+		if(device_names != "")
+			device_names += ", ";
 
-		devices += Device::string_from_type(type);
+		device_names += Device::string_from_type(type);
 	}
 
 	/* shading system */
@@ -230,7 +231,7 @@
 
 	ap.options ("Usage: cycles_test [options] file.xml",
 		"%*", files_parse, "",
-		"--device %s", &devicename, ("Devices to use: " + devices).c_str(),
+		"--device %s", &devicename, ("Devices to use: " + device_names).c_str(),
 		"--shadingsys %s", &ssname, "Shading system to use: svm, osl",
 		"--background", &options.session_params.background, "Render in background, without user interface",
 		"--quiet", &options.quiet, "In background mode, don't print progress messages",
@@ -239,6 +240,7 @@
 		"--threads %d", &options.session_params.threads, "CPU Rendering Threads",
 		"--width  %d", &options.width, "Window width in pixel",
 		"--height %d", &options.height, "Window height in pixel",
+		"--list-devices", &list, "List information about all available devices",
 		"--help", &help, "Print help message",
 		NULL);
 	
@@ -247,26 +249,44 @@
 		ap.usage();
 		exit(EXIT_FAILURE);
 	}
+	else if(list) {
+		vector<DeviceInfo>& devices = Device::available_devices();
+		printf("Devices:\n");
+
+		foreach(DeviceInfo& info, devices) {
+			printf("    %s%s\n",
+				info.description.c_str(),
+				(info.display_device)? " (display)": "");
+		}
+
+		exit(EXIT_SUCCESS);
+	}
 	else if(help || options.filepath == "") {
 		ap.usage();
 		exit(EXIT_SUCCESS);
 	}
 
-	options.session_params.device_type = Device::type_from_string(devicename.c_str());
-
 	if(ssname == "osl")
 		options.scene_params.shadingsystem = SceneParams::OSL;
 	else if(ssname == "svm")
 		options.scene_params.shadingsystem = SceneParams::SVM;
 
-	/* handle invalid configurations */
-	bool type_available = false;
+	/* find matching device */
+	DeviceType device_type = Device::type_from_string(devicename.c_str());
+	vector<DeviceInfo>& devices = Device::available_devices();
+	DeviceInfo device_info;
+	bool device_available = false;
 
-	foreach(DeviceType dtype, types)
-		if(options.session_params.device_type == dtype)
-			type_available = true;
+	foreach(DeviceInfo& device, devices) {
+		if(device_type == device.type) {
+			options.session_params.device = device;
+			device_available = true;
+			break;
+		}
+	}
 
-	if(options.session_params.device_type == DEVICE_NONE || !type_available) {
+	/* handle invalid configurations */
+	if(options.session_params.device.type == DEVICE_NONE || !device_available) {
 		fprintf(stderr, "Unknown device: %s\n", devicename.c_str());
 		exit(EXIT_FAILURE);
 	}
@@ -278,7 +298,7 @@
 		fprintf(stderr, "Unknown shading system: %s\n", ssname.c_str());
 		exit(EXIT_FAILURE);
 	}
-	else if(options.scene_params.shadingsystem == SceneParams::OSL && options.session_params.device_type != DEVICE_CPU) {
+	else if(options.scene_params.shadingsystem == SceneParams::OSL && options.session_params.device.type != DEVICE_CPU) {
 		fprintf(stderr, "OSL shading system only works with CPU device\n");
 		exit(EXIT_FAILURE);
 	}

Modified: trunk/blender/intern/cycles/blender/blender_sync.cpp
===================================================================
--- trunk/blender/intern/cycles/blender/blender_sync.cpp	2012-01-04 17:33:47 UTC (rev 43135)
+++ trunk/blender/intern/cycles/blender/blender_sync.cpp	2012-01-04 18:06:32 UTC (rev 43136)
@@ -248,10 +248,10 @@
 	return (background)? false: get_boolean(cscene, "preview_pause");
 }
 
-static bool device_type_available(vector<DeviceType>& types, DeviceType dtype)
+static bool device_type_available(vector<DeviceInfo>& devices, DeviceType dtype)
 {
-	foreach(DeviceType dt, types)
-		if(dt == dtype)
+	foreach(DeviceInfo& info, devices)
+		if(info.type == dtype)
 			return true;
 
 	return false;
@@ -266,24 +266,28 @@
 	params.experimental = (RNA_enum_get(&cscene, "feature_set") != 0);
 
 	/* device type */
-	params.device_type = DEVICE_CPU;
+	vector<DeviceInfo> devices = Device::available_devices();
+	DeviceType device_type = DEVICE_CPU;
 
 	if(RNA_enum_get(&cscene, "device") != 0) {
-		vector<DeviceType> types = Device::available_types();
-		DeviceType dtype;
 		
 		if(!params.experimental || RNA_enum_get(&cscene, "gpu_type") == 0)
-			dtype = DEVICE_CUDA;
+			device_type = DEVICE_CUDA;
 		else
-			dtype = DEVICE_OPENCL;
+			device_type = DEVICE_OPENCL;
 
-		if(device_type_available(types, dtype))
-			params.device_type = dtype;
-		else if(params.experimental && device_type_available(types, DEVICE_OPENCL))
-			params.device_type = DEVICE_OPENCL;
-		else if(device_type_available(types, DEVICE_CUDA))
-			params.device_type = DEVICE_CUDA;
+		if(device_type_available(devices, device_type))
+			;
+		else if(params.experimental && device_type_available(devices, DEVICE_OPENCL))
+			device_type = DEVICE_OPENCL;
+		else if(device_type_available(devices, DEVICE_CUDA))
+			device_type = DEVICE_CUDA;
 	}
+
+	params.device = devices[0];
+	foreach(DeviceInfo& info, devices)
+		if(info.type == device_type)
+			params.device = info;
 			
 	/* Background */
 	params.background = background;

Modified: trunk/blender/intern/cycles/device/device.cpp
===================================================================
--- trunk/blender/intern/cycles/device/device.cpp	2012-01-04 17:33:47 UTC (rev 43135)
+++ trunk/blender/intern/cycles/device/device.cpp	2012-01-04 18:06:32 UTC (rev 43136)
@@ -118,7 +118,7 @@
 	mem_free(mem);
 }
 
-void Device::draw_pixels(device_memory& rgba, int y, int w, int h, int width, int height, bool transparent)
+void Device::draw_pixels(device_memory& rgba, int y, int w, int h, int dy, int width, int height, bool transparent)
 {
 	pixels_copy_from(rgba, y, w, h);
 
@@ -128,7 +128,7 @@
 	}
 
 	glPixelZoom((float)width/(float)w, (float)height/(float)h);
-	glRasterPos2f(0, y);
+	glRasterPos2f(0, dy);
 
 	uint8_t *pixels = (uint8_t*)rgba.data_pointer;
 
@@ -145,36 +145,36 @@
 		glDisable(GL_BLEND);
 }
 
-Device *Device::create(DeviceType type, bool background, int threads)
+Device *Device::create(DeviceInfo& info, bool background, int threads)
 {
 	Device *device;
 
-	switch(type) {
+	switch(info.type) {
 		case DEVICE_CPU:
-			device = device_cpu_create(threads);
+			device = device_cpu_create(info, threads);
 			break;
 #ifdef WITH_CUDA
 		case DEVICE_CUDA:
 			if(cuLibraryInit())
-				device = device_cuda_create(background);
+				device = device_cuda_create(info, background);
 			else
 				device = NULL;
 			break;
 #endif
 #ifdef WITH_MULTI
 		case DEVICE_MULTI:
-			device = device_multi_create(background);
+			device = device_multi_create(info, background);
 			break;
 #endif
 #ifdef WITH_NETWORK
 		case DEVICE_NETWORK:
-			device = device_network_create("127.0.0.1");
+			device = device_network_create(info, "127.0.0.1");
 			break;
 #endif
 #ifdef WITH_OPENCL
 		case DEVICE_OPENCL:
 			if(clLibraryInit())
-				device = device_opencl_create(background);
+				device = device_opencl_create(info, background);
 			else
 				device = NULL;
 			break;
@@ -218,31 +218,68 @@
 	return "";
 }
 
-vector<DeviceType> Device::available_types()
+vector<DeviceType>& Device::available_types()
 {
-	vector<DeviceType> types;
+	static vector<DeviceType> types;
+	static bool types_init = false;
 
-	types.push_back(DEVICE_CPU);
+	if(!types_init) {
+		types.push_back(DEVICE_CPU);
 
 #ifdef WITH_CUDA
-	if(cuLibraryInit())
-		types.push_back(DEVICE_CUDA);
+		if(cuLibraryInit())
+			types.push_back(DEVICE_CUDA);
 #endif
 
 #ifdef WITH_OPENCL
-	if(clLibraryInit())
-		types.push_back(DEVICE_OPENCL);
+		if(clLibraryInit())
+			types.push_back(DEVICE_OPENCL);
 #endif
 
 #ifdef WITH_NETWORK
-	types.push_back(DEVICE_NETWORK);
+		types.push_back(DEVICE_NETWORK);
 #endif
 #ifdef WITH_MULTI
-	types.push_back(DEVICE_MULTI);
+		types.push_back(DEVICE_MULTI);
 #endif
 
+		types_init = true;
+	}
+
 	return types;
 }
 
+vector<DeviceInfo>& Device::available_devices()
+{
+	static vector<DeviceInfo> devices;
+	static bool devices_init = false;
+
+	if(!devices_init) {
+		device_cpu_info(devices);
+
+#ifdef WITH_CUDA
+		if(cuLibraryInit())

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list