summarylogtreecommitdiffstats
path: root/wine-optical-flow.patch
blob: 84099a5c4ed410a678ccf3118bbee3e93c9450dc (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
From 4380f7d89bbdcfce68357c48896592e779bdfdc7 Mon Sep 17 00:00:00 2001
From: Peter Jung <admin@ptr1337.dev>
Date: Thu, 17 Oct 2024 14:05:12 +0200
Subject: [PATCH 1/6] Revert "win32u: Allow faking HAGS in QueryAdapterInfo."

This reverts commit ccceb1989c5e7b3c8a46ad43624c714fd5436167.
---
 dlls/win32u/driver.c   | 31 ++-----------------------------
 include/ddk/d3dkmthk.h | 16 ----------------
 2 files changed, 2 insertions(+), 45 deletions(-)

diff --git a/dlls/win32u/driver.c b/dlls/win32u/driver.c
index 3ceb61ef820..e4d229940fc 100644
--- a/dlls/win32u/driver.c
+++ b/dlls/win32u/driver.c
@@ -1678,43 +1678,16 @@ NTSTATUS WINAPI NtGdiDdDDIDestroyDevice( const D3DKMT_DESTROYDEVICE *desc )
     return status;
 }
 
-static BOOL check_hags_enabled( void )
-{
-    const char *winehags = getenv( "WINEHAGS" );
-    return winehags && *winehags && *winehags != '0';
-}
-
 /******************************************************************************
  *           NtGdiDdDDIQueryAdapterInfo    (win32u.@)
  */
 NTSTATUS WINAPI NtGdiDdDDIQueryAdapterInfo( D3DKMT_QUERYADAPTERINFO *desc )
 {
-    D3DKMT_WDDM_2_7_CAPS *d3dkmt_wddm_2_7_caps;
-
     if (!desc)
         return STATUS_INVALID_PARAMETER;
 
-    TRACE("desc %p, type %d\n", desc, desc->Type);
-
-    switch (desc->Type)
-    {
-        case KMTQAITYPE_WDDM_2_7_CAPS:
-            if (!desc->pPrivateDriverData || desc->PrivateDriverDataSize != sizeof(D3DKMT_WDDM_2_7_CAPS))
-                return STATUS_INVALID_PARAMETER;
-
-            d3dkmt_wddm_2_7_caps = desc->pPrivateDriverData;
-            d3dkmt_wddm_2_7_caps->HwSchSupported = 1;
-            d3dkmt_wddm_2_7_caps->HwSchEnabled = check_hags_enabled() ? 1 : 0;
-            d3dkmt_wddm_2_7_caps->HwSchEnabledByDefault = 0;
-            d3dkmt_wddm_2_7_caps->IndependentVidPnVSyncControl = 0;
-            break;
-
-        default:
-            FIXME("type %d not supported\n", desc->Type);
-            return STATUS_NOT_IMPLEMENTED;
-    }
-
-    return STATUS_SUCCESS;
+    FIXME("desc %p, type %d stub\n", desc, desc->Type);
+    return STATUS_NOT_IMPLEMENTED;
 }
 
 /******************************************************************************
diff --git a/include/ddk/d3dkmthk.h b/include/ddk/d3dkmthk.h
index 4b2c5a7f5a3..918a4ad4ed2 100644
--- a/include/ddk/d3dkmthk.h
+++ b/include/ddk/d3dkmthk.h
@@ -773,22 +773,6 @@ typedef struct _D3DKMT_ENUMADAPTERS2
   D3DKMT_ADAPTERINFO *pAdapters;
 } D3DKMT_ENUMADAPTERS2;
 
-typedef struct _D3DKMT_WDDM_2_7_CAPS
-{
-  union
-  {
-    struct
-    {
-      UINT HwSchSupported               :  1;
-      UINT HwSchEnabled                 :  1;
-      UINT HwSchEnabledByDefault        :  1;
-      UINT IndependentVidPnVSyncControl :  1;
-      UINT Reserved                     : 28;
-    };
-    UINT Value;
-  };
-} D3DKMT_WDDM_2_7_CAPS;
-
 #ifdef __cplusplus
 extern "C"
 {
-- 
2.47.0.rc0

From 3884d88d592b9bcc7c2e1fbfce9ae962ffe2fc20 Mon Sep 17 00:00:00 2001
From: Peter Jung <admin@ptr1337.dev>
Date: Thu, 17 Oct 2024 14:05:16 +0200
Subject: [PATCH 2/6] Revert "gdi32,win32u,winex11: Implement
 D3DKMTEnumAdapters2."

This reverts commit 1a95d73070d47972b1cf71d1d65a7af60c51a1ee.
---
 dlls/gdi32/gdi32.spec          |   1 -
 dlls/win32u/dibdrv/dc.c        |   2 -
 dlls/win32u/driver.c           |  48 +------
 dlls/win32u/emfdrv.c           |   1 -
 dlls/win32u/font.c             |   1 -
 dlls/win32u/main.c             |   5 -
 dlls/win32u/path.c             |   1 -
 dlls/win32u/win32u.spec        |   2 +-
 dlls/winex11.drv/init.c        |   1 -
 dlls/winex11.drv/x11drv.h      |   1 -
 dlls/winex11.drv/x11drv_main.c | 237 ---------------------------------
 dlls/winex11.drv/xrender.c     |   1 -
 dlls/wow64win/gdi.c            |  22 ---
 include/ddk/d3dkmthk.h         |   1 -
 include/ntgdi.h                |   1 -
 include/wine/gdi_driver.h      |   1 -
 16 files changed, 2 insertions(+), 324 deletions(-)

diff --git a/dlls/gdi32/gdi32.spec b/dlls/gdi32/gdi32.spec
index 69ad9b2d60a..0ad47111eaa 100644
--- a/dlls/gdi32/gdi32.spec
+++ b/dlls/gdi32/gdi32.spec
@@ -79,7 +79,6 @@
 @ stdcall D3DKMTCreateDevice(ptr) win32u.NtGdiDdDDICreateDevice
 @ stdcall D3DKMTDestroyDCFromMemory(ptr) win32u.NtGdiDdDDIDestroyDCFromMemory
 @ stdcall D3DKMTDestroyDevice(ptr) win32u.NtGdiDdDDIDestroyDevice
-@ stdcall D3DKMTEnumAdapters2(ptr) win32u.NtGdiDdDDIEnumAdapters2
 @ stdcall D3DKMTEscape(ptr) win32u.NtGdiDdDDIEscape
 @ stdcall D3DKMTOpenAdapterFromDeviceName(ptr) win32u.NtGdiDdDDIOpenAdapterFromDeviceName
 @ stdcall D3DKMTOpenAdapterFromGdiDisplayName(ptr)
diff --git a/dlls/win32u/dibdrv/dc.c b/dlls/win32u/dibdrv/dc.c
index 0a4b0ac3da0..7fe4b765a78 100644
--- a/dlls/win32u/dibdrv/dc.c
+++ b/dlls/win32u/dibdrv/dc.c
@@ -709,7 +709,6 @@ const struct gdi_dc_funcs dib_driver =
     NULL,                               /* pUnrealizePalette */
     NULL,                               /* pD3DKMTCheckVidPnExclusiveOwnership */
     NULL,                               /* pD3DKMTCloseAdapter */
-    NULL,                               /* pD3DKMTEnumAdapters2 */
     NULL,                               /* pD3DKMTOpenAdapterFromLuid */
     NULL,                               /* pD3DKMTQueryVideoMemoryInfo */
     NULL,                               /* pD3DKMTSetVidPnSourceOwner */
@@ -1271,7 +1270,6 @@ static const struct gdi_dc_funcs window_driver =
     NULL,                               /* pUnrealizePalette */
     NULL,                               /* pD3DKMTCheckVidPnExclusiveOwnership */
     NULL,                               /* pD3DKMTCloseAdapter */
-    NULL,                               /* pD3DKMTEnumAdapters2 */
     NULL,                               /* pD3DKMTOpenAdapterFromLuid */
     NULL,                               /* pD3DKMTQueryVideoMemoryInfo */
     NULL,                               /* pD3DKMTSetVidPnSourceOwner */
diff --git a/dlls/win32u/driver.c b/dlls/win32u/driver.c
index e4d229940fc..bc3409a9e34 100644
--- a/dlls/win32u/driver.c
+++ b/dlls/win32u/driver.c
@@ -54,7 +54,6 @@ static struct user_driver_funcs null_user_driver;
 
 static struct list d3dkmt_adapters = LIST_INIT( d3dkmt_adapters );
 static struct list d3dkmt_devices = LIST_INIT( d3dkmt_devices );
-static D3DKMT_HANDLE handle_start = 0;
 
 static pthread_mutex_t driver_lock = PTHREAD_MUTEX_INITIALIZER;
 static WCHAR driver_load_error[80];
@@ -550,11 +549,6 @@ static NTSTATUS nulldrv_D3DKMTCloseAdapter( const D3DKMT_CLOSEADAPTER *desc )
     return STATUS_PROCEDURE_NOT_FOUND;
 }
 
-static NTSTATUS nulldrv_D3DKMTEnumAdapters2( D3DKMT_ENUMADAPTERS2 *desc )
-{
-    return STATUS_PROCEDURE_NOT_FOUND;
-}
-
 static NTSTATUS nulldrv_D3DKMTOpenAdapterFromLuid( D3DKMT_OPENADAPTERFROMLUID *desc )
 {
     return STATUS_PROCEDURE_NOT_FOUND;
@@ -663,7 +657,6 @@ const struct gdi_dc_funcs null_driver =
     nulldrv_UnrealizePalette,           /* pUnrealizePalette */
     nulldrv_D3DKMTCheckVidPnExclusiveOwnership, /* pD3DKMTCheckVidPnExclusiveOwnership */
     nulldrv_D3DKMTCloseAdapter,         /* pD3DKMTCloseAdapter */
-    nulldrv_D3DKMTEnumAdapters2,        /* pD3DKMTEnumAdapters2 */
     nulldrv_D3DKMTOpenAdapterFromLuid,  /* pD3DKMTOpenAdapterFromLuid */
     nulldrv_D3DKMTQueryVideoMemoryInfo, /* pD3DKMTQueryVideoMemoryInfo */
     nulldrv_D3DKMTSetVidPnSourceOwner,  /* pD3DKMTSetVidPnSourceOwner */
@@ -1520,46 +1513,6 @@ NTSTATUS WINAPI NtGdiDdDDICloseAdapter( const D3DKMT_CLOSEADAPTER *desc )
     return status;
 }
 
-/******************************************************************************
- *           NtGdiDdDDIEnumAdapters2    (win32u.@)
- */
-NTSTATUS WINAPI NtGdiDdDDIEnumAdapters2( D3DKMT_ENUMADAPTERS2 *desc )
-{
-    NTSTATUS status = STATUS_UNSUCCESSFUL;
-    struct d3dkmt_adapter *adapter;
-    ULONG i;
-
-    TRACE("(%p)\n", desc);
-
-    if (!desc) return STATUS_INVALID_PARAMETER;
-
-    if (get_display_driver()->pD3DKMTEnumAdapters2)
-    {
-        if (desc->pAdapters)
-        {
-            pthread_mutex_lock( &driver_lock );
-
-            for (i = 0; i < desc->NumAdapters; ++i)
-            {
-                if (!(adapter = malloc( sizeof( *adapter ) )))
-                {
-                    pthread_mutex_unlock( &driver_lock );
-                    return STATUS_NO_MEMORY;
-                }
-
-                desc->pAdapters[i].hAdapter = adapter->handle = ++handle_start;
-                list_add_tail( &d3dkmt_adapters, &adapter->entry );
-            }
-
-            pthread_mutex_unlock( &driver_lock );
-        }
-
-        status = get_display_driver()->pD3DKMTEnumAdapters2( desc );
-    }
-
-    return status;
-}
-
 /******************************************************************************
  *           NtGdiDdDDIOpenAdapterFromDeviceName    (win32u.@)
  */
@@ -1585,6 +1538,7 @@ NTSTATUS WINAPI NtGdiDdDDIOpenAdapterFromDeviceName( D3DKMT_OPENADAPTERFROMDEVIC
  */
 NTSTATUS WINAPI NtGdiDdDDIOpenAdapterFromLuid( D3DKMT_OPENADAPTERFROMLUID *desc )
 {
+    static D3DKMT_HANDLE handle_start = 0;
     struct d3dkmt_adapter *adapter;
 
     if (!(adapter = malloc( sizeof( *adapter ) ))) return STATUS_NO_MEMORY;
diff --git a/dlls/win32u/emfdrv.c b/dlls/win32u/emfdrv.c
index 9c07f9ef341..069ad9d1297 100644
--- a/dlls/win32u/emfdrv.c
+++ b/dlls/win32u/emfdrv.c
@@ -521,7 +521,6 @@ static const struct gdi_dc_funcs emfdrv_driver =
     NULL,                            /* pUnrealizePalette */
     NULL,                            /* pD3DKMTCheckVidPnExclusiveOwnership */
     NULL,                            /* pD3DKMTCloseAdapter */
-    NULL,                            /* pD3DKMTEnumAdapters2 */
     NULL,                            /* pD3DKMTOpenAdapterFromLuid */
     NULL,                            /* pD3DKMTQueryVideoMemoryInfo */
     NULL,                            /* pD3DKMTSetVidPnSourceOwner */
diff --git a/dlls/win32u/font.c b/dlls/win32u/font.c
index 33c7beaefbb..9b918624e24 100644
--- a/dlls/win32u/font.c
+++ b/dlls/win32u/font.c
@@ -4795,7 +4795,6 @@ const struct gdi_dc_funcs font_driver =
     NULL,                           /* pUnrealizePalette */
     NULL,                           /* pD3DKMTCheckVidPnExclusiveOwnership */
     NULL,                           /* pD3DKMTCloseAdapter */
-    NULL,                           /* pD3DKMTEnumAdapters2 */
     NULL,                           /* pD3DKMTOpenAdapterFromLuid */
     NULL,                           /* pD3DKMTQueryVideoMemoryInfo */
     NULL,                           /* pD3DKMTSetVidPnSourceOwner */
diff --git a/dlls/win32u/main.c b/dlls/win32u/main.c
index 54c7693069e..ea3578407a1 100644
--- a/dlls/win32u/main.c
+++ b/dlls/win32u/main.c
@@ -236,11 +236,6 @@ NTSTATUS SYSCALL_API NtGdiDdDDIDestroyDevice( const D3DKMT_DESTROYDEVICE *desc )
     __ASM_SYSCALL_FUNC( __id_NtGdiDdDDIDestroyDevice );
 }
 
-NTSTATUS SYSCALL_API NtGdiDdDDIEnumAdapters2( D3DKMT_ENUMADAPTERS2 *desc )
-{
-    __ASM_SYSCALL_FUNC( __id_NtGdiDdDDIEnumAdapters2 );
-}
-
 NTSTATUS SYSCALL_API NtGdiDdDDIEscape( const D3DKMT_ESCAPE *desc )
 {
     __ASM_SYSCALL_FUNC( __id_NtGdiDdDDIEscape );
diff --git a/dlls/win32u/path.c b/dlls/win32u/path.c
index 6d494a92233..e0c96f5ef6f 100644
--- a/dlls/win32u/path.c
+++ b/dlls/win32u/path.c
@@ -2120,7 +2120,6 @@ const struct gdi_dc_funcs path_driver =
     NULL,                               /* pUnrealizePalette */
     NULL,                               /* pD3DKMTCheckVidPnExclusiveOwnership */
     NULL,                               /* pD3DKMTCloseAdapter */
-    NULL,                               /* pD3DKMTEnumAdapters2 */
     NULL,                               /* pD3DKMTOpenAdapterFromLuid */
     NULL,                               /* pD3DKMTQueryVideoMemoryInfo */
     NULL,                               /* pD3DKMTSetVidPnSourceOwner */
diff --git a/dlls/win32u/win32u.spec b/dlls/win32u/win32u.spec
index d9050cee8a6..e5586fd67a6 100644
--- a/dlls/win32u/win32u.spec
+++ b/dlls/win32u/win32u.spec
@@ -223,7 +223,7 @@
 @ stub NtGdiDdDDIDispMgrSourceOperation
 @ stub NtGdiDdDDIDispMgrTargetOperation
 @ stub NtGdiDdDDIEnumAdapters
-@ stdcall -syscall NtGdiDdDDIEnumAdapters2(ptr)
+@ stub NtGdiDdDDIEnumAdapters2
 @ stdcall -syscall NtGdiDdDDIEscape(ptr)
 @ stub NtGdiDdDDIEvict
 @ stub NtGdiDdDDIExtractBundleObject
diff --git a/dlls/winex11.drv/init.c b/dlls/winex11.drv/init.c
index 998f704b390..5576fdd50e6 100644
--- a/dlls/winex11.drv/init.c
+++ b/dlls/winex11.drv/init.c
@@ -388,7 +388,6 @@ static const struct user_driver_funcs x11drv_funcs =
     .dc_funcs.pUnrealizePalette = X11DRV_UnrealizePalette,
     .dc_funcs.pD3DKMTCheckVidPnExclusiveOwnership = X11DRV_D3DKMTCheckVidPnExclusiveOwnership,
     .dc_funcs.pD3DKMTCloseAdapter = X11DRV_D3DKMTCloseAdapter,
-    .dc_funcs.pD3DKMTEnumAdapters2 = X11DRV_D3DKMTEnumAdapters2,
     .dc_funcs.pD3DKMTOpenAdapterFromLuid = X11DRV_D3DKMTOpenAdapterFromLuid,
     .dc_funcs.pD3DKMTQueryVideoMemoryInfo = X11DRV_D3DKMTQueryVideoMemoryInfo,
     .dc_funcs.pD3DKMTSetVidPnSourceOwner = X11DRV_D3DKMTSetVidPnSourceOwner,
diff --git a/dlls/winex11.drv/x11drv.h b/dlls/winex11.drv/x11drv.h
index 9f80842e004..be4f0cb99ff 100644
--- a/dlls/winex11.drv/x11drv.h
+++ b/dlls/winex11.drv/x11drv.h
@@ -162,7 +162,6 @@ extern BOOL X11DRV_Chord( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
                           INT xstart, INT ystart, INT xend, INT yend );
 extern NTSTATUS X11DRV_D3DKMTCheckVidPnExclusiveOwnership( const D3DKMT_CHECKVIDPNEXCLUSIVEOWNERSHIP *desc );
 extern NTSTATUS X11DRV_D3DKMTCloseAdapter( const D3DKMT_CLOSEADAPTER *desc );
-extern NTSTATUS X11DRV_D3DKMTEnumAdapters2( D3DKMT_ENUMADAPTERS2 *desc );
 extern NTSTATUS X11DRV_D3DKMTOpenAdapterFromLuid( D3DKMT_OPENADAPTERFROMLUID *desc );
 extern NTSTATUS X11DRV_D3DKMTQueryVideoMemoryInfo( D3DKMT_QUERYVIDEOMEMORYINFO *desc );
 extern NTSTATUS X11DRV_D3DKMTSetVidPnSourceOwner( const D3DKMT_SETVIDPNSOURCEOWNER *desc );
diff --git a/dlls/winex11.drv/x11drv_main.c b/dlls/winex11.drv/x11drv_main.c
index 2902f309bd2..fcfa3b064fb 100644
--- a/dlls/winex11.drv/x11drv_main.c
+++ b/dlls/winex11.drv/x11drv_main.c
@@ -1266,243 +1266,6 @@ static void release_display_device_init_mutex(HANDLE mutex)
     NtClose( mutex );
 }
 
-/* Find the Vulkan device LUID corresponding to a GUID */
-static BOOL get_vulkan_luid_from_uuid( const GUID *uuid, LUID *luid )
-{
-    static const WCHAR class_guidW[] = {'C','l','a','s','s','G','U','I','D',0};
-    static const WCHAR devpropkey_gpu_vulkan_uuidW[] =
-    {
-        'P','r','o','p','e','r','t','i','e','s',
-        '\\','{','2','3','3','A','9','E','F','3','-','A','F','C','4','-','4','A','B','D',
-        '-','B','5','6','4','-','C','3','2','F','2','1','F','1','5','3','5','C','}',
-        '\\','0','0','0','2'
-    };
-    static const WCHAR devpropkey_gpu_luidW[] =
-    {
-        'P','r','o','p','e','r','t','i','e','s',
-        '\\','{','6','0','B','1','9','3','C','B','-','5','2','7','6','-','4','D','0','F',
-        '-','9','6','F','C','-','F','1','7','3','A','B','A','D','3','E','C','6','}',
-        '\\','0','0','0','2'
-    };
-    static const WCHAR guid_devclass_displayW[] =
-        {'{','4','D','3','6','E','9','6','8','-','E','3','2','5','-','1','1','C','E','-',
-         'B','F','C','1','-','0','8','0','0','2','B','E','1','0','3','1','8','}',0};
-    static const WCHAR pci_keyW[] =
-    {
-        '\\','R','e','g','i','s','t','r','y',
-        '\\','M','a','c','h','i','n','e',
-        '\\','S','y','s','t','e','m',
-        '\\','C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t',
-        '\\','E','n','u','m',
-        '\\','P','C','I'
-    };
-    char buffer[4096];
-    KEY_VALUE_PARTIAL_INFORMATION *value = (void *)buffer;
-    HKEY subkey, device_key, prop_key, pci_key;
-    KEY_NODE_INFORMATION *key = (void *)buffer;
-    DWORD size, i = 0;
-    HANDLE mutex;
-
-    mutex = get_display_device_init_mutex();
-
-    pci_key = reg_open_key(NULL, pci_keyW, sizeof(pci_keyW));
-    while (!NtEnumerateKey(pci_key, i++, KeyNodeInformation, key, sizeof(buffer), &size))
-    {
-        unsigned int j = 0;
-
-        if (!(subkey = reg_open_key(pci_key, key->Name, key->NameLength)))
-            continue;
-
-        while (!NtEnumerateKey(subkey, j++, KeyNodeInformation, key, sizeof(buffer), &size))
-        {
-            if (!(device_key = reg_open_key(subkey, key->Name, key->NameLength)))
-                continue;
-
-            size = query_reg_value(device_key, class_guidW, value, sizeof(buffer));
-            if (size != sizeof(guid_devclass_displayW) ||
-                wcscmp((WCHAR *)value->Data, guid_devclass_displayW))
-            {
-                NtClose(device_key);
-                continue;
-            }
-
-            if (!(prop_key = reg_open_key(device_key, devpropkey_gpu_vulkan_uuidW,
-                                          sizeof(devpropkey_gpu_vulkan_uuidW))))
-            {
-                NtClose(device_key);
-                continue;
-            }
-
-            size = query_reg_value(prop_key, NULL, value, sizeof(buffer));
-            NtClose(prop_key);
-            if (size != sizeof(GUID) || memcmp(value->Data, uuid, sizeof(GUID)))
-            {
-                NtClose(device_key);
-                continue;
-            }
-
-            if (!(prop_key = reg_open_key(device_key, devpropkey_gpu_luidW,
-                                          sizeof(devpropkey_gpu_luidW))))
-            {
-                NtClose(device_key);
-                continue;
-            }
-
-            size = query_reg_value(prop_key, NULL, value, sizeof(buffer));
-            NtClose(prop_key);
-            if (size != sizeof(LUID))
-            {
-                NtClose(device_key);
-                continue;
-            }
-
-            *luid = *(const LUID *)value->Data;
-            NtClose(device_key);
-            NtClose(subkey);
-            NtClose(pci_key);
-            release_display_device_init_mutex(mutex);
-            return TRUE;
-        }
-        NtClose(subkey);
-    }
-    NtClose(pci_key);
-
-    release_display_device_init_mutex(mutex);
-    return FALSE;
-}
-
-NTSTATUS X11DRV_D3DKMTEnumAdapters2( D3DKMT_ENUMADAPTERS2 *desc )
-{
-    static const char *extensions[] =
-    {
-        VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME,
-        VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME,
-    };
-    const struct vulkan_funcs *vulkan_funcs;
-    PFN_vkGetPhysicalDeviceProperties2KHR pvkGetPhysicalDeviceProperties2KHR;
-    PFN_vkEnumeratePhysicalDevices pvkEnumeratePhysicalDevices;
-    VkPhysicalDevice *vk_physical_devices = NULL;
-    VkPhysicalDeviceProperties2 properties2;
-    NTSTATUS status = STATUS_UNSUCCESSFUL;
-    UINT device_count = 0, device_idx = 0;
-    struct x11_d3dkmt_adapter *adapter;
-    VkInstanceCreateInfo create_info;
-    VkPhysicalDeviceIDProperties id;
-    VkResult vr;
-    LUID luid;
-
-    if (!(vulkan_funcs = get_vulkan_driver(WINE_VULKAN_DRIVER_VERSION)))
-    {
-        WARN("Vulkan is unavailable.\n");
-        return STATUS_UNSUCCESSFUL;
-    }
-
-    pthread_mutex_lock(&d3dkmt_mutex);
-
-    if (!d3dkmt_vk_instance)
-    {
-        memset(&create_info, 0, sizeof(create_info));
-        create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
-        create_info.enabledExtensionCount = ARRAY_SIZE(extensions);
-        create_info.ppEnabledExtensionNames = extensions;
-
-        vr = vulkan_funcs->p_vkCreateInstance(&create_info, NULL, &d3dkmt_vk_instance);
-        if (vr != VK_SUCCESS)
-        {
-            WARN("Failed to create a Vulkan instance, vr %d.\n", vr);
-            goto done;
-        }
-    }
-
-#define LOAD_VK_FUNC(f)                                                                  \
-    if (!(p##f = (void *)vulkan_funcs->p_vkGetInstanceProcAddr(d3dkmt_vk_instance, #f))) \
-    {                                                                                    \
-        WARN("Failed to load " #f ".\n");                                                \
-        goto done;                                                                       \
-    }
-
-    LOAD_VK_FUNC(vkEnumeratePhysicalDevices)
-    LOAD_VK_FUNC(vkGetPhysicalDeviceProperties2KHR)
-#undef LOAD_VK_FUNC
-
-    vr = pvkEnumeratePhysicalDevices(d3dkmt_vk_instance, &device_count, NULL);
-    if (vr != VK_SUCCESS || !device_count)
-    {
-        WARN("No Vulkan device found, vr %d, device_count %d.\n", vr, device_count);
-        goto done;
-    }
-
-    if (!desc->pAdapters)
-    {
-        status = STATUS_SUCCESS;
-        goto done;
-    }
-    else if (desc->NumAdapters < device_count)
-    {
-        status = STATUS_BUFFER_TOO_SMALL;
-        goto done;
-    }
-
-    if (!(vk_physical_devices = calloc(device_count, sizeof(*vk_physical_devices))))
-    {
-        status = STATUS_NO_MEMORY;
-        goto done;
-    }
-
-    vr = pvkEnumeratePhysicalDevices(d3dkmt_vk_instance, &device_count, vk_physical_devices);
-    if (vr != VK_SUCCESS)
-    {
-        WARN("vkEnumeratePhysicalDevices failed, vr %d.\n", vr);
-        goto done;
-    }
-
-    for (device_idx = 0; device_idx < device_count; ++device_idx)
-    {
-        memset(&id, 0, sizeof(id));
-        id.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES;
-        properties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
-        properties2.pNext = &id;
-
-        pvkGetPhysicalDeviceProperties2KHR(vk_physical_devices[device_idx], &properties2);
-
-        if (!(adapter = malloc(sizeof(*adapter))))
-        {
-            status = STATUS_NO_MEMORY;
-            goto done;
-        }
-
-        adapter->handle = desc->pAdapters[device_idx].hAdapter;
-        adapter->vk_device = vk_physical_devices[device_idx];
-        list_add_tail(&x11_d3dkmt_adapters, &adapter->entry);
-
-        if (get_vulkan_luid_from_uuid((const GUID *)id.deviceUUID, &luid))
-        {
-            memcpy(&desc->pAdapters[device_idx].AdapterLuid, &luid, sizeof(LUID));
-        }
-        else
-        {
-            WARN("get_vulkan_luid_from_uuid failed, AdapterLuid will remain empty.\n");
-            memset(&desc->pAdapters[device_idx].AdapterLuid, 0, sizeof(LUID));
-        }
-
-        desc->pAdapters[device_idx].NumOfSources = 1;
-        desc->pAdapters[device_idx].bPrecisePresentRegionsPreferred = FALSE;
-    }
-
-    status = STATUS_SUCCESS;
-
-done:
-    desc->NumAdapters = device_count;
-    if (d3dkmt_vk_instance && list_empty(&x11_d3dkmt_adapters))
-    {
-        vulkan_funcs->p_vkDestroyInstance(d3dkmt_vk_instance, NULL);
-        d3dkmt_vk_instance = NULL;
-    }
-    pthread_mutex_unlock(&d3dkmt_mutex);
-    free(vk_physical_devices);
-    return status;
-}
-
 /* Find the Vulkan device UUID corresponding to a LUID */
 static BOOL get_vulkan_uuid_from_luid( const LUID *luid, GUID *uuid )
 {
diff --git a/dlls/winex11.drv/xrender.c b/dlls/winex11.drv/xrender.c
index 084e6665981..7656c0637df 100644
--- a/dlls/winex11.drv/xrender.c
+++ b/dlls/winex11.drv/xrender.c
@@ -2433,7 +2433,6 @@ static const struct gdi_dc_funcs xrender_funcs =
     NULL,                               /* pUnrealizePalette */
     NULL,                               /* pD3DKMTCheckVidPnExclusiveOwnership */
     NULL,                               /* pD3DKMTCloseAdapter */
-    NULL,                               /* pD3DKMTEnumAdapters2 */
     NULL,                               /* pD3DKMTOpenAdapterFromLuid */
     NULL,                               /* pD3DKMTQueryVideoMemoryInfo */
     NULL,                               /* pD3DKMTSetVidPnSourceOwner */
diff --git a/dlls/wow64win/gdi.c b/dlls/wow64win/gdi.c
index 993580c32c3..36af173405c 100644
--- a/dlls/wow64win/gdi.c
+++ b/dlls/wow64win/gdi.c
@@ -507,28 +507,6 @@ NTSTATUS WINAPI wow64_NtGdiDdDDIDestroyDevice( UINT *args )
     return NtGdiDdDDIDestroyDevice( desc );
 }
 
-NTSTATUS WINAPI wow64_NtGdiDdDDIEnumAdapters2( UINT *args )
-{
-    struct
-    {
-        ULONG NumAdapters;
-        ULONG pAdapters;
-    } *desc32 = get_ptr( &args );
-    D3DKMT_ENUMADAPTERS2 desc;
-    NTSTATUS status;
-
-    if (!desc32) return STATUS_INVALID_PARAMETER;
-
-    desc.NumAdapters = desc32->NumAdapters;
-    desc.pAdapters = UlongToPtr( desc32->pAdapters );
-
-    status = NtGdiDdDDIEnumAdapters2( &desc );
-
-    desc32->NumAdapters = desc.NumAdapters;
-
-    return status;
-}
-
 NTSTATUS WINAPI wow64_NtGdiDdDDIEscape( UINT *args )
 {
     const struct
diff --git a/include/ddk/d3dkmthk.h b/include/ddk/d3dkmthk.h
index 918a4ad4ed2..2d30bdd8777 100644
--- a/include/ddk/d3dkmthk.h
+++ b/include/ddk/d3dkmthk.h
@@ -785,7 +785,6 @@ NTSTATUS WINAPI D3DKMTCreateDCFromMemory(D3DKMT_CREATEDCFROMMEMORY *desc);
 NTSTATUS WINAPI D3DKMTDestroyDCFromMemory(const D3DKMT_DESTROYDCFROMMEMORY *desc);
 NTSTATUS WINAPI D3DKMTDestroyDevice(const D3DKMT_DESTROYDEVICE *desc);
 NTSTATUS WINAPI D3DKMTEscape( const D3DKMT_ESCAPE *desc );
-NTSTATUS WINAPI D3DKMTEnumAdapters2(D3DKMT_ENUMADAPTERS2 *desc);
 NTSTATUS WINAPI D3DKMTOpenAdapterFromGdiDisplayName(D3DKMT_OPENADAPTERFROMGDIDISPLAYNAME *desc);
 NTSTATUS WINAPI D3DKMTOpenAdapterFromHdc( D3DKMT_OPENADAPTERFROMHDC *desc );
 NTSTATUS WINAPI D3DKMTOpenAdapterFromLuid( D3DKMT_OPENADAPTERFROMLUID * desc );
diff --git a/include/ntgdi.h b/include/ntgdi.h
index 50973535c7a..c2cb1924730 100644
--- a/include/ntgdi.h
+++ b/include/ntgdi.h
@@ -481,7 +481,6 @@ W32KAPI NTSTATUS WINAPI NtGdiDdDDICreateDCFromMemory( D3DKMT_CREATEDCFROMMEMORY
 W32KAPI NTSTATUS WINAPI NtGdiDdDDICreateDevice( D3DKMT_CREATEDEVICE *desc );
 W32KAPI NTSTATUS WINAPI NtGdiDdDDIDestroyDCFromMemory( const D3DKMT_DESTROYDCFROMMEMORY *desc );
 W32KAPI NTSTATUS WINAPI NtGdiDdDDIDestroyDevice( const D3DKMT_DESTROYDEVICE *desc );
-W32KAPI NTSTATUS WINAPI NtGdiDdDDIEnumAdapters2( D3DKMT_ENUMADAPTERS2 *desc );
 W32KAPI NTSTATUS WINAPI NtGdiDdDDIEscape( const D3DKMT_ESCAPE *desc );
 W32KAPI NTSTATUS WINAPI NtGdiDdDDIOpenAdapterFromHdc( D3DKMT_OPENADAPTERFROMHDC *desc );
 W32KAPI NTSTATUS WINAPI NtGdiDdDDIOpenAdapterFromDeviceName( D3DKMT_OPENADAPTERFROMDEVICENAME *desc );
diff --git a/include/wine/gdi_driver.h b/include/wine/gdi_driver.h
index ba37098f7ad..26562bfef2b 100644
--- a/include/wine/gdi_driver.h
+++ b/include/wine/gdi_driver.h
@@ -168,7 +168,6 @@ struct gdi_dc_funcs
     BOOL     (*pUnrealizePalette)(HPALETTE);
     NTSTATUS (*pD3DKMTCheckVidPnExclusiveOwnership)(const D3DKMT_CHECKVIDPNEXCLUSIVEOWNERSHIP *);
     NTSTATUS (*pD3DKMTCloseAdapter)(const D3DKMT_CLOSEADAPTER *);
-    NTSTATUS (*pD3DKMTEnumAdapters2)(D3DKMT_ENUMADAPTERS2 *);
     NTSTATUS (*pD3DKMTOpenAdapterFromLuid)(D3DKMT_OPENADAPTERFROMLUID *);
     NTSTATUS (*pD3DKMTQueryVideoMemoryInfo)(D3DKMT_QUERYVIDEOMEMORYINFO *);
     NTSTATUS (*pD3DKMTSetVidPnSourceOwner)(const D3DKMT_SETVIDPNSOURCEOWNER *);
-- 
2.47.0.rc0

From 4c1eede18092d6b843be6bcf556c36f3b99c05e6 Mon Sep 17 00:00:00 2001
From: Peter Jung <admin@ptr1337.dev>
Date: Thu, 17 Oct 2024 14:05:20 +0200
Subject: [PATCH 3/6] Reapply "gdi32: Add stub for D3DKMTEnumAdapters2()."

This reverts commit eec1ca48e8d452a8593159ef2f16b8462213f836.
---
 dlls/gdi32/gdi32.spec | 1 +
 dlls/gdi32/objects.c  | 6 ++++++
 2 files changed, 7 insertions(+)

diff --git a/dlls/gdi32/gdi32.spec b/dlls/gdi32/gdi32.spec
index 0ad47111eaa..44783e3600a 100644
--- a/dlls/gdi32/gdi32.spec
+++ b/dlls/gdi32/gdi32.spec
@@ -79,6 +79,7 @@
 @ stdcall D3DKMTCreateDevice(ptr) win32u.NtGdiDdDDICreateDevice
 @ stdcall D3DKMTDestroyDCFromMemory(ptr) win32u.NtGdiDdDDIDestroyDCFromMemory
 @ stdcall D3DKMTDestroyDevice(ptr) win32u.NtGdiDdDDIDestroyDevice
+@ stdcall D3DKMTEnumAdapters2(ptr)
 @ stdcall D3DKMTEscape(ptr) win32u.NtGdiDdDDIEscape
 @ stdcall D3DKMTOpenAdapterFromDeviceName(ptr) win32u.NtGdiDdDDIOpenAdapterFromDeviceName
 @ stdcall D3DKMTOpenAdapterFromGdiDisplayName(ptr)
diff --git a/dlls/gdi32/objects.c b/dlls/gdi32/objects.c
index 070ce9c3885..bddc29a3007 100644
--- a/dlls/gdi32/objects.c
+++ b/dlls/gdi32/objects.c
@@ -971,6 +971,12 @@ done:
     return status;
 }
 
+NTSTATUS WINAPI D3DKMTEnumAdapters2( const void *param )
+{
+    FIXME( "param %p stub.\n", param );
+    return STATUS_NOT_SUPPORTED;
+}
+
 /***********************************************************************
  *           SetObjectOwner    (GDI32.@)
  */
-- 
2.47.0.rc0

From 185ff0b03e4cfc87ca38a0022227eb5efdc56671 Mon Sep 17 00:00:00 2001
From: Liam Middlebrook <lmiddlebrook@nvidia.com>
Date: Sat, 12 Oct 2024 15:15:30 -0700
Subject: [PATCH 4/6] gdi32: Implement D3DKMTEnumAdapters2

Signed-off-by: Liam Middlebrook <lmiddlebrook@nvidia.com>

Note: This commit is specifically targeted towards ValveSoftware/wine experimental_9.0 branch.
Upstream wine contains commits which already implement this, but are part of a larger series of
changes inter-twined with WoW64 and unification of GDI backends.
---
 dlls/gdi32/objects.c | 74 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 71 insertions(+), 3 deletions(-)

diff --git a/dlls/gdi32/objects.c b/dlls/gdi32/objects.c
index bddc29a3007..093039c3509 100644
--- a/dlls/gdi32/objects.c
+++ b/dlls/gdi32/objects.c
@@ -971,10 +971,78 @@ done:
     return status;
 }
 
-NTSTATUS WINAPI D3DKMTEnumAdapters2( const void *param )
+NTSTATUS WINAPI D3DKMTEnumAdapters2( D3DKMT_ENUMADAPTERS2 *enumAdapters )
 {
-    FIXME( "param %p stub.\n", param );
-    return STATUS_NOT_SUPPORTED;
+    NTSTATUS status = STATUS_SUCCESS;
+    SP_DEVINFO_DATA device_data;
+    DEVPROPTYPE type;
+    HDEVINFO devinfo;
+    UINT dev_count = 0;
+    HANDLE mutex;
+
+    TRACE("(%p)\n", enumAdapters);
+
+    mutex = get_display_device_init_mutex();
+    devinfo = SetupDiGetClassDevsW(&GUID_DEVCLASS_DISPLAY, L"PCI", NULL, 0);
+    device_data.cbSize = sizeof(device_data);
+
+    while(SetupDiEnumDeviceInfo(devinfo, dev_count++, &device_data))
+    {
+        D3DKMT_OPENADAPTERFROMLUID luid_desc;
+        UINT dev_idx = dev_count - 1;
+        D3DKMT_ADAPTERINFO *adapter;
+
+        TRACE("Device: %u\n", dev_idx);
+
+        /* If nothing to write, just pass through the loop */
+        if (!enumAdapters->pAdapters)
+            continue;
+
+        adapter = (D3DKMT_ADAPTERINFO*)(enumAdapters->pAdapters + dev_idx);
+
+        if (SetupDiGetDevicePropertyW(devinfo, &device_data, &DEVPROPKEY_GPU_LUID, &type,
+                (BYTE *)&luid_desc.AdapterLuid, sizeof(luid_desc.AdapterLuid), NULL, 0))
+        {
+            /* NumOfSources appears to be in reference to displays. This could mean connected
+             * displays, maximum number of "heads", surfaces for direct scanout, or something else
+             * entirely. It's not clear from the MSDN page what kind of value is actually expected
+             * here.
+             *
+             * bPrecisePresentRegionsPreferred sounds like a scanout-level optimization. Again, MSDN
+             * isn't very descriptive about what this really means. Given that it's typical for
+             * modern GPUs to scanout an entire surface at once, leave this falsey.
+             */
+            adapter->NumOfSources = 0;
+            adapter->bPrecisePresentRegionsPreferred = FALSE;
+            FIXME("NumOfSources and bPrecisePresentRegionsPreferred not set, need implementation.\n");
+
+            if ((status = NtGdiDdDDIOpenAdapterFromLuid(&luid_desc)))
+                break;
+
+            adapter->AdapterLuid = luid_desc.AdapterLuid;
+            adapter->hAdapter = luid_desc.hAdapter;
+
+            TRACE("hAdapter: %u AdapterLuid: %08lx:%08lx NumOfSources: %lu bPrecisePresentRegionsPreferred: %d\n",
+                  adapter->hAdapter,
+                  adapter->AdapterLuid.HighPart,
+                  adapter->AdapterLuid.LowPart,
+                  adapter->NumOfSources,
+                  adapter->bPrecisePresentRegionsPreferred);
+        }
+        else
+        {
+            TRACE("no known adapter\n");
+        }
+    }
+    /* decrement dev count to actual count */
+    dev_count--;
+    SetupDiDestroyDeviceInfoList(devinfo);
+    release_display_device_init_mutex(mutex);
+
+    TRACE("Devices enumerated: %u\n", dev_count);
+    enumAdapters->NumAdapters = dev_count;
+
+    return status;
 }
 
 /***********************************************************************
-- 
2.47.0.rc0

From 529af77c268b5a857cbf7b3c52fa67a4ac4dbb3f Mon Sep 17 00:00:00 2001
From: Liam Middlebrook <lmiddlebrook@nvidia.com>
Date: Sat, 12 Oct 2024 15:31:38 -0700
Subject: [PATCH 5/6] win32u: Move D3DKMTQueryAdapterInfo into gdi_dc_funcs

Signed-off-by: Liam Middlebrook <lmiddlebrook@nvidia.com>

Note: This commit is specifically targeted towards ValveSoftware/wine experimental_9.0 branch.
Upstream wine contains commits which already implement this, but are part of a larger series of
changes inter-twined with WoW64 and unification of GDI backends.
---
 dlls/win32u/dibdrv/dc.c        |  2 ++
 dlls/win32u/driver.c           | 15 ++++++++++++---
 dlls/win32u/emfdrv.c           |  1 +
 dlls/win32u/font.c             |  1 +
 dlls/win32u/path.c             |  1 +
 dlls/winex11.drv/init.c        |  1 +
 dlls/winex11.drv/x11drv.h      |  1 +
 dlls/winex11.drv/x11drv_main.c | 19 +++++++++++++++++++
 dlls/winex11.drv/xrender.c     |  1 +
 include/wine/gdi_driver.h      |  1 +
 10 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/dlls/win32u/dibdrv/dc.c b/dlls/win32u/dibdrv/dc.c
index 7fe4b765a78..737c28adc8a 100644
--- a/dlls/win32u/dibdrv/dc.c
+++ b/dlls/win32u/dibdrv/dc.c
@@ -710,6 +710,7 @@ const struct gdi_dc_funcs dib_driver =
     NULL,                               /* pD3DKMTCheckVidPnExclusiveOwnership */
     NULL,                               /* pD3DKMTCloseAdapter */
     NULL,                               /* pD3DKMTOpenAdapterFromLuid */
+    NULL,                               /* pD3DKMTQueryAdapterInfo */
     NULL,                               /* pD3DKMTQueryVideoMemoryInfo */
     NULL,                               /* pD3DKMTSetVidPnSourceOwner */
     GDI_PRIORITY_DIB_DRV                /* priority */
@@ -1271,6 +1272,7 @@ static const struct gdi_dc_funcs window_driver =
     NULL,                               /* pD3DKMTCheckVidPnExclusiveOwnership */
     NULL,                               /* pD3DKMTCloseAdapter */
     NULL,                               /* pD3DKMTOpenAdapterFromLuid */
+    NULL,                               /* pD3DKMTQueryAdapterInfo */
     NULL,                               /* pD3DKMTQueryVideoMemoryInfo */
     NULL,                               /* pD3DKMTSetVidPnSourceOwner */
     GDI_PRIORITY_DIB_DRV + 10           /* priority */
diff --git a/dlls/win32u/driver.c b/dlls/win32u/driver.c
index bc3409a9e34..ccfe684b28e 100644
--- a/dlls/win32u/driver.c
+++ b/dlls/win32u/driver.c
@@ -554,6 +554,11 @@ static NTSTATUS nulldrv_D3DKMTOpenAdapterFromLuid( D3DKMT_OPENADAPTERFROMLUID *d
     return STATUS_PROCEDURE_NOT_FOUND;
 }
 
+static NTSTATUS nulldrv_D3DKMTQueryAdapterInfo( D3DKMT_QUERYADAPTERINFO *desc )
+{
+    return STATUS_PROCEDURE_NOT_FOUND;
+}
+
 static NTSTATUS nulldrv_D3DKMTQueryVideoMemoryInfo( D3DKMT_QUERYVIDEOMEMORYINFO *desc )
 {
     return STATUS_PROCEDURE_NOT_FOUND;
@@ -658,6 +663,7 @@ const struct gdi_dc_funcs null_driver =
     nulldrv_D3DKMTCheckVidPnExclusiveOwnership, /* pD3DKMTCheckVidPnExclusiveOwnership */
     nulldrv_D3DKMTCloseAdapter,         /* pD3DKMTCloseAdapter */
     nulldrv_D3DKMTOpenAdapterFromLuid,  /* pD3DKMTOpenAdapterFromLuid */
+    nulldrv_D3DKMTQueryAdapterInfo,     /* pD3DKMTQueryAdapterInfo */
     nulldrv_D3DKMTQueryVideoMemoryInfo, /* pD3DKMTQueryVideoMemoryInfo */
     nulldrv_D3DKMTSetVidPnSourceOwner,  /* pD3DKMTSetVidPnSourceOwner */
 
@@ -1637,11 +1643,14 @@ NTSTATUS WINAPI NtGdiDdDDIDestroyDevice( const D3DKMT_DESTROYDEVICE *desc )
  */
 NTSTATUS WINAPI NtGdiDdDDIQueryAdapterInfo( D3DKMT_QUERYADAPTERINFO *desc )
 {
-    if (!desc)
+    TRACE("(%p)\n", desc);
+
+    if (!desc || !desc->hAdapter)
         return STATUS_INVALID_PARAMETER;
 
-    FIXME("desc %p, type %d stub\n", desc, desc->Type);
-    return STATUS_NOT_IMPLEMENTED;
+    if (!get_display_driver()->pD3DKMTQueryAdapterInfo)
+        return STATUS_PROCEDURE_NOT_FOUND;
+    return get_display_driver()->pD3DKMTQueryAdapterInfo(desc);
 }
 
 /******************************************************************************
diff --git a/dlls/win32u/emfdrv.c b/dlls/win32u/emfdrv.c
index 069ad9d1297..28bc47772d4 100644
--- a/dlls/win32u/emfdrv.c
+++ b/dlls/win32u/emfdrv.c
@@ -522,6 +522,7 @@ static const struct gdi_dc_funcs emfdrv_driver =
     NULL,                            /* pD3DKMTCheckVidPnExclusiveOwnership */
     NULL,                            /* pD3DKMTCloseAdapter */
     NULL,                            /* pD3DKMTOpenAdapterFromLuid */
+    NULL,                            /* pD3DKMTQueryAdapterInfo */
     NULL,                            /* pD3DKMTQueryVideoMemoryInfo */
     NULL,                            /* pD3DKMTSetVidPnSourceOwner */
     GDI_PRIORITY_GRAPHICS_DRV        /* priority */
diff --git a/dlls/win32u/font.c b/dlls/win32u/font.c
index 9b918624e24..2de8b31df99 100644
--- a/dlls/win32u/font.c
+++ b/dlls/win32u/font.c
@@ -4796,6 +4796,7 @@ const struct gdi_dc_funcs font_driver =
     NULL,                           /* pD3DKMTCheckVidPnExclusiveOwnership */
     NULL,                           /* pD3DKMTCloseAdapter */
     NULL,                           /* pD3DKMTOpenAdapterFromLuid */
+    NULL,                           /* pD3DKMTQueryAdapterInfo */
     NULL,                           /* pD3DKMTQueryVideoMemoryInfo */
     NULL,                           /* pD3DKMTSetVidPnSourceOwner */
     GDI_PRIORITY_FONT_DRV           /* priority */
diff --git a/dlls/win32u/path.c b/dlls/win32u/path.c
index e0c96f5ef6f..2783cd51832 100644
--- a/dlls/win32u/path.c
+++ b/dlls/win32u/path.c
@@ -2121,6 +2121,7 @@ const struct gdi_dc_funcs path_driver =
     NULL,                               /* pD3DKMTCheckVidPnExclusiveOwnership */
     NULL,                               /* pD3DKMTCloseAdapter */
     NULL,                               /* pD3DKMTOpenAdapterFromLuid */
+    NULL,                               /* pD3DKMTQueryAdapterInfo */
     NULL,                               /* pD3DKMTQueryVideoMemoryInfo */
     NULL,                               /* pD3DKMTSetVidPnSourceOwner */
     GDI_PRIORITY_PATH_DRV               /* priority */
diff --git a/dlls/winex11.drv/init.c b/dlls/winex11.drv/init.c
index 5576fdd50e6..9bce0740fd3 100644
--- a/dlls/winex11.drv/init.c
+++ b/dlls/winex11.drv/init.c
@@ -389,6 +389,7 @@ static const struct user_driver_funcs x11drv_funcs =
     .dc_funcs.pD3DKMTCheckVidPnExclusiveOwnership = X11DRV_D3DKMTCheckVidPnExclusiveOwnership,
     .dc_funcs.pD3DKMTCloseAdapter = X11DRV_D3DKMTCloseAdapter,
     .dc_funcs.pD3DKMTOpenAdapterFromLuid = X11DRV_D3DKMTOpenAdapterFromLuid,
+    .dc_funcs.pD3DKMTQueryAdapterInfo = X11DRV_D3DKMTQueryAdapterInfo,
     .dc_funcs.pD3DKMTQueryVideoMemoryInfo = X11DRV_D3DKMTQueryVideoMemoryInfo,
     .dc_funcs.pD3DKMTSetVidPnSourceOwner = X11DRV_D3DKMTSetVidPnSourceOwner,
     .dc_funcs.priority = GDI_PRIORITY_GRAPHICS_DRV,
diff --git a/dlls/winex11.drv/x11drv.h b/dlls/winex11.drv/x11drv.h
index be4f0cb99ff..97eccd4d9d8 100644
--- a/dlls/winex11.drv/x11drv.h
+++ b/dlls/winex11.drv/x11drv.h
@@ -163,6 +163,7 @@ extern BOOL X11DRV_Chord( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
 extern NTSTATUS X11DRV_D3DKMTCheckVidPnExclusiveOwnership( const D3DKMT_CHECKVIDPNEXCLUSIVEOWNERSHIP *desc );
 extern NTSTATUS X11DRV_D3DKMTCloseAdapter( const D3DKMT_CLOSEADAPTER *desc );
 extern NTSTATUS X11DRV_D3DKMTOpenAdapterFromLuid( D3DKMT_OPENADAPTERFROMLUID *desc );
+extern NTSTATUS X11DRV_D3DKMTQueryAdapterInfo( D3DKMT_QUERYADAPTERINFO *desc );
 extern NTSTATUS X11DRV_D3DKMTQueryVideoMemoryInfo( D3DKMT_QUERYVIDEOMEMORYINFO *desc );
 extern NTSTATUS X11DRV_D3DKMTSetVidPnSourceOwner( const D3DKMT_SETVIDPNSOURCEOWNER *desc );
 extern BOOL X11DRV_Ellipse( PHYSDEV dev, INT left, INT top, INT right, INT bottom );
diff --git a/dlls/winex11.drv/x11drv_main.c b/dlls/winex11.drv/x11drv_main.c
index fcfa3b064fb..1dbf2e78623 100644
--- a/dlls/winex11.drv/x11drv_main.c
+++ b/dlls/winex11.drv/x11drv_main.c
@@ -1485,6 +1485,25 @@ done:
     return status;
 }
 
+NTSTATUS X11DRV_D3DKMTQueryAdapterInfo( D3DKMT_QUERYADAPTERINFO *desc )
+{
+    NTSTATUS status = STATUS_INVALID_PARAMETER;
+    struct x11_d3dkmt_adapter *adapter;
+
+    pthread_mutex_lock(&d3dkmt_mutex);
+    LIST_FOR_EACH_ENTRY(adapter, &x11_d3dkmt_adapters, struct x11_d3dkmt_adapter, entry)
+    {
+        if (adapter->handle != desc->hAdapter)
+            continue;
+
+        FIXME("desc %p, type %d stub\n", desc, desc->Type);
+        status = STATUS_NOT_IMPLEMENTED;
+        break;
+    }
+    pthread_mutex_unlock(&d3dkmt_mutex);
+    return status;
+}
+
 NTSTATUS X11DRV_D3DKMTQueryVideoMemoryInfo( D3DKMT_QUERYVIDEOMEMORYINFO *desc )
 {
     const struct vulkan_funcs *vulkan_funcs = get_vulkan_driver(WINE_VULKAN_DRIVER_VERSION);
diff --git a/dlls/winex11.drv/xrender.c b/dlls/winex11.drv/xrender.c
index 7656c0637df..c69c260138f 100644
--- a/dlls/winex11.drv/xrender.c
+++ b/dlls/winex11.drv/xrender.c
@@ -2434,6 +2434,7 @@ static const struct gdi_dc_funcs xrender_funcs =
     NULL,                               /* pD3DKMTCheckVidPnExclusiveOwnership */
     NULL,                               /* pD3DKMTCloseAdapter */
     NULL,                               /* pD3DKMTOpenAdapterFromLuid */
+    NULL,                               /* pD3DKMTQueryAdapterInfo */
     NULL,                               /* pD3DKMTQueryVideoMemoryInfo */
     NULL,                               /* pD3DKMTSetVidPnSourceOwner */
     GDI_PRIORITY_GRAPHICS_DRV + 10      /* priority */
diff --git a/include/wine/gdi_driver.h b/include/wine/gdi_driver.h
index 26562bfef2b..bd1ae446f73 100644
--- a/include/wine/gdi_driver.h
+++ b/include/wine/gdi_driver.h
@@ -169,6 +169,7 @@ struct gdi_dc_funcs
     NTSTATUS (*pD3DKMTCheckVidPnExclusiveOwnership)(const D3DKMT_CHECKVIDPNEXCLUSIVEOWNERSHIP *);
     NTSTATUS (*pD3DKMTCloseAdapter)(const D3DKMT_CLOSEADAPTER *);
     NTSTATUS (*pD3DKMTOpenAdapterFromLuid)(D3DKMT_OPENADAPTERFROMLUID *);
+    NTSTATUS (*pD3DKMTQueryAdapterInfo)(D3DKMT_QUERYADAPTERINFO *);
     NTSTATUS (*pD3DKMTQueryVideoMemoryInfo)(D3DKMT_QUERYVIDEOMEMORYINFO *);
     NTSTATUS (*pD3DKMTSetVidPnSourceOwner)(const D3DKMT_SETVIDPNSOURCEOWNER *);
 
-- 
2.47.0.rc0

From b239fbc3f17f4e464c634064d15037471ea0985c Mon Sep 17 00:00:00 2001
From: Liam Middlebrook <lmiddlebrook@nvidia.com>
Date: Sat, 12 Oct 2024 15:35:53 -0700
Subject: [PATCH] winex11.drv: Implement D3DKMTQueryAdapterInfo WDDM_2_7_CAPS

Used by applications to query support for "Hardware Scheduling" for GPU
workloads. This is used as a proxy to determine scheduling guarantees
between userspace command submission and GPU execution.

Signed-off-by: Liam Middlebrook <lmiddlebrook@nvidia.com>

Note: This commit is specifically targeted towards ValveSoftware/wine experimental_9.0 branch.
Upstream wine contains commits which change how this would be implemented. Notably, the changes in
`dlls/winex11.drv/x11drv_main.c` should be instead made in `dlls/win32u/d3dkmt.c`.
---
 dlls/winex11.drv/x11drv_main.c | 53 ++++++++++++++++++++++++++++++++++
 include/ddk/d3dkmthk.h         | 14 +++++++++
 2 files changed, 67 insertions(+)

diff --git a/dlls/winex11.drv/x11drv_main.c b/dlls/winex11.drv/x11drv_main.c
index d5461e1124e..4ee4a372367 100644
--- a/dlls/winex11.drv/x11drv_main.c
+++ b/dlls/winex11.drv/x11drv_main.c
@@ -1401,19 +1401,72 @@ NTSTATUS X11DRV_D3DKMTOpenAdapterFromLuid( D3DKMT_OPENADAPTERFROMLUID *desc )
 
 NTSTATUS X11DRV_D3DKMTQueryAdapterInfo( D3DKMT_QUERYADAPTERINFO *desc )
 {
+    const struct vulkan_funcs *vulkan_funcs = get_vulkan_driver(WINE_VULKAN_DRIVER_VERSION);
+    PFN_vkGetPhysicalDeviceProperties2KHR pvkGetPhysicalDeviceProperties2KHR;
+    VkPhysicalDeviceDriverPropertiesKHR driverProperties;
+    VkPhysicalDeviceProperties2KHR properties2;
     NTSTATUS status = STATUS_INVALID_PARAMETER;
     struct x11_d3dkmt_adapter *adapter;
 
+    if (!vulkan_funcs)
+    {
+        WARN("Vulkan is unavailable.\n");
+        return STATUS_UNSUCCESSFUL;
+    }
+
     pthread_mutex_lock(&d3dkmt_mutex);
     LIST_FOR_EACH_ENTRY(adapter, &x11_d3dkmt_adapters, struct x11_d3dkmt_adapter, entry)
     {
         if (adapter->handle != desc->hAdapter)
             continue;
 
+        if (!(pvkGetPhysicalDeviceProperties2KHR = (void *)vulkan_funcs->p_vkGetInstanceProcAddr(d3dkmt_vk_instance, "vkGetPhysicalDeviceProperties2KHR")))
+        {
+            WARN("Failed to load vkGetPhysicalDeviceProperties2KHR.\n");
+            status = STATUS_UNSUCCESSFUL;
+            goto done;
+        }
+
+        memset(&driverProperties, 0, sizeof(driverProperties));
+        memset(&properties2, 0, sizeof(properties2));
+        driverProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR;
+        properties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR;
+        properties2.pNext = &driverProperties;
+        pvkGetPhysicalDeviceProperties2KHR(adapter->vk_device, &properties2);
+
+        if (desc->Type == KMTQAITYPE_WDDM_2_7_CAPS)
+        {
+            /*
+             * Advertise Hardware-Scheduling as enabled for NVIDIA Adapters. NVIDIA driver does
+             * userspace submission. Allow overriding this value via the
+             * WINE_DISABLE_HARDWARE_SCHEDULING environment variable.
+             */
+            D3DKMT_WDDM_2_7_CAPS *data = desc->pPrivateDriverData;
+            const char *e = getenv("WINE_DISABLE_HARDWARE_SCHEDULING");
+            if ((!e || *e == '\0' || *e == '0') &&
+                    (driverProperties.driverID == VK_DRIVER_ID_NVIDIA_PROPRIETARY))
+            {
+                data->HwSchEnabled = 1;
+                data->HwSchSupported = 1;
+                data->HwSchEnabledByDefault = 1;
+                status = STATUS_SUCCESS;
+                goto done;
+            }
+            else
+            {
+                data->HwSchEnabled = 0;
+                data->HwSchSupported = 0;
+                data->HwSchEnabledByDefault = 0;
+                status = STATUS_SUCCESS;
+                goto done;
+            }
+        }
+
         FIXME("desc %p, type %d stub\n", desc, desc->Type);
         status = STATUS_NOT_IMPLEMENTED;
         break;
     }
+done:
     pthread_mutex_unlock(&d3dkmt_mutex);
     return status;
 }
diff --git a/include/ddk/d3dkmthk.h b/include/ddk/d3dkmthk.h
index 2d30bdd8777..d4d4f88a605 100644
--- a/include/ddk/d3dkmthk.h
+++ b/include/ddk/d3dkmthk.h
@@ -266,6 +266,20 @@ typedef struct _D3DKMT_QUERYADAPTERINFO
     UINT                    PrivateDriverDataSize;
 } D3DKMT_QUERYADAPTERINFO;
 
+typedef struct _D3DKMT_WDDM_2_7_CAPS
+{
+    union {
+        struct {
+            UINT HwSchSupported : 1;
+            UINT HwSchEnabled : 1;
+            UINT HwSchEnabledByDefault : 1;
+            UINT IndependentVidPnVSyncControl : 1;
+            UINT Reserved : 28;
+        };
+        UINT Value;
+    };
+} D3DKMT_WDDM_2_7_CAPS;
+
 typedef enum _D3DKMT_QUERYRESULT_PREEMPTION_ATTEMPT_RESULT
 {
     D3DKMT_PreemptionAttempt                               = 0,