Cycles: correction to how device of lists is exposed to blender

compute_device_list is using static vector of device information which
had pointers (identifier and name) to values from device information
structures. That structures are also stored in static vector and being
refreshed every 5 seconds.

The issue is, as soon as device information is being updated, pointers
in vector from compute_device_list became incorrect.

Seems it was the reason of issues with sudden switching from CUDA to
OpenCL on my desktop and from CUDA to CPU on my laptop, It was also
seems to be making persistent images behaves instable.

Made it so device identifier and name are copied from device info
to structures used by RNA (CCLDeviceInfo).

Alternative could be avoid cacheing CCLDeviceInfo and always use actual
list of device information by RNA. It shouldn't be so much slow.
This commit is contained in:
Sergey Sharybin
2012-11-10 08:37:02 +00:00
parent c9cd4d61ba
commit f5c9f2c253
3 changed files with 15 additions and 6 deletions

View File

@@ -23,12 +23,12 @@
extern "C" {
#endif
/* returns a list of devices for selection, array is name NULL pointer
/* returns a list of devices for selection, array is empty identifier
* terminated and must not be freed */
typedef struct CCLDeviceInfo {
const char *identifier;
const char *name;
char identifier[128];
char name[512];
int value;
} CCLDeviceInfo;

View File

@@ -418,14 +418,23 @@ static CCLDeviceInfo *compute_device_list(DeviceType type)
if(info.type == type ||
(info.type == DEVICE_MULTI && info.multi_devices[0].type == type))
{
CCLDeviceInfo cinfo = {info.id.c_str(), info.description.c_str(), i++};
CCLDeviceInfo cinfo;
strncpy(cinfo.identifier, info.id.c_str(), sizeof(cinfo.identifier));
cinfo.identifier[info.id.length()] = '\0';
strncpy(cinfo.name, info.description.c_str(), sizeof(cinfo.name));
cinfo.name[info.description.length()] = '\0';
cinfo.value = i++;
device_list.push_back(cinfo);
}
}
/* null terminate */
if(!device_list.empty()) {
CCLDeviceInfo cinfo = {NULL, NULL, 0};
CCLDeviceInfo cinfo = {"", "", 0};
device_list.push_back(cinfo);
}
}

View File

@@ -395,7 +395,7 @@ static EnumPropertyItem *rna_userdef_compute_device_itemf(bContext *UNUSED(C), P
int a;
if (devices) {
for (a = 0; devices[a].name; a++) {
for (a = 0; devices[a].identifier[0]; a++) {
tmp.value = devices[a].value;
tmp.identifier = devices[a].identifier;
tmp.name = devices[a].name;