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 std::system((binary + " > " + filename).c_str());
8 std::vector<std::string> gpu_names;
9 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) : wxPanel(parent, wxID_ANY), selection(0) {
25 comboBox = new wxComboBox(this, wxID_ANY, "", wxDefaultPosition, wxSize(400, -1));
26 comboBox->Bind(wxEVT_COMBOBOX, &GpuList::OnComboBox, this);
29 wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
31 sizer->Add(comboBox, 0, wxALIGN_CENTER_VERTICAL); // Vertically center the comboBox
33 this->SetSizerAndFit(sizer);
36 auto cfg = Config::instance();
37 auto lister_binary = cfg->gpu_binary_location() + "/" + "gpu_lister";
38 auto lister_file = cfg->gpu_binary_location () + "/" + "gpus.txt";
39 if (boost::filesystem::exists(lister_binary)) {
40 auto gpu_names = get_gpu_names(lister_binary, lister_file);
43 for (const auto& name : gpu_names)
44 comboBox->Append(name);
48 int getSelection(void) {
51 void setSelection(int sel) {
52 if ((int)comboBox->GetCount() > sel)
53 comboBox->SetSelection(sel);
57 void OnComboBox([[maybe_unused]] wxCommandEvent& event) {
58 selection = comboBox->GetSelection();
59 if (selection != wxNOT_FOUND)
60 Config::instance ()->set_selected_gpu(selection);
67 class GPUPage : public Page
70 GPUPage (wxSize panel_size, int border)
71 : Page (panel_size, border),
72 _enable_gpu(nullptr), _binary_location(nullptr), _gpu_list_control(nullptr)
75 wxString GetName () const override
81 wxBitmap GetLargeIcon () const override
83 return wxBitmap(icon_path("tms"), wxBITMAP_TYPE_PNG);
88 void setup () override
90 auto config = Config::instance ();
92 _enable_gpu = new CheckBox (_panel, _("Enable GPU Acceleration"));
93 _panel->GetSizer()->Add (_enable_gpu, 0, wxALL | wxEXPAND, _border);
95 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
96 table->AddGrowableCol (1, 1);
97 _panel->GetSizer()->Add (table, 1, wxALL | wxEXPAND, _border);
99 add_label_to_sizer (table, _panel, _("Acceleration Binary Folder"), true, 0, wxLEFT | wxLEFT | wxALIGN_CENTRE_VERTICAL);
100 _binary_location = new wxDirPickerCtrl (_panel, wxDD_DIR_MUST_EXIST);
101 table->Add (_binary_location, 1, wxEXPAND);
103 add_label_to_sizer (table, _panel, _("GPU Selection"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
104 _gpu_list_control = new GpuList(_panel);
105 table->Add (_gpu_list_control, 1, wxEXPAND);
107 add_label_to_sizer (table, _panel, _("License Server"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
108 _server = new wxTextCtrl (_panel, wxID_ANY);
109 table->Add (_server, 1, wxEXPAND | wxALL);
111 add_label_to_sizer (table, _panel, _("Port"), false, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
112 _port = new wxSpinCtrl (_panel, wxID_ANY);
113 _port->SetRange (0, 65535);
116 add_label_to_sizer (table, _panel, _("License"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
117 _license = new PasswordEntry (_panel);
118 table->Add (_license->get_panel(), 1, wxEXPAND | wxALL);
120 _enable_gpu->bind(&GPUPage::enable_gpu_changed, this);
121 _binary_location->Bind (wxEVT_DIRPICKER_CHANGED, boost::bind (&GPUPage::binary_location_changed, this));
122 _server->Bind (wxEVT_TEXT, boost::bind(&GPUPage::server_changed, this));
123 _port->Bind (wxEVT_SPINCTRL, boost::bind(&GPUPage::port_changed, this));
124 _license->Changed.connect (boost::bind(&GPUPage::license_changed, this));
126 _binary_location->Enable(config->enable_gpu());
127 _gpu_list_control->Enable(config->enable_gpu());
128 _server->Enable(config->enable_gpu());
129 _port->Enable(config->enable_gpu());
130 _license->get_panel()->Enable(config->enable_gpu());
134 void config_changed () override
136 auto config = Config::instance ();
138 checked_set (_enable_gpu, config->enable_gpu());
139 _binary_location->SetPath(config->gpu_binary_location ());
140 _gpu_list_control->update();
141 _gpu_list_control->setSelection(config->selected_gpu());
142 checked_set (_server, config->gpu_license_server());
143 checked_set (_port, config->gpu_license_port());
144 checked_set (_license, config->gpu_license());
147 void enable_gpu_changed ()
149 auto config = Config::instance ();
151 config->set_enable_gpu (_enable_gpu->GetValue());
152 _binary_location->Enable(config->enable_gpu());
153 _gpu_list_control->Enable(config->enable_gpu());
154 _server->Enable(config->enable_gpu());
155 _port->Enable(config->enable_gpu());
156 _license->get_panel()->Enable(config->enable_gpu());
159 void binary_location_changed ()
161 Config::instance()->set_gpu_binary_location (wx_to_std (_binary_location->GetPath ()));
162 _gpu_list_control->update();
165 void server_changed ()
167 Config::instance()->set_gpu_license_server(wx_to_std(_server->GetValue()));
172 Config::instance()->set_gpu_license_port(_port->GetValue());
175 void license_changed ()
177 Config::instance()->set_gpu_license(_license->get());
180 CheckBox* _enable_gpu;
181 wxDirPickerCtrl* _binary_location;
182 GpuList *_gpu_list_control;
185 PasswordEntry* _license;