forked from llvm/offload-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDevice.cpp
More file actions
2464 lines (2211 loc) · 101 KB
/
Device.cpp
File metadata and controls
2464 lines (2211 loc) · 101 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//===- VX/Device.cpp - Vulkan Device API ----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
//
//===----------------------------------------------------------------------===//
#include "API/Device.h"
#include "Support/Pipeline.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/Support/Error.h"
#include <algorithm>
#include <cmath>
#include <memory>
#include <numeric>
#include <system_error>
#include <vulkan/vulkan.h>
using namespace offloadtest;
#define VKFormats(FMT, BITS) \
if (Channels == 1) \
return VK_FORMAT_R##BITS##_##FMT; \
if (Channels == 2) \
return VK_FORMAT_R##BITS##G##BITS##_##FMT; \
if (Channels == 3) \
return VK_FORMAT_R##BITS##G##BITS##B##BITS##_##FMT; \
if (Channels == 4) \
return VK_FORMAT_R##BITS##G##BITS##B##BITS##A##BITS##_##FMT;
static VkFormat getVKFormat(DataFormat Format, int Channels) {
switch (Format) {
case DataFormat::Int16:
VKFormats(SINT, 16) break;
case DataFormat::UInt16:
VKFormats(UINT, 16) break;
case DataFormat::Int32:
VKFormats(SINT, 32) break;
case DataFormat::UInt32:
VKFormats(UINT, 32) break;
case DataFormat::Float32:
VKFormats(SFLOAT, 32) break;
case DataFormat::Int64:
VKFormats(SINT, 64) break;
case DataFormat::UInt64:
VKFormats(UINT, 64) break;
case DataFormat::Float64:
VKFormats(SFLOAT, 64) break;
case DataFormat::Depth32:
if (Channels != 1)
llvm_unreachable("Depth32 format only supports a single channel.");
return VK_FORMAT_D32_SFLOAT;
default:
llvm_unreachable("Unsupported Resource format specified");
}
return VK_FORMAT_UNDEFINED;
}
static VkDescriptorType getDescriptorType(const ResourceKind RK) {
switch (RK) {
case ResourceKind::Buffer:
case ResourceKind::RWBuffer:
return VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
case ResourceKind::Texture2D:
return VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
case ResourceKind::RWTexture2D:
return VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
case ResourceKind::ByteAddressBuffer:
case ResourceKind::RWByteAddressBuffer:
case ResourceKind::StructuredBuffer:
case ResourceKind::RWStructuredBuffer:
return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
case ResourceKind::ConstantBuffer:
return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
case ResourceKind::Sampler:
return VK_DESCRIPTOR_TYPE_SAMPLER;
case ResourceKind::SampledTexture2D:
return VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
}
llvm_unreachable("All cases handled");
}
static VkFilter getVKFilter(FilterMode Mode) {
switch (Mode) {
case FilterMode::Nearest:
return VK_FILTER_NEAREST;
case FilterMode::Linear:
return VK_FILTER_LINEAR;
}
llvm_unreachable("All filter cases handled");
}
static VkSamplerAddressMode getVKAddressMode(AddressMode Mode) {
switch (Mode) {
case AddressMode::Clamp:
return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
case AddressMode::Repeat:
return VK_SAMPLER_ADDRESS_MODE_REPEAT;
case AddressMode::Mirror:
return VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT;
case AddressMode::Border:
return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
case AddressMode::MirrorOnce:
return VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE;
}
llvm_unreachable("All address mode cases handled");
}
static VkCompareOp getVKCompareOp(CompareFunction Func) {
switch (Func) {
case CompareFunction::Never:
return VK_COMPARE_OP_NEVER;
case CompareFunction::Less:
return VK_COMPARE_OP_LESS;
case CompareFunction::Equal:
return VK_COMPARE_OP_EQUAL;
case CompareFunction::LessEqual:
return VK_COMPARE_OP_LESS_OR_EQUAL;
case CompareFunction::Greater:
return VK_COMPARE_OP_GREATER;
case CompareFunction::NotEqual:
return VK_COMPARE_OP_NOT_EQUAL;
case CompareFunction::GreaterEqual:
return VK_COMPARE_OP_GREATER_OR_EQUAL;
case CompareFunction::Always:
return VK_COMPARE_OP_ALWAYS;
}
llvm_unreachable("All compare op cases handled");
}
static VkBufferUsageFlagBits getFlagBits(const ResourceKind RK) {
switch (RK) {
case ResourceKind::Buffer:
return VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
case ResourceKind::RWBuffer:
return VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
case ResourceKind::ByteAddressBuffer:
case ResourceKind::RWByteAddressBuffer:
case ResourceKind::StructuredBuffer:
case ResourceKind::RWStructuredBuffer:
return VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
case ResourceKind::ConstantBuffer:
return VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
case ResourceKind::Texture2D:
case ResourceKind::RWTexture2D:
case ResourceKind::Sampler:
case ResourceKind::SampledTexture2D:
llvm_unreachable("Textures and samplers don't have buffer usage bits!");
}
llvm_unreachable("All cases handled");
}
static VkImageViewType getImageViewType(const ResourceKind RK) {
switch (RK) {
case ResourceKind::Texture2D:
case ResourceKind::RWTexture2D:
case ResourceKind::SampledTexture2D:
return VK_IMAGE_VIEW_TYPE_2D;
case ResourceKind::Buffer:
case ResourceKind::RWBuffer:
case ResourceKind::ByteAddressBuffer:
case ResourceKind::RWByteAddressBuffer:
case ResourceKind::StructuredBuffer:
case ResourceKind::RWStructuredBuffer:
case ResourceKind::ConstantBuffer:
case ResourceKind::Sampler:
llvm_unreachable("Not an image view!");
}
llvm_unreachable("All cases handled");
}
static VkImageType getVKImageType(const ResourceKind RK) {
switch (RK) {
case ResourceKind::Texture2D:
case ResourceKind::RWTexture2D:
case ResourceKind::SampledTexture2D:
return VK_IMAGE_TYPE_2D;
default:
llvm_unreachable("Unsupported image kind");
}
llvm_unreachable("All cases handled");
}
static VkShaderStageFlagBits getShaderStageFlag(Stages Stage) {
switch (Stage) {
case Stages::Compute:
return VK_SHADER_STAGE_COMPUTE_BIT;
case Stages::Vertex:
return VK_SHADER_STAGE_VERTEX_BIT;
case Stages::Pixel:
return VK_SHADER_STAGE_FRAGMENT_BIT;
}
llvm_unreachable("All cases handled");
}
static std::string getMessageSeverityString(
VkDebugUtilsMessageSeverityFlagBitsEXT MessageSeverity) {
if (MessageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT)
return "Error";
if (MessageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT)
return "Warning";
if (MessageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT)
return "Info";
if (MessageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT)
return "Verbose";
return "Unknown";
}
static VkBool32
debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT MessageSeverity,
VkDebugUtilsMessageTypeFlagsEXT MessageType,
const VkDebugUtilsMessengerCallbackDataEXT *Data, void *) {
// Only interested in messages from the validation layers.
if (!(MessageType & VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT))
return VK_FALSE;
llvm::dbgs() << "Validation " << getMessageSeverityString(MessageSeverity);
llvm::dbgs() << ": [ " << Data->pMessageIdName << " ]\n";
llvm::dbgs() << Data->pMessage;
for (uint32_t I = 0; I < Data->objectCount; I++) {
llvm::dbgs() << '\n';
if (Data->pObjects[I].pObjectName) {
llvm::dbgs() << "[" << Data->pObjects[I].pObjectName << "]";
}
}
llvm::dbgs() << '\n';
// Return true to turn the validation error or warning into an error in the
// vulkan API. This should causes tests to fail.
const bool IsErrorOrWarning =
MessageSeverity & (VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT |
VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT);
if (IsErrorOrWarning)
return VK_TRUE;
// Continue to run even with VERBOSE and INFO messages.
return VK_FALSE;
}
static VkDebugUtilsMessengerEXT registerDebugUtilCallback(VkInstance Instance) {
VkDebugUtilsMessengerCreateInfoEXT CreateInfo = {};
CreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT;
CreateInfo.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT |
VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT |
VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT;
CreateInfo.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT |
VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT |
VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT;
CreateInfo.pfnUserCallback = debugCallback;
CreateInfo.pUserData = nullptr; // Optional
auto Func = (PFN_vkCreateDebugUtilsMessengerEXT)vkGetInstanceProcAddr(
Instance, "vkCreateDebugUtilsMessengerEXT");
if (Func == nullptr)
return VK_NULL_HANDLE;
VkDebugUtilsMessengerEXT DebugMessenger;
Func(Instance, &CreateInfo, nullptr, &DebugMessenger);
return DebugMessenger;
}
static llvm::Expected<uint32_t>
getMemoryIndex(VkPhysicalDevice Device, uint32_t MemoryTypeBits,
VkMemoryPropertyFlags MemoryFlags) {
VkPhysicalDeviceMemoryProperties MemProperties;
vkGetPhysicalDeviceMemoryProperties(Device, &MemProperties);
for (uint32_t I = 0; I < MemProperties.memoryTypeCount; ++I) {
const uint32_t Bit = (1u << I);
if ((MemoryTypeBits & Bit) == 0)
continue;
if ((MemProperties.memoryTypes[I].propertyFlags & MemoryFlags) ==
MemoryFlags)
return I;
}
return llvm::createStringError(std::errc::not_enough_memory,
"Could not identify appropriate memory.");
}
static llvm::SmallVector<VkLayerProperties, 0> queryInstanceLayers() {
uint32_t LayerCount;
vkEnumerateInstanceLayerProperties(&LayerCount, nullptr);
llvm::SmallVector<VkLayerProperties, 0> Layers;
if (LayerCount == 0)
return Layers;
Layers.resize(LayerCount);
vkEnumerateInstanceLayerProperties(&LayerCount, Layers.data());
return Layers;
}
static bool
isLayerSupported(const llvm::SmallVector<VkLayerProperties, 0> &Layers,
llvm::StringRef QueryName) {
for (auto &Layer : Layers) {
if (Layer.layerName == QueryName)
return true;
}
return false;
}
static llvm::SmallVector<VkExtensionProperties, 0>
queryInstanceExtensions(const char *InstanceLayer) {
uint32_t ExtCount;
vkEnumerateInstanceExtensionProperties(InstanceLayer, &ExtCount, nullptr);
llvm::SmallVector<VkExtensionProperties, 0> Extensions;
if (ExtCount == 0)
return Extensions;
Extensions.resize(ExtCount);
vkEnumerateInstanceExtensionProperties(nullptr, &ExtCount, Extensions.data());
return Extensions;
}
static llvm::SmallVector<VkExtensionProperties, 0>
queryDeviceExtensions(VkPhysicalDevice PhysicalDevice) {
uint32_t ExtCount;
vkEnumerateDeviceExtensionProperties(PhysicalDevice, nullptr, &ExtCount,
nullptr);
llvm::SmallVector<VkExtensionProperties, 0> Extensions;
if (ExtCount == 0)
return Extensions;
Extensions.resize(ExtCount);
vkEnumerateDeviceExtensionProperties(PhysicalDevice, nullptr, &ExtCount,
Extensions.data());
return Extensions;
}
static bool isExtensionSupported(
const llvm::SmallVector<VkExtensionProperties, 0> &Extensions,
llvm::StringRef QueryName) {
for (const auto &Ext : Extensions) {
if (Ext.extensionName == QueryName)
return true;
}
return false;
}
struct VulkanInstance {
VkInstance Instance;
VkDebugUtilsMessengerEXT DebugMessenger;
VulkanInstance(VkInstance Instance, VkDebugUtilsMessengerEXT DebugMessenger)
: Instance(Instance), DebugMessenger(DebugMessenger) {}
VulkanInstance(const VulkanInstance &) = delete;
VulkanInstance(VulkanInstance &&) = delete;
VulkanInstance &operator=(const VulkanInstance &) = delete;
VulkanInstance &operator=(VulkanInstance &&) = delete;
~VulkanInstance() {
if (DebugMessenger) {
auto Func = (PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr(
Instance, "vkDestroyDebugUtilsMessengerEXT");
assert(Func != nullptr);
Func(Instance, DebugMessenger, nullptr);
}
vkDestroyInstance(Instance, nullptr);
}
};
namespace {
class VulkanBuffer : public offloadtest::Buffer {
public:
VkDevice Dev; // Needed for clean-up
VkBuffer Buffer;
VkDeviceMemory Memory;
std::string Name;
BufferCreateDesc Desc;
size_t SizeInBytes;
VulkanBuffer(VkDevice Dev, VkBuffer Buffer, VkDeviceMemory Memory,
llvm::StringRef Name, BufferCreateDesc Desc, size_t SizeInBytes)
: Dev(Dev), Buffer(Buffer), Memory(Memory), Name(Name), Desc(Desc),
SizeInBytes(SizeInBytes) {}
~VulkanBuffer() override {
vkDestroyBuffer(Dev, Buffer, nullptr);
vkFreeMemory(Dev, Memory, nullptr);
}
};
class VulkanQueue : public offloadtest::Queue {
public:
VkQueue Queue = VK_NULL_HANDLE;
uint32_t QueueFamilyIdx = 0;
VulkanQueue(VkQueue Q, uint32_t QueueFamilyIdx)
: Queue(Q), QueueFamilyIdx(QueueFamilyIdx) {}
};
class VulkanDevice : public offloadtest::Device {
private:
std::shared_ptr<VulkanInstance> Instance;
VkPhysicalDevice PhysicalDevice = VK_NULL_HANDLE;
VkPhysicalDeviceProperties Props;
VkPhysicalDeviceProperties2 Props2;
VkPhysicalDeviceFloatControlsProperties FloatControlProp;
VkPhysicalDeviceDriverProperties DriverProps;
VkDevice Device = VK_NULL_HANDLE;
VulkanQueue GraphicsQueue;
Capabilities Caps;
using LayerVector = llvm::SmallVector<VkLayerProperties, 0>;
LayerVector InstanceLayers;
using ExtensionVector = llvm::SmallVector<VkExtensionProperties, 0>;
ExtensionVector DeviceExtensions;
struct BufferRef {
VkBuffer Buffer;
VkDeviceMemory Memory;
};
struct ImageRef {
VkImage Image;
VkSampler Sampler;
VkDeviceMemory Memory;
};
struct ResourceRef {
ResourceRef(BufferRef H, BufferRef D) : Host(H), Device(D) {}
ResourceRef(BufferRef H, ImageRef I) : Host(H), Image(I) {}
BufferRef Host;
BufferRef Device;
ImageRef Image;
};
struct ResourceBundle {
ResourceBundle(VkDescriptorType DescriptorType, uint64_t Size,
CPUBuffer *BufferPtr)
: DescriptorType(DescriptorType), Size(Size), BufferPtr(BufferPtr) {}
bool isImage() const {
return DescriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE ||
DescriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE ||
DescriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
}
bool isSampler() const {
return DescriptorType == VK_DESCRIPTOR_TYPE_SAMPLER;
}
bool isBuffer() const {
return DescriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER ||
DescriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ||
DescriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER ||
DescriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
}
bool isReadWrite() const {
return DescriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE ||
DescriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER ||
DescriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
}
uint32_t size() const { return BufferPtr->size(); }
VkDescriptorType DescriptorType;
uint64_t Size;
CPUBuffer *BufferPtr;
VkImageLayout ImageLayout = VK_IMAGE_LAYOUT_UNDEFINED;
llvm::SmallVector<ResourceRef> ResourceRefs;
llvm::SmallVector<ResourceRef> CounterResourceRefs;
};
struct CompiledShader {
Stages Stage;
std::string Entry;
VkShaderModule Shader;
};
struct InvocationState {
VkCommandPool CmdPool = VK_NULL_HANDLE;
VkCommandBuffer CmdBuffer = VK_NULL_HANDLE;
VkPipelineLayout PipelineLayout = VK_NULL_HANDLE;
VkDescriptorPool Pool = VK_NULL_HANDLE;
VkPipelineCache PipelineCache = VK_NULL_HANDLE;
VkPipeline Pipeline = VK_NULL_HANDLE;
// FrameBuffer associated data for offscreen rendering.
VkFramebuffer FrameBuffer = VK_NULL_HANDLE;
ResourceBundle FrameBufferResource = {VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 0,
nullptr};
ImageRef DepthStencil = {0, 0, 0};
std::optional<ResourceRef> VertexBuffer = std::nullopt;
VkRenderPass RenderPass = VK_NULL_HANDLE;
uint32_t ShaderStageMask = 0;
llvm::SmallVector<CompiledShader> Shaders;
llvm::SmallVector<VkDescriptorSetLayout> DescriptorSetLayouts;
llvm::SmallVector<ResourceBundle> Resources;
llvm::SmallVector<VkDescriptorSet> DescriptorSets;
llvm::SmallVector<VkBufferView> BufferViews;
llvm::SmallVector<VkImageView> ImageViews;
uint32_t getFullShaderStageMask() {
if (0 != ShaderStageMask)
return ShaderStageMask;
for (const auto &S : Shaders)
ShaderStageMask |= getShaderStageFlag(S.Stage);
return ShaderStageMask;
}
};
public:
static llvm::Expected<std::unique_ptr<VulkanDevice>>
create(std::shared_ptr<VulkanInstance> Instance,
VkPhysicalDevice PhysicalDevice,
llvm::SmallVector<VkLayerProperties, 0> InstanceLayers) {
VkPhysicalDeviceProperties Props;
vkGetPhysicalDeviceProperties(PhysicalDevice, &Props);
// Find a queue family that supports both graphics and compute.
uint32_t QueueCount = 0;
vkGetPhysicalDeviceQueueFamilyProperties(PhysicalDevice, &QueueCount,
nullptr);
if (QueueCount == 0)
return llvm::createStringError(std::errc::no_such_device,
"No queue families reported.");
const std::unique_ptr<VkQueueFamilyProperties[]> QueueFamilyProps(
new VkQueueFamilyProperties[QueueCount]);
vkGetPhysicalDeviceQueueFamilyProperties(PhysicalDevice, &QueueCount,
QueueFamilyProps.get());
std::optional<uint32_t> SelectedIdx;
for (uint32_t I = 0; I < QueueCount; ++I) {
const VkQueueFlags Flags = QueueFamilyProps[I].queueFlags;
// Prefer family supporting both GRAPHICS and COMPUTE
if ((Flags & VK_QUEUE_GRAPHICS_BIT) && (Flags & VK_QUEUE_COMPUTE_BIT)) {
SelectedIdx = static_cast<int>(I);
break;
}
}
if (!SelectedIdx)
return llvm::createStringError(std::errc::no_such_device,
"No suitable queue family found.");
const uint32_t QueueFamilyIdx = *SelectedIdx;
VkDeviceQueueCreateInfo QueueInfo = {};
const float QueuePriority = 1.0f;
QueueInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
QueueInfo.queueFamilyIndex = QueueFamilyIdx;
QueueInfo.queueCount = 1;
QueueInfo.pQueuePriorities = &QueuePriority;
VkDeviceCreateInfo DeviceInfo = {};
DeviceInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
DeviceInfo.queueCreateInfoCount = 1;
DeviceInfo.pQueueCreateInfos = &QueueInfo;
VkPhysicalDeviceFeatures2 Features{};
Features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
VkPhysicalDeviceVulkan11Features Features11{};
Features11.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES;
VkPhysicalDeviceVulkan12Features Features12{};
Features12.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES;
VkPhysicalDeviceVulkan13Features Features13{};
Features13.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES;
#ifdef VK_VERSION_1_4
VkPhysicalDeviceVulkan14Features Features14{};
Features14.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_4_FEATURES;
#endif
Features.pNext = &Features11;
if (Props.apiVersion >= VK_MAKE_API_VERSION(0, 1, 2, 0))
Features11.pNext = &Features12;
if (Props.apiVersion >= VK_MAKE_API_VERSION(0, 1, 3, 0))
Features12.pNext = &Features13;
#ifdef VK_VERSION_1_4
if (Props.apiVersion >= VK_MAKE_API_VERSION(0, 1, 4, 0))
Features13.pNext = &Features14;
#endif
vkGetPhysicalDeviceFeatures2(PhysicalDevice, &Features);
DeviceInfo.pEnabledFeatures = &Features.features;
DeviceInfo.pNext = Features.pNext;
VkDevice Device = VK_NULL_HANDLE;
if (vkCreateDevice(PhysicalDevice, &DeviceInfo, nullptr, &Device))
return llvm::createStringError(std::errc::no_such_device,
"Could not create Vulkan logical device.");
VkQueue DeviceQueue = VK_NULL_HANDLE;
vkGetDeviceQueue(Device, QueueFamilyIdx, 0, &DeviceQueue);
const VulkanQueue GraphicsQueue = VulkanQueue(DeviceQueue, QueueFamilyIdx);
return std::make_unique<VulkanDevice>(Instance, PhysicalDevice, Props,
Device, std::move(GraphicsQueue),
std::move(InstanceLayers));
}
VulkanDevice(std::shared_ptr<VulkanInstance> I, VkPhysicalDevice P,
VkPhysicalDeviceProperties Props, VkDevice D, VulkanQueue Q,
llvm::SmallVector<VkLayerProperties, 0> InstanceLayers)
: Instance(I), PhysicalDevice(P), Props(Props), Device(D),
GraphicsQueue(std::move(Q)), InstanceLayers(std::move(InstanceLayers)) {
const uint64_t DeviceNameSz =
strnlen(Props.deviceName, VK_MAX_PHYSICAL_DEVICE_NAME_SIZE);
Description = std::string(Props.deviceName, DeviceNameSz);
FloatControlProp.sType =
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT_CONTROLS_PROPERTIES;
FloatControlProp.pNext = nullptr;
DriverProps.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES;
DriverProps.pNext = &FloatControlProp;
Props2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
Props2.pNext = &DriverProps;
vkGetPhysicalDeviceProperties2(PhysicalDevice, &Props2);
const uint64_t DriverNameSz =
strnlen(DriverProps.driverName, VK_MAX_DRIVER_NAME_SIZE);
DriverName = std::string(DriverProps.driverName, DriverNameSz);
#if defined(__APPLE__) && defined(__aarch64__)
// Apple silicon Macs may have multiple Vulkan drivers sharing one device
// name. Include the driver name in the description to enable
// adapter-regex matching.
Description += " (" + DriverName + ")";
#endif
DeviceExtensions = queryDeviceExtensions(PhysicalDevice);
}
VulkanDevice(const VulkanDevice &) = delete;
~VulkanDevice() override {
if (Device != VK_NULL_HANDLE) {
vkDeviceWaitIdle(Device);
vkDestroyDevice(Device, nullptr);
}
}
llvm::StringRef getAPIName() const override { return "Vulkan"; }
GPUAPI getAPI() const override { return GPUAPI::Vulkan; }
Queue &getGraphicsQueue() override { return GraphicsQueue; }
llvm::Expected<std::shared_ptr<offloadtest::Buffer>>
createBuffer(std::string Name, BufferCreateDesc &Desc,
size_t SizeInBytes) override {
VkMemoryPropertyFlags MemFlags = 0;
switch (Desc.Location) {
case MemoryLocation::GpuOnly:
MemFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
break;
case MemoryLocation::CpuToGpu:
MemFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
break;
case MemoryLocation::GpuToCpu:
MemFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
VK_MEMORY_PROPERTY_HOST_CACHED_BIT;
break;
}
VkBufferCreateInfo BufInfo = {};
BufInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
BufInfo.size = SizeInBytes;
BufInfo.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
VK_BUFFER_USAGE_TRANSFER_SRC_BIT |
VK_BUFFER_USAGE_TRANSFER_DST_BIT;
BufInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
VkBuffer DeviceBuffer;
if (vkCreateBuffer(Device, &BufInfo, nullptr, &DeviceBuffer))
return llvm::createStringError(std::errc::not_enough_memory,
"Failed to create device buffer.");
VkMemoryRequirements MemReqs;
vkGetBufferMemoryRequirements(Device, DeviceBuffer, &MemReqs);
VkMemoryAllocateInfo AllocInfo = {};
AllocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
AllocInfo.allocationSize = MemReqs.size;
auto MemIdx =
getMemoryIndex(PhysicalDevice, MemReqs.memoryTypeBits, MemFlags);
if (!MemIdx)
return MemIdx.takeError();
AllocInfo.memoryTypeIndex = *MemIdx;
VkDeviceMemory DeviceMemory;
if (vkAllocateMemory(Device, &AllocInfo, nullptr, &DeviceMemory))
return llvm::createStringError(std::errc::not_enough_memory,
"Failed to allocate device memory.");
if (vkBindBufferMemory(Device, DeviceBuffer, DeviceMemory, 0))
return llvm::createStringError(std::errc::io_error,
"Failed to bind device buffer memory.");
return std::make_shared<VulkanBuffer>(Device, DeviceBuffer, DeviceMemory,
Name, Desc, SizeInBytes);
}
const Capabilities &getCapabilities() override {
if (Caps.empty())
queryCapabilities();
return Caps;
}
void printExtra(llvm::raw_ostream &OS) override {
OS << " Layers:\n";
for (auto &Layer : InstanceLayers) {
uint64_t Sz = strnlen(Layer.layerName, VK_MAX_EXTENSION_NAME_SIZE);
OS << " - LayerName: " << llvm::StringRef(Layer.layerName, Sz) << "\n";
OS << " SpecVersion: " << Layer.specVersion << "\n";
OS << " ImplVersion: " << Layer.implementationVersion << "\n";
Sz = strnlen(Layer.description, VK_MAX_DESCRIPTION_SIZE);
OS << " LayerDesc: " << llvm::StringRef(Layer.description, Sz) << "\n";
}
OS << " Extensions:\n";
for (const auto &Ext : DeviceExtensions) {
OS << " - ExtensionName: " << llvm::StringRef(Ext.extensionName) << "\n";
OS << " SpecVersion: " << Ext.specVersion << "\n";
}
}
const VkPhysicalDeviceProperties &getProps() const { return Props; }
private:
void queryCapabilities() {
VkPhysicalDeviceFeatures2 Features{};
Features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
VkPhysicalDeviceVulkan11Features Features11{};
Features11.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES;
VkPhysicalDeviceVulkan12Features Features12{};
Features12.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES;
VkPhysicalDeviceVulkan13Features Features13{};
Features13.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES;
#ifdef VK_VERSION_1_4
VkPhysicalDeviceVulkan14Features Features14{};
Features14.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_4_FEATURES;
#endif
Features.pNext = &Features11;
if (Props.apiVersion >= VK_MAKE_API_VERSION(0, 1, 2, 0))
Features11.pNext = &Features12;
if (Props.apiVersion >= VK_MAKE_API_VERSION(0, 1, 3, 0))
Features12.pNext = &Features13;
#ifdef VK_VERSION_1_4
if (Props.apiVersion >= VK_MAKE_API_VERSION(0, 1, 4, 0))
Features13.pNext = &Features14;
#endif
vkGetPhysicalDeviceFeatures2(PhysicalDevice, &Features);
Caps.insert(std::make_pair(
"APIMajorVersion",
makeCapability<uint32_t>("APIMajorVersion",
VK_API_VERSION_MAJOR(Props.apiVersion))));
Caps.insert(std::make_pair(
"APIMinorVersion",
makeCapability<uint32_t>("APIMinorVersion",
VK_API_VERSION_MINOR(Props.apiVersion))));
#define VULKAN_FLOAT_CONTROLS_FEATURE_BOOL(Name) \
Caps.insert(std::make_pair( \
#Name, makeCapability<bool>(#Name, FloatControlProp.Name)));
#define VULKAN_FEATURE_BOOL(Name) \
Caps.insert(std::make_pair( \
#Name, makeCapability<bool>(#Name, Features.features.Name)));
#define VULKAN11_FEATURE_BOOL(Name) \
Caps.insert( \
std::make_pair(#Name, makeCapability<bool>(#Name, Features11.Name)));
#define VULKAN12_FEATURE_BOOL(Name) \
Caps.insert( \
std::make_pair(#Name, makeCapability<bool>(#Name, Features12.Name)));
#define VULKAN13_FEATURE_BOOL(Name) \
Caps.insert( \
std::make_pair(#Name, makeCapability<bool>(#Name, Features13.Name)));
#ifdef VK_VERSION_1_4
#define VULKAN14_FEATURE_BOOL(Name) \
Caps.insert( \
std::make_pair(#Name, makeCapability<bool>(#Name, Features14.Name)));
#endif
#include "VKFeatures.def"
}
public:
llvm::Error createDevice(InvocationState &IS) {
VkCommandPoolCreateInfo CmdPoolInfo = {};
CmdPoolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
CmdPoolInfo.queueFamilyIndex = GraphicsQueue.QueueFamilyIdx;
CmdPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
if (vkCreateCommandPool(Device, &CmdPoolInfo, nullptr, &IS.CmdPool))
return llvm::createStringError(std::errc::device_or_resource_busy,
"Could not create command pool.");
return llvm::Error::success();
}
llvm::Error createCommandBuffer(InvocationState &IS) {
VkCommandBufferAllocateInfo CBufAllocInfo = {};
CBufAllocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
CBufAllocInfo.commandPool = IS.CmdPool;
CBufAllocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
CBufAllocInfo.commandBufferCount = 1;
if (vkAllocateCommandBuffers(Device, &CBufAllocInfo, &IS.CmdBuffer))
return llvm::createStringError(std::errc::device_or_resource_busy,
"Could not create command buffer.");
VkCommandBufferBeginInfo BufferInfo = {};
BufferInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
if (vkBeginCommandBuffer(IS.CmdBuffer, &BufferInfo))
return llvm::createStringError(std::errc::device_or_resource_busy,
"Could not begin command buffer.");
return llvm::Error::success();
}
llvm::Expected<BufferRef> createBuffer(VkBufferUsageFlags Usage,
VkMemoryPropertyFlags MemoryFlags,
size_t Size, void *Data = nullptr) {
VkBuffer Buffer;
VkDeviceMemory Memory;
VkBufferCreateInfo BufferInfo = {};
BufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
BufferInfo.size = Size;
BufferInfo.usage = Usage;
BufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
if (vkCreateBuffer(Device, &BufferInfo, nullptr, &Buffer))
return llvm::createStringError(std::errc::not_enough_memory,
"Could not create buffer.");
VkMemoryRequirements MemReqs;
vkGetBufferMemoryRequirements(Device, Buffer, &MemReqs);
VkMemoryAllocateInfo AllocInfo = {};
AllocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
AllocInfo.allocationSize = MemReqs.size;
llvm::Expected<uint32_t> MemIdx =
getMemoryIndex(PhysicalDevice, MemReqs.memoryTypeBits, MemoryFlags);
if (!MemIdx)
return MemIdx.takeError();
AllocInfo.memoryTypeIndex = *MemIdx;
if (vkAllocateMemory(Device, &AllocInfo, nullptr, &Memory))
return llvm::createStringError(std::errc::not_enough_memory,
"Memory allocation failed.");
if (Data) {
void *Dst = nullptr;
if (vkMapMemory(Device, Memory, 0, VK_WHOLE_SIZE, 0, &Dst))
return llvm::createStringError(std::errc::not_enough_memory,
"Failed to map memory.");
memcpy(Dst, Data, Size);
VkMappedMemoryRange Range = {};
Range.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Range.memory = Memory;
Range.offset = 0;
Range.size = VK_WHOLE_SIZE;
vkFlushMappedMemoryRanges(Device, 1, &Range);
vkUnmapMemory(Device, Memory);
}
if (vkBindBufferMemory(Device, Buffer, Memory, 0))
return llvm::createStringError(std::errc::not_enough_memory,
"Failed to bind buffer to memory.");
return BufferRef{Buffer, Memory};
}
llvm::Expected<ResourceRef> createImage(Resource &R, BufferRef &Host,
int UsageOverride = 0) {
const offloadtest::CPUBuffer &B = *R.BufferPtr;
if (B.Format == DataFormat::Depth32 && R.isReadWrite())
return llvm::createStringError(std::errc::invalid_argument,
"Image memory allocation failed.");
VkImageCreateInfo ImageCreateInfo = {};
ImageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
ImageCreateInfo.imageType = getVKImageType(R.Kind);
ImageCreateInfo.format = getVKFormat(B.Format, B.Channels);
ImageCreateInfo.mipLevels = B.OutputProps.MipLevels;
ImageCreateInfo.arrayLayers = 1;
ImageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT;
ImageCreateInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
ImageCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
// Set initial layout of the image to undefined
ImageCreateInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
ImageCreateInfo.extent = {static_cast<uint32_t>(B.OutputProps.Width),
static_cast<uint32_t>(B.OutputProps.Height), 1};
if (UsageOverride == 0) {
ImageCreateInfo.usage =
VK_IMAGE_USAGE_TRANSFER_DST_BIT |
(R.isReadWrite()
? (VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT)
: VK_IMAGE_USAGE_SAMPLED_BIT);
} else {
ImageCreateInfo.usage = UsageOverride;
}
VkImage Image;
if (vkCreateImage(Device, &ImageCreateInfo, nullptr, &Image))
return llvm::createStringError(std::errc::io_error,
"Failed to create image.");
VkSampler Sampler = 0;
VkMemoryRequirements MemReqs;
vkGetImageMemoryRequirements(Device, Image, &MemReqs);
VkMemoryAllocateInfo AllocInfo = {};
AllocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
AllocInfo.allocationSize = MemReqs.size;
VkDeviceMemory Memory;
if (vkAllocateMemory(Device, &AllocInfo, nullptr, &Memory))
return llvm::createStringError(std::errc::not_enough_memory,
"Image memory allocation failed.");
if (vkBindImageMemory(Device, Image, Memory, 0))
return llvm::createStringError(std::errc::not_enough_memory,
"Image memory binding failed.");
return ResourceRef(Host, ImageRef{Image, Sampler, Memory});
}
llvm::Expected<ResourceRef> createSampler(Resource &R, BufferRef &Host) {
VkSamplerCreateInfo SamplerInfo = {};
SamplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
const Sampler &S = *R.SamplerPtr;
SamplerInfo.magFilter = getVKFilter(S.MagFilter);
SamplerInfo.minFilter = getVKFilter(S.MinFilter);
SamplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
SamplerInfo.addressModeU = getVKAddressMode(S.Address);
SamplerInfo.addressModeV = getVKAddressMode(S.Address);
SamplerInfo.addressModeW = getVKAddressMode(S.Address);
SamplerInfo.mipLodBias = S.MipLODBias;
SamplerInfo.anisotropyEnable = VK_FALSE;
SamplerInfo.maxAnisotropy = 1.0f;
SamplerInfo.compareEnable =
S.Kind == SamplerKind::SamplerComparison ? VK_TRUE : VK_FALSE;
SamplerInfo.compareOp = getVKCompareOp(S.ComparisonOp);
SamplerInfo.minLod = S.MinLOD;
SamplerInfo.maxLod = S.MaxLOD;
SamplerInfo.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK;
SamplerInfo.unnormalizedCoordinates = VK_FALSE;
VkSampler Sampler;
if (vkCreateSampler(Device, &SamplerInfo, nullptr, &Sampler))
return llvm::createStringError(std::errc::device_or_resource_busy,
"Failed to create sampler.");
return ResourceRef(Host, ImageRef{0, Sampler, 0});
}
llvm::Error createResource(Resource &R, InvocationState &IS) {
// Samplers don't have backing data buffers, so handle them separately
if (R.isSampler()) {
ResourceBundle Bundle{getDescriptorType(R.Kind), 0, nullptr};
BufferRef HostBuf = {0, 0};
auto ExSamplerRef = createSampler(R, HostBuf);
if (!ExSamplerRef)
return ExSamplerRef.takeError();
Bundle.ResourceRefs.push_back(*ExSamplerRef);
IS.Resources.push_back(Bundle);
return llvm::Error::success();
}
ResourceBundle Bundle{getDescriptorType(R.Kind), R.size(), R.BufferPtr};
for (auto &ResData : R.BufferPtr->Data) {
auto ExHostBuf = createBuffer(
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, R.size(), ResData.get());
if (!ExHostBuf)
return ExHostBuf.takeError();
if (R.isTexture()) {
auto ExImageRef = createImage(R, *ExHostBuf);
if (!ExImageRef)
return ExImageRef.takeError();
// Sampled textures use combined-image-sampler descriptors and need
// both valid image and sampler handles.
if (R.isSampledTexture()) {
BufferRef NullHost = {0, 0};
auto ExSamplerRef = createSampler(R, NullHost);
if (!ExSamplerRef)
return ExSamplerRef.takeError();
ExImageRef->Image.Sampler = ExSamplerRef->Image.Sampler;
}
Bundle.ResourceRefs.push_back(*ExImageRef);
} else {
auto ExDeviceBuf = createBuffer(
getFlagBits(R.Kind) | VK_BUFFER_USAGE_TRANSFER_SRC_BIT |
VK_BUFFER_USAGE_TRANSFER_DST_BIT,