3 static std::vector<std::string>
4 get_gpu_names(std::string binary, std::string filename)
6 // Execute the GPU listing program and redirect its output to a file
7 std::system((binary + " > " + filename).c_str());
9 std::vector<std::string> gpu_names;
10 std::ifstream file(filename);
13 while (std::getline(file, line))
14 gpu_names.push_back(line);
21 class GpuList : public wxPanel
24 GpuList(wxPanel* parent)
25 : wxPanel(parent, wxID_ANY)
28 comboBox = new wxComboBox(this, wxID_ANY, "", wxDefaultPosition, wxSize(400, -1));
29 comboBox->Bind(wxEVT_COMBOBOX, &GpuList::OnComboBox, this);
32 wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
34 sizer->Add(comboBox, 0, wxALIGN_CENTER_VERTICAL); // Vertically center the comboBox
36 this->SetSizerAndFit(sizer);
41 auto cfg = Config::instance();
42 auto lister_binary = cfg->gpu_binary_location() + "/" + "gpu_lister";
43 auto lister_file = cfg->gpu_binary_location() + "/" + "gpus.txt";
44 if (boost::filesystem::exists(lister_binary)) {
45 auto gpu_names = get_gpu_names(lister_binary, lister_file);
48 for (const auto& name : gpu_names)
49 comboBox->Append(name);
53 int getSelection(void)
58 void setSelection(int sel)
60 if ((int)comboBox->GetCount() > sel)
61 comboBox->SetSelection(sel);
65 void OnComboBox([[maybe_unused]] wxCommandEvent& event)
67 selection = comboBox->GetSelection();
68 if (selection != wxNOT_FOUND)
69 Config::instance()->set_selected_gpu(selection);
76 class GPUPage : public Page
79 GPUPage(wxSize panel_size, int border)
80 : Page(panel_size, border)
81 , _enable_gpu(nullptr)
82 , _binary_location(nullptr)
83 , _gpu_list_control(nullptr)
87 wxString GetName() const override
93 wxBitmap GetLargeIcon() const override
95 return wxBitmap(icon_path("tms"), wxBITMAP_TYPE_PNG);
100 void setup() override
102 auto config = Config::instance();
104 _enable_gpu = new CheckBox(_panel, _("Enable GPU Acceleration"));
105 _panel->GetSizer()->Add(_enable_gpu, 0, wxALL | wxEXPAND, _border);
107 wxFlexGridSizer* table = new wxFlexGridSizer(2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
108 table->AddGrowableCol(1, 1);
109 _panel->GetSizer()->Add(table, 1, wxALL | wxEXPAND, _border);
111 add_label_to_sizer(table, _panel, _("Acceleration Binary Folder"), true, 0, wxLEFT | wxLEFT | wxALIGN_CENTRE_VERTICAL);
112 _binary_location = new wxDirPickerCtrl(_panel, wxDD_DIR_MUST_EXIST);
113 table->Add(_binary_location, 1, wxEXPAND);
115 add_label_to_sizer(table, _panel, _("GPU Selection"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
116 _gpu_list_control = new GpuList(_panel);
117 table->Add(_gpu_list_control, 1, wxEXPAND);
119 add_label_to_sizer(table, _panel, _("License Server"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
120 _server = new wxTextCtrl(_panel, wxID_ANY);
121 table->Add(_server, 1, wxEXPAND | wxALL);
123 add_label_to_sizer(table, _panel, _("Port"), false, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
124 _port = new wxSpinCtrl(_panel, wxID_ANY);
125 _port->SetRange(0, 65535);
128 add_label_to_sizer(table, _panel, _("License"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
129 _license = new PasswordEntry(_panel);
130 table->Add(_license->get_panel(), 1, wxEXPAND | wxALL);
132 _enable_gpu->bind(&GPUPage::enable_gpu_changed, this);
133 _binary_location->Bind(wxEVT_DIRPICKER_CHANGED, boost::bind(&GPUPage::binary_location_changed, this));
134 _server->Bind(wxEVT_TEXT, boost::bind(&GPUPage::server_changed, this));
135 _port->Bind(wxEVT_SPINCTRL, boost::bind(&GPUPage::port_changed, this));
136 _license->Changed.connect(boost::bind(&GPUPage::license_changed, this));
138 _binary_location->Enable(config->enable_gpu());
139 _gpu_list_control->Enable(config->enable_gpu());
140 _server->Enable(config->enable_gpu());
141 _port->Enable(config->enable_gpu());
142 _license->get_panel()->Enable(config->enable_gpu());
145 void config_changed() override
147 auto config = Config::instance();
149 checked_set(_enable_gpu, config->enable_gpu());
150 _binary_location->SetPath(config->gpu_binary_location());
151 _gpu_list_control->update();
152 _gpu_list_control->setSelection(config->selected_gpu());
153 checked_set(_server, config->gpu_license_server());
154 checked_set(_port, config->gpu_license_port());
155 checked_set(_license, config->gpu_license());
158 void enable_gpu_changed()
160 auto config = Config::instance();
162 config->set_enable_gpu(_enable_gpu->GetValue());
163 _binary_location->Enable(config->enable_gpu());
164 _gpu_list_control->Enable(config->enable_gpu());
165 _server->Enable(config->enable_gpu());
166 _port->Enable(config->enable_gpu());
167 _license->get_panel()->Enable(config->enable_gpu());
170 void binary_location_changed()
172 Config::instance()->set_gpu_binary_location(wx_to_std(_binary_location->GetPath()));
173 _gpu_list_control->update();
176 void server_changed()
178 Config::instance()->set_gpu_license_server(wx_to_std(_server->GetValue()));
183 Config::instance()->set_gpu_license_port(_port->GetValue());
186 void license_changed()
188 Config::instance()->set_gpu_license(_license->get());
191 CheckBox* _enable_gpu;
192 wxDirPickerCtrl* _binary_location;
193 GpuList* _gpu_list_control;
196 PasswordEntry* _license;