-
Notifications
You must be signed in to change notification settings - Fork 326
Expand file tree
/
Copy pathFrameInterpolationSwapchainVK.cpp
More file actions
2918 lines (2443 loc) · 137 KB
/
FrameInterpolationSwapchainVK.cpp
File metadata and controls
2918 lines (2443 loc) · 137 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
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include "FrameInterpolationSwapchainVK.h"
#include "FrameInterpolationSwapchainVK_UiComposition.h"
#include <FidelityFX/host/ffx_assert.h>
///////////////////////////////////////////////////////////////////
// MODES EXPLAINED
///////////////////////////////////////////////////////////////////
//
// 1. FGSwapchainCompositionMode::eComposeOnPresentQueue
// - closest mode to DX12
// - the present queue needs to have graphics and compute capabilities
// - in FrameInterpolationSwapChainVK::queuePresent:
// - game queue signals the game semaphore
// - dispatches the interpolation on the interpolation queue (can be the game queue). This waits for the game semaphore. Signals the interpolation semaphore
// - interpolation thread:
// - computes the execution time of the interpolation by waiting on the interpolation semaphore
// - computes when the second present should be called
// - present thread (composeAndPresent_presenterThread):
// - acquires a new backbuffer image.
// - Present queue waits for the interpolation and image available semaphores then executes the UI composition of the interpolated image. Signals the composition and frame rendered semaphores.
// - presents the interpolated image (waiting on the frame rendered semaphore).
// - acquires a new backbuffer image.
// - Present queue waits for the image available semaphore then executes the UI composition of the real image. Signals the composition, frame rendered and the present semaphores.
// - thread waits for a given time
// - presents the real image (waiting on the frame rendered semaphore).
//
//
// 2. FGSwapchainCompositionMode::eComposeOnGameQueue
// - legacy vulkan mode
// - the present queue needs to have transfer capability
// - in FrameInterpolationSwapChainVK::queuePresent:
// - game queue signals the game semaphore
// - dispatches the interpolation on the interpolation queue (can be the game queue). This waits for the game semaphore. Signals the interpolation semaphore.
// - game queue waits for the interpolation semaphore then executes the composition of the interpolated image into an intermediate texture. Copies this texture back into the interpolation buffer. Signals the composition semaphore.
// - game queue executes the composition of the real image on the game queue into an intermediate texture. Copies this texture back into the replacement buffer. Signals the composition semaphore.
// - interpolation thread:
// - computes the execution time of the interpolation by waiting on the interpolation semaphore
// - computes when the second present should be called
// - present thread (copyAndPresent_presenterThread):
// - acquires a new backbuffer image.
// - present queue waits for composition and image available semaphores then copies the interpolated image (composed with UI) into the backbuffer image. Signals frame rendered and present semaphores.
// - presents the interpolated image (waiting on the frame rendered semaphore).
// - acquires a new backbuffer image.
// - present queue waits for composition and image available semaphores then copies the replacement image (composed with UI) into the backbuffer image. Signals frame rendered and present semaphores.
// - thread waits for a given time
// - presents the real image (waiting on the frame rendered semaphore).
//
//////////////////////////////////////////////
/// Helper functions and classes
//////////////////////////////////////////////
#define EXIT_ON_VKRESULT_NOT_SUCCESS(res) if (res != VK_SUCCESS) return res;
#define FFX_ASSERT_MESSAGE_FORMAT(test, ...) \
{ \
char msg[128]; \
snprintf(msg, 128 * sizeof(char), __VA_ARGS__); \
FFX_ASSERT_MESSAGE(test, msg); \
} \
#define GET_DEVICE_PROC_ADDR(name) name##Proc = (PFN_##name)vkGetDeviceProcAddr(device, #name);
#define HAS_FLAG(options, flags) (((options) & (flags)) == (flags))
// Some known states during queue family ownership transfer
struct ImageState
{
VkAccessFlags accessMask;
VkImageLayout layout;
};
constexpr ImageState ReplacementBufferTransferState = {VK_ACCESS_SHADER_READ_BIT, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL};
constexpr ImageState InterpolationBufferTransferState = {VK_ACCESS_SHADER_WRITE_BIT, VK_IMAGE_LAYOUT_GENERAL};
VkImageMemoryBarrier getImageMemoryBarrier(VkImage image,
VkAccessFlags srcAccessMask,
VkAccessFlags dstAccessMask,
VkImageLayout oldLayout,
VkImageLayout newLayout,
uint32_t srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
uint32_t dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
uint32_t levelCount = VK_REMAINING_MIP_LEVELS,
uint32_t layerCount = VK_REMAINING_ARRAY_LAYERS)
{
VkImageMemoryBarrier barrier = {};
barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
barrier.pNext = nullptr;
barrier.srcAccessMask = srcAccessMask;
barrier.dstAccessMask = dstAccessMask;
barrier.oldLayout = oldLayout;
barrier.newLayout = newLayout;
barrier.srcQueueFamilyIndex = srcQueueFamilyIndex;
barrier.dstQueueFamilyIndex = dstQueueFamilyIndex;
barrier.image = image;
barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
barrier.subresourceRange.baseMipLevel = 0;
barrier.subresourceRange.levelCount = levelCount;
barrier.subresourceRange.baseArrayLayer = 0;
barrier.subresourceRange.layerCount = layerCount;
return barrier;
}
struct ImageBarrierHelper
{
static const uint32_t Capacity = 3;
VkImageMemoryBarrier barriers[Capacity] = {};
uint32_t count = 0;
void add(VkImageMemoryBarrier barrier)
{
FFX_ASSERT_MESSAGE(count < Capacity, "ImageBarrierHelper capacity exceeded. Please increase it.");
barriers[count] = barrier;
++count;
}
template<typename... T>
void add(T... args)
{
add(getImageMemoryBarrier(args...));
}
void record(VkCommandBuffer commandBuffer,
VkPipelineStageFlags srcStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT)
{
if (count > 0)
{
vkCmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, 0, 0, nullptr, 0, nullptr, count, barriers);
}
}
};
inline void flipBarrier(VkImageMemoryBarrier& barrier)
{
VkAccessFlags dstAccessMask = barrier.dstAccessMask;
barrier.dstAccessMask = barrier.srcAccessMask;
barrier.srcAccessMask = dstAccessMask;
VkImageLayout newLayout = barrier.newLayout;
barrier.newLayout = barrier.oldLayout;
barrier.oldLayout = newLayout;
}
void recordCopy(VkCommandBuffer commandBuffer, VkImage srcImage, VkImage dstImage, uint32_t width, uint32_t height, uint32_t depth = 1)
{
VkImageCopy imageCopy = {};
imageCopy.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
imageCopy.srcSubresource.mipLevel = 0;
imageCopy.srcSubresource.baseArrayLayer = 0;
imageCopy.srcSubresource.layerCount = 1;
imageCopy.srcOffset.x = 0;
imageCopy.srcOffset.y = 0;
imageCopy.srcOffset.z = 0;
imageCopy.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
imageCopy.dstSubresource.mipLevel = 0;
imageCopy.dstSubresource.baseArrayLayer = 0;
imageCopy.dstSubresource.layerCount = 1;
imageCopy.dstOffset.x = 0;
imageCopy.dstOffset.y = 0;
imageCopy.dstOffset.z = 0;
imageCopy.extent.width = width;
imageCopy.extent.height = height;
imageCopy.extent.depth = depth;
vkCmdCopyImage(commandBuffer, srcImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, dstImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &imageCopy);
}
/// Helper class to set the debug name
struct DebugNameSetter
{
VkDevice device;
PFN_vkSetDebugUtilsObjectNameEXT vkSetDebugUtilsObjectNameEXTProc;
DebugNameSetter(VkDevice dev)
{
device = dev;
GET_DEVICE_PROC_ADDR(vkSetDebugUtilsObjectNameEXT);
}
VkResult setDebugName(void* pObject, VkObjectType type, const char* name)
{
if (pObject != nullptr && vkSetDebugUtilsObjectNameEXTProc != nullptr && name != nullptr)
{
VkDebugUtilsObjectNameInfoEXT nameInfo = {};
nameInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
nameInfo.pNext = nullptr;
nameInfo.objectType = type;
nameInfo.objectHandle = (uint64_t)pObject;
nameInfo.pObjectName = name;
return vkSetDebugUtilsObjectNameEXTProc(device, &nameInfo);
}
return VK_SUCCESS;
}
VkResult setDebugName(void* pObject, VkObjectType type, const char* name, uint32_t i)
{
constexpr size_t cBufferSize = 64;
char finalName[cBufferSize];
snprintf(finalName, cBufferSize, name, i);
return setDebugName(pObject, type, finalName);
}
};
VkAccessFlags getVKAccessFlagsFromResourceState2(FfxResourceStates state)
{
switch (state)
{
case FFX_RESOURCE_STATE_COMMON:
return VK_ACCESS_NONE;
case FFX_RESOURCE_STATE_GENERIC_READ:
return VK_ACCESS_SHADER_READ_BIT;
case FFX_RESOURCE_STATE_UNORDERED_ACCESS:
return VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT;
case FFX_RESOURCE_STATE_COMPUTE_READ:
case FFX_RESOURCE_STATE_PIXEL_READ:
case FFX_RESOURCE_STATE_PIXEL_COMPUTE_READ:
return VK_ACCESS_SHADER_READ_BIT;
case FFX_RESOURCE_STATE_COPY_SRC:
return VK_ACCESS_TRANSFER_READ_BIT;
case FFX_RESOURCE_STATE_COPY_DEST:
return VK_ACCESS_TRANSFER_WRITE_BIT;
case FFX_RESOURCE_STATE_INDIRECT_ARGUMENT:
return VK_ACCESS_INDIRECT_COMMAND_READ_BIT;
case FFX_RESOURCE_STATE_PRESENT:
return VK_ACCESS_NONE;
case FFX_RESOURCE_STATE_RENDER_TARGET:
return VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT;
default:
FFX_ASSERT_MESSAGE(false, "State flag not yet supported");
return VK_ACCESS_SHADER_READ_BIT;
}
}
VkImageLayout getVKImageLayoutFromResourceState2(FfxResourceStates state)
{
switch (state)
{
case FFX_RESOURCE_STATE_COMMON:
return VK_IMAGE_LAYOUT_GENERAL;
case FFX_RESOURCE_STATE_GENERIC_READ:
return VK_IMAGE_LAYOUT_GENERAL;
case FFX_RESOURCE_STATE_UNORDERED_ACCESS:
return VK_IMAGE_LAYOUT_GENERAL;
case FFX_RESOURCE_STATE_COMPUTE_READ:
case FFX_RESOURCE_STATE_PIXEL_COMPUTE_READ:
case FFX_RESOURCE_STATE_PIXEL_READ:
return VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
case FFX_RESOURCE_STATE_COPY_SRC:
return VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
case FFX_RESOURCE_STATE_COPY_DEST:
return VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
case FFX_RESOURCE_STATE_PRESENT:
return VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
case FFX_RESOURCE_STATE_RENDER_TARGET:
return VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
case FFX_RESOURCE_STATE_INDIRECT_ARGUMENT:
// this case is for buffers
default:
FFX_ASSERT_MESSAGE(false, "Image layout flag not yet supported");
return VK_IMAGE_LAYOUT_GENERAL;
}
}
// Put the wait semaphores from the VkPresentInfo into the SubmissionSemaphores
void addPresentInfoSemaphores(const VkPresentInfoKHR* pPresentInfo, SubmissionSemaphores& toWait)
{
for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; ++i)
{
toWait.add(pPresentInfo->pWaitSemaphores[i]); // those aren't timeline semaphores
}
}
uint32_t findMemoryType(const VkPhysicalDeviceMemoryProperties& memProperties, uint32_t memoryTypeBits, VkMemoryPropertyFlags properties)
{
for (uint32_t i = 0; i < memProperties.memoryTypeCount; i++)
{
if ((memoryTypeBits & (1 << i)) && (memProperties.memoryTypes[i].propertyFlags & properties) == properties)
{
return i;
}
}
return 0u;
};
bool waitForSemaphoreValue(VkDevice device, VkSemaphore semaphore, uint64_t value, uint64_t nanoseconds = UINT64_MAX, FfxWaitCallbackFunc waitCallback = nullptr)
{
if (semaphore != VK_NULL_HANDLE)
{
VkSemaphoreWaitInfo waitInfo = {};
waitInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_WAIT_INFO;
waitInfo.pNext = nullptr;
waitInfo.flags = 0;
waitInfo.semaphoreCount = 1;
waitInfo.pSemaphores = &semaphore;
waitInfo.pValues = &value;
VkResult res = VK_TIMEOUT;
if (nanoseconds == UINT64_MAX)
{
if (waitCallback)
{
uint64_t waitIntervalInNanoSeconds = 1000000; //1ms
res = vkWaitSemaphores(device, &waitInfo, waitIntervalInNanoSeconds);
while (res == VK_TIMEOUT)
{
res = vkWaitSemaphores(device, &waitInfo, waitIntervalInNanoSeconds);
waitCallback(L"FenceName", value);
}
}
else
{
res = vkWaitSemaphores(device, &waitInfo, nanoseconds);
}
}
else
{
res = vkWaitSemaphores(device, &waitInfo, nanoseconds);
}
return (res == VK_SUCCESS);
}
return false;
}
inline void SafeCloseHandle(HANDLE& handle)
{
if (handle)
{
CloseHandle(handle);
handle = NULL;
}
}
FrameInterpolationSwapChainVK* createFrameInterpolationSwapChain(const VkAllocationCallbacks* pAllocator)
{
FrameInterpolationSwapChainVK* pSwapChainVK = nullptr;
if (pAllocator != nullptr && pAllocator->pfnAllocation != nullptr)
{
void* pData = pAllocator->pfnAllocation(pAllocator->pUserData,
sizeof(FrameInterpolationSwapChainVK),
std::alignment_of<FrameInterpolationSwapChainVK>::value,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
pSwapChainVK = new (pData) FrameInterpolationSwapChainVK();
}
else
{
pSwapChainVK = new FrameInterpolationSwapChainVK();
if (pAllocator != nullptr && pAllocator->pfnInternalAllocation != nullptr)
{
pAllocator->pfnInternalAllocation(
pAllocator->pUserData, sizeof(FrameInterpolationSwapChainVK), VK_INTERNAL_ALLOCATION_TYPE_EXECUTABLE, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
}
}
return pSwapChainVK;
}
void deleteFrameInterpolationSwapChain(FrameInterpolationSwapChainVK* pSwapChainVK, const VkAllocationCallbacks* pAllocator)
{
if (pSwapChainVK != nullptr)
{
if (pAllocator != nullptr && pAllocator->pfnFree != nullptr)
{
pSwapChainVK->~FrameInterpolationSwapChainVK();
pAllocator->pfnFree(pAllocator->pUserData, pSwapChainVK);
}
else
{
delete pSwapChainVK;
if (pAllocator != nullptr && pAllocator->pfnInternalFree != nullptr)
{
pAllocator->pfnInternalFree(
pAllocator->pUserData, sizeof(FrameInterpolationSwapChainVK), VK_INTERNAL_ALLOCATION_TYPE_EXECUTABLE, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
}
}
}
}
VkResult FrameInterpolationSwapChainVK::createImage(ReplacementResource& resource,
VkImageCreateInfo& info,
FfxSurfaceFormat format,
const char* name,
const VkPhysicalDeviceMemoryProperties& memProperties,
const VkAllocationCallbacks* pAllocator)
{
VkResult res = vkCreateImage(presentInfo.device, &info, pAllocator, &resource.image);
EXIT_ON_VKRESULT_NOT_SUCCESS(res);
if (res == VK_SUCCESS)
{
DebugNameSetter debugNameSetter(presentInfo.device);
debugNameSetter.setDebugName(resource.image, VK_OBJECT_TYPE_IMAGE, name); // it's fine if this fails
resource.description.type = FFX_RESOURCE_TYPE_TEXTURE2D;
resource.description.format = format;
resource.description.width = info.extent.width;
resource.description.height = info.extent.height;
resource.description.depth = info.extent.depth;
resource.description.mipCount = info.mipLevels;
resource.description.flags = FFX_RESOURCE_FLAGS_NONE;
resource.description.usage = static_cast<FfxResourceUsage>(FFX_RESOURCE_USAGE_RENDERTARGET | FFX_RESOURCE_USAGE_UAV);
VkMemoryRequirements memRequirements;
vkGetImageMemoryRequirements(presentInfo.device, resource.image, &memRequirements);
VkMemoryAllocateInfo allocateInfo = {};
allocateInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
allocateInfo.pNext = nullptr;
allocateInfo.allocationSize = memRequirements.size;
allocateInfo.memoryTypeIndex = findMemoryType(memProperties, memRequirements.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
res = vkAllocateMemory(presentInfo.device, &allocateInfo, pAllocator, &resource.memory);
if (res == VK_SUCCESS)
{
resource.allocationSize = allocateInfo.allocationSize;
totalUsageInBytes += resource.allocationSize;
}
}
if (res == VK_SUCCESS)
res = vkBindImageMemory(presentInfo.device, resource.image, resource.memory, 0);
if (res != VK_SUCCESS)
destroyImage(resource, pAllocator);
return res;
}
VkResult FrameInterpolationSwapChainVK::createImage(ReplacementResource& resource,
VkImageCreateInfo& info,
FfxSurfaceFormat format,
const char* name,
uint32_t index,
const VkPhysicalDeviceMemoryProperties& memProperties,
const VkAllocationCallbacks* pAllocator)
{
constexpr size_t cBufferSize = 64;
char finalName[cBufferSize];
snprintf(finalName, cBufferSize, name, index);
return createImage(resource, info, format, finalName, memProperties, pAllocator);
}
void FrameInterpolationSwapChainVK::destroyImage(ReplacementResource& resource, const VkAllocationCallbacks* pAllocator)
{
if (resource.image != VK_NULL_HANDLE)
{
vkDestroyImage(presentInfo.device, resource.image, pAllocator);
resource.image = VK_NULL_HANDLE;
}
if (resource.memory != VK_NULL_HANDLE)
{
vkFreeMemory(presentInfo.device, resource.memory, pAllocator);
resource.memory = VK_NULL_HANDLE;
totalUsageInBytes -= resource.allocationSize;
resource.allocationSize = 0;
}
}
//////////////////////////////////////////////
/// Vulkan API overridden functions
//////////////////////////////////////////////
VkResult vkAcquireNextImageFFX(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout, VkSemaphore semaphore, VkFence fence, uint32_t* pImageIndex)
{
if (swapchain != VK_NULL_HANDLE)
{
FrameInterpolationSwapChainVK* pSwapChainVK = reinterpret_cast<FrameInterpolationSwapChainVK*>(swapchain);
return pSwapChainVK->acquireNextImage(device, swapchain, timeout, semaphore, fence, pImageIndex);
}
else
{
// vkAcquireNextImageKHR would crash if swapchain is null.
return VK_ERROR_SURFACE_LOST_KHR;
}
}
VkResult vkCreateSwapchainFFX(VkDevice device,
const VkSwapchainCreateInfoKHR* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkSwapchainKHR* pSwapchain,
const VkFrameInterpolationInfoFFX* pFrameInterpolationInfo)
{
if (pCreateInfo == nullptr || pFrameInterpolationInfo == nullptr)
return VK_ERROR_INITIALIZATION_FAILED;
FrameInterpolationSwapChainVK* pSwapChainVK = createFrameInterpolationSwapChain(pAllocator);
VkResult result = pSwapChainVK->init(pCreateInfo, pFrameInterpolationInfo);
if (result == VK_SUCCESS)
{
*pSwapchain = reinterpret_cast<VkSwapchainKHR>(pSwapChainVK);
}
else
{
pSwapChainVK->destroySwapchain(device, pAllocator);
deleteFrameInterpolationSwapChain(pSwapChainVK, pAllocator);
pSwapChainVK = nullptr;
}
return result;
}
void vkDestroySwapchainFFX(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks* pAllocator)
{
if (swapchain != VK_NULL_HANDLE)
{
FrameInterpolationSwapChainVK* pSwapChainVK = reinterpret_cast<FrameInterpolationSwapChainVK*>(swapchain);
pSwapChainVK->destroySwapchain(device, pAllocator);
delete pSwapChainVK;
}
}
VkResult vkGetSwapchainImagesFFX(VkDevice device, VkSwapchainKHR swapchain, uint32_t* pSwapchainImageCount, VkImage* pSwapchainImages)
{
if (swapchain != VK_NULL_HANDLE)
{
FrameInterpolationSwapChainVK* pSwapChainVK = reinterpret_cast<FrameInterpolationSwapChainVK*>(swapchain);
return pSwapChainVK->getSwapchainImages(device, pSwapchainImageCount, pSwapchainImages);
}
else
{
// vkGetSwapchainImagesKHR would crash if swapchain is null.
// no need to handle the case where pSwapchainImageCount is null as Vulkan itself doesn't handle it
pSwapchainImageCount = 0;
return VK_INCOMPLETE;
}
}
VkResult vkQueuePresentFFX(VkQueue queue, const VkPresentInfoKHR* pPresentInfo)
{
if (pPresentInfo->swapchainCount == 0)
{
return VK_SUCCESS;
}
// We DO NOT support multiple swapchains for now as there is no way to know which swapchain is a frame interpolation one.
// We need to assume that the only one that is passed is indeed a frame interpolation one.
FFX_ASSERT_MESSAGE(pPresentInfo->swapchainCount == 1, "vkQueuePresentFFX doesn't support multiple swapchains");
FrameInterpolationSwapChainVK* pSwapChainVK = reinterpret_cast<FrameInterpolationSwapChainVK*>(pPresentInfo->pSwapchains[0]);
if (pSwapChainVK != nullptr)
{
VkResult res = pSwapChainVK->queuePresent(queue, pPresentInfo);
if (pPresentInfo->pResults != nullptr)
{
pPresentInfo->pResults[0] = res;
}
return res;
}
return VK_ERROR_SURFACE_LOST_KHR;
}
// Provided by VK_EXT_hdr_metadata
void vkSetHdrMetadataFFX(VkDevice device, uint32_t swapchainCount, const VkSwapchainKHR* pSwapchains, const VkHdrMetadataEXT* pMetadata)
{
for (uint32_t i = 0; i < swapchainCount; ++i)
{
FrameInterpolationSwapChainVK* pSwapChainVK = reinterpret_cast<FrameInterpolationSwapChainVK*>(pSwapchains[i]);
pSwapChainVK->setHdrMetadata(device, &pMetadata[i]);
}
}
//////////////////////////////////////////////
/// FFX additional functions
//////////////////////////////////////////////
uint64_t getLastPresentCountFFX(VkSwapchainKHR swapchain)
{
FrameInterpolationSwapChainVK* pSwapChainVK = reinterpret_cast<FrameInterpolationSwapChainVK*>(swapchain);
return pSwapChainVK->getLastPresentCount();
}
//////////////////////////////////////////////
/// FFX API overridden functions
//////////////////////////////////////////////
FFX_API FfxErrorCode ffxGetSwapchainReplacementFunctionsVK(FfxDevice ffxDevice, FfxSwapchainReplacementFunctions* functions)
{
functions->createSwapchainFFX = vkCreateSwapchainFFX;
functions->destroySwapchainKHR = vkDestroySwapchainFFX;
functions->getSwapchainImagesKHR = vkGetSwapchainImagesFFX;
functions->acquireNextImageKHR = vkAcquireNextImageFFX;
functions->queuePresentKHR = vkQueuePresentFFX;
// for extensions, make sure the base functions exist
VkDevice device = static_cast<VkDevice>(ffxDevice);
FFX_ASSERT(device != VK_NULL_HANDLE);
// VK_EXT_hdr_metadata
if (vkGetDeviceProcAddr(device, "vkSetHdrMetadataEXT") != nullptr)
functions->setHdrMetadataEXT = vkSetHdrMetadataFFX;
else
functions->setHdrMetadataEXT = nullptr;
// additional functions only available for frame interpolation swapchain
functions->getLastPresentCountFFX = getLastPresentCountFFX;
return FFX_OK;
}
FfxErrorCode ffxRegisterFrameinterpolationUiResourceVK(FfxSwapchain gameSwapChain, FfxResource uiResource, uint32_t flags)
{
FrameInterpolationSwapChainVK* pSwapChainVK = reinterpret_cast<FrameInterpolationSwapChainVK*>(gameSwapChain);
pSwapChainVK->registerUiResource(uiResource, flags);
return FFX_OK;
}
FFX_API FfxErrorCode ffxSetFrameGenerationConfigToSwapchainVK(FfxFrameGenerationConfig const* config)
{
FfxErrorCode result = FFX_ERROR_INVALID_ARGUMENT;
if (config->swapChain)
{
FrameInterpolationSwapChainVK* frameinterpolationSwapchain = reinterpret_cast<FrameInterpolationSwapChainVK*>(config->swapChain);
if (frameinterpolationSwapchain != VK_NULL_HANDLE)
{
frameinterpolationSwapchain->setFrameGenerationConfig(config);
result = FFX_OK;
}
}
return result;
}
FfxErrorCode ffxConfigureFrameInterpolationSwapchainVK(FfxSwapchain gameSwapChain, FfxFrameInterpolationSwapchainConfigureKey key, void* valuePtr)
{
if (gameSwapChain)
{
FrameInterpolationSwapChainVK* pSwapChainVK = reinterpret_cast<FrameInterpolationSwapChainVK*>(gameSwapChain);
switch (key)
{
case FFX_FI_SWAPCHAIN_CONFIGURE_KEY_WAITCALLBACK:
pSwapChainVK->setWaitCallback(static_cast<FfxWaitCallbackFunc>(valuePtr));
break;
case FFX_FI_SWAPCHAIN_CONFIGURE_KEY_FRAMEPACINGTUNING:
if (valuePtr != nullptr)
{
pSwapChainVK->setFramePacingTuning(static_cast<FfxSwapchainFramePacingTuning*>(valuePtr));
}
break;
return FFX_OK;
}
}
return FFX_ERROR_INVALID_ARGUMENT;
}
FfxResource ffxGetFrameinterpolationTextureVK(FfxSwapchain gameSwapChain)
{
FrameInterpolationSwapChainVK* pSwapChainVK = reinterpret_cast<FrameInterpolationSwapChainVK*>(gameSwapChain);
FfxResource res = pSwapChainVK->interpolationOutput(0);
return res;
}
FfxErrorCode ffxGetFrameinterpolationCommandlistVK(FfxSwapchain gameSwapChain, FfxCommandList& gameCommandlist)
{
FrameInterpolationSwapChainVK* frameinterpolationSwapchain = reinterpret_cast<FrameInterpolationSwapChainVK*>(gameSwapChain);
gameCommandlist = reinterpret_cast<FfxCommandList>(frameinterpolationSwapchain->getInterpolationCommandList());
return FFX_OK;
}
FfxErrorCode ffxReplaceSwapchainForFrameinterpolationVK(FfxCommandQueue gameQueue,
FfxSwapchain& gameSwapChain,
const VkSwapchainCreateInfoKHR* swapchainCreateInfo,
const VkFrameInterpolationInfoFFX* frameInterpolationInfo)
{
FfxErrorCode status = FFX_OK;
VkSwapchainKHR gameSwapchain = reinterpret_cast<VkSwapchainKHR>(gameSwapChain);
FFX_ASSERT(swapchainCreateInfo != VK_NULL_HANDLE);
if (frameInterpolationInfo == nullptr)
return FFX_ERROR_INVALID_ARGUMENT;
FFX_ASSERT(frameInterpolationInfo->device != VK_NULL_HANDLE);
FFX_ASSERT(frameInterpolationInfo->physicalDevice != VK_NULL_HANDLE);
FFX_ASSERT(gameQueue != VK_NULL_HANDLE);
FFX_ASSERT(gameQueue == frameInterpolationInfo->gameQueue.queue);
const VkAllocationCallbacks* pAllocator = frameInterpolationInfo->pAllocator;
VkSwapchainCreateInfoKHR createInfo = *swapchainCreateInfo; // copy
// createInfo.oldSwapchain should be the same as gameSwapchain if not VK_NULL_HANDLE
if (createInfo.oldSwapchain != VK_NULL_HANDLE && createInfo.oldSwapchain != gameSwapchain)
return FFX_ERROR_INVALID_ARGUMENT;
// use the old swapchain to help with resource reuse
createInfo.oldSwapchain = gameSwapchain;
FrameInterpolationSwapChainVK* pSwapChainVK = createFrameInterpolationSwapChain(pAllocator);
VkResult result = pSwapChainVK->init(&createInfo, frameInterpolationInfo);
if (result != VK_SUCCESS)
{
pSwapChainVK->destroySwapchain(frameInterpolationInfo->device, pAllocator);
deleteFrameInterpolationSwapChain(pSwapChainVK, pAllocator);
pSwapChainVK = nullptr;
status = FFX_ERROR_BACKEND_API_ERROR;
}
// as per Vulkan documentation, oldSwapchain is retired - even if creation of the new swapchain fails.
vkDestroySwapchainKHR(frameInterpolationInfo->device, gameSwapchain, pAllocator);
gameSwapChain = reinterpret_cast<VkSwapchainKHR>(pSwapChainVK);
return status;
}
FfxErrorCode ffxWaitForPresents(FfxSwapchain gameSwapChain)
{
FrameInterpolationSwapChainVK* frameinterpolationSwapchain = reinterpret_cast<FrameInterpolationSwapChainVK*>(gameSwapChain);
frameinterpolationSwapchain->waitForPresents();
return FFX_OK;
}
FfxErrorCode ffxFrameInterpolationSwapchainGetGpuMemoryUsageVK(FfxSwapchain gameSwapChain, FfxEffectMemoryUsage* vramUsage)
{
FFX_RETURN_ON_ERROR(vramUsage, FFX_ERROR_INVALID_POINTER);
FrameInterpolationSwapChainVK* pSwapChainVK = reinterpret_cast<FrameInterpolationSwapChainVK*>(gameSwapChain);
pSwapChainVK->getGpuMemoryUsage(vramUsage);
return FFX_OK;
}
//////////////////////////////////////////////
/// Present
//////////////////////////////////////////////
VkResult presentToSwapChain(FrameinterpolationPresentInfo* pPresenter, uint32_t imageIndex, uint32_t semaphoreIndex = 0)
{
VkPresentInfoKHR presentInfoKHR = {};
presentInfoKHR.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
presentInfoKHR.pNext = nullptr;
presentInfoKHR.waitSemaphoreCount = 1;
presentInfoKHR.pWaitSemaphores = &pPresenter->frameRenderedSemaphores[semaphoreIndex];
presentInfoKHR.swapchainCount = 1;
presentInfoKHR.pSwapchains = &pPresenter->realSwapchain;
presentInfoKHR.pImageIndices = &imageIndex;
presentInfoKHR.pResults = nullptr; // Optional
EnterCriticalSection(&pPresenter->swapchainCriticalSection);
VkResult res = vkQueuePresentKHR(pPresenter->presentQueue.queue, &presentInfoKHR);
LeaveCriticalSection(&pPresenter->swapchainCriticalSection);
++(pPresenter->realPresentCount);
return res;
}
VkResult compositeSwapChainFrame(FrameinterpolationPresentInfo* pPresenter,
const PacingData* pPacingEntry,
const PacingData::FrameType frameType,
const uint32_t realSwapchainImageIndex,
const VulkanQueue compositionQueue,
SubmissionSemaphores& semaphoresToWait,
SubmissionSemaphores& semaphoresToSignal,
bool& uiSurfaceTransfered)
{
const PacingData::FrameInfo& frameInfo = pPacingEntry->frames[frameType];
semaphoresToWait.add(pPresenter->interpolationSemaphore, frameInfo.interpolationCompletedSemaphoreValue);
semaphoresToSignal.add(pPresenter->compositionSemaphore, frameInfo.presentIndex);
if (pPacingEntry->presentCallback)
{
auto compositeCommandList = pPresenter->commandPool.get(pPresenter->device, compositionQueue, "compositeCommandList");
VkCommandBuffer compositeCommandBuffer = compositeCommandList->reset();
FfxPresentCallbackDescription desc{};
desc.commandList = ffxGetCommandListVK(compositeCommandBuffer);
desc.device = pPresenter->device;
desc.isInterpolatedFrame = frameType != PacingData::FrameType::Real;
if (pPresenter->compositionMode == FGSwapchainCompositionMode::eComposeOnPresentQueue)
{
desc.outputSwapChainBuffer = ffxGetResourceVK(
pPresenter->realSwapchainImages[realSwapchainImageIndex], pPresenter->realSwapchainImageDescription, nullptr, FFX_RESOURCE_STATE_PRESENT);
}
if (pPresenter->compositionMode == FGSwapchainCompositionMode::eComposeOnGameQueue)
{
desc.outputSwapChainBuffer =
ffxGetResourceVK(pPresenter->compositionOutput.image, pPresenter->compositionOutput.description, nullptr, FFX_RESOURCE_STATE_COPY_SRC);
}
desc.currentBackBuffer = frameInfo.resource;
desc.currentUI = pPacingEntry->uiSurface;
desc.usePremulAlpha = pPacingEntry->usePremulAlphaComposite;
desc.frameID = pPacingEntry->currentFrameID;
// queue family ownership transfer for interpolation output & UI surface
ImageBarrierHelper preCallbackBarriers;
if (pPresenter->interpolationQueue.familyIndex != compositionQueue.familyIndex)
{
if (frameType == PacingData::FrameType::Interpolated_1)
{
// this is the interpolation buffer
preCallbackBarriers.add(static_cast<VkImage>(frameInfo.resource.resource),
InterpolationBufferTransferState.accessMask,
InterpolationBufferTransferState.accessMask,
InterpolationBufferTransferState.layout,
InterpolationBufferTransferState.layout,
pPresenter->interpolationQueue.familyIndex,
compositionQueue.familyIndex);
}
else if (frameType == PacingData::FrameType::Real)
{
// this is the replacement buffer
preCallbackBarriers.add(static_cast<VkImage>(frameInfo.resource.resource),
ReplacementBufferTransferState.accessMask,
ReplacementBufferTransferState.accessMask,
ReplacementBufferTransferState.layout,
ReplacementBufferTransferState.layout,
pPresenter->interpolationQueue.familyIndex,
compositionQueue.familyIndex);
}
}
if (!uiSurfaceTransfered)
{
preCallbackBarriers.add(pPresenter->queueFamilyOwnershipTransferGameToPresent(pPacingEntry->uiSurface));
uiSurfaceTransfered = true;
}
if (pPresenter->compositionMode == FGSwapchainCompositionMode::eComposeOnPresentQueue)
{
// change real image to present layout
preCallbackBarriers.add(pPresenter->realSwapchainImages[realSwapchainImageIndex], 0, 0, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
}
else if (pPresenter->compositionMode == FGSwapchainCompositionMode::eComposeOnGameQueue)
{
// prepare for copy
preCallbackBarriers.add(
pPresenter->compositionOutput.image, 0, VK_ACCESS_TRANSFER_READ_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
}
preCallbackBarriers.record(compositeCommandBuffer);
pPacingEntry->presentCallback(&desc, pPacingEntry->presentCallbackContext);
if (pPresenter->compositionMode == FGSwapchainCompositionMode::eComposeOnGameQueue)
{
// copy back the content of the composition in the replacement or the interpolation output buffer
ImageBarrierHelper preCopyBarriers;
// composition output buffer is already in a VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL layout on the compose queue
// just set resource to copy dest layout
preCopyBarriers.add(static_cast<VkImage>(frameInfo.resource.resource),
0,
VK_ACCESS_TRANSFER_WRITE_BIT,
VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
preCopyBarriers.record(compositeCommandBuffer, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
recordCopy(compositeCommandBuffer,
pPresenter->compositionOutput.image,
static_cast<VkImage>(frameInfo.resource.resource),
pPresenter->realSwapchainImageDescription.width,
pPresenter->realSwapchainImageDescription.height);
ImageBarrierHelper postCopyBarriers;
postCopyBarriers.add(static_cast<VkImage>(frameInfo.resource.resource),
VK_ACCESS_TRANSFER_WRITE_BIT,
VK_ACCESS_TRANSFER_READ_BIT,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
// this will handle the queue family ownership transfer if any
compositionQueue.familyIndex,
pPresenter->presentQueue.familyIndex);
postCopyBarriers.record(compositeCommandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
}
return compositeCommandList->execute(semaphoresToWait, semaphoresToSignal);
}
else
{
return pPresenter->presentQueue.submit(VK_NULL_HANDLE, semaphoresToWait, semaphoresToSignal);
}
}
DWORD WINAPI copyAndPresent_presenterThread(LPVOID pParam)
{
FrameinterpolationPresentInfo* presenter = static_cast<FrameinterpolationPresentInfo*>(pParam);
if (presenter)
{
uint64_t numFramesSentForPresentation = 0;
int64_t previousPresentQpc = 0;
while (!presenter->shutdown)
{
WaitForSingleObject(presenter->pacerEvent, INFINITE);
if (!presenter->shutdown)
{
EnterCriticalSection(&presenter->scheduledFrameCriticalSection);
PacingData entry = presenter->scheduledPresents;
presenter->scheduledPresents.invalidate();
LeaveCriticalSection(&presenter->scheduledFrameCriticalSection);
if (entry.numFramesToPresent > 0)
{
// we might have dropped entries so have to update here, otherwise we might deadlock
// we need to track the latest signaled value to avoid validation warnings
if (presenter->lastPresentSemaphoreValue != entry.numFramesSentForPresentationBase)
{
presenter->presentQueue.submit(VK_NULL_HANDLE, presenter->presentSemaphore, entry.numFramesSentForPresentationBase);
presenter->lastPresentSemaphoreValue = entry.numFramesSentForPresentationBase;
}
for (uint32_t frameType = 0; frameType < PacingData::FrameType::Count; frameType++)
{
const PacingData::FrameInfo& frameInfo = entry.frames[frameType];
if (frameInfo.doPresent)
{
uint32_t imageIndex = 0;
VkSemaphore imageAvailableSemaphore = VK_NULL_HANDLE;
VkResult res = presenter->acquireNextRealImage(imageIndex, imageAvailableSemaphore);
FFX_ASSERT_MESSAGE_FORMAT(res == VK_SUCCESS || res == VK_SUBOPTIMAL_KHR || res == VK_ERROR_OUT_OF_DATE_KHR, "[copyAndPresent_presenterThread] failed to acquire swapchain image");
SubmissionSemaphores toSignal;
SubmissionSemaphores toWait;
toWait.add(presenter->compositionSemaphore, frameInfo.presentIndex); // composition to finish
// no image was acquired, just skip everything and signal the appropriate semaphores
// signal replacement buffer availability
// this is the last present of this entry
if (frameInfo.presentIndex == entry.replacementBufferSemaphoreSignal)
{
toSignal.add(presenter->replacementBufferSemaphore, entry.replacementBufferSemaphoreSignal);
}
// There is no way to signal a semaphore after Present, so signal it before it.
if (frameInfo.presentIndex != entry.numFramesSentForPresentationBase)
{
// no need to signal twice
toSignal.add(presenter->presentSemaphore, frameInfo.presentIndex);
presenter->lastPresentSemaphoreValue = frameInfo.presentIndex;
}
if (res == VK_SUCCESS || res == VK_SUBOPTIMAL_KHR)
{
toWait.add(imageAvailableSemaphore); // swapchain image to be available
auto presentCommandList = presenter->commandPool.get(presenter->device, presenter->presentQueue, "presentCommandList");
VkCommandBuffer presentCommandBuffer = presentCommandList->reset();
ImageBarrierHelper preCopyBarriers;
// newly acquired image transition
preCopyBarriers.add(presenter->realSwapchainImages[imageIndex],
0,
VK_ACCESS_TRANSFER_WRITE_BIT,
VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
// queue family ownership transfer for the texture containing the final image
if (presenter->gameQueue.familyIndex != presenter->presentQueue.familyIndex)
{
preCopyBarriers.add(static_cast<VkImage>(frameInfo.resource.resource),
VK_ACCESS_TRANSFER_WRITE_BIT,
VK_ACCESS_TRANSFER_READ_BIT,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
presenter->gameQueue.familyIndex,
presenter->presentQueue.familyIndex);
}
preCopyBarriers.record(presentCommandBuffer, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);