@@ -181,6 +181,43 @@ static std::vector<SP<CSessionDevice>> scanGPUs(SP<CBackend> backend) {
181
181
return vecDevices;
182
182
}
183
183
184
+ SP<CDRMBackend> Aquamarine::CDRMBackend::fromGpu (std::string path, SP<CBackend> backend, SP<CDRMBackend> primary) {
185
+ auto gpu = CSessionDevice::openIfKMS (backend->session , path);
186
+ if (!gpu) {
187
+ return nullptr ;
188
+ }
189
+
190
+ auto drmBackend = SP<CDRMBackend>(new CDRMBackend (backend));
191
+ drmBackend->self = drmBackend;
192
+
193
+ if (!drmBackend->registerGPU (gpu, primary)) {
194
+ backend->log (AQ_LOG_ERROR, std::format (" drm: Failed to register gpu {}" , gpu->path ));
195
+ return nullptr ;
196
+ } else
197
+ backend->log (AQ_LOG_DEBUG, std::format (" drm: Registered gpu {}" , gpu->path ));
198
+
199
+ if (!drmBackend->checkFeatures ()) {
200
+ backend->log (AQ_LOG_ERROR, " drm: Failed checking features" );
201
+ return nullptr ;
202
+ }
203
+
204
+ if (!drmBackend->initResources ()) {
205
+ backend->log (AQ_LOG_ERROR, " drm: Failed initializing resources" );
206
+ return nullptr ;
207
+ }
208
+
209
+ backend->log (AQ_LOG_DEBUG, std::format (" drm: Basic init pass for gpu {}" , gpu->path ));
210
+
211
+ drmBackend->grabFormats ();
212
+
213
+ drmBackend->dumbAllocator = CDRMDumbAllocator::create (gpu->fd , backend);
214
+
215
+ // so that session can handle udev change/remove events for this gpu
216
+ backend->session ->sessionDevices .push_back (gpu);
217
+
218
+ return drmBackend;
219
+ }
220
+
184
221
std::vector<SP<CDRMBackend>> Aquamarine::CDRMBackend::attempt (SP<CBackend> backend) {
185
222
if (!backend->session )
186
223
backend->session = CSession::attempt (backend);
@@ -269,7 +306,15 @@ std::vector<SP<CDRMBackend>> Aquamarine::CDRMBackend::attempt(SP<CBackend> backe
269
306
}
270
307
271
308
Aquamarine::CDRMBackend::~CDRMBackend () {
272
- ;
309
+ for (auto conn : connectors) {
310
+ conn->disconnect ();
311
+ conn.reset ();
312
+ }
313
+
314
+ rendererState.allocator ->destroyBuffers ();
315
+
316
+ rendererState.renderer .reset ();
317
+ rendererState.allocator .reset ();
273
318
}
274
319
275
320
void Aquamarine::CDRMBackend::log (eBackendLogLevel l, const std::string& s) {
@@ -663,8 +708,10 @@ bool Aquamarine::CDRMBackend::registerGPU(SP<CSessionDevice> gpu_, SP<CDRMBacken
663
708
}
664
709
});
665
710
666
- listeners.gpuRemove = gpu->events .remove .registerListener (
667
- [this ](std::any d) { backend->log (AQ_LOG_ERROR, std::format (" drm: !!!!FIXME: Got a remove event for {}, this is not handled properly!!!!!" , gpuName)); });
711
+ listeners.gpuRemove = gpu->events .remove .registerListener ([this ](std::any d) {
712
+ std::erase_if (backend->implementations , [this ](const auto & impl) { return impl->drmFD () == this ->drmFD (); });
713
+ backend->events .pollFDsChanged .emit ();
714
+ });
668
715
669
716
return true ;
670
717
}
0 commit comments