-
Notifications
You must be signed in to change notification settings - Fork 167
/
Copy pathfunction_definitions.h
8550 lines (7342 loc) · 331 KB
/
function_definitions.h
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-2024 The Khronos Group 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.
*/
/*
** This header is generated from the Khronos Vulkan XML API Registry.
**
*/
#pragma once
#include "mock_icd.h"
#include "function_declarations.h"
namespace vkmock {
static VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(
const VkInstanceCreateInfo* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkInstance* pInstance)
{
// TODO: If loader ver <=4 ICD must fail with VK_ERROR_INCOMPATIBLE_DRIVER for all vkCreateInstance calls with
// apiVersion set to > Vulkan 1.0 because the loader is still at interface version <= 4. Otherwise, the
// ICD should behave as normal.
if (loader_interface_version <= 4) {
return VK_ERROR_INCOMPATIBLE_DRIVER;
}
*pInstance = (VkInstance)CreateDispObjHandle();
for (auto& physical_device : physical_device_map[*pInstance])
physical_device = (VkPhysicalDevice)CreateDispObjHandle();
// TODO: If emulating specific device caps, will need to add intelligence here
return VK_SUCCESS;
}
static VKAPI_ATTR void VKAPI_CALL DestroyInstance(
VkInstance instance,
const VkAllocationCallbacks* pAllocator)
{
if (instance) {
for (const auto physical_device : physical_device_map.at(instance)) {
display_map.erase(physical_device);
DestroyDispObjHandle((void*)physical_device);
}
physical_device_map.erase(instance);
DestroyDispObjHandle((void*)instance);
}
}
static VKAPI_ATTR VkResult VKAPI_CALL EnumeratePhysicalDevices(
VkInstance instance,
uint32_t* pPhysicalDeviceCount,
VkPhysicalDevice* pPhysicalDevices)
{
VkResult result_code = VK_SUCCESS;
if (pPhysicalDevices) {
const auto return_count = (std::min)(*pPhysicalDeviceCount, icd_physical_device_count);
for (uint32_t i = 0; i < return_count; ++i) pPhysicalDevices[i] = physical_device_map.at(instance)[i];
if (return_count < icd_physical_device_count) result_code = VK_INCOMPLETE;
*pPhysicalDeviceCount = return_count;
} else {
*pPhysicalDeviceCount = icd_physical_device_count;
}
return result_code;
}
static VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceFeatures(
VkPhysicalDevice physicalDevice,
VkPhysicalDeviceFeatures* pFeatures)
{
uint32_t num_bools = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
VkBool32 *bool_array = &pFeatures->robustBufferAccess;
SetBoolArrayTrue(bool_array, num_bools);
}
static VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceFormatProperties(
VkPhysicalDevice physicalDevice,
VkFormat format,
VkFormatProperties* pFormatProperties)
{
if (VK_FORMAT_UNDEFINED == format) {
*pFormatProperties = { 0x0, 0x0, 0x0 };
} else {
// Default to a color format, skip DS bit
*pFormatProperties = { 0x00FFFDFF, 0x00FFFDFF, 0x00FFFDFF };
switch (format) {
case VK_FORMAT_D16_UNORM:
case VK_FORMAT_X8_D24_UNORM_PACK32:
case VK_FORMAT_D32_SFLOAT:
case VK_FORMAT_S8_UINT:
case VK_FORMAT_D16_UNORM_S8_UINT:
case VK_FORMAT_D24_UNORM_S8_UINT:
case VK_FORMAT_D32_SFLOAT_S8_UINT:
// Don't set color bits for DS formats
*pFormatProperties = { 0x00FFFE7F, 0x00FFFE7F, 0x00FFFE7F };
break;
case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
case VK_FORMAT_G8_B8R8_2PLANE_422_UNORM:
case VK_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16:
case VK_FORMAT_G8_B8R8_2PLANE_444_UNORM:
// Set decode/encode bits for these formats
*pFormatProperties = { 0x1EFFFDFF, 0x1EFFFDFF, 0x00FFFDFF };
break;
default:
break;
}
}
}
static VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceImageFormatProperties(
VkPhysicalDevice physicalDevice,
VkFormat format,
VkImageType type,
VkImageTiling tiling,
VkImageUsageFlags usage,
VkImageCreateFlags flags,
VkImageFormatProperties* pImageFormatProperties)
{
// A hardcoded unsupported format
if (format == VK_FORMAT_E5B9G9R9_UFLOAT_PACK32) {
return VK_ERROR_FORMAT_NOT_SUPPORTED;
}
// TODO: Just hard-coding some values for now
// TODO: If tiling is linear, limit the mips, levels, & sample count
if (VK_IMAGE_TILING_LINEAR == tiling) {
*pImageFormatProperties = { { 4096, 4096, 256 }, 1, 1, VK_SAMPLE_COUNT_1_BIT, 4294967296 };
} else {
// We hard-code support for all sample counts except 64 bits.
*pImageFormatProperties = { { 4096, 4096, 256 }, 12, 256, 0x7F & ~VK_SAMPLE_COUNT_64_BIT, 4294967296 };
}
return VK_SUCCESS;
}
static VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceProperties(
VkPhysicalDevice physicalDevice,
VkPhysicalDeviceProperties* pProperties)
{
pProperties->apiVersion = VK_HEADER_VERSION_COMPLETE;
pProperties->driverVersion = 1;
pProperties->vendorID = 0xba5eba11;
pProperties->deviceID = 0xf005ba11;
pProperties->deviceType = VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU;
//std::string devName = "Vulkan Mock Device";
strcpy(pProperties->deviceName, "Vulkan Mock Device");
pProperties->pipelineCacheUUID[0] = 18;
pProperties->limits = SetLimits(&pProperties->limits);
pProperties->sparseProperties = { VK_TRUE, VK_TRUE, VK_TRUE, VK_TRUE, VK_TRUE };
}
static VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceQueueFamilyProperties(
VkPhysicalDevice physicalDevice,
uint32_t* pQueueFamilyPropertyCount,
VkQueueFamilyProperties* pQueueFamilyProperties)
{
if (pQueueFamilyProperties) {
std::vector<VkQueueFamilyProperties2KHR> props2(*pQueueFamilyPropertyCount, {
VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2_KHR});
GetPhysicalDeviceQueueFamilyProperties2KHR(physicalDevice, pQueueFamilyPropertyCount, props2.data());
for (uint32_t i = 0; i < *pQueueFamilyPropertyCount; ++i) {
pQueueFamilyProperties[i] = props2[i].queueFamilyProperties;
}
} else {
GetPhysicalDeviceQueueFamilyProperties2KHR(physicalDevice, pQueueFamilyPropertyCount, nullptr);
}
}
static VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceMemoryProperties(
VkPhysicalDevice physicalDevice,
VkPhysicalDeviceMemoryProperties* pMemoryProperties)
{
pMemoryProperties->memoryTypeCount = 6;
// Host visible Coherent
pMemoryProperties->memoryTypes[0].propertyFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
pMemoryProperties->memoryTypes[0].heapIndex = 0;
// Host visible Cached
pMemoryProperties->memoryTypes[1].propertyFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT;
pMemoryProperties->memoryTypes[1].heapIndex = 0;
// Device local and Host visible
pMemoryProperties->memoryTypes[2].propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
pMemoryProperties->memoryTypes[2].heapIndex = 1;
// Device local lazily
pMemoryProperties->memoryTypes[3].propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT;
pMemoryProperties->memoryTypes[3].heapIndex = 1;
// Device local protected
pMemoryProperties->memoryTypes[4].propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_PROTECTED_BIT;
pMemoryProperties->memoryTypes[4].heapIndex = 1;
// Device local only
pMemoryProperties->memoryTypes[5].propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
pMemoryProperties->memoryTypes[5].heapIndex = 1;
pMemoryProperties->memoryHeapCount = 2;
pMemoryProperties->memoryHeaps[0].flags = VK_MEMORY_HEAP_MULTI_INSTANCE_BIT;
pMemoryProperties->memoryHeaps[0].size = 8000000000;
pMemoryProperties->memoryHeaps[1].flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT;
pMemoryProperties->memoryHeaps[1].size = 8000000000;
}
static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetInstanceProcAddr(
VkInstance instance,
const char* pName)
{
if (!negotiate_loader_icd_interface_called) {
loader_interface_version = 0;
}
const auto &item = name_to_funcptr_map.find(pName);
if (item != name_to_funcptr_map.end()) {
return reinterpret_cast<PFN_vkVoidFunction>(item->second);
}
// Mock should intercept all functions so if we get here just return null
return nullptr;
}
static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(
VkDevice device,
const char* pName)
{
return GetInstanceProcAddr(nullptr, pName);
}
static VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(
VkPhysicalDevice physicalDevice,
const VkDeviceCreateInfo* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkDevice* pDevice)
{
*pDevice = (VkDevice)CreateDispObjHandle();
// TODO: If emulating specific device caps, will need to add intelligence here
return VK_SUCCESS;
}
static VKAPI_ATTR void VKAPI_CALL DestroyDevice(
VkDevice device,
const VkAllocationCallbacks* pAllocator)
{
unique_lock_t lock(global_lock);
// First destroy sub-device objects
// Destroy Queues
for (auto queue_family_map_pair : queue_map[device]) {
for (auto index_queue_pair : queue_map[device][queue_family_map_pair.first]) {
DestroyDispObjHandle((void*)index_queue_pair.second);
}
}
for (auto& cp : command_pool_map[device]) {
for (auto& cb : command_pool_buffer_map[cp]) {
DestroyDispObjHandle((void*) cb);
}
command_pool_buffer_map.erase(cp);
}
command_pool_map[device].clear();
queue_map.erase(device);
buffer_map.erase(device);
image_memory_size_map.erase(device);
// Now destroy device
DestroyDispObjHandle((void*)device);
// TODO: If emulating specific device caps, will need to add intelligence here
}
static VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceExtensionProperties(
const char* pLayerName,
uint32_t* pPropertyCount,
VkExtensionProperties* pProperties)
{
// If requesting number of extensions, return that
if (!pLayerName) {
if (!pProperties) {
*pPropertyCount = (uint32_t)instance_extension_map.size();
} else {
uint32_t i = 0;
for (const auto &name_ver_pair : instance_extension_map) {
if (i == *pPropertyCount) {
break;
}
std::strncpy(pProperties[i].extensionName, name_ver_pair.first.c_str(), sizeof(pProperties[i].extensionName));
pProperties[i].extensionName[sizeof(pProperties[i].extensionName) - 1] = 0;
pProperties[i].specVersion = name_ver_pair.second;
++i;
}
if (i != instance_extension_map.size()) {
return VK_INCOMPLETE;
}
}
}
// If requesting extension properties, fill in data struct for number of extensions
return VK_SUCCESS;
}
static VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceExtensionProperties(
VkPhysicalDevice physicalDevice,
const char* pLayerName,
uint32_t* pPropertyCount,
VkExtensionProperties* pProperties)
{
// If requesting number of extensions, return that
if (!pLayerName) {
if (!pProperties) {
*pPropertyCount = (uint32_t)device_extension_map.size();
} else {
uint32_t i = 0;
for (const auto &name_ver_pair : device_extension_map) {
if (i == *pPropertyCount) {
break;
}
std::strncpy(pProperties[i].extensionName, name_ver_pair.first.c_str(), sizeof(pProperties[i].extensionName));
pProperties[i].extensionName[sizeof(pProperties[i].extensionName) - 1] = 0;
pProperties[i].specVersion = name_ver_pair.second;
++i;
}
if (i != device_extension_map.size()) {
return VK_INCOMPLETE;
}
}
}
// If requesting extension properties, fill in data struct for number of extensions
return VK_SUCCESS;
}
static VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceLayerProperties(
uint32_t* pPropertyCount,
VkLayerProperties* pProperties)
{
return VK_SUCCESS;
}
static VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceLayerProperties(
VkPhysicalDevice physicalDevice,
uint32_t* pPropertyCount,
VkLayerProperties* pProperties)
{
return VK_SUCCESS;
}
static VKAPI_ATTR void VKAPI_CALL GetDeviceQueue(
VkDevice device,
uint32_t queueFamilyIndex,
uint32_t queueIndex,
VkQueue* pQueue)
{
unique_lock_t lock(global_lock);
auto queue = queue_map[device][queueFamilyIndex][queueIndex];
if (queue) {
*pQueue = queue;
} else {
*pQueue = queue_map[device][queueFamilyIndex][queueIndex] = (VkQueue)CreateDispObjHandle();
}
// TODO: If emulating specific device caps, will need to add intelligence here
return;
}
static VKAPI_ATTR VkResult VKAPI_CALL QueueSubmit(
VkQueue queue,
uint32_t submitCount,
const VkSubmitInfo* pSubmits,
VkFence fence)
{
// Special way to cause DEVICE_LOST
// Picked VkExportFenceCreateInfo because needed some struct that wouldn't get cleared by validation Safe Struct
// ... TODO - It would be MUCH nicer to have a layer or other setting control when this occured
// For now this is used to allow Validation Layers test reacting to device losts
if (submitCount > 0 && pSubmits) {
auto pNext = reinterpret_cast<const VkBaseInStructure *>(pSubmits[0].pNext);
if (pNext && pNext->sType == VK_STRUCTURE_TYPE_EXPORT_FENCE_CREATE_INFO && pNext->pNext == nullptr) {
return VK_ERROR_DEVICE_LOST;
}
}
return VK_SUCCESS;
}
static VKAPI_ATTR VkResult VKAPI_CALL QueueWaitIdle(
VkQueue queue)
{
//Not a CREATE or DESTROY function
return VK_SUCCESS;
}
static VKAPI_ATTR VkResult VKAPI_CALL DeviceWaitIdle(
VkDevice device)
{
//Not a CREATE or DESTROY function
return VK_SUCCESS;
}
static VKAPI_ATTR VkResult VKAPI_CALL AllocateMemory(
VkDevice device,
const VkMemoryAllocateInfo* pAllocateInfo,
const VkAllocationCallbacks* pAllocator,
VkDeviceMemory* pMemory)
{
unique_lock_t lock(global_lock);
allocated_memory_size_map[(VkDeviceMemory)global_unique_handle] = pAllocateInfo->allocationSize;
*pMemory = (VkDeviceMemory)global_unique_handle++;
return VK_SUCCESS;
}
static VKAPI_ATTR void VKAPI_CALL FreeMemory(
VkDevice device,
VkDeviceMemory memory,
const VkAllocationCallbacks* pAllocator)
{
//Destroy object
UnmapMemory(device, memory);
unique_lock_t lock(global_lock);
allocated_memory_size_map.erase(memory);
}
static VKAPI_ATTR VkResult VKAPI_CALL MapMemory(
VkDevice device,
VkDeviceMemory memory,
VkDeviceSize offset,
VkDeviceSize size,
VkMemoryMapFlags flags,
void** ppData)
{
unique_lock_t lock(global_lock);
if (VK_WHOLE_SIZE == size) {
if (allocated_memory_size_map.count(memory) != 0)
size = allocated_memory_size_map[memory] - offset;
else
size = 0x10000;
}
void* map_addr = malloc((size_t)size);
mapped_memory_map[memory].push_back(map_addr);
*ppData = map_addr;
return VK_SUCCESS;
}
static VKAPI_ATTR void VKAPI_CALL UnmapMemory(
VkDevice device,
VkDeviceMemory memory)
{
unique_lock_t lock(global_lock);
for (auto map_addr : mapped_memory_map[memory]) {
free(map_addr);
}
mapped_memory_map.erase(memory);
}
static VKAPI_ATTR VkResult VKAPI_CALL FlushMappedMemoryRanges(
VkDevice device,
uint32_t memoryRangeCount,
const VkMappedMemoryRange* pMemoryRanges)
{
//Not a CREATE or DESTROY function
return VK_SUCCESS;
}
static VKAPI_ATTR VkResult VKAPI_CALL InvalidateMappedMemoryRanges(
VkDevice device,
uint32_t memoryRangeCount,
const VkMappedMemoryRange* pMemoryRanges)
{
//Not a CREATE or DESTROY function
return VK_SUCCESS;
}
static VKAPI_ATTR void VKAPI_CALL GetDeviceMemoryCommitment(
VkDevice device,
VkDeviceMemory memory,
VkDeviceSize* pCommittedMemoryInBytes)
{
//Not a CREATE or DESTROY function
}
static VKAPI_ATTR VkResult VKAPI_CALL BindBufferMemory(
VkDevice device,
VkBuffer buffer,
VkDeviceMemory memory,
VkDeviceSize memoryOffset)
{
//Not a CREATE or DESTROY function
return VK_SUCCESS;
}
static VKAPI_ATTR VkResult VKAPI_CALL BindImageMemory(
VkDevice device,
VkImage image,
VkDeviceMemory memory,
VkDeviceSize memoryOffset)
{
//Not a CREATE or DESTROY function
return VK_SUCCESS;
}
static VKAPI_ATTR void VKAPI_CALL GetBufferMemoryRequirements(
VkDevice device,
VkBuffer buffer,
VkMemoryRequirements* pMemoryRequirements)
{
// TODO: Just hard-coding reqs for now
pMemoryRequirements->size = 4096;
pMemoryRequirements->alignment = 1;
pMemoryRequirements->memoryTypeBits = 0xFFFF;
// Return a better size based on the buffer size from the create info.
unique_lock_t lock(global_lock);
auto d_iter = buffer_map.find(device);
if (d_iter != buffer_map.end()) {
auto iter = d_iter->second.find(buffer);
if (iter != d_iter->second.end()) {
pMemoryRequirements->size = ((iter->second.size + 4095) / 4096) * 4096;
}
}
}
static VKAPI_ATTR void VKAPI_CALL GetImageMemoryRequirements(
VkDevice device,
VkImage image,
VkMemoryRequirements* pMemoryRequirements)
{
pMemoryRequirements->size = 0;
pMemoryRequirements->alignment = 1;
unique_lock_t lock(global_lock);
auto d_iter = image_memory_size_map.find(device);
if(d_iter != image_memory_size_map.end()){
auto iter = d_iter->second.find(image);
if (iter != d_iter->second.end()) {
pMemoryRequirements->size = iter->second;
}
}
// Here we hard-code that the memory type at index 3 doesn't support this image.
pMemoryRequirements->memoryTypeBits = 0xFFFF & ~(0x1 << 3);
}
static VKAPI_ATTR void VKAPI_CALL GetImageSparseMemoryRequirements(
VkDevice device,
VkImage image,
uint32_t* pSparseMemoryRequirementCount,
VkSparseImageMemoryRequirements* pSparseMemoryRequirements)
{
if (!pSparseMemoryRequirements) {
*pSparseMemoryRequirementCount = 1;
} else {
// arbitrary
pSparseMemoryRequirements->imageMipTailFirstLod = 0;
pSparseMemoryRequirements->imageMipTailSize = 8;
pSparseMemoryRequirements->imageMipTailOffset = 0;
pSparseMemoryRequirements->imageMipTailStride = 4;
pSparseMemoryRequirements->formatProperties.imageGranularity = {4, 4, 4};
pSparseMemoryRequirements->formatProperties.flags = VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT;
// Would need to track the VkImage to know format for better value here
pSparseMemoryRequirements->formatProperties.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT;
}
}
static VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceSparseImageFormatProperties(
VkPhysicalDevice physicalDevice,
VkFormat format,
VkImageType type,
VkSampleCountFlagBits samples,
VkImageUsageFlags usage,
VkImageTiling tiling,
uint32_t* pPropertyCount,
VkSparseImageFormatProperties* pProperties)
{
if (!pProperties) {
*pPropertyCount = 1;
} else {
// arbitrary
pProperties->imageGranularity = {4, 4, 4};
pProperties->flags = VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT;
switch (format) {
case VK_FORMAT_D16_UNORM:
case VK_FORMAT_D32_SFLOAT:
pProperties->aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
break;
case VK_FORMAT_S8_UINT:
pProperties->aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
break;
case VK_FORMAT_X8_D24_UNORM_PACK32:
case VK_FORMAT_D16_UNORM_S8_UINT:
case VK_FORMAT_D24_UNORM_S8_UINT:
case VK_FORMAT_D32_SFLOAT_S8_UINT:
pProperties->aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
break;
default:
pProperties->aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
break;
}
}
}
static VKAPI_ATTR VkResult VKAPI_CALL QueueBindSparse(
VkQueue queue,
uint32_t bindInfoCount,
const VkBindSparseInfo* pBindInfo,
VkFence fence)
{
//Not a CREATE or DESTROY function
return VK_SUCCESS;
}
static VKAPI_ATTR VkResult VKAPI_CALL CreateFence(
VkDevice device,
const VkFenceCreateInfo* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkFence* pFence)
{
unique_lock_t lock(global_lock);
*pFence = (VkFence)global_unique_handle++;
return VK_SUCCESS;
}
static VKAPI_ATTR void VKAPI_CALL DestroyFence(
VkDevice device,
VkFence fence,
const VkAllocationCallbacks* pAllocator)
{
//Destroy object
}
static VKAPI_ATTR VkResult VKAPI_CALL ResetFences(
VkDevice device,
uint32_t fenceCount,
const VkFence* pFences)
{
//Not a CREATE or DESTROY function
return VK_SUCCESS;
}
static VKAPI_ATTR VkResult VKAPI_CALL GetFenceStatus(
VkDevice device,
VkFence fence)
{
//Not a CREATE or DESTROY function
return VK_SUCCESS;
}
static VKAPI_ATTR VkResult VKAPI_CALL WaitForFences(
VkDevice device,
uint32_t fenceCount,
const VkFence* pFences,
VkBool32 waitAll,
uint64_t timeout)
{
//Not a CREATE or DESTROY function
return VK_SUCCESS;
}
static VKAPI_ATTR VkResult VKAPI_CALL CreateSemaphore(
VkDevice device,
const VkSemaphoreCreateInfo* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkSemaphore* pSemaphore)
{
unique_lock_t lock(global_lock);
*pSemaphore = (VkSemaphore)global_unique_handle++;
return VK_SUCCESS;
}
static VKAPI_ATTR void VKAPI_CALL DestroySemaphore(
VkDevice device,
VkSemaphore semaphore,
const VkAllocationCallbacks* pAllocator)
{
//Destroy object
}
static VKAPI_ATTR VkResult VKAPI_CALL CreateEvent(
VkDevice device,
const VkEventCreateInfo* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkEvent* pEvent)
{
unique_lock_t lock(global_lock);
*pEvent = (VkEvent)global_unique_handle++;
return VK_SUCCESS;
}
static VKAPI_ATTR void VKAPI_CALL DestroyEvent(
VkDevice device,
VkEvent event,
const VkAllocationCallbacks* pAllocator)
{
//Destroy object
}
static VKAPI_ATTR VkResult VKAPI_CALL GetEventStatus(
VkDevice device,
VkEvent event)
{
//Not a CREATE or DESTROY function
return VK_EVENT_SET;
}
static VKAPI_ATTR VkResult VKAPI_CALL SetEvent(
VkDevice device,
VkEvent event)
{
//Not a CREATE or DESTROY function
return VK_SUCCESS;
}
static VKAPI_ATTR VkResult VKAPI_CALL ResetEvent(
VkDevice device,
VkEvent event)
{
//Not a CREATE or DESTROY function
return VK_SUCCESS;
}
static VKAPI_ATTR VkResult VKAPI_CALL CreateQueryPool(
VkDevice device,
const VkQueryPoolCreateInfo* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkQueryPool* pQueryPool)
{
unique_lock_t lock(global_lock);
*pQueryPool = (VkQueryPool)global_unique_handle++;
return VK_SUCCESS;
}
static VKAPI_ATTR void VKAPI_CALL DestroyQueryPool(
VkDevice device,
VkQueryPool queryPool,
const VkAllocationCallbacks* pAllocator)
{
//Destroy object
}
static VKAPI_ATTR VkResult VKAPI_CALL GetQueryPoolResults(
VkDevice device,
VkQueryPool queryPool,
uint32_t firstQuery,
uint32_t queryCount,
size_t dataSize,
void* pData,
VkDeviceSize stride,
VkQueryResultFlags flags)
{
//Not a CREATE or DESTROY function
return VK_SUCCESS;
}
static VKAPI_ATTR VkResult VKAPI_CALL CreateBuffer(
VkDevice device,
const VkBufferCreateInfo* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkBuffer* pBuffer)
{
unique_lock_t lock(global_lock);
*pBuffer = (VkBuffer)global_unique_handle++;
buffer_map[device][*pBuffer] = {
pCreateInfo->size,
current_available_address
};
current_available_address += pCreateInfo->size;
// Always align to next 64-bit pointer
const uint64_t alignment = current_available_address % 64;
if (alignment != 0) {
current_available_address += (64 - alignment);
}
return VK_SUCCESS;
}
static VKAPI_ATTR void VKAPI_CALL DestroyBuffer(
VkDevice device,
VkBuffer buffer,
const VkAllocationCallbacks* pAllocator)
{
unique_lock_t lock(global_lock);
buffer_map[device].erase(buffer);
}
static VKAPI_ATTR VkResult VKAPI_CALL CreateBufferView(
VkDevice device,
const VkBufferViewCreateInfo* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkBufferView* pView)
{
unique_lock_t lock(global_lock);
*pView = (VkBufferView)global_unique_handle++;
return VK_SUCCESS;
}
static VKAPI_ATTR void VKAPI_CALL DestroyBufferView(
VkDevice device,
VkBufferView bufferView,
const VkAllocationCallbacks* pAllocator)
{
//Destroy object
}
static VKAPI_ATTR VkResult VKAPI_CALL CreateImage(
VkDevice device,
const VkImageCreateInfo* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkImage* pImage)
{
unique_lock_t lock(global_lock);
*pImage = (VkImage)global_unique_handle++;
image_memory_size_map[device][*pImage] = GetImageSizeFromCreateInfo(pCreateInfo);
return VK_SUCCESS;
}
static VKAPI_ATTR void VKAPI_CALL DestroyImage(
VkDevice device,
VkImage image,
const VkAllocationCallbacks* pAllocator)
{
unique_lock_t lock(global_lock);
image_memory_size_map[device].erase(image);
}
static VKAPI_ATTR void VKAPI_CALL GetImageSubresourceLayout(
VkDevice device,
VkImage image,
const VkImageSubresource* pSubresource,
VkSubresourceLayout* pLayout)
{
// Need safe values. Callers are computing memory offsets from pLayout, with no return code to flag failure.
*pLayout = VkSubresourceLayout(); // Default constructor zero values.
}
static VKAPI_ATTR VkResult VKAPI_CALL CreateImageView(
VkDevice device,
const VkImageViewCreateInfo* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkImageView* pView)
{
unique_lock_t lock(global_lock);
*pView = (VkImageView)global_unique_handle++;
return VK_SUCCESS;
}
static VKAPI_ATTR void VKAPI_CALL DestroyImageView(
VkDevice device,
VkImageView imageView,
const VkAllocationCallbacks* pAllocator)
{
//Destroy object
}
static VKAPI_ATTR VkResult VKAPI_CALL CreateShaderModule(
VkDevice device,
const VkShaderModuleCreateInfo* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkShaderModule* pShaderModule)
{
unique_lock_t lock(global_lock);
*pShaderModule = (VkShaderModule)global_unique_handle++;
return VK_SUCCESS;
}
static VKAPI_ATTR void VKAPI_CALL DestroyShaderModule(
VkDevice device,
VkShaderModule shaderModule,
const VkAllocationCallbacks* pAllocator)
{
//Destroy object
}
static VKAPI_ATTR VkResult VKAPI_CALL CreatePipelineCache(
VkDevice device,
const VkPipelineCacheCreateInfo* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkPipelineCache* pPipelineCache)
{
unique_lock_t lock(global_lock);
*pPipelineCache = (VkPipelineCache)global_unique_handle++;
return VK_SUCCESS;
}
static VKAPI_ATTR void VKAPI_CALL DestroyPipelineCache(
VkDevice device,
VkPipelineCache pipelineCache,
const VkAllocationCallbacks* pAllocator)
{
//Destroy object
}
static VKAPI_ATTR VkResult VKAPI_CALL GetPipelineCacheData(
VkDevice device,
VkPipelineCache pipelineCache,
size_t* pDataSize,
void* pData)
{
//Not a CREATE or DESTROY function
return VK_SUCCESS;
}
static VKAPI_ATTR VkResult VKAPI_CALL MergePipelineCaches(
VkDevice device,
VkPipelineCache dstCache,
uint32_t srcCacheCount,
const VkPipelineCache* pSrcCaches)
{
//Not a CREATE or DESTROY function
return VK_SUCCESS;
}
static VKAPI_ATTR VkResult VKAPI_CALL CreateGraphicsPipelines(
VkDevice device,
VkPipelineCache pipelineCache,
uint32_t createInfoCount,
const VkGraphicsPipelineCreateInfo* pCreateInfos,
const VkAllocationCallbacks* pAllocator,
VkPipeline* pPipelines)
{
unique_lock_t lock(global_lock);
for (uint32_t i = 0; i < createInfoCount; ++i) {
pPipelines[i] = (VkPipeline)global_unique_handle++;
}
return VK_SUCCESS;
}
static VKAPI_ATTR VkResult VKAPI_CALL CreateComputePipelines(
VkDevice device,
VkPipelineCache pipelineCache,
uint32_t createInfoCount,
const VkComputePipelineCreateInfo* pCreateInfos,
const VkAllocationCallbacks* pAllocator,
VkPipeline* pPipelines)
{
unique_lock_t lock(global_lock);
for (uint32_t i = 0; i < createInfoCount; ++i) {
pPipelines[i] = (VkPipeline)global_unique_handle++;
}
return VK_SUCCESS;
}
static VKAPI_ATTR void VKAPI_CALL DestroyPipeline(
VkDevice device,
VkPipeline pipeline,
const VkAllocationCallbacks* pAllocator)
{
//Destroy object
}
static VKAPI_ATTR VkResult VKAPI_CALL CreatePipelineLayout(
VkDevice device,
const VkPipelineLayoutCreateInfo* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkPipelineLayout* pPipelineLayout)
{
unique_lock_t lock(global_lock);
*pPipelineLayout = (VkPipelineLayout)global_unique_handle++;
return VK_SUCCESS;
}
static VKAPI_ATTR void VKAPI_CALL DestroyPipelineLayout(
VkDevice device,
VkPipelineLayout pipelineLayout,
const VkAllocationCallbacks* pAllocator)
{
//Destroy object
}
static VKAPI_ATTR VkResult VKAPI_CALL CreateSampler(
VkDevice device,
const VkSamplerCreateInfo* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkSampler* pSampler)
{
unique_lock_t lock(global_lock);
*pSampler = (VkSampler)global_unique_handle++;
return VK_SUCCESS;
}
static VKAPI_ATTR void VKAPI_CALL DestroySampler(
VkDevice device,
VkSampler sampler,
const VkAllocationCallbacks* pAllocator)
{
//Destroy object
}
static VKAPI_ATTR VkResult VKAPI_CALL CreateDescriptorSetLayout(
VkDevice device,
const VkDescriptorSetLayoutCreateInfo* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkDescriptorSetLayout* pSetLayout)
{
unique_lock_t lock(global_lock);
*pSetLayout = (VkDescriptorSetLayout)global_unique_handle++;
return VK_SUCCESS;