-
Notifications
You must be signed in to change notification settings - Fork 0
/
1441.patch
4155 lines (3645 loc) · 152 KB
/
1441.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From ca329a50d020f30539e163626f7e041faf504c58 Mon Sep 17 00:00:00 2001
From: Daniel van Vugt <[email protected]>
Date: Wed, 10 Nov 2021 18:55:53 +0800
Subject: [PATCH 01/49] onscreen/native: Tidy up secondary GPU buffer tracking
The primary plane of a CRTC can only have one `current_fb` and therefore
only one `next_fb`, so don't confuse the situation by maintaining two of
each. In the past a single onscreen targeted multiple CRTCs meaning
separate tracking was necessary, but not anymore.
If we're using `COPY_MODE_ZERO` then the `imported_buffer` will reference
the importee internally. We don't need to keep a redundant reference to
the old buffer after importation.
If we're using `COPY_MODE_PRIMARY` or `COPY_MODE_SECONDARY_GPU` then we
only need to keep the final copy for the duration of scanout.
All of that happens before the flip so only one `next_fb` needs to live on
after the flip. And if there's only one `next_fb` then there's only one
`current_fb`.
In a related cleanup we now also ensure that `onscreen_native->gbm.next_fb`
is only assigned once per frame.
---
src/backends/native/meta-onscreen-native.c | 195 +++++++++------------
1 file changed, 87 insertions(+), 108 deletions(-)
diff --git a/src/backends/native/meta-onscreen-native.c b/src/backends/native/meta-onscreen-native.c
index a107a99bb3..a6052305e0 100644
--- a/src/backends/native/meta-onscreen-native.c
+++ b/src/backends/native/meta-onscreen-native.c
@@ -67,8 +67,6 @@ typedef struct _MetaOnscreenNativeSecondaryGpuState
struct {
struct gbm_surface *surface;
- MetaDrmBuffer *current_fb;
- MetaDrmBuffer *next_fb;
} gbm;
struct {
@@ -117,41 +115,12 @@ init_secondary_gpu_state (MetaRendererNative *renderer_native,
CoglOnscreen *onscreen,
GError **error);
-static void
-swap_secondary_drm_fb (CoglOnscreen *onscreen)
-{
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
- MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state;
-
- secondary_gpu_state = onscreen_native->secondary_gpu_state;
- if (!secondary_gpu_state)
- return;
-
- g_set_object (&secondary_gpu_state->gbm.current_fb,
- secondary_gpu_state->gbm.next_fb);
- g_clear_object (&secondary_gpu_state->gbm.next_fb);
-}
-
-static void
-free_current_secondary_bo (CoglOnscreen *onscreen)
-{
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
- MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state;
-
- secondary_gpu_state = onscreen_native->secondary_gpu_state;
- if (!secondary_gpu_state)
- return;
-
- g_clear_object (&secondary_gpu_state->gbm.current_fb);
-}
-
static void
free_current_bo (CoglOnscreen *onscreen)
{
MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
g_clear_object (&onscreen_native->gbm.current_fb);
- free_current_secondary_bo (onscreen);
}
static void
@@ -166,8 +135,6 @@ meta_onscreen_native_swap_drm_fb (CoglOnscreen *onscreen)
g_set_object (&onscreen_native->gbm.current_fb, onscreen_native->gbm.next_fb);
g_clear_object (&onscreen_native->gbm.next_fb);
-
- swap_secondary_drm_fb (onscreen);
}
static void
@@ -436,7 +403,6 @@ meta_onscreen_native_flip_crtc (CoglOnscreen *onscreen,
MetaKmsDevice *kms_device;
MetaKms *kms;
MetaKmsUpdate *kms_update;
- MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state = NULL;
MetaDrmBuffer *buffer;
MetaKmsPlaneAssignment *plane_assignment;
@@ -455,15 +421,7 @@ meta_onscreen_native_flip_crtc (CoglOnscreen *onscreen,
switch (renderer_gpu_data->mode)
{
case META_RENDERER_NATIVE_MODE_GBM:
- if (gpu_kms == render_gpu)
- {
- buffer = onscreen_native->gbm.next_fb;
- }
- else
- {
- secondary_gpu_state = onscreen_native->secondary_gpu_state;
- buffer = secondary_gpu_state->gbm.next_fb;
- }
+ buffer = onscreen_native->gbm.next_fb;
plane_assignment = meta_crtc_kms_assign_primary_plane (crtc_kms,
buffer,
@@ -568,8 +526,6 @@ secondary_gpu_state_free (MetaOnscreenNativeSecondaryGpuState *secondary_gpu_sta
NULL);
}
- g_clear_object (&secondary_gpu_state->gbm.current_fb);
- g_clear_object (&secondary_gpu_state->gbm.next_fb);
g_clear_pointer (&secondary_gpu_state->gbm.surface, gbm_surface_destroy);
secondary_gpu_release_dumb (secondary_gpu_state);
@@ -577,11 +533,11 @@ secondary_gpu_state_free (MetaOnscreenNativeSecondaryGpuState *secondary_gpu_sta
g_free (secondary_gpu_state);
}
-static gboolean
+static MetaDrmBuffer *
import_shared_framebuffer (CoglOnscreen *onscreen,
- MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state)
+ MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state,
+ MetaDrmBuffer *primary_gpu_fb)
{
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
MetaRenderDevice *render_device;
g_autoptr (GError) error = NULL;
MetaDrmBuffer *imported_buffer;
@@ -589,7 +545,7 @@ import_shared_framebuffer (CoglOnscreen *onscreen,
render_device = secondary_gpu_state->renderer_gpu_data->render_device;
imported_buffer =
meta_render_device_import_dma_buf (render_device,
- onscreen_native->gbm.next_fb,
+ primary_gpu_fb,
&error);
if (!imported_buffer)
{
@@ -603,16 +559,9 @@ import_shared_framebuffer (CoglOnscreen *onscreen,
META_SHARED_FRAMEBUFFER_IMPORT_STATUS_NONE);
secondary_gpu_state->import_status =
META_SHARED_FRAMEBUFFER_IMPORT_STATUS_FAILED;
- return FALSE;
+ return NULL;
}
- /*
- * next_fb may already contain a fallback buffer, so clear it only
- * when we are sure to succeed.
- */
- g_clear_object (&secondary_gpu_state->gbm.next_fb);
- secondary_gpu_state->gbm.next_fb = imported_buffer;
-
if (secondary_gpu_state->import_status ==
META_SHARED_FRAMEBUFFER_IMPORT_STATUS_NONE)
{
@@ -629,16 +578,16 @@ import_shared_framebuffer (CoglOnscreen *onscreen,
secondary_gpu_state->import_status =
META_SHARED_FRAMEBUFFER_IMPORT_STATUS_OK;
- return TRUE;
+ return imported_buffer;
}
-static void
+static MetaDrmBuffer *
copy_shared_framebuffer_gpu (CoglOnscreen *onscreen,
MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state,
MetaRendererNativeGpuData *renderer_gpu_data,
- gboolean *egl_context_changed)
+ gboolean *egl_context_changed,
+ MetaDrmBuffer *primary_gpu_fb)
{
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
MetaRendererNative *renderer_native = renderer_gpu_data->renderer_native;
MetaEgl *egl = meta_renderer_native_get_egl (renderer_native);
MetaGles3 *gles3 = meta_renderer_native_get_gles3 (renderer_native);
@@ -654,9 +603,6 @@ copy_shared_framebuffer_gpu (CoglOnscreen *onscreen,
COGL_TRACE_BEGIN_SCOPED (CopySharedFramebufferSecondaryGpu,
"FB Copy (secondary GPU)");
- g_warn_if_fail (secondary_gpu_state->gbm.next_fb == NULL);
- g_clear_object (&secondary_gpu_state->gbm.next_fb);
-
render_device = renderer_gpu_data->render_device;
egl_display = meta_render_device_get_egl_display (render_device);
@@ -669,13 +615,13 @@ copy_shared_framebuffer_gpu (CoglOnscreen *onscreen,
{
g_warning ("Failed to make current: %s", error->message);
g_error_free (error);
- return;
+ return NULL;
}
*egl_context_changed = TRUE;
- buffer_gbm = META_DRM_BUFFER_GBM (onscreen_native->gbm.next_fb);
+ buffer_gbm = META_DRM_BUFFER_GBM (primary_gpu_fb);
bo = meta_drm_buffer_gbm_get_bo (buffer_gbm);
if (!meta_renderer_native_gles3_blit_shared_bo (egl,
gles3,
@@ -687,7 +633,7 @@ copy_shared_framebuffer_gpu (CoglOnscreen *onscreen,
{
g_warning ("Failed to blit shared framebuffer: %s", error->message);
g_error_free (error);
- return;
+ return NULL;
}
if (!meta_egl_swap_buffers (egl,
@@ -697,7 +643,7 @@ copy_shared_framebuffer_gpu (CoglOnscreen *onscreen,
{
g_warning ("Failed to swap buffers: %s", error->message);
g_error_free (error);
- return;
+ return NULL;
}
use_modifiers = meta_renderer_native_use_modifiers (renderer_native);
@@ -717,10 +663,10 @@ copy_shared_framebuffer_gpu (CoglOnscreen *onscreen,
g_warning ("meta_drm_buffer_gbm_new_lock_front failed: %s",
error->message);
g_error_free (error);
- return;
+ return NULL;
}
- secondary_gpu_state->gbm.next_fb = META_DRM_BUFFER (buffer_gbm);
+ return META_DRM_BUFFER (buffer_gbm);
}
static MetaDrmBufferDumb *
@@ -735,7 +681,7 @@ secondary_gpu_get_next_dumb_buffer (MetaOnscreenNativeSecondaryGpuState *seconda
return secondary_gpu_state->cpu.dumb_fbs[0];
}
-static gboolean
+static MetaDrmBuffer *
copy_shared_framebuffer_primary_gpu (CoglOnscreen *onscreen,
MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state,
const int *rectangles,
@@ -761,13 +707,13 @@ copy_shared_framebuffer_primary_gpu (CoglOnscreen *onscre
if (!secondary_gpu_state ||
secondary_gpu_state->egl_surface == EGL_NO_SURFACE)
- return FALSE;
+ return NULL;
primary_gpu = meta_renderer_native_get_primary_gpu (renderer_native);
primary_gpu_data =
meta_renderer_native_get_gpu_data (renderer_native, primary_gpu);
if (!primary_gpu_data->secondary.has_EGL_EXT_image_dma_buf_import_modifiers)
- return FALSE;
+ return NULL;
buffer_dumb = secondary_gpu_get_next_dumb_buffer (secondary_gpu_state);
buffer = META_DRM_BUFFER (buffer_dumb);
@@ -790,7 +736,7 @@ copy_shared_framebuffer_primary_gpu (CoglOnscreen *onscre
{
meta_topic (META_DEBUG_KMS,
"Failed to create DMA buffer: %s", error->message);
- return FALSE;
+ return NULL;
}
dmabuf_fb =
@@ -808,7 +754,7 @@ copy_shared_framebuffer_primary_gpu (CoglOnscreen *onscre
meta_topic (META_DEBUG_KMS,
"Failed to create DMA buffer for blitting: %s",
error->message);
- return FALSE;
+ return NULL;
}
/* Limit the number of individual copies to 16 */
#define MAX_RECTS 16
@@ -821,7 +767,7 @@ copy_shared_framebuffer_primary_gpu (CoglOnscreen *onscre
&error))
{
g_object_unref (dmabuf_fb);
- return FALSE;
+ return NULL;
}
}
else
@@ -838,20 +784,19 @@ copy_shared_framebuffer_primary_gpu (CoglOnscreen *onscre
&error))
{
g_object_unref (dmabuf_fb);
- return FALSE;
+ return NULL;
}
}
}
g_object_unref (dmabuf_fb);
- g_set_object (&secondary_gpu_state->gbm.next_fb, buffer);
secondary_gpu_state->cpu.current_dumb_fb = buffer_dumb;
- return TRUE;
+ return g_object_ref (buffer);
}
-static void
+static MetaDrmBuffer *
copy_shared_framebuffer_cpu (CoglOnscreen *onscreen,
MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state,
MetaRendererNativeGpuData *renderer_gpu_data)
@@ -903,17 +848,19 @@ copy_shared_framebuffer_cpu (CoglOnscreen *onscreen,
cogl_object_unref (dumb_bitmap);
- g_set_object (&secondary_gpu_state->gbm.next_fb, buffer);
secondary_gpu_state->cpu.current_dumb_fb = buffer_dumb;
+
+ return g_object_ref (buffer);
}
-static void
+static MetaDrmBuffer *
update_secondary_gpu_state_pre_swap_buffers (CoglOnscreen *onscreen,
const int *rectangles,
int n_rectangles)
{
MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state;
+ MetaDrmBuffer *copy = NULL;
COGL_TRACE_BEGIN_SCOPED (MetaRendererNativeGpuStatePreSwapBuffers,
"Onscreen (secondary gpu pre-swap-buffers)");
@@ -939,10 +886,11 @@ update_secondary_gpu_state_pre_swap_buffers (CoglOnscreen *onscreen,
/* prepare fallback */
G_GNUC_FALLTHROUGH;
case META_SHARED_FRAMEBUFFER_COPY_MODE_PRIMARY:
- if (!copy_shared_framebuffer_primary_gpu (onscreen,
- secondary_gpu_state,
- rectangles,
- n_rectangles))
+ copy = copy_shared_framebuffer_primary_gpu (onscreen,
+ secondary_gpu_state,
+ rectangles,
+ n_rectangles);
+ if (!copy)
{
if (!secondary_gpu_state->noted_primary_gpu_copy_failed)
{
@@ -952,9 +900,9 @@ update_secondary_gpu_state_pre_swap_buffers (CoglOnscreen *onscreen,
secondary_gpu_state->noted_primary_gpu_copy_failed = TRUE;
}
- copy_shared_framebuffer_cpu (onscreen,
- secondary_gpu_state,
- renderer_gpu_data);
+ copy = copy_shared_framebuffer_cpu (onscreen,
+ secondary_gpu_state,
+ renderer_gpu_data);
}
else if (!secondary_gpu_state->noted_primary_gpu_copy_ok)
{
@@ -966,11 +914,15 @@ update_secondary_gpu_state_pre_swap_buffers (CoglOnscreen *onscreen,
break;
}
}
+
+ return copy;
}
static void
-update_secondary_gpu_state_post_swap_buffers (CoglOnscreen *onscreen,
- gboolean *egl_context_changed)
+update_secondary_gpu_state_post_swap_buffers (CoglOnscreen *onscreen,
+ gboolean *egl_context_changed,
+ MetaDrmBuffer *primary_gpu_fb,
+ MetaDrmBuffer **secondary_gpu_fb)
{
MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
MetaRendererNative *renderer_native = onscreen_native->renderer_native;
@@ -983,6 +935,7 @@ update_secondary_gpu_state_post_swap_buffers (CoglOnscreen *onscreen,
if (secondary_gpu_state)
{
MetaRendererNativeGpuData *renderer_gpu_data;
+ g_autoptr (MetaDrmBuffer) next_fb = NULL;
renderer_gpu_data =
meta_renderer_native_get_gpu_data (renderer_native,
@@ -990,23 +943,30 @@ update_secondary_gpu_state_post_swap_buffers (CoglOnscreen *onscreen,
switch (renderer_gpu_data->secondary.copy_mode)
{
case META_SHARED_FRAMEBUFFER_COPY_MODE_ZERO:
- if (import_shared_framebuffer (onscreen, secondary_gpu_state))
+ next_fb = import_shared_framebuffer (onscreen,
+ secondary_gpu_state,
+ primary_gpu_fb);
+ if (next_fb)
break;
-
- /* The fallback was prepared in pre_swap_buffers */
+ /* The fallback was prepared in pre_swap_buffers and is currently
+ * in secondary_gpu_fb.
+ */
renderer_gpu_data->secondary.copy_mode =
META_SHARED_FRAMEBUFFER_COPY_MODE_PRIMARY;
G_GNUC_FALLTHROUGH;
case META_SHARED_FRAMEBUFFER_COPY_MODE_PRIMARY:
- /* Done before eglSwapBuffers. */
+ next_fb = g_object_ref (*secondary_gpu_fb);
break;
case META_SHARED_FRAMEBUFFER_COPY_MODE_SECONDARY_GPU:
- copy_shared_framebuffer_gpu (onscreen,
- secondary_gpu_state,
- renderer_gpu_data,
- egl_context_changed);
+ next_fb = copy_shared_framebuffer_gpu (onscreen,
+ secondary_gpu_state,
+ renderer_gpu_data,
+ egl_context_changed,
+ primary_gpu_fb);
break;
}
+
+ g_set_object (secondary_gpu_fb, next_fb);
}
}
@@ -1056,6 +1016,8 @@ meta_onscreen_native_swap_buffers_with_damage (CoglOnscreen *onscreen,
g_autoptr (GError) error = NULL;
MetaDrmBufferFlags buffer_flags;
MetaDrmBufferGbm *buffer_gbm;
+ g_autoptr (MetaDrmBuffer) primary_gpu_fb = NULL;
+ g_autoptr (MetaDrmBuffer) secondary_gpu_fb = NULL;
MetaKmsCrtc *kms_crtc;
MetaKmsDevice *kms_device;
MetaKmsUpdateFlag flags;
@@ -1065,9 +1027,10 @@ meta_onscreen_native_swap_buffers_with_damage (CoglOnscreen *onscreen,
COGL_TRACE_BEGIN_SCOPED (MetaRendererNativeSwapBuffers,
"Onscreen (swap-buffers)");
- update_secondary_gpu_state_pre_swap_buffers (onscreen,
- rectangles,
- n_rectangles);
+ secondary_gpu_fb =
+ update_secondary_gpu_state_pre_swap_buffers (onscreen,
+ rectangles,
+ n_rectangles);
parent_class = COGL_ONSCREEN_CLASS (meta_onscreen_native_parent_class);
parent_class->swap_buffers_with_damage (onscreen,
@@ -1083,9 +1046,6 @@ meta_onscreen_native_swap_buffers_with_damage (CoglOnscreen *onscreen,
switch (renderer_gpu_data->mode)
{
case META_RENDERER_NATIVE_MODE_GBM:
- g_warn_if_fail (onscreen_native->gbm.next_fb == NULL);
- g_clear_object (&onscreen_native->gbm.next_fb);
-
buffer_flags = META_DRM_BUFFER_FLAG_NONE;
if (!meta_renderer_native_use_modifiers (renderer_native))
buffer_flags |= META_DRM_BUFFER_FLAG_DISABLE_MODIFIERS;
@@ -1103,8 +1063,7 @@ meta_onscreen_native_swap_buffers_with_damage (CoglOnscreen *onscreen,
return;
}
- onscreen_native->gbm.next_fb = META_DRM_BUFFER (buffer_gbm);
-
+ primary_gpu_fb = META_DRM_BUFFER (g_steal_pointer (&buffer_gbm));
break;
case META_RENDERER_NATIVE_MODE_SURFACELESS:
g_assert_not_reached ();
@@ -1115,7 +1074,27 @@ meta_onscreen_native_swap_buffers_with_damage (CoglOnscreen *onscreen,
#endif
}
- update_secondary_gpu_state_post_swap_buffers (onscreen, &egl_context_changed);
+ update_secondary_gpu_state_post_swap_buffers (onscreen,
+ &egl_context_changed,
+ primary_gpu_fb,
+ &secondary_gpu_fb);
+
+ switch (renderer_gpu_data->mode)
+ {
+ case META_RENDERER_NATIVE_MODE_GBM:
+ g_warn_if_fail (onscreen_native->gbm.next_fb == NULL);
+ if (onscreen_native->secondary_gpu_state)
+ g_set_object (&onscreen_native->gbm.next_fb, secondary_gpu_fb);
+ else
+ g_set_object (&onscreen_native->gbm.next_fb, primary_gpu_fb);
+ break;
+ case META_RENDERER_NATIVE_MODE_SURFACELESS:
+ break;
+#ifdef HAVE_EGL_DEVICE
+ case META_RENDERER_NATIVE_MODE_EGL_DEVICE:
+ break;
+#endif
+ }
/*
* If we changed EGL context, cogl will have the wrong idea about what is
--
GitLab
From 367e654d7aea9af328c534e566326089149087f4 Mon Sep 17 00:00:00 2001
From: Daniel van Vugt <[email protected]>
Date: Wed, 19 Jan 2022 18:43:15 +0800
Subject: [PATCH 02/49] onscreen/native: Hold primary GPU FBs for the secondary
scanout lifetime
This is out of an abundance of caution. In cases where we have copied the
primary GPU's buffer to a dumb buffer for secondary GPU (DisplayLink)
scanout, we don't really know how long OpenGL will take to complete that
copy in the background. And there is no swap buffers or locking of the
secondary GPU front buffer to guarantee when.
So to avoid needing `glFinish` or similar we now reference the original
source FB for the scanout lifetime of the secondary (dumb) buffer. This
is effectively identical to the pre-!2087 behaviour.
Although it's not theoretically optimal because the primary GPU FB is
not needed after scanout starts (`next_fb` is moved to `current_fb`),
this approach does give us the simplicity of only having to track the
lifetime of a single buffer after it is flipped.
---
src/backends/native/meta-onscreen-native.c | 64 +++++++++++++++++++++-
1 file changed, 61 insertions(+), 3 deletions(-)
diff --git a/src/backends/native/meta-onscreen-native.c b/src/backends/native/meta-onscreen-native.c
index a6052305e0..ffdfeb3148 100644
--- a/src/backends/native/meta-onscreen-native.c
+++ b/src/backends/native/meta-onscreen-native.c
@@ -72,6 +72,7 @@ typedef struct _MetaOnscreenNativeSecondaryGpuState
struct {
MetaDrmBufferDumb *current_dumb_fb;
MetaDrmBufferDumb *dumb_fbs[2];
+ MetaDrmBuffer *source_fbs[2];
} cpu;
gboolean noted_primary_gpu_copy_ok;
@@ -495,13 +496,41 @@ meta_onscreen_native_set_crtc_mode (CoglOnscreen *onscreen,
kms_update);
}
+static void
+hold_primary_gpu_fb_for_secondary_gpu_scanout (MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state,
+ MetaDrmBuffer *primary_gpu_fb,
+ MetaDrmBuffer *secondary_gpu_fb)
+{
+ if (META_IS_DRM_BUFFER_DUMB (secondary_gpu_fb))
+ {
+ MetaDrmBufferDumb *dumb_fb = META_DRM_BUFFER_DUMB (secondary_gpu_fb);
+ int i;
+ const int n = G_N_ELEMENTS (secondary_gpu_state->cpu.dumb_fbs);
+
+ for (i = 0; i < n; i++)
+ {
+ if (dumb_fb == secondary_gpu_state->cpu.dumb_fbs[i])
+ {
+ g_set_object (&secondary_gpu_state->cpu.source_fbs[i],
+ primary_gpu_fb);
+ break;
+ }
+ }
+
+ g_warn_if_fail (i < n);
+ }
+}
+
static void
secondary_gpu_release_dumb (MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state)
{
unsigned i;
for (i = 0; i < G_N_ELEMENTS (secondary_gpu_state->cpu.dumb_fbs); i++)
- g_clear_object (&secondary_gpu_state->cpu.dumb_fbs[i]);
+ {
+ g_clear_object (&secondary_gpu_state->cpu.dumb_fbs[i]);
+ g_clear_object (&secondary_gpu_state->cpu.source_fbs[i]);
+ }
}
static void
@@ -1084,9 +1113,17 @@ meta_onscreen_native_swap_buffers_with_damage (CoglOnscreen *onscreen,
case META_RENDERER_NATIVE_MODE_GBM:
g_warn_if_fail (onscreen_native->gbm.next_fb == NULL);
if (onscreen_native->secondary_gpu_state)
- g_set_object (&onscreen_native->gbm.next_fb, secondary_gpu_fb);
+ {
+ g_set_object (&onscreen_native->gbm.next_fb, secondary_gpu_fb);
+ hold_primary_gpu_fb_for_secondary_gpu_scanout (
+ onscreen_native->secondary_gpu_state,
+ primary_gpu_fb,
+ secondary_gpu_fb);
+ }
else
- g_set_object (&onscreen_native->gbm.next_fb, primary_gpu_fb);
+ {
+ g_set_object (&onscreen_native->gbm.next_fb, primary_gpu_fb);
+ }
break;
case META_RENDERER_NATIVE_MODE_SURFACELESS:
break;
@@ -1966,6 +2003,21 @@ pick_secondary_gpu_framebuffer_format_for_cpu (CoglOnscreen *onscreen)
return DRM_FORMAT_INVALID;
}
+static void
+dumb_toggle_notify (gpointer data,
+ GObject *object,
+ gboolean is_last_ref)
+{
+ MetaDrmBuffer **source_fb = data;
+
+ g_return_if_fail (source_fb != NULL);
+ if (is_last_ref && *source_fb)
+ {
+ g_return_if_fail (META_IS_DRM_BUFFER (*source_fb));
+ g_clear_object (source_fb);
+ }
+}
+
static gboolean
init_secondary_gpu_state_cpu_copy_mode (MetaRendererNative *renderer_native,
CoglOnscreen *onscreen,
@@ -2022,6 +2074,12 @@ init_secondary_gpu_state_cpu_copy_mode (MetaRendererNative *renderer_nat
}
secondary_gpu_state->cpu.dumb_fbs[i] = META_DRM_BUFFER_DUMB (dumb_buffer);
+ g_object_add_toggle_ref (G_OBJECT (dumb_buffer),
+ dumb_toggle_notify,
+ &secondary_gpu_state->cpu.source_fbs[i]);
+
+ /* It was incremented higher than we need by add_toggle_ref */
+ g_object_unref (dumb_buffer);
}
/*
--
GitLab
From 3c771ad854d988b074d5ebc98cafe11ea7b8ae3a Mon Sep 17 00:00:00 2001
From: Daniel van Vugt <[email protected]>
Date: Mon, 16 Aug 2021 17:06:43 +0800
Subject: [PATCH 03/49] kms/update: Hold a reference to the buffer used in a
plane assignment
---
src/backends/native/meta-kms-update.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/backends/native/meta-kms-update.c b/src/backends/native/meta-kms-update.c
index 4c34000ef5..0adb0467b2 100644
--- a/src/backends/native/meta-kms-update.c
+++ b/src/backends/native/meta-kms-update.c
@@ -149,6 +149,7 @@ static void
meta_kms_plane_assignment_free (MetaKmsPlaneAssignment *plane_assignment)
{
g_clear_pointer (&plane_assignment->fb_damage, meta_kms_fb_damage_free);
+ g_clear_object (&plane_assignment->buffer);
g_free (plane_assignment);
}
@@ -228,7 +229,7 @@ meta_kms_update_assign_plane (MetaKmsUpdate *update,
.update = update,
.crtc = crtc,
.plane = plane,
- .buffer = buffer,
+ .buffer = g_object_ref (buffer),
.src_rect = src_rect,
.dst_rect = dst_rect,
.flags = flags,
--
GitLab
From 6fbf7443fd4516ed9f5fed752d3eabd2450f8e89 Mon Sep 17 00:00:00 2001
From: Daniel van Vugt <[email protected]>
Date: Mon, 16 Aug 2021 18:04:10 +0800
Subject: [PATCH 04/49] kms/crtc: Add an API to hold references to buffers
while asssigned to planes
---
src/backends/native/meta-kms-crtc.c | 80 +++++++++++++++++++++++++++++
src/backends/native/meta-kms-crtc.h | 9 ++++
2 files changed, 89 insertions(+)
diff --git a/src/backends/native/meta-kms-crtc.c b/src/backends/native/meta-kms-crtc.c
index ee9e19d2d9..0da9a77853 100644
--- a/src/backends/native/meta-kms-crtc.c
+++ b/src/backends/native/meta-kms-crtc.c
@@ -32,6 +32,12 @@ typedef struct _MetaKmsCrtcPropTable
MetaKmsProp props[META_KMS_CRTC_N_PROPS];
} MetaKmsCrtcPropTable;
+typedef struct
+{
+ MetaDrmBuffer *front, *back;
+ gboolean back_is_set;
+} PlaneState;
+
struct _MetaKmsCrtc
{
GObject parent;
@@ -44,6 +50,8 @@ struct _MetaKmsCrtc
MetaKmsCrtcState current_state;
MetaKmsCrtcPropTable prop_table;
+
+ GHashTable *plane_states;
};
G_DEFINE_TYPE (MetaKmsCrtc, meta_kms_crtc, G_TYPE_OBJECT)
@@ -403,20 +411,91 @@ meta_kms_crtc_new (MetaKmsImplDevice *impl_device,
return crtc;
}
+void
+meta_kms_crtc_remember_plane_buffer (MetaKmsCrtc *crtc,
+ uint32_t plane_id,
+ MetaDrmBuffer *buffer)
+{
+ gpointer key = GUINT_TO_POINTER (plane_id);
+ PlaneState *plane_state;
+
+ plane_state = g_hash_table_lookup (crtc->plane_states, key);
+ if (plane_state == NULL)
+ {
+ plane_state = g_new0 (PlaneState, 1);
+ g_hash_table_insert (crtc->plane_states, key, plane_state);
+ }
+
+ plane_state->back_is_set = TRUE; /* note buffer may be NULL */
+ g_set_object (&plane_state->back, buffer);
+}
+
+static void
+swap_plane_buffers (gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ PlaneState *plane_state = value;
+
+ if (plane_state->back_is_set)
+ {
+ g_set_object (&plane_state->front, plane_state->back);
+ g_clear_object (&plane_state->back);
+ plane_state->back_is_set = FALSE;
+ }
+}
+
+void
+meta_kms_crtc_on_scanout_started (MetaKmsCrtc *crtc)
+{
+ g_hash_table_foreach (crtc->plane_states, swap_plane_buffers, NULL);
+}
+
+void
+meta_kms_crtc_release_buffers (MetaKmsCrtc *crtc)
+{
+ g_hash_table_remove_all (crtc->plane_states);
+}
+
+static void
+meta_kms_crtc_dispose (GObject *object)
+{
+ MetaKmsCrtc *crtc = META_KMS_CRTC (object);
+
+ meta_kms_crtc_release_buffers (crtc);
+
+ G_OBJECT_CLASS (meta_kms_crtc_parent_class)->dispose (object);
+}
+
static void
meta_kms_crtc_finalize (GObject *object)
{
MetaKmsCrtc *crtc = META_KMS_CRTC (object);
clear_gamma_state (&crtc->current_state);
+ g_hash_table_unref (crtc->plane_states);
G_OBJECT_CLASS (meta_kms_crtc_parent_class)->finalize (object);
}
+static void
+destroy_plane_state (gpointer data)
+{
+ PlaneState *plane_state = data;
+
+ g_clear_object (&plane_state->front);
+ g_clear_object (&plane_state->back);
+ g_free (plane_state);
+}
+
static void
meta_kms_crtc_init (MetaKmsCrtc *crtc)
{
crtc->current_state.gamma.size = 0;
+ crtc->plane_states = g_hash_table_new_full (NULL,
+ NULL,
+ NULL,
+ destroy_plane_state);
}
static void
@@ -424,5 +503,6 @@ meta_kms_crtc_class_init (MetaKmsCrtcClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->dispose = meta_kms_crtc_dispose;
object_class->finalize = meta_kms_crtc_finalize;
}
diff --git a/src/backends/native/meta-kms-crtc.h b/src/backends/native/meta-kms-crtc.h
index 54801dd96a..deafeb61e0 100644
--- a/src/backends/native/meta-kms-crtc.h
+++ b/src/backends/native/meta-kms-crtc.h
@@ -25,6 +25,7 @@
#include <xf86drmMode.h>
#include "backends/native/meta-kms-types.h"
+#include "backends/native/meta-drm-buffer.h"
#include "core/util-private.h"
#include "meta/boxes.h"
@@ -84,4 +85,12 @@ MetaKmsCrtcGamma * meta_kms_crtc_gamma_new (MetaKmsCrtc *crtc,
const uint16_t *green,
const uint16_t *blue);
+void meta_kms_crtc_remember_plane_buffer (MetaKmsCrtc *crtc,
+ uint32_t plane_id,
+ MetaDrmBuffer *buffer);
+
+void meta_kms_crtc_on_scanout_started (MetaKmsCrtc *crtc);
+
+void meta_kms_crtc_release_buffers (MetaKmsCrtc *crtc);
+
#endif /* META_KMS_CRTC_H */
--
GitLab
From cb4949f30eefb71b57920ba91531c5e55c8d5077 Mon Sep 17 00:00:00 2001
From: Daniel van Vugt <[email protected]>
Date: Tue, 17 Aug 2021 16:35:18 +0800
Subject: [PATCH 05/49] kms/page-flip: Pump the CRTC's buffer reference queue
on scanout
Precise timing of this call is not important. We only need to notify
that the *previous* scanout is definitely no longer happening. So any
old buffers no longer used in the latest scanout can be released.
---
src/backends/native/meta-kms-page-flip.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/backends/native/meta-kms-page-flip.c b/src/backends/native/meta-kms-page-flip.c
index c1c29905c6..a6fbaf2f88 100644
--- a/src/backends/native/meta-kms-page-flip.c
+++ b/src/backends/native/meta-kms-page-flip.c
@@ -25,6 +25,7 @@
#include "backends/native/meta-kms-impl.h"
#include "backends/native/meta-kms-private.h"
#include "backends/native/meta-kms-update.h"
+#include "backends/native/meta-kms-crtc.h"
typedef struct _MetaKmsPageFlipClosure
{
@@ -150,6 +151,8 @@ meta_kms_page_flip_data_flipped (MetaKms *kms,
meta_assert_not_in_kms_impl (kms);
+ meta_kms_crtc_on_scanout_started (page_flip_data->crtc);
+
for (l = page_flip_data->closures; l; l = l->next)
{
MetaKmsPageFlipClosure *closure = l->data;
--
GitLab
From 2328461897e2bf7de378a711a57815e37877a725 Mon Sep 17 00:00:00 2001
From: Daniel van Vugt <[email protected]>
Date: Wed, 9 Feb 2022 16:44:09 +0800
Subject: [PATCH 06/49] kms/impl-device: Release buffers from MetaKmsCrtc in
prepare_shutdown
This allows them to release their buffers cleanly while all the
associated resources to do the release still exist. Otherwise we
might crash later in meta_drm_buffer_finalize.
---
src/backends/native/meta-kms-impl-device.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/backends/native/meta-kms-impl-device.c b/src/backends/native/meta-kms-impl-device.c
index b1dd321a7f..c42320a84d 100644
--- a/src/backends/native/meta-kms-impl-device.c
+++ b/src/backends/native/meta-kms-impl-device.c
@@ -1206,8 +1206,12 @@ meta_kms_impl_device_init_mode_setting (MetaKmsImplDevice *impl_device,
void
meta_kms_impl_device_prepare_shutdown (MetaKmsImplDevice *impl_device)
{
+ MetaKmsImplDevicePrivate *priv =
+ meta_kms_impl_device_get_instance_private (impl_device);
MetaKmsImplDeviceClass *klass = META_KMS_IMPL_DEVICE_GET_CLASS (impl_device);
+ g_list_foreach (priv->crtcs, (GFunc) meta_kms_crtc_release_buffers, NULL);
+
if (klass->prepare_shutdown)
klass->prepare_shutdown (impl_device);
--
GitLab
From 6b4156a7c3152206e57271fe0df80af753ee9fb9 Mon Sep 17 00:00:00 2001
From: Daniel van Vugt <[email protected]>
Date: Tue, 7 Dec 2021 18:31:16 +0800
Subject: [PATCH 07/49] kms/impl-device/simple: Pump the CRTC's buffer
reference queue on scanout
In this case "on scanout" means when `drmModeSetCrtc` succeeds. This is
the only case where there won't be a `meta_kms_page_flip_data_flipped` to
do it for us.
---
src/backends/native/meta-kms-impl-device-simple.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/backends/native/meta-kms-impl-device-simple.c b/src/backends/native/meta-kms-impl-device-simple.c
index 648de51c65..b5b179cfe4 100644
--- a/src/backends/native/meta-kms-impl-device-simple.c
+++ b/src/backends/native/meta-kms-impl-device-simple.c
@@ -486,6 +486,8 @@ process_mode_set (MetaKmsImplDevice *impl_device,
return FALSE;
}
+ meta_kms_crtc_on_scanout_started (crtc);
+
if (drm_mode)
{
g_hash_table_replace (impl_device_simple->cached_mode_sets,
@@ -875,6 +877,8 @@ mode_set_fallback (MetaKmsImplDeviceSimple *impl_device_simple,
return FALSE;
}
+ meta_kms_crtc_on_scanout_started (crtc);
+
if (!impl_device_simple->mode_set_fallback_feedback_source)
{
GSource *source;
--
GitLab
From eb211d79ee17fd61cf9c332cefa49ea4e31bde7e Mon Sep 17 00:00:00 2001
From: Daniel van Vugt <[email protected]>
Date: Tue, 17 Aug 2021 17:40:57 +0800
Subject: [PATCH 08/49] kms/impl-device/simple: Keep a reference to buffers
assigned to planes
The MetaKmsCrtc will hold these references during future scanouts until
such time as a new buffer is assigned to the plane AND another scanout
has occurred after that.
---
src/backends/native/meta-kms-impl-device-simple.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/backends/native/meta-kms-impl-device-simple.c b/src/backends/native/meta-kms-impl-device-simple.c
index b5b179cfe4..8f5481d43a 100644
--- a/src/backends/native/meta-kms-impl-device-simple.c
+++ b/src/backends/native/meta-kms-impl-device-simple.c
@@ -1306,7 +1306,7 @@ process_plane_assignment (MetaKmsImplDevice *impl_device,
{
case META_KMS_PLANE_TYPE_PRIMARY:
/* Handled as part of the mode-set and page flip. */
- return TRUE;
+ goto assigned;
case META_KMS_PLANE_TYPE_CURSOR:
if (!process_cursor_plane_assignment (impl_device, update,
plane_assignment,
@@ -1320,7 +1320,7 @@ process_plane_assignment (MetaKmsImplDevice *impl_device,
}
else
{
- return TRUE;
+ goto assigned;
}
case META_KMS_PLANE_TYPE_OVERLAY:
error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED,
@@ -1333,6 +1333,12 @@ process_plane_assignment (MetaKmsImplDevice *impl_device,
}