3 #include "gpu_config_panel.h"
4 #include "password_entry.h"
13 static std::vector<std::string>
14 get_gpu_names(std::string binary, std::string filename)
16 // Execute the GPU listing program and redirect its output to a file
17 std::system((binary + " > " + filename).c_str());
19 std::vector<std::string> gpu_names;
20 std::ifstream file(filename);
23 while (std::getline(file, line)) {
24 gpu_names.push_back(line);
33 class GPUList : public wxPanel
36 GPUList(wxPanel* parent)
37 : wxPanel(parent, wxID_ANY)
40 _combo_box = new wxComboBox(this, wxID_ANY, "", wxDefaultPosition, wxSize(400, -1));
41 _combo_box->Bind(wxEVT_COMBOBOX, &GPUList::on_combo_box, this);
44 wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
46 sizer->Add(_combo_box, 0, wxALIGN_CENTER_VERTICAL); // Vertically center the comboBox
48 this->SetSizerAndFit(sizer);
53 auto cfg = Config::instance();
54 auto lister_binary = cfg->gpu_binary_location() + "/" + "gpu_lister";
55 auto lister_file = cfg->gpu_binary_location() + "/" + "gpus.txt";
56 if (boost::filesystem::exists(lister_binary)) {
57 auto gpu_names = get_gpu_names(lister_binary, lister_file);
60 for (const auto& name : gpu_names) {
61 _combo_box->Append(name);
71 void set_selection(int sel)
73 if ((int)_combo_box->GetCount() > sel) {
74 _combo_box->SetSelection(sel);
79 void on_combo_box([[maybe_unused]] wxCommandEvent& event)
81 _selection = _combo_box->GetSelection();
82 if (_selection != wxNOT_FOUND) {
83 Config::instance()->set_selected_gpu(_selection);
87 wxComboBox* _combo_box;
92 GPUPage::GPUPage(wxSize panel_size, int border)
93 : Page(panel_size, border)
94 , _enable_gpu(nullptr)
95 , _binary_location(nullptr)
96 , _gpu_list_control(nullptr)
103 GPUPage::GetName() const
111 GPUPage::GetLargeIcon() const
113 return wxBitmap(icon_path("tms"), wxBITMAP_TYPE_PNG);
121 auto config = Config::instance();
123 _enable_gpu = new CheckBox(_panel, _("Enable GPU Acceleration"));
124 _panel->GetSizer()->Add(_enable_gpu, 0, wxALL | wxEXPAND, _border);
126 wxFlexGridSizer* table = new wxFlexGridSizer(2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
127 table->AddGrowableCol(1, 1);
128 _panel->GetSizer()->Add(table, 1, wxALL | wxEXPAND, _border);
130 add_label_to_sizer(table, _panel, _("Acceleration Binary Folder"), true, 0, wxLEFT | wxLEFT | wxALIGN_CENTRE_VERTICAL);
131 _binary_location = new wxDirPickerCtrl(_panel, wxDD_DIR_MUST_EXIST);
132 table->Add(_binary_location, 1, wxEXPAND);
134 add_label_to_sizer(table, _panel, _("GPU Selection"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
135 _gpu_list_control = new GPUList(_panel);
136 table->Add(_gpu_list_control, 1, wxEXPAND);
138 add_label_to_sizer(table, _panel, _("License Server"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
139 _server = new wxTextCtrl(_panel, wxID_ANY);
140 table->Add(_server, 1, wxEXPAND | wxALL);
142 add_label_to_sizer(table, _panel, _("Port"), false, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
143 _port = new wxSpinCtrl(_panel, wxID_ANY);
144 _port->SetRange(0, 65535);
147 add_label_to_sizer(table, _panel, _("License"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
148 _license = new PasswordEntry(_panel);
149 table->Add(_license->get_panel(), 1, wxEXPAND | wxALL);
151 _enable_gpu->bind(&GPUPage::enable_gpu_changed, this);
152 _binary_location->Bind(wxEVT_DIRPICKER_CHANGED, boost::bind(&GPUPage::binary_location_changed, this));
153 _server->Bind(wxEVT_TEXT, boost::bind(&GPUPage::server_changed, this));
154 _port->Bind(wxEVT_SPINCTRL, boost::bind(&GPUPage::port_changed, this));
155 _license->Changed.connect(boost::bind(&GPUPage::license_changed, this));
157 _binary_location->Enable(config->enable_gpu());
158 _gpu_list_control->Enable(config->enable_gpu());
159 _server->Enable(config->enable_gpu());
160 _port->Enable(config->enable_gpu());
161 _license->get_panel()->Enable(config->enable_gpu());
165 void GPUPage::config_changed()
167 auto config = Config::instance();
169 checked_set(_enable_gpu, config->enable_gpu());
170 _binary_location->SetPath(config->gpu_binary_location());
171 _gpu_list_control->update();
172 _gpu_list_control->set_selection(config->selected_gpu());
173 checked_set(_server, config->gpu_license_server());
174 checked_set(_port, config->gpu_license_port());
175 checked_set(_license, config->gpu_license());
179 void GPUPage::enable_gpu_changed()
181 auto config = Config::instance();
183 config->set_enable_gpu(_enable_gpu->GetValue());
184 _binary_location->Enable(config->enable_gpu());
185 _gpu_list_control->Enable(config->enable_gpu());
186 _server->Enable(config->enable_gpu());
187 _port->Enable(config->enable_gpu());
188 _license->get_panel()->Enable(config->enable_gpu());
192 void GPUPage::binary_location_changed()
194 Config::instance()->set_gpu_binary_location(wx_to_std(_binary_location->GetPath()));
195 _gpu_list_control->update();
199 void GPUPage::server_changed()
201 Config::instance()->set_gpu_license_server(wx_to_std(_server->GetValue()));
205 void GPUPage::port_changed()
207 Config::instance()->set_gpu_license_port(_port->GetValue());
211 void GPUPage::license_changed()
213 Config::instance()->set_gpu_license(_license->get());