3 static std::vector<std::string> get_gpu_names(std::string binary, std::string filename)
5 // Execute the GPU listing program and redirect its output to a file
6 if (std::system((binary + " > " + filename).c_str()) < 0) {
10 std::vector<std::string> gpu_names;
11 std::ifstream file(filename);
15 while (std::getline(file, line))
16 gpu_names.push_back(line);
23 class GpuList : public wxPanel
26 GpuList(wxPanel* parent) : wxPanel(parent, wxID_ANY), selection(0) {
27 comboBox = new wxComboBox(this, wxID_ANY, "", wxDefaultPosition, wxSize(400, -1));
28 comboBox->Bind(wxEVT_COMBOBOX, &GpuList::OnComboBox, this);
31 wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
33 sizer->Add(comboBox, 0, wxALIGN_CENTER_VERTICAL); // Vertically center the comboBox
35 this->SetSizerAndFit(sizer);
38 auto cfg = Config::instance();
39 auto lister_binary = cfg->gpu_binary_location() + "/" + "gpu_lister";
40 auto lister_file = cfg->gpu_binary_location () + "/" + "gpus.txt";
41 if (boost::filesystem::exists(lister_binary)) {
42 auto gpu_names = get_gpu_names(lister_binary, lister_file);
45 for (const auto& name : gpu_names)
46 comboBox->Append(name);
50 int getSelection(void) {
53 void setSelection(int sel) {
54 if ((int)comboBox->GetCount() > sel)
55 comboBox->SetSelection(sel);
59 void OnComboBox([[maybe_unused]] wxCommandEvent& event) {
60 selection = comboBox->GetSelection();
61 if (selection != wxNOT_FOUND)
62 Config::instance ()->set_selected_gpu(selection);
69 class GPUPage : public Page
72 GPUPage (wxSize panel_size, int border)
73 : Page (panel_size, border),
74 _enable_gpu(nullptr), _binary_location(nullptr), _gpu_list_control(nullptr)
77 wxString GetName () const override
83 wxBitmap GetLargeIcon () const override
85 return wxBitmap(icon_path("tms"), wxBITMAP_TYPE_PNG);
90 void setup () override
92 auto config = Config::instance ();
94 _enable_gpu = new CheckBox (_panel, _("Enable GPU Acceleration"));
95 _panel->GetSizer()->Add (_enable_gpu, 0, wxALL | wxEXPAND, _border);
97 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
98 table->AddGrowableCol (1, 1);
99 _panel->GetSizer()->Add (table, 1, wxALL | wxEXPAND, _border);
101 add_label_to_sizer (table, _panel, _("Acceleration Binary Folder"), true, 0, wxLEFT | wxLEFT | wxALIGN_CENTRE_VERTICAL);
102 _binary_location = new wxDirPickerCtrl (_panel, wxDD_DIR_MUST_EXIST);
103 table->Add (_binary_location, 1, wxEXPAND);
105 add_label_to_sizer (table, _panel, _("GPU Selection"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
106 _gpu_list_control = new GpuList(_panel);
107 table->Add (_gpu_list_control, 1, wxEXPAND);
109 add_label_to_sizer (table, _panel, _("License Server"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
110 _server = new wxTextCtrl (_panel, wxID_ANY);
111 table->Add (_server, 1, wxEXPAND | wxALL);
113 add_label_to_sizer (table, _panel, _("Port"), false, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
114 _port = new wxSpinCtrl (_panel, wxID_ANY);
115 _port->SetRange (0, 65535);
118 add_label_to_sizer (table, _panel, _("License"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
119 _license = new PasswordEntry (_panel);
120 table->Add (_license->get_panel(), 1, wxEXPAND | wxALL);
122 _enable_gpu->bind(&GPUPage::enable_gpu_changed, this);
123 _binary_location->Bind (wxEVT_DIRPICKER_CHANGED, boost::bind (&GPUPage::binary_location_changed, this));
124 _server->Bind (wxEVT_TEXT, boost::bind(&GPUPage::server_changed, this));
125 _port->Bind (wxEVT_SPINCTRL, boost::bind(&GPUPage::port_changed, this));
126 _license->Changed.connect (boost::bind(&GPUPage::license_changed, this));
128 _binary_location->Enable(config->enable_gpu());
129 _gpu_list_control->Enable(config->enable_gpu());
130 _server->Enable(config->enable_gpu());
131 _port->Enable(config->enable_gpu());
132 _license->get_panel()->Enable(config->enable_gpu());
136 void config_changed () override
138 auto config = Config::instance ();
140 checked_set (_enable_gpu, config->enable_gpu());
141 _binary_location->SetPath(config->gpu_binary_location ());
142 _gpu_list_control->update();
143 _gpu_list_control->setSelection(config->selected_gpu());
144 checked_set (_server, config->gpu_license_server());
145 checked_set (_port, config->gpu_license_port());
146 checked_set (_license, config->gpu_license());
149 void enable_gpu_changed ()
151 auto config = Config::instance ();
153 config->set_enable_gpu (_enable_gpu->GetValue());
154 _binary_location->Enable(config->enable_gpu());
155 _gpu_list_control->Enable(config->enable_gpu());
156 _server->Enable(config->enable_gpu());
157 _port->Enable(config->enable_gpu());
158 _license->get_panel()->Enable(config->enable_gpu());
161 void binary_location_changed ()
163 Config::instance()->set_gpu_binary_location (wx_to_std (_binary_location->GetPath ()));
164 _gpu_list_control->update();
167 void server_changed ()
169 Config::instance()->set_gpu_license_server(wx_to_std(_server->GetValue()));
174 Config::instance()->set_gpu_license_port(_port->GetValue());
177 void license_changed ()
179 Config::instance()->set_gpu_license(_license->get());
182 CheckBox* _enable_gpu;
183 wxDirPickerCtrl* _binary_location;
184 GpuList *_gpu_list_control;
187 PasswordEntry* _license;