Skip to content

Commit

Permalink
Fixed problem with re-enabling GPU
Browse files Browse the repository at this point in the history
  • Loading branch information
buddhi1980 committed Jun 7, 2017
1 parent f87c93b commit e6f51f1
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 51 deletions.
34 changes: 19 additions & 15 deletions mandelbulber2/qt/preferences_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,30 +378,34 @@ QList<QPair<QString, QString>> cPreferencesDialog::GetOpenCLDevices()
#ifdef USE_OPENCL
void cPreferencesDialog::on_listWidget_gpu_platform_list_currentRowChanged(int index)
{
gOpenCl->openClEngineRenderFractal->Reset();
gOpenCl->openClHardware->CreateContext(
index, cOpenClDevice::enumOpenClDeviceType(ui->comboBox_gpu_device_type->currentIndex()));
gOpenCl->openClHardware->getClDevices();
if (index >= 0)
{
gOpenCl->openClEngineRenderFractal->Reset();
gOpenCl->openClHardware->CreateContext(
index, cOpenClDevice::enumOpenClDeviceType(ui->comboBox_gpu_device_type->currentIndex()));
gOpenCl->openClHardware->getClDevices();

ui->listWidget_gpu_device_list->clear();
ui->listWidget_gpu_device_list->clear();

QList<QPair<QString, QString>> devices = GetOpenCLDevices();
QStringList selectedDevices = gPar->Get<QString>("gpu_device_list").split("|");
for (int i = 0; i < devices.size(); i++)
{
QPair<QString, QString> device = devices.at(i);
QListWidgetItem *item = new QListWidgetItem(device.second);
item->setData(1, device.first);
bool selected = selectedDevices.contains(device.first);
ui->listWidget_gpu_device_list->addItem(item);
item->setSelected(selected);
QList<QPair<QString, QString>> devices = GetOpenCLDevices();
QStringList selectedDevices = gPar->Get<QString>("gpu_device_list").split("|");
for (int i = 0; i < devices.size(); i++)
{
QPair<QString, QString> device = devices.at(i);
QListWidgetItem *item = new QListWidgetItem(device.second);
item->setData(1, device.first);
bool selected = selectedDevices.contains(device.first);
ui->listWidget_gpu_device_list->addItem(item);
item->setSelected(selected);
}
}
}

void cPreferencesDialog::on_groupCheck_gpu_enabled_toggled(bool state)
{
if (state)
{
gOpenCl->openClEngineRenderFractal->Reset();
gOpenCl->openClHardware->ListOpenClPlatforms();
if (gPar->Get<int>("gpu_platform") >= 0)
{
Expand Down
80 changes: 44 additions & 36 deletions mandelbulber2/src/opencl_hardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,56 +123,64 @@ void cOpenClHardware::ListOpenClPlatforms()
void cOpenClHardware::CreateContext(
int platformIndex, cOpenClDevice::enumOpenClDeviceType deviceType)
{
if (openClAvailable)
if (platformIndex >= 0)
{
devicesInformation.clear();
clDeviceWorkers.clear();
clDevices.clear();
if (openClAvailable)
{
devicesInformation.clear();
clDeviceWorkers.clear();
clDevices.clear();

// platformIndex required
// context operates exclusively with (1) platform
cl_context_properties cprops[3] = {
CL_CONTEXT_PLATFORM, cl_context_properties((clPlatforms[platformIndex])()), 0};
// platformIndex required
// context operates exclusively with (1) platform
cl_context_properties cprops[3] = {
CL_CONTEXT_PLATFORM, cl_context_properties((clPlatforms[platformIndex])()), 0};

if (context) delete context;
contextReady = false;
if (context) delete context;
contextReady = false;

cl_int err = 0;
cl_int err = 0;

switch (deviceType)
{
case cOpenClDevice::openClDeviceTypeACC:
context = new cl::Context(CL_DEVICE_TYPE_ACCELERATOR, cprops, nullptr, nullptr, &err);
break;
case cOpenClDevice::openClDeviceTypeALL:
context = new cl::Context(CL_DEVICE_TYPE_ALL, cprops, nullptr, nullptr, &err);
break;
case cOpenClDevice::openClDeviceTypeCPU:
context = new cl::Context(CL_DEVICE_TYPE_CPU, cprops, nullptr, nullptr, &err);
break;
case cOpenClDevice::openClDeviceTypeDEF:
context = new cl::Context(CL_DEVICE_TYPE_DEFAULT, cprops, nullptr, nullptr, &err);
break;
case cOpenClDevice::openClDeviceTypeGPU:
context = new cl::Context(CL_DEVICE_TYPE_GPU, cprops, nullptr, nullptr, &err);
break;
}
switch (deviceType)
{
case cOpenClDevice::openClDeviceTypeACC:
context = new cl::Context(CL_DEVICE_TYPE_ACCELERATOR, cprops, nullptr, nullptr, &err);
break;
case cOpenClDevice::openClDeviceTypeALL:
context = new cl::Context(CL_DEVICE_TYPE_ALL, cprops, nullptr, nullptr, &err);
break;
case cOpenClDevice::openClDeviceTypeCPU:
context = new cl::Context(CL_DEVICE_TYPE_CPU, cprops, nullptr, nullptr, &err);
break;
case cOpenClDevice::openClDeviceTypeDEF:
context = new cl::Context(CL_DEVICE_TYPE_DEFAULT, cprops, nullptr, nullptr, &err);
break;
case cOpenClDevice::openClDeviceTypeGPU:
context = new cl::Context(CL_DEVICE_TYPE_GPU, cprops, nullptr, nullptr, &err);
break;
}

if (checkErr(err, "Context::Context()"))
{
contextReady = true;
ListOpenClDevices();
if (checkErr(err, "Context::Context()"))
{
contextReady = true;
ListOpenClDevices();
}
else
{
contextReady = false;
cErrorMessage::showMessage(
QObject::tr("OpenCL context cannot be created!"), cErrorMessage::errorMessage);
}
}
else
{
qCritical() << "OpenCl is not available";
contextReady = false;
cErrorMessage::showMessage(
QObject::tr("OpenCL context cannot be created!"), cErrorMessage::errorMessage);
}
}
else
{
qCritical() << "OpenCl is not available";
qCritical() << "OpenCL platform index is negative number!";
contextReady = false;
}
}
Expand Down

0 comments on commit e6f51f1

Please sign in to comment.