forked from KhronosGroup/Vulkan-LoaderAndValidationLayers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
swapchain.cpp
2568 lines (2304 loc) · 135 KB
/
swapchain.cpp
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
/* Copyright (c) 2015-2016 The Khronos Group Inc.
* Copyright (c) 2015-2016 Valve Corporation
* Copyright (c) 2015-2016 LunarG, Inc.
* Copyright (C) 2015-2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Author: Ian Elliott <[email protected]>
* Author: Ian Elliott <[email protected]>
*/
#include <mutex>
#include <stdio.h>
#include <string.h>
#include <vk_loader_platform.h>
#include <vulkan/vk_icd.h>
#include "swapchain.h"
#include "vk_layer_extension_utils.h"
#include "vk_enum_string_helper.h"
#include "vk_layer_utils.h"
namespace swapchain {
static std::mutex global_lock;
// The following is for logging error messages:
static std::unordered_map<void *, layer_data *> layer_data_map;
static const VkExtensionProperties instance_extensions[] = {{VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_SPEC_VERSION}};
static const VkLayerProperties swapchain_layer = {
"VK_LAYER_LUNARG_swapchain", VK_LAYER_API_VERSION, 1, "LunarG Validation Layer",
};
static void checkDeviceRegisterExtensions(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, VkDevice device) {
uint32_t i;
layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
SwpPhysicalDevice *pPhysicalDevice = NULL;
{
auto it = my_instance_data->physicalDeviceMap.find(physicalDevice);
pPhysicalDevice = (it == my_instance_data->physicalDeviceMap.end()) ? NULL : &it->second;
}
if (pPhysicalDevice) {
my_device_data->deviceMap[device].pPhysicalDevice = pPhysicalDevice;
pPhysicalDevice->pDevice = &my_device_data->deviceMap[device];
} else {
// TBD: Should we leave error in (since Swapchain really needs this
// link)?
log_msg(my_instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
reinterpret_cast<uint64_t>(physicalDevice), __LINE__, SWAPCHAIN_INVALID_HANDLE, "Swapchain",
"vkCreateDevice() called with a non-valid VkPhysicalDevice.");
}
my_device_data->deviceMap[device].device = device;
my_device_data->deviceMap[device].swapchainExtensionEnabled = false;
// Record whether the WSI device extension was enabled for this VkDevice.
// No need to check if the extension was advertised by
// vkEnumerateDeviceExtensionProperties(), since the loader handles that.
for (i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
my_device_data->deviceMap[device].swapchainExtensionEnabled = true;
}
}
}
static void checkInstanceRegisterExtensions(const VkInstanceCreateInfo *pCreateInfo, VkInstance instance) {
uint32_t i;
layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
// Remember this instance, and whether the VK_KHR_surface extension
// was enabled for it:
my_data->instanceMap[instance].instance = instance;
my_data->instanceMap[instance].surfaceExtensionEnabled = false;
my_data->instanceMap[instance].displayExtensionEnabled = false;
#ifdef VK_USE_PLATFORM_ANDROID_KHR
my_data->instanceMap[instance].androidSurfaceExtensionEnabled = false;
#endif // VK_USE_PLATFORM_ANDROID_KHR
#ifdef VK_USE_PLATFORM_MIR_KHR
my_data->instanceMap[instance].mirSurfaceExtensionEnabled = false;
#endif // VK_USE_PLATFORM_MIR_KHR
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
my_data->instanceMap[instance].waylandSurfaceExtensionEnabled = false;
#endif // VK_USE_PLATFORM_WAYLAND_KHR
#ifdef VK_USE_PLATFORM_WIN32_KHR
my_data->instanceMap[instance].win32SurfaceExtensionEnabled = false;
#endif // VK_USE_PLATFORM_WIN32_KHR
#ifdef VK_USE_PLATFORM_XCB_KHR
my_data->instanceMap[instance].xcbSurfaceExtensionEnabled = false;
#endif // VK_USE_PLATFORM_XCB_KHR
#ifdef VK_USE_PLATFORM_XLIB_KHR
my_data->instanceMap[instance].xlibSurfaceExtensionEnabled = false;
#endif // VK_USE_PLATFORM_XLIB_KHR
// Look for one or more debug report create info structures, and copy the
// callback(s) for each one found (for use by vkDestroyInstance)
layer_copy_tmp_callbacks(pCreateInfo->pNext, &my_data->num_tmp_callbacks, &my_data->tmp_dbg_create_infos,
&my_data->tmp_callbacks);
// Record whether the WSI instance extension was enabled for this
// VkInstance. No need to check if the extension was advertised by
// vkEnumerateInstanceExtensionProperties(), since the loader handles that.
for (i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SURFACE_EXTENSION_NAME) == 0) {
my_data->instanceMap[instance].surfaceExtensionEnabled = true;
}
if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_DISPLAY_EXTENSION_NAME) == 0) {
my_data->instanceMap[instance].displayExtensionEnabled = true;
}
#ifdef VK_USE_PLATFORM_ANDROID_KHR
if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_ANDROID_SURFACE_EXTENSION_NAME) == 0) {
my_data->instanceMap[instance].androidSurfaceExtensionEnabled = true;
}
#endif // VK_USE_PLATFORM_ANDROID_KHR
#ifdef VK_USE_PLATFORM_MIR_KHR
if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_MIR_SURFACE_EXTENSION_NAME) == 0) {
my_data->instanceMap[instance].mirSurfaceExtensionEnabled = true;
}
#endif // VK_USE_PLATFORM_MIR_KHR
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) == 0) {
my_data->instanceMap[instance].waylandSurfaceExtensionEnabled = true;
}
#endif // VK_USE_PLATFORM_WAYLAND_KHR
#ifdef VK_USE_PLATFORM_WIN32_KHR
if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WIN32_SURFACE_EXTENSION_NAME) == 0) {
my_data->instanceMap[instance].win32SurfaceExtensionEnabled = true;
}
#endif // VK_USE_PLATFORM_WIN32_KHR
#ifdef VK_USE_PLATFORM_XCB_KHR
if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XCB_SURFACE_EXTENSION_NAME) == 0) {
my_data->instanceMap[instance].xcbSurfaceExtensionEnabled = true;
}
#endif // VK_USE_PLATFORM_XCB_KHR
#ifdef VK_USE_PLATFORM_XLIB_KHR
if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XLIB_SURFACE_EXTENSION_NAME) == 0) {
my_data->instanceMap[instance].xlibSurfaceExtensionEnabled = true;
}
#endif // VK_USE_PLATFORM_XLIB_KHR
}
}
#include "vk_dispatch_table_helper.h"
static void init_swapchain(layer_data *my_data, const VkAllocationCallbacks *pAllocator) {
layer_debug_actions(my_data->report_data, my_data->logging_callback, pAllocator, "lunarg_swapchain");
}
static const char *surfaceTransformStr(VkSurfaceTransformFlagBitsKHR value) {
// Return a string corresponding to the value:
return string_VkSurfaceTransformFlagBitsKHR(value);
}
static const char *surfaceCompositeAlphaStr(VkCompositeAlphaFlagBitsKHR value) {
// Return a string corresponding to the value:
return string_VkCompositeAlphaFlagBitsKHR(value);
}
static const char *presentModeStr(VkPresentModeKHR value) {
// Return a string corresponding to the value:
return string_VkPresentModeKHR(value);
}
static const char *sharingModeStr(VkSharingMode value) {
// Return a string corresponding to the value:
return string_VkSharingMode(value);
}
static bool ValidateQueueFamilyIndex(layer_data *my_data, uint32_t queue_family_index, uint32_t queue_family_count,
VkPhysicalDevice physical_device, const char *function) {
bool skip_call = false;
if (queue_family_index >= queue_family_count) {
skip_call = log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
reinterpret_cast<uint64_t>(physical_device), __LINE__, SWAPCHAIN_QUEUE_FAMILY_INDEX_TOO_LARGE,
swapchain_layer_name,
"%s() called with a queueFamilyIndex that is too large (i.e. %d). The maximum value (returned by "
"vkGetPhysicalDeviceQueueFamilyProperties) is only %d.",
function, queue_family_index, queue_family_count);
}
return skip_call;
}
VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
VkInstance *pInstance) {
VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
assert(chain_info->u.pLayerInfo);
PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance");
if (fpCreateInstance == NULL) {
return VK_ERROR_INITIALIZATION_FAILED;
}
// Advance the link info for the next element on the chain
chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
if (result != VK_SUCCESS) {
return result;
}
layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
my_data->instance = *pInstance;
my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
layer_init_instance_dispatch_table(*pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr);
my_data->report_data = debug_report_create_instance(my_data->instance_dispatch_table, *pInstance,
pCreateInfo->enabledExtensionCount, pCreateInfo->ppEnabledExtensionNames);
// Call the following function after my_data is initialized:
checkInstanceRegisterExtensions(pCreateInfo, *pInstance);
init_swapchain(my_data, pAllocator);
return result;
}
VKAPI_ATTR void VKAPI_CALL DestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) {
dispatch_key key = get_dispatch_key(instance);
layer_data *my_data = get_my_data_ptr(key, layer_data_map);
SwpInstance *pInstance = NULL;
{
auto it = my_data->instanceMap.find(instance);
pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second;
}
// Call down the call chain:
my_data->instance_dispatch_table->DestroyInstance(instance, pAllocator);
std::lock_guard<std::mutex> lock(global_lock);
// Enable the temporary callback(s) here to catch cleanup issues:
bool callback_setup = false;
if (my_data->num_tmp_callbacks > 0) {
if (!layer_enable_tmp_callbacks(my_data->report_data, my_data->num_tmp_callbacks, my_data->tmp_dbg_create_infos,
my_data->tmp_callbacks)) {
callback_setup = true;
}
}
// Do additional internal cleanup:
if (pInstance) {
// Delete all of the SwpPhysicalDevice's, SwpSurface's, and the
// SwpInstance associated with this instance:
for (auto it = pInstance->physicalDevices.begin(); it != pInstance->physicalDevices.end(); it++) {
// Free memory that was allocated for/by this SwpPhysicalDevice:
SwpPhysicalDevice *pPhysicalDevice = it->second;
if (pPhysicalDevice) {
if (pPhysicalDevice->pDevice) {
log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
reinterpret_cast<uint64_t>(pPhysicalDevice->pDevice->device), __LINE__,
SWAPCHAIN_DEL_OBJECT_BEFORE_CHILDREN, swapchain_layer_name,
"VkDestroyInstance() called before all of its associated VkDevices were destroyed.");
}
free(pPhysicalDevice->pSurfaceFormats);
free(pPhysicalDevice->pPresentModes);
}
// Erase the SwpPhysicalDevice's from the my_data->physicalDeviceMap (which
// are simply pointed to by the SwpInstance):
my_data->physicalDeviceMap.erase(it->second->physicalDevice);
}
for (auto it = pInstance->surfaces.begin(); it != pInstance->surfaces.end(); it++) {
// Free memory that was allocated for/by this SwpPhysicalDevice:
SwpSurface *pSurface = it->second;
if (pSurface) {
log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
reinterpret_cast<uint64_t>(pInstance->instance), __LINE__, SWAPCHAIN_DEL_OBJECT_BEFORE_CHILDREN,
swapchain_layer_name,
"VkDestroyInstance() called before all of its associated VkSurfaceKHRs were destroyed.");
}
}
my_data->instanceMap.erase(instance);
}
// Disable and cleanup the temporary callback(s):
if (callback_setup) {
layer_disable_tmp_callbacks(my_data->report_data, my_data->num_tmp_callbacks, my_data->tmp_callbacks);
}
if (my_data->num_tmp_callbacks > 0) {
layer_free_tmp_callbacks(my_data->tmp_dbg_create_infos, my_data->tmp_callbacks);
my_data->num_tmp_callbacks = 0;
}
// Clean up logging callback, if any
while (my_data->logging_callback.size() > 0) {
VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
my_data->logging_callback.pop_back();
}
layer_debug_report_destroy_instance(my_data->report_data);
delete my_data->instance_dispatch_table;
layer_data_map.erase(key);
}
VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
uint32_t *pQueueFamilyPropertyCount,
VkQueueFamilyProperties *pQueueFamilyProperties) {
layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
// Call down the call chain:
my_data->instance_dispatch_table->GetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount,
pQueueFamilyProperties);
// Record the result of this query:
std::lock_guard<std::mutex> lock(global_lock);
SwpPhysicalDevice *pPhysicalDevice = NULL;
{
auto it = my_data->physicalDeviceMap.find(physicalDevice);
pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second;
}
// Note: for poorly-written applications (e.g. that don't call this command
// twice, the first time with pQueueFamilyProperties set to NULL, and the
// second time with a non-NULL pQueueFamilyProperties and with the same
// count as returned the first time), record the count when
// pQueueFamilyProperties is non-NULL:
if (pPhysicalDevice && pQueueFamilyPropertyCount && pQueueFamilyProperties) {
pPhysicalDevice->gotQueueFamilyPropertyCount = true;
pPhysicalDevice->numOfQueueFamilies = *pQueueFamilyPropertyCount;
}
}
#ifdef VK_USE_PLATFORM_ANDROID_KHR
VKAPI_ATTR VkResult VKAPI_CALL CreateAndroidSurfaceKHR(VkInstance instance, const VkAndroidSurfaceCreateInfoKHR *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
VkResult result = VK_SUCCESS;
bool skip_call = false;
layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
std::unique_lock<std::mutex> lock(global_lock);
SwpInstance *pInstance = NULL;
{
auto it = my_data->instanceMap.find(instance);
pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second;
}
// Validate that the platform extension was enabled:
if (pInstance && !pInstance->androidSurfaceExtensionEnabled) {
skip_call |=
log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
reinterpret_cast<uint64_t>(instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, swapchain_layer_name,
"vkCreateAndroidSurfaceKHR() called even though the %s extension was not enabled for this VkInstance.",
VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
}
lock.unlock();
if (!skip_call) {
// Call down the call chain:
result = my_data->instance_dispatch_table->CreateAndroidSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
lock.lock();
// Obtain this pointer again after locking:
{
auto it = my_data->instanceMap.find(instance);
pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second;
}
if ((result == VK_SUCCESS) && pInstance && pSurface) {
// Record the VkSurfaceKHR returned by the ICD:
my_data->surfaceMap[*pSurface].surface = *pSurface;
my_data->surfaceMap[*pSurface].pInstance = pInstance;
my_data->surfaceMap[*pSurface].usedAllocatorToCreate = (pAllocator != NULL);
my_data->surfaceMap[*pSurface].numQueueFamilyIndexSupport = 0;
my_data->surfaceMap[*pSurface].pQueueFamilyIndexSupport = NULL;
// Point to the associated SwpInstance:
pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface];
}
lock.unlock();
return result;
}
return VK_ERROR_VALIDATION_FAILED_EXT;
}
#endif // VK_USE_PLATFORM_ANDROID_KHR
#ifdef VK_USE_PLATFORM_MIR_KHR
VKAPI_ATTR VkResult VKAPI_CALL CreateMirSurfaceKHR(VkInstance instance, const VkMirSurfaceCreateInfoKHR *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
VkResult result = VK_SUCCESS;
bool skip_call = false;
layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
std::unique_lock<std::mutex> lock(global_lock);
SwpInstance *pInstance = NULL;
{
auto it = my_data->instanceMap.find(instance);
pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second;
}
// Validate that the platform extension was enabled:
if (pInstance && !pInstance->mirSurfaceExtensionEnabled) {
skip_call |=
log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
reinterpret_cast<uint64_t>(instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, swapchain_layer_name,
"vkCreateMirSurfaceKHR() called even though the %s extension was not enabled for this VkInstance.",
VK_KHR_MIR_SURFACE_EXTENSION_NAME);
}
lock.unlock();
if (!skip_call) {
// Call down the call chain:
result = my_data->instance_dispatch_table->CreateMirSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
lock.lock();
// Obtain this pointer again after locking:
{
auto it = my_data->instanceMap.find(instance);
pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second;
}
if ((result == VK_SUCCESS) && pInstance && pSurface) {
// Record the VkSurfaceKHR returned by the ICD:
my_data->surfaceMap[*pSurface].surface = *pSurface;
my_data->surfaceMap[*pSurface].pInstance = pInstance;
my_data->surfaceMap[*pSurface].usedAllocatorToCreate = (pAllocator != NULL);
my_data->surfaceMap[*pSurface].numQueueFamilyIndexSupport = 0;
my_data->surfaceMap[*pSurface].pQueueFamilyIndexSupport = NULL;
// Point to the associated SwpInstance:
pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface];
}
lock.unlock();
return result;
}
return VK_ERROR_VALIDATION_FAILED_EXT;
}
VKAPI_ATTR VkBool32 VKAPI_CALL GetPhysicalDeviceMirPresentationSupportKHR(VkPhysicalDevice physicalDevice,
uint32_t queueFamilyIndex, MirConnection *connection) {
VkBool32 result = VK_FALSE;
bool skip_call = false;
layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
std::unique_lock<std::mutex> lock(global_lock);
SwpPhysicalDevice *pPhysicalDevice = NULL;
{
auto it = my_data->physicalDeviceMap.find(physicalDevice);
pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second;
}
// Validate that the platform extension was enabled:
if (pPhysicalDevice && pPhysicalDevice->pInstance && !pPhysicalDevice->pInstance->mirSurfaceExtensionEnabled) {
skip_call |=
log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
swapchain_layer_name, "vkGetPhysicalDeviceMirPresentationSupportKHR() called even though the %s "
"extension was not enabled for this VkInstance.",
VK_KHR_MIR_SURFACE_EXTENSION_NAME);
}
if (pPhysicalDevice->gotQueueFamilyPropertyCount) {
skip_call |= ValidateQueueFamilyIndex(my_data, queueFamilyIndex, pPhysicalDevice->numOfQueueFamilies,
pPhysicalDevice->physicalDevice, "vkGetPhysicalDeviceMirPresentationSupportKHR");
}
lock.unlock();
if (!skip_call) {
// Call down the call chain:
result = my_data->instance_dispatch_table->GetPhysicalDeviceMirPresentationSupportKHR(physicalDevice, queueFamilyIndex,
connection);
}
return result;
}
#endif // VK_USE_PLATFORM_MIR_KHR
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
VKAPI_ATTR VkResult VKAPI_CALL CreateWaylandSurfaceKHR(VkInstance instance, const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
VkResult result = VK_SUCCESS;
bool skip_call = false;
layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
std::unique_lock<std::mutex> lock(global_lock);
SwpInstance *pInstance = NULL;
{
auto it = my_data->instanceMap.find(instance);
pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second;
}
// Validate that the platform extension was enabled:
if (pInstance && !pInstance->waylandSurfaceExtensionEnabled) {
skip_call |=
log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
reinterpret_cast<uint64_t>(instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, swapchain_layer_name,
"vkCreateWaylandSurfaceKHR() called even though the %s extension was not enabled for this VkInstance.",
VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
}
lock.unlock();
if (!skip_call) {
// Call down the call chain:
result = my_data->instance_dispatch_table->CreateWaylandSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
lock.lock();
// Obtain this pointer again after locking:
{
auto it = my_data->instanceMap.find(instance);
pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second;
}
if ((result == VK_SUCCESS) && pInstance && pSurface) {
// Record the VkSurfaceKHR returned by the ICD:
my_data->surfaceMap[*pSurface].surface = *pSurface;
my_data->surfaceMap[*pSurface].pInstance = pInstance;
my_data->surfaceMap[*pSurface].usedAllocatorToCreate = (pAllocator != NULL);
my_data->surfaceMap[*pSurface].numQueueFamilyIndexSupport = 0;
my_data->surfaceMap[*pSurface].pQueueFamilyIndexSupport = NULL;
// Point to the associated SwpInstance:
pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface];
}
lock.unlock();
return result;
}
return VK_ERROR_VALIDATION_FAILED_EXT;
}
VKAPI_ATTR VkBool32 VKAPI_CALL GetPhysicalDeviceWaylandPresentationSupportKHR(VkPhysicalDevice physicalDevice,
uint32_t queueFamilyIndex,
struct wl_display *display) {
VkBool32 result = VK_FALSE;
bool skip_call = false;
layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
std::unique_lock<std::mutex> lock(global_lock);
SwpPhysicalDevice *pPhysicalDevice = NULL;
{
auto it = my_data->physicalDeviceMap.find(physicalDevice);
pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second;
}
// Validate that the platform extension was enabled:
if (pPhysicalDevice && pPhysicalDevice->pInstance && !pPhysicalDevice->pInstance->waylandSurfaceExtensionEnabled) {
skip_call |=
log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
swapchain_layer_name, "vkGetPhysicalDeviceWaylandPresentationSupportKHR() called even though the %s "
"extension was not enabled for this VkInstance.",
VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
}
if (pPhysicalDevice->gotQueueFamilyPropertyCount) {
skip_call |= ValidateQueueFamilyIndex(my_data, queueFamilyIndex, pPhysicalDevice->numOfQueueFamilies,
pPhysicalDevice->physicalDevice, "vkGetPhysicalDeviceWaylandPresentationSupportKHR");
}
lock.unlock();
if (!skip_call) {
// Call down the call chain:
result = my_data->instance_dispatch_table->GetPhysicalDeviceWaylandPresentationSupportKHR(physicalDevice, queueFamilyIndex,
display);
}
return result;
}
#endif // VK_USE_PLATFORM_WAYLAND_KHR
#ifdef VK_USE_PLATFORM_WIN32_KHR
VKAPI_ATTR VkResult VKAPI_CALL CreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
VkResult result = VK_SUCCESS;
bool skip_call = false;
layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
std::unique_lock<std::mutex> lock(global_lock);
SwpInstance *pInstance = NULL;
{
auto it = my_data->instanceMap.find(instance);
pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second;
}
// Validate that the platform extension was enabled:
if (pInstance && !pInstance->win32SurfaceExtensionEnabled) {
skip_call |=
log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
reinterpret_cast<uint64_t>(instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, swapchain_layer_name,
"vkCreateWin32SurfaceKHR() called even though the %s extension was not enabled for this VkInstance.",
VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
}
lock.unlock();
if (!skip_call) {
// Call down the call chain:
result = my_data->instance_dispatch_table->CreateWin32SurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
lock.lock();
// Obtain this pointer again after locking:
{
auto it = my_data->instanceMap.find(instance);
pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second;
}
if ((result == VK_SUCCESS) && pInstance && pSurface) {
// Record the VkSurfaceKHR returned by the ICD:
my_data->surfaceMap[*pSurface].surface = *pSurface;
my_data->surfaceMap[*pSurface].pInstance = pInstance;
my_data->surfaceMap[*pSurface].usedAllocatorToCreate = (pAllocator != NULL);
my_data->surfaceMap[*pSurface].numQueueFamilyIndexSupport = 0;
my_data->surfaceMap[*pSurface].pQueueFamilyIndexSupport = NULL;
// Point to the associated SwpInstance:
pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface];
}
lock.unlock();
return result;
}
return VK_ERROR_VALIDATION_FAILED_EXT;
}
VKAPI_ATTR VkBool32 VKAPI_CALL GetPhysicalDeviceWin32PresentationSupportKHR(VkPhysicalDevice physicalDevice,
uint32_t queueFamilyIndex) {
VkBool32 result = VK_FALSE;
bool skip_call = false;
layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
std::unique_lock<std::mutex> lock(global_lock);
SwpPhysicalDevice *pPhysicalDevice = NULL;
{
auto it = my_data->physicalDeviceMap.find(physicalDevice);
pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second;
}
// Validate that the platform extension was enabled:
if (pPhysicalDevice && pPhysicalDevice->pInstance && !pPhysicalDevice->pInstance->win32SurfaceExtensionEnabled) {
skip_call |=
log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
swapchain_layer_name, "vkGetPhysicalDeviceWin32PresentationSupportKHR() called even though the %s extension "
"was not enabled for this VkInstance.",
VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
}
if (pPhysicalDevice->gotQueueFamilyPropertyCount) {
skip_call |= ValidateQueueFamilyIndex(my_data, queueFamilyIndex, pPhysicalDevice->numOfQueueFamilies,
pPhysicalDevice->physicalDevice, "vkGetPhysicalDeviceWin32PresentationSupportKHR");
}
lock.unlock();
if (!skip_call) {
// Call down the call chain:
result = my_data->instance_dispatch_table->GetPhysicalDeviceWin32PresentationSupportKHR(physicalDevice, queueFamilyIndex);
}
return result;
}
#endif // VK_USE_PLATFORM_WIN32_KHR
#ifdef VK_USE_PLATFORM_XCB_KHR
VKAPI_ATTR VkResult VKAPI_CALL CreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
VkResult result = VK_SUCCESS;
bool skip_call = false;
layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
std::unique_lock<std::mutex> lock(global_lock);
SwpInstance *pInstance = NULL;
{
auto it = my_data->instanceMap.find(instance);
pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second;
}
// Validate that the platform extension was enabled:
if (pInstance && !pInstance->xcbSurfaceExtensionEnabled) {
skip_call |=
log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
reinterpret_cast<uint64_t>(instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, swapchain_layer_name,
"vkCreateXcbSurfaceKHR() called even though the %s extension was not enabled for this VkInstance.",
VK_KHR_XCB_SURFACE_EXTENSION_NAME);
}
lock.unlock();
if (!skip_call) {
// Call down the call chain:
result = my_data->instance_dispatch_table->CreateXcbSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
lock.lock();
// Obtain this pointer again after locking:
{
auto it = my_data->instanceMap.find(instance);
pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second;
}
if ((result == VK_SUCCESS) && pInstance && pSurface) {
// Record the VkSurfaceKHR returned by the ICD:
my_data->surfaceMap[*pSurface].surface = *pSurface;
my_data->surfaceMap[*pSurface].pInstance = pInstance;
my_data->surfaceMap[*pSurface].usedAllocatorToCreate = (pAllocator != NULL);
my_data->surfaceMap[*pSurface].numQueueFamilyIndexSupport = 0;
my_data->surfaceMap[*pSurface].pQueueFamilyIndexSupport = NULL;
// Point to the associated SwpInstance:
pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface];
}
lock.unlock();
return result;
}
return VK_ERROR_VALIDATION_FAILED_EXT;
}
VKAPI_ATTR VkBool32 VKAPI_CALL GetPhysicalDeviceXcbPresentationSupportKHR(VkPhysicalDevice physicalDevice,
uint32_t queueFamilyIndex, xcb_connection_t *connection,
xcb_visualid_t visual_id) {
VkBool32 result = VK_FALSE;
bool skip_call = false;
layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
std::unique_lock<std::mutex> lock(global_lock);
SwpPhysicalDevice *pPhysicalDevice = NULL;
{
auto it = my_data->physicalDeviceMap.find(physicalDevice);
pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second;
}
// Validate that the platform extension was enabled:
if (pPhysicalDevice && pPhysicalDevice->pInstance && !pPhysicalDevice->pInstance->xcbSurfaceExtensionEnabled) {
skip_call |=
log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
swapchain_layer_name, "vkGetPhysicalDeviceXcbPresentationSupportKHR() called even though the %s "
"extension was not enabled for this VkInstance.",
VK_KHR_XCB_SURFACE_EXTENSION_NAME);
}
if (pPhysicalDevice->gotQueueFamilyPropertyCount) {
skip_call |= ValidateQueueFamilyIndex(my_data, queueFamilyIndex, pPhysicalDevice->numOfQueueFamilies,
pPhysicalDevice->physicalDevice, "vkGetPhysicalDeviceXcbPresentationSupportKHR");
}
lock.unlock();
if (!skip_call) {
// Call down the call chain:
result = my_data->instance_dispatch_table->GetPhysicalDeviceXcbPresentationSupportKHR(physicalDevice, queueFamilyIndex,
connection, visual_id);
}
return result;
}
#endif // VK_USE_PLATFORM_XCB_KHR
#ifdef VK_USE_PLATFORM_XLIB_KHR
VKAPI_ATTR VkResult VKAPI_CALL CreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
VkResult result = VK_SUCCESS;
bool skip_call = false;
layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
std::unique_lock<std::mutex> lock(global_lock);
SwpInstance *pInstance = NULL;
{
auto it = my_data->instanceMap.find(instance);
pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second;
}
// Validate that the platform extension was enabled:
if (pInstance && !pInstance->xlibSurfaceExtensionEnabled) {
skip_call |=
log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
reinterpret_cast<uint64_t>(instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, swapchain_layer_name,
"vkCreateXlibSurfaceKHR() called even though the %s extension was not enabled for this VkInstance.",
VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
}
lock.unlock();
if (!skip_call) {
// Call down the call chain:
result = my_data->instance_dispatch_table->CreateXlibSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
lock.lock();
// Obtain this pointer again after locking:
{
auto it = my_data->instanceMap.find(instance);
pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second;
}
if ((result == VK_SUCCESS) && pInstance && pSurface) {
// Record the VkSurfaceKHR returned by the ICD:
my_data->surfaceMap[*pSurface].surface = *pSurface;
my_data->surfaceMap[*pSurface].pInstance = pInstance;
my_data->surfaceMap[*pSurface].usedAllocatorToCreate = (pAllocator != NULL);
my_data->surfaceMap[*pSurface].numQueueFamilyIndexSupport = 0;
my_data->surfaceMap[*pSurface].pQueueFamilyIndexSupport = NULL;
// Point to the associated SwpInstance:
pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface];
}
lock.unlock();
return result;
}
return VK_ERROR_VALIDATION_FAILED_EXT;
}
VKAPI_ATTR VkBool32 VKAPI_CALL GetPhysicalDeviceXlibPresentationSupportKHR(VkPhysicalDevice physicalDevice,
uint32_t queueFamilyIndex, Display *dpy,
VisualID visualID) {
VkBool32 result = VK_FALSE;
bool skip_call = false;
layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
std::unique_lock<std::mutex> lock(global_lock);
SwpPhysicalDevice *pPhysicalDevice = NULL;
{
auto it = my_data->physicalDeviceMap.find(physicalDevice);
pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second;
}
// Validate that the platform extension was enabled:
if (pPhysicalDevice && pPhysicalDevice->pInstance && !pPhysicalDevice->pInstance->xlibSurfaceExtensionEnabled) {
skip_call |=
log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
swapchain_layer_name, "vkGetPhysicalDeviceXlibPresentationSupportKHR() called even though the %s "
"extension was not enabled for this VkInstance.",
VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
}
if (pPhysicalDevice->gotQueueFamilyPropertyCount) {
skip_call |= ValidateQueueFamilyIndex(my_data, queueFamilyIndex, pPhysicalDevice->numOfQueueFamilies,
pPhysicalDevice->physicalDevice, "vkGetPhysicalDeviceXlibPresentationSupportKHR");
}
lock.unlock();
if (!skip_call) {
// Call down the call chain:
result = my_data->instance_dispatch_table->GetPhysicalDeviceXlibPresentationSupportKHR(physicalDevice, queueFamilyIndex,
dpy, visualID);
}
return result;
}
#endif // VK_USE_PLATFORM_XLIB_KHR
VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount,
VkDisplayPropertiesKHR *pProperties) {
VkResult result = VK_SUCCESS;
bool skip_call = false;
layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
std::unique_lock<std::mutex> lock(global_lock);
SwpPhysicalDevice *pPhysicalDevice = NULL;
{
auto it = my_data->physicalDeviceMap.find(physicalDevice);
pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second;
}
if (pPhysicalDevice && pPhysicalDevice->pInstance && !pPhysicalDevice->pInstance->displayExtensionEnabled) {
skip_call |=
log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
swapchain_layer_name, "vkGetPhysicalDeviceDisplayPropertiesKHR() called even though the %s "
"extension was not enabled for this VkInstance.",
VK_KHR_DISPLAY_EXTENSION_NAME);
}
lock.unlock();
if (!skip_call) {
result =
my_data->instance_dispatch_table->GetPhysicalDeviceDisplayPropertiesKHR(physicalDevice, pPropertyCount, pProperties);
return result;
}
return VK_ERROR_VALIDATION_FAILED_EXT;
}
VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount,
VkDisplayPlanePropertiesKHR *pProperties) {
VkResult result = VK_SUCCESS;
bool skip_call = false;
layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
std::unique_lock<std::mutex> lock(global_lock);
SwpPhysicalDevice *pPhysicalDevice = NULL;
{
auto it = my_data->physicalDeviceMap.find(physicalDevice);
pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second;
}
if (pPhysicalDevice && pPhysicalDevice->pInstance && !pPhysicalDevice->pInstance->displayExtensionEnabled) {
skip_call |=
log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
swapchain_layer_name, "vkGetPhysicalDeviceDisplayPlanePropertiesKHR() called even though the %s "
"extension was not enabled for this VkInstance.",
VK_KHR_DISPLAY_EXTENSION_NAME);
}
lock.unlock();
if (!skip_call) {
result = my_data->instance_dispatch_table->GetPhysicalDeviceDisplayPlanePropertiesKHR(physicalDevice, pPropertyCount,
pProperties);
lock.lock();
if (!pPhysicalDevice->gotDisplayPlanePropertyCount) {
pPhysicalDevice->displayPlanePropertyCount = *pPropertyCount;
pPhysicalDevice->gotDisplayPlanePropertyCount = true;
}
// TODO store the properties for later checks
lock.unlock();
return result;
}
return VK_ERROR_VALIDATION_FAILED_EXT;
}
VKAPI_ATTR VkResult VKAPI_CALL GetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice, uint32_t planeIndex,
uint32_t *pDisplayCount, VkDisplayKHR *pDisplays) {
VkResult result = VK_SUCCESS;
bool skip_call = false;
layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
std::unique_lock<std::mutex> lock(global_lock);
SwpPhysicalDevice *pPhysicalDevice = NULL;
{
auto it = my_data->physicalDeviceMap.find(physicalDevice);
pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second;
}
if (pPhysicalDevice && pPhysicalDevice->pInstance && !pPhysicalDevice->pInstance->displayExtensionEnabled) {
skip_call |=
log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
swapchain_layer_name, "vkGetDisplayPlaneSupportedDisplaysKHR() called even though the %s "
"extension was not enabled for this VkInstance.",
VK_KHR_DISPLAY_EXTENSION_NAME);
}
if (!pPhysicalDevice->gotDisplayPlanePropertyCount) {
skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__,
SWAPCHAIN_GET_SUPPORTED_DISPLAYS_WITHOUT_QUERY, swapchain_layer_name,
"Potential problem with calling vkGetDisplayPlaneSupportedDisplaysKHR() without first "
"querying vkGetPhysicalDeviceDisplayPlanePropertiesKHR.");
}
if (pPhysicalDevice->gotDisplayPlanePropertyCount && planeIndex >= pPhysicalDevice->displayPlanePropertyCount) {
skip_call |=
log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_PLANE_INDEX_TOO_LARGE,
swapchain_layer_name,
"vkGetDisplayPlaneSupportedDisplaysKHR(): planeIndex must be in the range [0, %d] that was returned by "
"vkGetPhysicalDeviceDisplayPlanePropertiesKHR. Do you have the plane index hardcoded?",
pPhysicalDevice->displayPlanePropertyCount - 1);
}
lock.unlock();
if (!skip_call) {
result = my_data->instance_dispatch_table->GetDisplayPlaneSupportedDisplaysKHR(physicalDevice, planeIndex, pDisplayCount,
pDisplays);
return result;
}
// TODO validate the returned display objects
return VK_ERROR_VALIDATION_FAILED_EXT;
}
VKAPI_ATTR VkResult VKAPI_CALL GetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
uint32_t *pPropertyCount, VkDisplayModePropertiesKHR *pProperties) {
VkResult result = VK_SUCCESS;
bool skip_call = false;
layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
std::unique_lock<std::mutex> lock(global_lock);
SwpPhysicalDevice *pPhysicalDevice = NULL;
{
auto it = my_data->physicalDeviceMap.find(physicalDevice);
pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second;
}
if (pPhysicalDevice && pPhysicalDevice->pInstance && !pPhysicalDevice->pInstance->displayExtensionEnabled) {
skip_call |=
log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
swapchain_layer_name,
"vkGetDisplayModePropertiesKHR() called even though the %s extension was not enabled for this VkInstance.",
VK_KHR_DISPLAY_EXTENSION_NAME);
}
lock.unlock();
if (!skip_call) {
result =
my_data->instance_dispatch_table->GetDisplayModePropertiesKHR(physicalDevice, display, pPropertyCount, pProperties);
return result;
}
// TODO store the displayMode for later checking
return VK_ERROR_VALIDATION_FAILED_EXT;
}
VKAPI_ATTR VkResult VKAPI_CALL CreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
const VkDisplayModeCreateInfoKHR *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode) {
VkResult result = VK_SUCCESS;
bool skip_call = false;
layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
std::unique_lock<std::mutex> lock(global_lock);
SwpPhysicalDevice *pPhysicalDevice = NULL;
{
auto it = my_data->physicalDeviceMap.find(physicalDevice);
pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second;
}
if (pPhysicalDevice && pPhysicalDevice->pInstance && !pPhysicalDevice->pInstance->displayExtensionEnabled) {
skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__,
SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, swapchain_layer_name,
"vkCreateDisplayModeKHR() called even though the %s extension was not enabled for this VkInstance.",
VK_KHR_DISPLAY_EXTENSION_NAME);
}
lock.unlock();