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);
22 class GpuList : public wxPanel
25 GpuList(wxPanel* parent)
26 : wxPanel(parent, wxID_ANY)
29 _combo_box = new wxComboBox(this, wxID_ANY, "", wxDefaultPosition, wxSize(400, -1));
30 _combo_box->Bind(wxEVT_COMBOBOX, &GpuList::on_combo_box, this);
33 wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
35 sizer->Add(_combo_box, 0, wxALIGN_CENTER_VERTICAL); // Vertically center the comboBox
37 this->SetSizerAndFit(sizer);
42 auto cfg = Config::instance();
43 auto lister_binary = cfg->gpu_binary_location() + "/" + "gpu_lister";
44 auto lister_file = cfg->gpu_binary_location() + "/" + "gpus.txt";
45 if (boost::filesystem::exists(lister_binary)) {
46 auto gpu_names = get_gpu_names(lister_binary, lister_file);
49 for (const auto& name : gpu_names) {
50 _combo_box->Append(name);
60 void set_selection(int sel)
62 if ((int)_combo_box->GetCount() > sel) {
63 _combo_box->SetSelection(sel);
68 void on_combo_box([[maybe_unused]] wxCommandEvent& event)
70 _selection = _combo_box->GetSelection();
71 if (_selection != wxNOT_FOUND) {
72 Config::instance()->set_selected_gpu(_selection);
76 wxComboBox* _combo_box;
80 class GPUPage : public Page
83 GPUPage(wxSize panel_size, int border)
84 : Page(panel_size, border)
85 , _enable_gpu(nullptr)
86 , _binary_location(nullptr)
87 , _gpu_list_control(nullptr)
91 wxString GetName() const override
97 wxBitmap GetLargeIcon() const override
99 return wxBitmap(icon_path("tms"), wxBITMAP_TYPE_PNG);
104 void setup() override
106 auto config = Config::instance();
108 _enable_gpu = new CheckBox(_panel, _("Enable GPU Acceleration"));
109 _panel->GetSizer()->Add(_enable_gpu, 0, wxALL | wxEXPAND, _border);
111 wxFlexGridSizer* table = new wxFlexGridSizer(2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
112 table->AddGrowableCol(1, 1);
113 _panel->GetSizer()->Add(table, 1, wxALL | wxEXPAND, _border);
115 add_label_to_sizer(table, _panel, _("Acceleration Binary Folder"), true, 0, wxLEFT | wxLEFT | wxALIGN_CENTRE_VERTICAL);
116 _binary_location = new wxDirPickerCtrl(_panel, wxDD_DIR_MUST_EXIST);
117 table->Add(_binary_location, 1, wxEXPAND);
119 add_label_to_sizer(table, _panel, _("GPU Selection"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
120 _gpu_list_control = new GpuList(_panel);
121 table->Add(_gpu_list_control, 1, wxEXPAND);
123 add_label_to_sizer(table, _panel, _("License Server"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
124 _server = new wxTextCtrl(_panel, wxID_ANY);
125 table->Add(_server, 1, wxEXPAND | wxALL);
127 add_label_to_sizer(table, _panel, _("Port"), false, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
128 _port = new wxSpinCtrl(_panel, wxID_ANY);
129 _port->SetRange(0, 65535);
132 add_label_to_sizer(table, _panel, _("License"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
133 _license = new PasswordEntry(_panel);
134 table->Add(_license->get_panel(), 1, wxEXPAND | wxALL);
136 _enable_gpu->bind(&GPUPage::enable_gpu_changed, this);
137 _binary_location->Bind(wxEVT_DIRPICKER_CHANGED, boost::bind(&GPUPage::binary_location_changed, this));
138 _server->Bind(wxEVT_TEXT, boost::bind(&GPUPage::server_changed, this));
139 _port->Bind(wxEVT_SPINCTRL, boost::bind(&GPUPage::port_changed, this));
140 _license->Changed.connect(boost::bind(&GPUPage::license_changed, this));
142 _binary_location->Enable(config->enable_gpu());
143 _gpu_list_control->Enable(config->enable_gpu());
144 _server->Enable(config->enable_gpu());
145 _port->Enable(config->enable_gpu());
146 _license->get_panel()->Enable(config->enable_gpu());
149 void config_changed() override
151 auto config = Config::instance();
153 checked_set(_enable_gpu, config->enable_gpu());
154 _binary_location->SetPath(config->gpu_binary_location());
155 _gpu_list_control->update();
156 _gpu_list_control->set_selection(config->selected_gpu());
157 checked_set(_server, config->gpu_license_server());
158 checked_set(_port, config->gpu_license_port());
159 checked_set(_license, config->gpu_license());
162 void enable_gpu_changed()
164 auto config = Config::instance();
166 config->set_enable_gpu(_enable_gpu->GetValue());
167 _binary_location->Enable(config->enable_gpu());
168 _gpu_list_control->Enable(config->enable_gpu());
169 _server->Enable(config->enable_gpu());
170 _port->Enable(config->enable_gpu());
171 _license->get_panel()->Enable(config->enable_gpu());
174 void binary_location_changed()
176 Config::instance()->set_gpu_binary_location(wx_to_std(_binary_location->GetPath()));
177 _gpu_list_control->update();
180 void server_changed()
182 Config::instance()->set_gpu_license_server(wx_to_std(_server->GetValue()));
187 Config::instance()->set_gpu_license_port(_port->GetValue());
190 void license_changed()
192 Config::instance()->set_gpu_license(_license->get());
195 CheckBox* _enable_gpu;
196 wxDirPickerCtrl* _binary_location;
197 GpuList* _gpu_list_control;
200 PasswordEntry* _license;