-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwip-wine-changes.patch
More file actions
1210 lines (1185 loc) · 50.9 KB
/
Copy pathwip-wine-changes.patch
File metadata and controls
1210 lines (1185 loc) · 50.9 KB
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
diff --git a/dlls/win32u/vulkan.c b/dlls/win32u/vulkan.c
index 826494706..2bc2964b0 100644
--- a/dlls/win32u/vulkan.c
+++ b/dlls/win32u/vulkan.c
@@ -142,6 +142,20 @@ static inline struct device_memory *device_memory_from_handle( VkDeviceMemory ha
return CONTAINING_RECORD( obj, struct device_memory, obj );
}
+/* Screen capture readback: shared data accessible by display drivers */
+struct wine_vk_readback_data
+{
+ UINT width;
+ UINT height;
+ UINT stride; /* bytes per row */
+ void *pixels; /* pixel data */
+ volatile LONG ready; /* set to 1 after first readback copy fence is waited */
+ BOOL needs_rb_swap; /* TRUE if pixels are RGBA and need R/B swap for GDI (BGRA) */
+};
+
+static const WCHAR readback_request_propW[] = {'_','_','w','i','n','e','_','v','k','_','r','b','_','r','e','q',0};
+static const WCHAR readback_data_propW[] = {'_','_','w','i','n','e','_','v','k','_','r','b','_','d','a','t','a',0};
+
struct surface
{
struct vulkan_surface obj;
@@ -232,6 +246,25 @@ struct swapchain
struct fs_comp_pipeline blit_pipeline;
struct fs_comp_pipeline fsr_easu_pipeline;
struct fs_comp_pipeline fsr_rcas_pipeline;
+
+ /* screen capture readback */
+ VkBuffer readback_buffer;
+ VkDeviceMemory readback_memory;
+ void *readback_data;
+ VkCommandPool readback_cmd_pool;
+ VkCommandBuffer readback_cmd;
+ VkFence readback_fence;
+ VkSemaphore readback_semaphore;
+ uint32_t readback_width;
+ uint32_t readback_height;
+ VkImage *readback_images;
+ uint32_t readback_image_count;
+ struct wine_vk_readback_data *readback_info;
+ BOOL readback_initialized;
+ BOOL readback_pending; /* a readback copy is in-flight (fence not yet waited) */
+ BOOL readback_active; /* readback is armed and should run every frame */
+ VkImage readback_blit_image; /* B8G8R8A8 intermediate for R/B swap on GPU */
+ VkDeviceMemory readback_blit_memory;
};
static struct swapchain *swapchain_from_handle( VkSwapchainKHR handle )
@@ -1726,6 +1759,8 @@ static VkResult win32u_vkGetPhysicalDeviceImageFormatProperties2KHR( VkPhysicalD
return get_physical_device_image_format_properties( physical_device, format_info, format_properties, instance->p_vkGetPhysicalDeviceImageFormatProperties2KHR );
}
+static void destroy_readback_resources( struct vulkan_device *device, struct swapchain *swapchain );
+
static VkResult win32u_vkCreateWin32SurfaceKHR( VkInstance client_instance, const VkWin32SurfaceCreateInfoKHR *create_info,
const VkAllocationCallbacks *allocator, VkSurfaceKHR *ret )
{
@@ -2860,6 +2895,9 @@ static VkResult win32u_vkCreateSwapchainKHR( VkDevice client_device, const VkSwa
create_info_host.imageFormat );
}
+ /* Ensure swapchain images can be used as transfer source for readback */
+ create_info_host.imageUsage |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
+
if ((res = device->p_vkCreateSwapchainKHR( device->host.device, &create_info_host, NULL, &host_swapchain )))
{
free( swapchain );
@@ -2871,6 +2909,7 @@ static VkResult win32u_vkCreateSwapchainKHR( VkDevice client_device, const VkSwa
client_surface_add_ref(surface->client);
surface->swapchain = swapchain;
swapchain->extents = create_info->imageExtent;
+ if (!swapchain->format) swapchain->format = create_info_host.imageFormat;
instance->p_insert_object( instance, &swapchain->obj.obj );
if (swapchain->fshack_dpi)
@@ -2933,6 +2972,15 @@ void win32u_vkDestroySwapchainKHR( VkDevice client_device, VkSwapchainKHR client
free( swapchain->fs_hack_images );
}
+ destroy_readback_resources( device, swapchain );
+
+ /* Clean up readback window property */
+ if (swapchain->surface && swapchain->surface->hwnd)
+ {
+ NtUserRemoveProp( swapchain->surface->hwnd, readback_data_propW );
+ NtUserRemoveProp( swapchain->surface->hwnd, readback_request_propW );
+ }
+
device->p_vkDestroySwapchainKHR( device->host.device, swapchain->obj.host.swapchain, NULL );
if (swapchain->surface)
{
@@ -3309,6 +3357,389 @@ static VkResult record_fsr_cmd(struct vulkan_device *device, struct swapchain *s
return VK_SUCCESS;
}
+
+static VkResult init_readback_resources( struct vulkan_device *device, struct swapchain *swapchain,
+ uint32_t queue_family_index )
+{
+ VkBufferCreateInfo buffer_info = {0};
+ VkMemoryRequirements mem_req;
+ VkMemoryAllocateInfo alloc_info = {0};
+ VkCommandPoolCreateInfo pool_info = {0};
+ VkCommandBufferAllocateInfo cmd_info = {0};
+ VkSemaphoreCreateInfo sema_info = {0};
+ VkFenceCreateInfo fence_info = {0};
+ struct vulkan_physical_device *physical_device = device->physical_device;
+ uint32_t mem_type = ~0u, i;
+ VkResult res;
+
+ swapchain->readback_width = swapchain->extents.width;
+ swapchain->readback_height = swapchain->extents.height;
+
+ buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
+ buffer_info.size = swapchain->readback_width * swapchain->readback_height * 4;
+ buffer_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
+ buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
+
+ if ((res = device->p_vkCreateBuffer( device->host.device, &buffer_info, NULL, &swapchain->readback_buffer )))
+ {
+ ERR( "vkCreateBuffer failed for readback: %d\n", res );
+ return res;
+ }
+
+ device->p_vkGetBufferMemoryRequirements( device->host.device, swapchain->readback_buffer, &mem_req );
+
+ {
+ VkPhysicalDeviceMemoryProperties mem_props;
+ uint32_t fallback_type = ~0u;
+ physical_device->instance->p_vkGetPhysicalDeviceMemoryProperties( physical_device->host.physical_device, &mem_props );
+ for (i = 0; i < mem_props.memoryTypeCount; i++)
+ {
+ if (!(mem_req.memoryTypeBits & (1u << i))) continue;
+ if ((mem_props.memoryTypes[i].propertyFlags &
+ (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))
+ != (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))
+ continue;
+ if (fallback_type == ~0u) fallback_type = i;
+ if (mem_props.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT)
+ {
+ mem_type = i;
+ break;
+ }
+ }
+ if (mem_type == ~0u) mem_type = fallback_type;
+ TRACE( "readback buffer memory type %u (cached=%d)\n", mem_type,
+ mem_type != ~0u && (mem_props.memoryTypes[mem_type].propertyFlags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) != 0 );
+ }
+
+ if (mem_type == ~0u)
+ {
+ ERR( "No suitable memory type for readback buffer\n" );
+ device->p_vkDestroyBuffer( device->host.device, swapchain->readback_buffer, NULL );
+ swapchain->readback_buffer = VK_NULL_HANDLE;
+ return VK_ERROR_OUT_OF_HOST_MEMORY;
+ }
+
+ alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
+ alloc_info.allocationSize = mem_req.size;
+ alloc_info.memoryTypeIndex = mem_type;
+
+ if ((res = device->p_vkAllocateMemory( device->host.device, &alloc_info, NULL, &swapchain->readback_memory )))
+ {
+ ERR( "vkAllocateMemory failed for readback: %d\n", res );
+ device->p_vkDestroyBuffer( device->host.device, swapchain->readback_buffer, NULL );
+ swapchain->readback_buffer = VK_NULL_HANDLE;
+ return res;
+ }
+
+ device->p_vkBindBufferMemory( device->host.device, swapchain->readback_buffer, swapchain->readback_memory, 0 );
+ device->p_vkMapMemory( device->host.device, swapchain->readback_memory, 0, VK_WHOLE_SIZE, 0, &swapchain->readback_data );
+
+ pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
+ pool_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
+ pool_info.queueFamilyIndex = queue_family_index;
+ if ((res = device->p_vkCreateCommandPool( device->host.device, &pool_info, NULL, &swapchain->readback_cmd_pool )))
+ {
+ ERR( "vkCreateCommandPool failed for readback: %d\n", res );
+ return res;
+ }
+
+ cmd_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
+ cmd_info.commandPool = swapchain->readback_cmd_pool;
+ cmd_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
+ cmd_info.commandBufferCount = 1;
+ device->p_vkAllocateCommandBuffers( device->host.device, &cmd_info, &swapchain->readback_cmd );
+
+ sema_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
+ device->p_vkCreateSemaphore( device->host.device, &sema_info, NULL, &swapchain->readback_semaphore );
+
+ fence_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
+ device->p_vkCreateFence( device->host.device, &fence_info, NULL, &swapchain->readback_fence );
+
+ device->p_vkGetSwapchainImagesKHR( device->host.device, swapchain->obj.host.swapchain,
+ &swapchain->readback_image_count, NULL );
+ swapchain->readback_images = calloc( swapchain->readback_image_count, sizeof(VkImage) );
+ device->p_vkGetSwapchainImagesKHR( device->host.device, swapchain->obj.host.swapchain,
+ &swapchain->readback_image_count, swapchain->readback_images );
+
+ swapchain->readback_info = calloc( 1, sizeof(*swapchain->readback_info) );
+ swapchain->readback_info->width = swapchain->readback_width;
+ swapchain->readback_info->height = swapchain->readback_height;
+ swapchain->readback_info->stride = swapchain->readback_width * 4;
+ swapchain->readback_info->pixels = swapchain->readback_data;
+
+ if (swapchain->format == VK_FORMAT_R8G8B8A8_UNORM ||
+ swapchain->format == VK_FORMAT_R8G8B8A8_SRGB ||
+ swapchain->format == VK_FORMAT_A8B8G8R8_UNORM_PACK32 ||
+ swapchain->format == VK_FORMAT_A8B8G8R8_SRGB_PACK32)
+ {
+ VkImageCreateInfo img_info = {0};
+ VkMemoryRequirements blit_mem_req;
+ VkMemoryAllocateInfo blit_alloc = {0};
+ VkPhysicalDeviceMemoryProperties mem_props2;
+ uint32_t blit_mem_type = ~0u;
+
+ img_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
+ img_info.imageType = VK_IMAGE_TYPE_2D;
+ img_info.format = VK_FORMAT_B8G8R8A8_UNORM;
+ img_info.extent.width = swapchain->readback_width;
+ img_info.extent.height = swapchain->readback_height;
+ img_info.extent.depth = 1;
+ img_info.mipLevels = 1;
+ img_info.arrayLayers = 1;
+ img_info.samples = VK_SAMPLE_COUNT_1_BIT;
+ img_info.tiling = VK_IMAGE_TILING_OPTIMAL;
+ img_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
+ img_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
+ img_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
+
+ if ((res = device->p_vkCreateImage( device->host.device, &img_info, NULL, &swapchain->readback_blit_image )))
+ {
+ WARN( "vkCreateImage for blit image failed: %d, falling back to CPU swap\n", res );
+ swapchain->readback_info->needs_rb_swap = TRUE;
+ }
+ else
+ {
+ device->p_vkGetImageMemoryRequirements( device->host.device, swapchain->readback_blit_image, &blit_mem_req );
+ physical_device->instance->p_vkGetPhysicalDeviceMemoryProperties( physical_device->host.physical_device, &mem_props2 );
+ for (i = 0; i < mem_props2.memoryTypeCount; i++)
+ {
+ if ((blit_mem_req.memoryTypeBits & (1u << i)) &&
+ (mem_props2.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT))
+ {
+ blit_mem_type = i;
+ break;
+ }
+ }
+ if (blit_mem_type == ~0u)
+ {
+ for (i = 0; i < mem_props2.memoryTypeCount; i++)
+ {
+ if (blit_mem_req.memoryTypeBits & (1u << i))
+ {
+ blit_mem_type = i;
+ break;
+ }
+ }
+ }
+ if (blit_mem_type != ~0u)
+ {
+ blit_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
+ blit_alloc.allocationSize = blit_mem_req.size;
+ blit_alloc.memoryTypeIndex = blit_mem_type;
+ if ((res = device->p_vkAllocateMemory( device->host.device, &blit_alloc, NULL, &swapchain->readback_blit_memory )))
+ {
+ WARN( "vkAllocateMemory for blit image failed: %d\n", res );
+ device->p_vkDestroyImage( device->host.device, swapchain->readback_blit_image, NULL );
+ swapchain->readback_blit_image = VK_NULL_HANDLE;
+ swapchain->readback_info->needs_rb_swap = TRUE;
+ }
+ else
+ {
+ device->p_vkBindImageMemory( device->host.device, swapchain->readback_blit_image, swapchain->readback_blit_memory, 0 );
+ swapchain->readback_info->needs_rb_swap = FALSE;
+ }
+ }
+ else
+ {
+ device->p_vkDestroyImage( device->host.device, swapchain->readback_blit_image, NULL );
+ swapchain->readback_blit_image = VK_NULL_HANDLE;
+ swapchain->readback_info->needs_rb_swap = TRUE;
+ }
+ }
+ }
+ else
+ {
+ swapchain->readback_info->needs_rb_swap = FALSE;
+ }
+
+ swapchain->readback_initialized = TRUE;
+ TRACE( "readback initialized: %ux%u, %u images, format=%d, gpu_blit=%d, needs_rb_swap=%d\n",
+ swapchain->readback_width, swapchain->readback_height,
+ swapchain->readback_image_count, swapchain->format,
+ !!swapchain->readback_blit_image, swapchain->readback_info->needs_rb_swap );
+ return VK_SUCCESS;
+}
+
+static void destroy_readback_resources( struct vulkan_device *device, struct swapchain *swapchain )
+{
+ if (!swapchain->readback_initialized) return;
+
+ if (swapchain->readback_pending)
+ {
+ device->p_vkWaitForFences( device->host.device, 1, &swapchain->readback_fence, VK_TRUE, ~0ull );
+ swapchain->readback_pending = FALSE;
+ }
+
+ if (swapchain->readback_data)
+ device->p_vkUnmapMemory( device->host.device, swapchain->readback_memory );
+ if (swapchain->readback_cmd)
+ device->p_vkFreeCommandBuffers( device->host.device, swapchain->readback_cmd_pool, 1, &swapchain->readback_cmd );
+ if (swapchain->readback_cmd_pool)
+ device->p_vkDestroyCommandPool( device->host.device, swapchain->readback_cmd_pool, NULL );
+ if (swapchain->readback_fence)
+ device->p_vkDestroyFence( device->host.device, swapchain->readback_fence, NULL );
+ if (swapchain->readback_semaphore)
+ device->p_vkDestroySemaphore( device->host.device, swapchain->readback_semaphore, NULL );
+ if (swapchain->readback_buffer)
+ device->p_vkDestroyBuffer( device->host.device, swapchain->readback_buffer, NULL );
+ if (swapchain->readback_memory)
+ device->p_vkFreeMemory( device->host.device, swapchain->readback_memory, NULL );
+
+ if (swapchain->readback_blit_image)
+ device->p_vkDestroyImage( device->host.device, swapchain->readback_blit_image, NULL );
+ if (swapchain->readback_blit_memory)
+ device->p_vkFreeMemory( device->host.device, swapchain->readback_blit_memory, NULL );
+
+ free( swapchain->readback_images );
+ free( swapchain->readback_info );
+
+ swapchain->readback_initialized = FALSE;
+ swapchain->readback_active = FALSE;
+}
+
+static VkResult do_readback_copy( struct vulkan_device *device, struct swapchain *swapchain,
+ struct vulkan_queue *queue, VkImage swapchain_image,
+ UINT wait_semaphore_count, const VkSemaphore *wait_semaphores )
+{
+ VkCommandBufferBeginInfo begin_info = {0};
+ VkImageMemoryBarrier barrier = {0};
+ VkBufferImageCopy region = {0};
+ VkSubmitInfo submit_info = {0};
+ VkPipelineStageFlags wait_stage = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
+ VkPipelineStageFlags *wait_stages = NULL;
+ VkResult res;
+ UINT i;
+
+ device->p_vkResetFences( device->host.device, 1, &swapchain->readback_fence );
+ device->p_vkResetCommandBuffer( swapchain->readback_cmd, 0 );
+
+ begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
+ begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
+ device->p_vkBeginCommandBuffer( swapchain->readback_cmd, &begin_info );
+
+ barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
+ barrier.srcAccessMask = VK_ACCESS_MEMORY_READ_BIT;
+ barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
+ barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
+ barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
+ barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
+ barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
+ barrier.image = swapchain_image;
+ barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+ barrier.subresourceRange.levelCount = 1;
+ barrier.subresourceRange.layerCount = 1;
+
+ device->p_vkCmdPipelineBarrier( swapchain->readback_cmd,
+ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
+ 0, 0, NULL, 0, NULL, 1, &barrier );
+
+ region.bufferOffset = 0;
+ region.bufferRowLength = 0;
+ region.bufferImageHeight = 0;
+ region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+ region.imageSubresource.layerCount = 1;
+ region.imageExtent.width = swapchain->readback_width;
+ region.imageExtent.height = swapchain->readback_height;
+ region.imageExtent.depth = 1;
+
+ if (swapchain->readback_blit_image)
+ {
+ VkImageMemoryBarrier blit_barrier = {0};
+ VkImageBlit blit_region = {0};
+
+ blit_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
+ blit_barrier.srcAccessMask = 0;
+ blit_barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
+ blit_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
+ blit_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
+ blit_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
+ blit_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
+ blit_barrier.image = swapchain->readback_blit_image;
+ blit_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+ blit_barrier.subresourceRange.levelCount = 1;
+ blit_barrier.subresourceRange.layerCount = 1;
+
+ device->p_vkCmdPipelineBarrier( swapchain->readback_cmd,
+ VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
+ 0, 0, NULL, 0, NULL, 1, &blit_barrier );
+
+ blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+ blit_region.srcSubresource.layerCount = 1;
+ blit_region.srcOffsets[1].x = swapchain->readback_width;
+ blit_region.srcOffsets[1].y = swapchain->readback_height;
+ blit_region.srcOffsets[1].z = 1;
+ blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+ blit_region.dstSubresource.layerCount = 1;
+ blit_region.dstOffsets[1].x = swapchain->readback_width;
+ blit_region.dstOffsets[1].y = swapchain->readback_height;
+ blit_region.dstOffsets[1].z = 1;
+
+ device->p_vkCmdBlitImage( swapchain->readback_cmd,
+ swapchain_image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
+ swapchain->readback_blit_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
+ 1, &blit_region, VK_FILTER_NEAREST );
+
+ blit_barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
+ blit_barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
+ blit_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
+ blit_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
+
+ device->p_vkCmdPipelineBarrier( swapchain->readback_cmd,
+ VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
+ 0, 0, NULL, 0, NULL, 1, &blit_barrier );
+
+ device->p_vkCmdCopyImageToBuffer( swapchain->readback_cmd,
+ swapchain->readback_blit_image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
+ swapchain->readback_buffer, 1, ®ion );
+ }
+ else
+ {
+ device->p_vkCmdCopyImageToBuffer( swapchain->readback_cmd,
+ swapchain_image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
+ swapchain->readback_buffer, 1, ®ion );
+ }
+
+ barrier.srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
+ barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
+ barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
+ barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
+
+ device->p_vkCmdPipelineBarrier( swapchain->readback_cmd,
+ VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
+ 0, 0, NULL, 0, NULL, 1, &barrier );
+
+ device->p_vkEndCommandBuffer( swapchain->readback_cmd );
+
+ if (wait_semaphore_count > 1)
+ {
+ wait_stages = malloc( wait_semaphore_count * sizeof(VkPipelineStageFlags) );
+ for (i = 0; i < wait_semaphore_count; i++)
+ wait_stages[i] = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
+ }
+
+ submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
+ submit_info.waitSemaphoreCount = wait_semaphore_count;
+ submit_info.pWaitSemaphores = wait_semaphores;
+ submit_info.pWaitDstStageMask = wait_stages ? wait_stages : &wait_stage;
+ submit_info.commandBufferCount = 1;
+ submit_info.pCommandBuffers = &swapchain->readback_cmd;
+ submit_info.signalSemaphoreCount = 1;
+ submit_info.pSignalSemaphores = &swapchain->readback_semaphore;
+
+ res = device->p_vkQueueSubmit( queue->host.queue, 1, &submit_info, swapchain->readback_fence );
+ free( wait_stages );
+
+ if (res != VK_SUCCESS)
+ {
+ ERR( "vkQueueSubmit for readback failed: %d\n", res );
+ return res;
+ }
+
+ swapchain->readback_pending = TRUE;
+
+ return VK_SUCCESS;
+}
+
#define win32u_vk_find_struct(s, t) win32u_vk_find_struct_((void *)s, VK_STRUCTURE_TYPE_##t)
static void *win32u_vk_find_struct_(void *s, VkStructureType t)
{
@@ -3426,6 +3857,72 @@ static VkResult win32u_vkQueuePresentKHR( VkQueue client_queue, const VkPresentI
present_info->pWaitSemaphores = &blit_sema;
}
+
+ /* Screen capture readback: if any swapchain's window has a readback request,
+ * copy the swapchain image to a staging buffer before presenting. */
+ for (uint32_t i = 0; i < present_info->swapchainCount; i++)
+ {
+ struct swapchain *swapchain = swapchain_from_handle( present_info->pSwapchains[i] );
+ struct surface *surface = swapchain->surface;
+ HANDLE prop;
+ VkImage src_image;
+ uint32_t image_idx;
+
+ if (!surface->hwnd) continue;
+
+ if (!swapchain->readback_initialized)
+ {
+ if (init_readback_resources( device, swapchain, queue->family_index ) != VK_SUCCESS)
+ continue;
+ NtUserSetProp( surface->hwnd, readback_data_propW, (HANDLE)swapchain->readback_info );
+ swapchain->readback_active = TRUE;
+ }
+ else
+ {
+ prop = NtUserGetProp( surface->hwnd, readback_request_propW );
+ if (prop)
+ {
+ NtUserRemoveProp( surface->hwnd, readback_request_propW );
+ WARN( "readback: rb_req consumed for hwnd %p, will copy this frame
+", surface->hwnd );
+ }
+ swapchain->readback_active = !!prop;
+ }
+
+ if (swapchain->readback_pending)
+ {
+ device->p_vkWaitForFences( device->host.device, 1, &swapchain->readback_fence, VK_TRUE, ~0ull );
+ swapchain->readback_pending = FALSE;
+ if (swapchain->readback_info)
+ {
+ InterlockedExchange( &swapchain->readback_info->ready, 1 );
+ WARN( "readback: fence done, ready=1 for hwnd %p
+", surface->hwnd );
+ }
+ }
+
+ if (!swapchain->readback_active) continue;
+
+ TRACE( "readback active for hwnd %p
+", surface->hwnd );
+
+ image_idx = present_info->pImageIndices[i];
+ if (swapchain->fshack_dpi && swapchain->fs_hack_images)
+ src_image = swapchain->fs_hack_images[image_idx].swapchain_image;
+ else if (swapchain->readback_images && image_idx < swapchain->readback_image_count)
+ src_image = swapchain->readback_images[image_idx];
+ else
+ continue;
+
+ if (do_readback_copy( device, swapchain, queue, src_image,
+ present_info->waitSemaphoreCount,
+ present_info->pWaitSemaphores ) == VK_SUCCESS)
+ {
+ present_info->waitSemaphoreCount = 1;
+ present_info->pWaitSemaphores = &swapchain->readback_semaphore;
+ }
+ }
+
pthread_mutex_lock( &lock );
res = device->p_vkQueuePresentKHR( queue->host.queue, present_info );
pthread_mutex_unlock( &lock );
diff --git a/dlls/winewayland.drv/Makefile.in b/dlls/winewayland.drv/Makefile.in
index 1d71d0a92..15c765b02 100644
--- a/dlls/winewayland.drv/Makefile.in
+++ b/dlls/winewayland.drv/Makefile.in
@@ -5,6 +5,7 @@ UNIX_LIBS = -lwin32u $(WAYLAND_CLIENT_LIBS) $(WAYLAND_EGL_LIBS) $(XKBCOMMON_LIBS
IMPORTS = user32 win32u
SOURCES = \
+ bitblt.c \
color-management-v1.xml \
content-type-v1.xml \
cursor-shape-v1.xml \
diff --git a/dlls/winewayland.drv/bitblt.c b/dlls/winewayland.drv/bitblt.c
new file mode 100644
index 000000000..34cb6de37
--- /dev/null
+++ b/dlls/winewayland.drv/bitblt.c
@@ -0,0 +1,164 @@
+/*
+ * Wayland driver BitBlt/GetImage implementation
+ *
+ * Copyright 2026 Alejandro Romano (Arecsu)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#if 0
+#pragma makedep unix
+#endif
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#include "waylanddrv.h"
+#include "wine/debug.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(waylanddrv);
+
+/* Minimal physdev for the wayland driver DC stack entry */
+struct wayland_physdev
+{
+ struct gdi_physdev dev;
+ RECT dc_rect;
+};
+
+static inline struct wayland_physdev *get_wayland_dev(PHYSDEV dev)
+{
+ return CONTAINING_RECORD(dev, struct wayland_physdev, dev);
+}
+
+/***********************************************************************
+ * WAYLAND_CreateDC
+ */
+BOOL WAYLAND_CreateDC(PHYSDEV *pdev, LPCWSTR device, LPCWSTR output,
+ const DEVMODEW *initData)
+{
+ struct wayland_physdev *physdev;
+
+ if (!(physdev = calloc(1, sizeof(*physdev)))) return FALSE;
+
+ physdev->dc_rect = NtUserGetVirtualScreenRect(MDT_DEFAULT);
+ OffsetRect(&physdev->dc_rect, -physdev->dc_rect.left, -physdev->dc_rect.top);
+ push_dc_driver(pdev, &physdev->dev, &waylanddrv_funcs.dc_funcs);
+ return TRUE;
+}
+
+/***********************************************************************
+ * WAYLAND_CreateCompatibleDC
+ */
+BOOL WAYLAND_CreateCompatibleDC(PHYSDEV orig, PHYSDEV *pdev)
+{
+ struct wayland_physdev *physdev;
+
+ if (!(physdev = calloc(1, sizeof(*physdev)))) return FALSE;
+
+ SetRect(&physdev->dc_rect, 0, 0, 1, 1);
+ push_dc_driver(pdev, &physdev->dev, &waylanddrv_funcs.dc_funcs);
+ return TRUE;
+}
+
+/***********************************************************************
+ * WAYLAND_DeleteDC
+ */
+BOOL WAYLAND_DeleteDC(PHYSDEV dev)
+{
+ struct wayland_physdev *physdev = get_wayland_dev(dev);
+ free(physdev);
+ return TRUE;
+}
+
+static void getimage_free(struct gdi_image_bits *bits)
+{
+ free(bits->param);
+}
+
+/***********************************************************************
+ * WAYLAND_GetImage
+ *
+ * Read pixels from a window's surface buffer. When called on a desktop DC
+ * (e.g., from Graphics.CopyFromScreen), finds the window at the requested
+ * coordinates and returns its pixel data.
+ */
+DWORD WAYLAND_GetImage(PHYSDEV dev, BITMAPINFO *info,
+ struct gdi_image_bits *bits,
+ struct bitblt_coords *src)
+{
+ int src_width, src_height;
+ void *alloc_bits;
+
+ WARN("GetImage called: dev=%p bits=%p src=%s\n", dev, bits,
+ wine_dbgstr_rect(&src->visrect));
+
+ /* Set up the BITMAPINFO for 32-bit BGRA */
+ info->bmiHeader.biSize = sizeof(info->bmiHeader);
+ info->bmiHeader.biPlanes = 1;
+ info->bmiHeader.biBitCount = 32;
+ info->bmiHeader.biCompression = BI_RGB;
+ info->bmiHeader.biXPelsPerMeter = 0;
+ info->bmiHeader.biYPelsPerMeter = 0;
+ info->bmiHeader.biClrImportant = 0;
+ info->bmiHeader.biClrUsed = 0;
+
+ if (!bits) return ERROR_SUCCESS; /* just querying color information */
+
+ src_width = src->visrect.right - src->visrect.left;
+ src_height = src->visrect.bottom - src->visrect.top;
+
+ info->bmiHeader.biWidth = src_width;
+ info->bmiHeader.biHeight = -src_height; /* top-down */
+ info->bmiHeader.biSizeImage = src_width * src_height * 4;
+
+ {
+ struct timespec t0, t1, t2;
+ long alloc_us, composite_us;
+
+ clock_gettime(CLOCK_MONOTONIC, &t0);
+
+ /* Allocate output buffer (zeroed = black background) */
+ alloc_bits = calloc(1, src_width * src_height * 4);
+ if (!alloc_bits) return ERROR_OUTOFMEMORY;
+
+ clock_gettime(CLOCK_MONOTONIC, &t1);
+
+ /* Composite all visible window surfaces into the output buffer */
+ composite_window_surface_contents(alloc_bits, src_width, src_height,
+ src->visrect.left, src->visrect.top);
+
+ clock_gettime(CLOCK_MONOTONIC, &t2);
+
+ alloc_us = (t1.tv_sec - t0.tv_sec) * 1000000 + (t1.tv_nsec - t0.tv_nsec) / 1000;
+ composite_us = (t2.tv_sec - t1.tv_sec) * 1000000 + (t2.tv_nsec - t1.tv_nsec) / 1000;
+ TRACE("GetImage %dx%d: alloc=%ldus composite=%ldus total=%ldus\n",
+ src_width, src_height, alloc_us, composite_us, alloc_us + composite_us);
+ }
+
+ /* Adjust source coordinates to be relative to the returned bitmap */
+ src->x -= src->visrect.left;
+ src->y -= src->visrect.top;
+ OffsetRect(&src->visrect, -src->visrect.left, -src->visrect.top);
+
+ bits->ptr = alloc_bits;
+ bits->is_copy = TRUE;
+ bits->free = getimage_free;
+ bits->param = alloc_bits;
+
+ return ERROR_SUCCESS;
+}
diff --git a/dlls/winewayland.drv/wayland_surface.c b/dlls/winewayland.drv/wayland_surface.c
index f9842e98f..ad1f77f43 100644
--- a/dlls/winewayland.drv/wayland_surface.c
+++ b/dlls/winewayland.drv/wayland_surface.c
@@ -26,6 +26,7 @@
#include <assert.h>
#include <stdlib.h>
+#include <time.h>
#include <unistd.h>
#include "waylanddrv.h"
@@ -1008,7 +1009,9 @@ static void wayland_surface_reconfigure_subsurface(struct wayland_surface *surfa
if (position_changed)
{
- TRACE("hwnd=%p pos=%d,%d\n", surface->hwnd, x, y);
+ TRACE("hwnd=%p pos=%d,%d (local=%d,%d toplevel_rect=%s)\n",
+ surface->hwnd, x, y, local_x, local_y,
+ wine_dbgstr_rect(&toplevel_surface->window.rect));
surface->subsurface_x = x;
surface->subsurface_y = y;
wl_subsurface_set_position(surface->wl_subsurface, x, y);
@@ -1019,6 +1022,12 @@ static void wayland_surface_reconfigure_subsurface(struct wayland_surface *surfa
place_above_ref = find_subsurface_below(surface, toplevel_data, toplevel_surface);
wl_subsurface_place_above(surface->wl_subsurface, place_above_ref);
+ /* Commit the parent only. Per the Wayland spec, wl_subsurface_set_position
+ * and wl_subsurface_place_above are pending state that take effect on the
+ * next parent commit — committing the subsurface itself is not needed and
+ * causes the compositor to re-process the subsurface state, triggering
+ * configure events that can temporarily hide the canvas and force DXVK to
+ * recreate its swapchain, causing frame drops. */
wl_surface_commit(toplevel_surface->wl_surface);
if (surface->processing.serial)
diff --git a/dlls/winewayland.drv/waylanddrv.h b/dlls/winewayland.drv/waylanddrv.h
index eef2b7da0..18ec07493 100644
--- a/dlls/winewayland.drv/waylanddrv.h
+++ b/dlls/winewayland.drv/waylanddrv.h
@@ -491,8 +491,38 @@ struct wayland_client_surface *get_client_surface(HWND hwnd);
void set_client_surface(HWND hwnd, struct wayland_client_surface *client);
BOOL set_window_surface_contents(HWND hwnd, struct wayland_shm_buffer *shm_buffer, HRGN damage_region);
struct wayland_shm_buffer *get_window_surface_contents(HWND hwnd);
+BOOL composite_window_surface_contents(char *dest, int dest_width, int dest_height,
+ int dest_x, int dest_y);
void ensure_window_surface_contents(HWND hwnd);
+/**********************************************************************
+ * Vulkan readback (shared with win32u/vulkan.c)
+ */
+
+struct wine_vk_readback_data
+{
+ UINT width;
+ UINT height;
+ UINT stride; /* bytes per row */
+ void *pixels; /* pixel data */
+ volatile LONG ready; /* set to 1 after first readback copy fence is waited */
+ BOOL needs_rb_swap; /* TRUE if pixels are RGBA and need R/B swap for GDI (BGRA) */
+};
+
+/**********************************************************************
+ * Wayland BitBlt / GDI
+ */
+
+extern const struct user_driver_funcs waylanddrv_funcs;
+
+BOOL WAYLAND_CreateDC(PHYSDEV *pdev, LPCWSTR device, LPCWSTR output,
+ const DEVMODEW *initData);
+BOOL WAYLAND_CreateCompatibleDC(PHYSDEV orig, PHYSDEV *pdev);
+BOOL WAYLAND_DeleteDC(PHYSDEV dev);
+DWORD WAYLAND_GetImage(PHYSDEV dev, BITMAPINFO *info,
+ struct gdi_image_bits *bits,
+ struct bitblt_coords *src);
+
/**********************************************************************
* Wayland Keyboard
*/
diff --git a/dlls/winewayland.drv/waylanddrv_main.c b/dlls/winewayland.drv/waylanddrv_main.c
index 30af71121..e7192cea5 100644
--- a/dlls/winewayland.drv/waylanddrv_main.c
+++ b/dlls/winewayland.drv/waylanddrv_main.c
@@ -33,8 +33,13 @@
char *process_name = NULL;
-static const struct user_driver_funcs waylanddrv_funcs =
+const struct user_driver_funcs waylanddrv_funcs =
{
+ .dc_funcs.pCreateDC = WAYLAND_CreateDC,
+ .dc_funcs.pCreateCompatibleDC = WAYLAND_CreateCompatibleDC,
+ .dc_funcs.pDeleteDC = WAYLAND_DeleteDC,
+ .dc_funcs.pGetImage = WAYLAND_GetImage,
+ .dc_funcs.priority = GDI_PRIORITY_GRAPHICS_DRV,
.pClipboardWindowProc = WAYLAND_ClipboardWindowProc,
.pClipCursor = WAYLAND_ClipCursor,
.pDesktopWindowProc = WAYLAND_DesktopWindowProc,
diff --git a/dlls/winewayland.drv/window.c b/dlls/winewayland.drv/window.c
index cbf19df24..c3c0a13e8 100644
--- a/dlls/winewayland.drv/window.c
+++ b/dlls/winewayland.drv/window.c
@@ -26,6 +26,7 @@
#include <assert.h>
#include <stdlib.h>
+#include <time.h>
#include "ntstatus.h"
#define WIN32_NO_STATUS
@@ -551,9 +552,59 @@ void WAYLAND_WindowPosChanged(HWND hwnd, HWND insert_after, HWND owner_hint, UIN
}
if (!(data = wayland_win_data_get(hwnd))) return;
+
+ /* For layered windows, if a window surface has been created (meaning win32u
+ * is ready to render content), mark layered attribs as set so the window
+ * becomes visible immediately rather than waiting for CreateWindowSurface
+ * to be called with layered=1. */
+ if (surface && !data->layered_attribs_set &&
+ (NtUserGetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_LAYERED))
+ {
+ data->layered_attribs_set = TRUE;
+ }
+
toplevel_data = toplevel && toplevel != hwnd ? wayland_win_data_get_nolock(toplevel) : NULL;
toplevel_surface = toplevel_data ? toplevel_data->wayland_surface : NULL;
+ /* If the toplevel surface has no role (e.g., a hidden/invisible window like
+ * DXVK's "Hidden Window"), it was never committed to the compositor, so any
+ * subsurface parented to it would also be invisible. Search for a visible
+ * toplevel surface to use as parent instead. */
+ if (toplevel_surface && toplevel_surface->role == WAYLAND_SURFACE_ROLE_NONE)
+ {
+ struct wayland_surface *found = NULL;
+ struct wayland_win_data *iter;
+
+ TRACE("toplevel %p has no role, searching for visible parent\n", toplevel);
+
+ /* Walk all windows looking for a visible toplevel surface.
+ * Prefer the largest one (likely the main app window). */
+ RB_FOR_EACH_ENTRY(iter, &win_data_rb, struct wayland_win_data, entry)
+ {
+ if (iter->wayland_surface &&
+ iter->wayland_surface->role == WAYLAND_SURFACE_ROLE_TOPLEVEL &&
+ iter->hwnd != hwnd)
+ {
+ if (!found || (iter->wayland_surface->content_width *
+ iter->wayland_surface->content_height >
+ found->content_width * found->content_height))
+ {
+ found = iter->wayland_surface;
+ }
+ }
+ }
+
+ if (found)
+ {
+ TRACE("reparenting to visible toplevel hwnd=%p\n", found->hwnd);
+ toplevel_surface = found;
+ }
+ else
+ {
+ toplevel_surface = NULL;
+ }
+ }
+
data->rects = *new_rects;
data->is_fullscreen = fullscreen;
data->managed = managed;
@@ -1065,6 +1116,277 @@ struct wayland_shm_buffer *get_window_surface_contents(HWND hwnd)
return shm_buffer;
}
+/* Snapshot of one window's data collected under the mutex, so pixel
+ * copying can happen without holding win_data_mutex. */
+struct composite_entry
+{
+ HWND hwnd;
+ RECT visible;
+ /* GDI surface */
+ void *shm_data;
+ int shm_width, shm_height;
+ /* Vulkan readback */
+ BOOL has_client;
+ struct wine_vk_readback_data *rb;
+};
+
+/**********************************************************************
+ * composite_window_surface_contents
+ *
+ * Composite all visible window surface contents into a single buffer,
+ * simulating a screen capture. Each window's pixels are placed at
+ * their screen position within the requested capture rect.
+ *
+ * The mutex is held only while snapshotting metadata; heavy pixel
+ * copies run lock-free so other threads can manage windows concurrently.
+ */
+BOOL composite_window_surface_contents(char *dest, int dest_width, int dest_height,
+ int dest_x, int dest_y)
+{
+ static const WCHAR rb_req[] = {'_','_','w','i','n','e','_','v','k','_','r','b','_','r','e','q',0};
+ static const WCHAR rb_data[] = {'_','_','w','i','n','e','_','v','k','_','r','b','_','d','a','t','a',0};
+
+ struct wayland_win_data *data;
+ struct composite_entry *entries = NULL;
+ int entry_count = 0, entry_capacity = 0;
+ BOOL found_any = FALSE;
+ int i;
+ struct timespec tp0, tp1, tp2, tp3;
+ long phase1_us, phase2_us, phase3_us;
+
+ clock_gettime(CLOCK_MONOTONIC, &tp0);
+
+ /* ---- Phase 1: snapshot window metadata under the mutex ---- */
+ pthread_mutex_lock(&win_data_mutex);
+ RB_FOR_EACH_ENTRY(data, &win_data_rb, struct wayland_win_data, entry)
+ {
+ struct composite_entry e = {0};
+ int win_w, win_h;
+
+ e.hwnd = data->hwnd;
+ e.visible = data->rects.visible;
+ win_w = e.visible.right - e.visible.left;
+ win_h = e.visible.bottom - e.visible.top;
+ if (win_w <= 0 || win_h <= 0) continue;
+
+ if (data->window_contents)
+ {
+ e.shm_data = data->window_contents->map_data;
+ e.shm_width = data->window_contents->width;
+ e.shm_height = data->window_contents->height;
+ }
+ e.has_client = (data->client_surface != NULL);
+
+ if (!e.shm_data && !e.has_client) continue;
+
+ if (entry_count >= entry_capacity)
+ {
+ entry_capacity = entry_capacity ? entry_capacity * 2 : 16;
+ entries = realloc(entries, entry_capacity * sizeof(*entries));
+ }
+ entries[entry_count++] = e;
+ }
+ pthread_mutex_unlock(&win_data_mutex);
+
+ clock_gettime(CLOCK_MONOTONIC, &tp1);
+
+ /* ---- Phase 2: arm readback + fetch readback pointers (no mutex) ---- */
+ for (i = 0; i < entry_count; i++)
+ {
+ struct wine_vk_readback_data *rb;
+
+ if (!entries[i].has_client) continue;
+
+ /* Fetch the readback info pointer first */
+ rb = (struct wine_vk_readback_data *)(ULONG_PTR)
+ NtUserGetProp(entries[i].hwnd, rb_data);
+ WARN("composite hwnd=%p rb_data=%p ready=%d\n", entries[i].hwnd, rb, rb ? (int)rb->ready : -1);
+ if (!rb) continue;
+