summaryrefslogtreecommitdiff
path: root/chapters/synchronization.adoc
blob: 6ffbe119bd2fbf4db07f20798f60b0ce8e844357 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
// Copyright 2015-2024 The Khronos Group Inc.
//
// SPDX-License-Identifier: CC-BY-4.0

[[synchronization]]
= Synchronization and Cache Control

Synchronization of access to resources is primarily the responsibility of
the application in Vulkan.
The order of execution of commands with respect to the host and other
commands on the device has few implicit guarantees, and needs to be
explicitly specified.
Memory caches and other optimizations are also explicitly managed, requiring
that the flow of data through the system is largely under application
control.

Whilst some implicit guarantees exist between commands, five explicit
synchronization mechanisms are exposed by Vulkan:

<<synchronization-fences,Fences>>::
    Fences can: be used to communicate to the host that execution of some
    task on the device has completed, controlling resource access between
    host and device.

<<synchronization-semaphores,Semaphores>>::
    Semaphores can: be used to control resource access across multiple
    queues.

<<synchronization-events,Events>>::
    Events provide a fine-grained synchronization primitive which can: be
    signaled either within a command buffer or by the host, and can: be
    waited upon within a command buffer or queried on the host.
    Events can: be used to control resource access within a single queue.

<<synchronization-pipeline-barriers,Pipeline Barriers>>::
    Pipeline barriers also provide synchronization control within a command
    buffer, but at a single point, rather than with separate signal and wait
    operations.
    Pipeline barriers can: be used to control resource access within a
    single queue.

<<renderpass,Render Passes>>::
    Render passes provide a useful synchronization framework for most
    rendering tasks, built upon the concepts in this chapter.
    Many cases that would otherwise need an application to use other
    synchronization primitives can: be expressed more efficiently as part of
    a render pass.
    Render pass objects can: be used to control resource access within a
    single queue.


[[synchronization-dependencies]]
== Execution and Memory Dependencies

An _operation_ is an arbitrary amount of work to be executed on the host, a
device, or an external entity such as a presentation engine.
Synchronization commands introduce explicit _execution dependencies_, and
_memory dependencies_ between two sets of operations defined by the
command's two _synchronization scopes_.

[[synchronization-dependencies-scopes]]
The synchronization scopes define which other operations a synchronization
command is able to create execution dependencies with.
Any type of operation that is not in a synchronization command's
synchronization scopes will not be included in the resulting dependency.
For example, for many synchronization commands, the synchronization scopes
can: be limited to just operations executing in specific
<<synchronization-pipeline-stages,pipeline stages>>, which allows other
pipeline stages to be excluded from a dependency.
Other scoping options are possible, depending on the particular command.

[[synchronization-dependencies-execution]]
An _execution dependency_ is a guarantee that for two sets of operations,
the first set must: _happen-before_ the second set.
If an operation happens-before another operation, then the first operation
must: complete before the second operation is initiated.
More precisely:

  * Let *Ops~1~* and *Ops~2~* be separate sets of operations.
  * Let *Sync* be a synchronization command.
  * Let *Scope~1st~* and *Scope~2nd~* be the synchronization scopes of
    *Sync*.
  * Let *ScopedOps~1~* be the intersection of sets *Ops~1~* and
    *Scope~1st~*.
  * Let *ScopedOps~2~* be the intersection of sets *Ops~2~* and
    *Scope~2nd~*.
  * Submitting *Ops~1~*, *Sync* and *Ops~2~* for execution, in that order,
    will result in execution dependency *ExeDep* between *ScopedOps~1~* and
    *ScopedOps~2~*.
  * Execution dependency *ExeDep* guarantees that *ScopedOps~1~*
    happen-before *ScopedOps~2~*.

[[synchronization-dependencies-chains]]
An _execution dependency chain_ is a sequence of execution dependencies that
form a happens-before relation between the first dependency's *ScopedOps~1~*
and the final dependency's *ScopedOps~2~*.
For each consecutive pair of execution dependencies, a chain exists if the
intersection of *Scope~2nd~* in the first dependency and *Scope~1st~* in the
second dependency is not an empty set.
The formation of a single execution dependency from an execution dependency
chain can be described by substituting the following in the description of
execution dependencies:

  * Let *Sync* be a set of synchronization commands that generate an
    execution dependency chain.
  * Let *Scope~1st~* be the first synchronization scope of the first command
    in *Sync*.
  * Let *Scope~2nd~* be the second synchronization scope of the last command
    in *Sync*.

Execution dependencies alone are not sufficient to guarantee that values
resulting from writes in one set of operations can: be read from another set
of operations.

[[synchronization-dependencies-available-and-visible]]
Three additional types of operations are used to control memory access.
_Availability operations_ cause the values generated by specified memory
write accesses to become _available_ to a memory domain for future access.
Any available value remains available until a subsequent write to the same
memory location occurs (whether it is made available or not) or the memory
is freed.
_Memory domain operations_ cause writes that are available to a source
memory domain to become available to a destination memory domain (an example
of this is making writes available to the host domain available to the
device domain).
_Visibility operations_ cause values available to a memory domain to become
_visible_ to specified memory accesses.

ifdef::VK_VERSION_1_2,VK_KHR_vulkan_memory_model[]
Availability, visibility, memory domains, and memory domain operations are
formally defined in the <<memory-model-availability-visibility,Availability
and Visibility>> section of the <<memory-model,Memory Model>> chapter.
Which API operations perform each of these operations is defined in
<<memory-model-vulkan-availability-visibility,Availability, Visibility, and
Domain Operations>>.
endif::VK_VERSION_1_2,VK_KHR_vulkan_memory_model[]

[[synchronization-dependencies-memory]]
A _memory dependency_ is an execution dependency which includes availability
and visibility operations such that:

  * The first set of operations happens-before the availability operation.
  * The availability operation happens-before the visibility operation.
  * The visibility operation happens-before the second set of operations.

Once written values are made visible to a particular type of memory access,
they can: be read or written by that type of memory access.
Most synchronization commands in Vulkan define a memory dependency.

[[synchronization-dependencies-access-scopes]]
The specific memory accesses that are made available and visible are defined
by the _access scopes_ of a memory dependency.
Any type of access that is in a memory dependency's first access scope and
occurs in *ScopedOps~1~* is made available.
Any type of access that is in a memory dependency's second access scope and
occurs in *ScopedOps~2~* has any available writes made visible to it.
Any type of operation that is not in a synchronization command's access
scopes will not be included in the resulting dependency.

A memory dependency enforces availability and visibility of memory accesses
and execution order between two sets of operations.
Adding to the description of <<synchronization-dependencies-chains,
execution dependency chains>>:

  * Let *MemOps~1~* be the set of memory accesses performed by
    *ScopedOps~1~*.
  * Let *MemOps~2~* be the set of memory accesses performed by
    *ScopedOps~2~*.
  * Let *AccessScope~1st~* be the first access scope of the first command in
    the *Sync* chain.
  * Let *AccessScope~2nd~* be the second access scope of the last command in
    the *Sync* chain.
  * Let *ScopedMemOps~1~* be the intersection of sets *MemOps~1~* and
    *AccessScope~1st~*.
  * Let *ScopedMemOps~2~* be the intersection of sets *MemOps~2~* and
    *AccessScope~2nd~*.
  * Submitting *Ops~1~*, *Sync*, and *Ops~2~* for execution, in that order,
    will result in a memory dependency *MemDep* between *ScopedOps~1~* and
    *ScopedOps~2~*.
  * Memory dependency *MemDep* guarantees that:
  ** Memory writes in *ScopedMemOps~1~* are made available.
  ** Available memory writes, including those from *ScopedMemOps~1~*, are
     made visible to *ScopedMemOps~2~*.

[NOTE]
.Note
====
Execution and memory dependencies are used to solve data hazards, i.e. to
ensure that read and write operations occur in a well-defined order.
Write-after-read hazards can be solved with just an execution dependency,
but read-after-write and write-after-write hazards need appropriate memory
dependencies to be included between them.
If an application does not include dependencies to solve these hazards, the
results and execution orders of memory accesses are undefined:.
====


[[synchronization-image-layout-transitions]]
=== Image Layout Transitions

Image subresources can: be transitioned from one <<resources-image-layouts,
layout>> to another as part of a <<synchronization-dependencies-memory,
memory dependency>> (e.g. by using an
<<synchronization-image-memory-barriers,image memory barrier>>).
When a layout transition is specified in a memory dependency, it
happens-after the availability operations in the memory dependency, and
happens-before the visibility operations.
Image layout transitions may: perform read and write accesses on all memory
bound to the image subresource range, so applications must: ensure that all
memory writes have been made
<<synchronization-dependencies-available-and-visible, available>> before a
layout transition is executed.
Available memory is automatically made visible to a layout transition, and
writes performed by a layout transition are automatically made available.

Layout transitions always apply to a particular image subresource range, and
specify both an old layout and new layout.
The old layout must: either be ename:VK_IMAGE_LAYOUT_UNDEFINED, or match the
current layout of the image subresource range.
If the old layout matches the current layout of the image subresource range,
the transition preserves the contents of that range.
If the old layout is ename:VK_IMAGE_LAYOUT_UNDEFINED, the contents of that
range may: be discarded.

[NOTE]
.Note
====
Image layout transitions with ename:VK_IMAGE_LAYOUT_UNDEFINED allow the
implementation to discard the image subresource range, which can provide
performance or power benefits.
Tile-based architectures may be able to avoid flushing tile data to memory,
and immediate style renderers may be able to achieve fast metadata clears to
reinitialize frame buffer compression state, or similar.

If the contents of an attachment are not needed after a render pass
completes, then applications should: use
ename:VK_ATTACHMENT_STORE_OP_DONT_CARE.
====

ifdef::VK_VERSION_1_1,VK_KHR_device_group[]
As image layout transitions may: perform read and write accesses on the
memory bound to the image, if the image subresource affected by the layout
transition is bound to peer memory for any device in the current device mask
then the memory heap the bound memory comes from must: support the
ename:VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT and
ename:VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT capabilities as returned by
flink:vkGetDeviceGroupPeerMemoryFeatures.
endif::VK_VERSION_1_1,VK_KHR_device_group[]

[NOTE]
.Note
====
Applications must: ensure that layout transitions happen-after all
operations accessing the image with the old layout, and happen-before any
operations that will access the image with the new layout.
Layout transitions are potentially read/write operations, so not defining
appropriate memory dependencies to guarantee this will result in a data
race.
====

Image layout transitions interact with <<resources-memory-aliasing,memory
aliasing>>.


[[synchronization-image-barrier-layout-transition-order]]
Layout transitions that are performed via image memory barriers execute in
their entirety in <<synchronization-submission-order, submission order>>,
relative to other image layout transitions submitted to the same queue,
including those performed by <<renderpass, render passes>>.
In effect there is an implicit execution dependency from each such layout
transition to all layout transitions previously submitted to the same queue.

ifdef::VK_EXT_sample_locations[]

The image layout of each image subresource of a depth/stencil image created
with ename:VK_IMAGE_CREATE_SAMPLE_LOCATIONS_COMPATIBLE_DEPTH_BIT_EXT is
dependent on the last sample locations used to render to the image
subresource as a depth/stencil attachment, thus when the pname:image member
of an <<synchronization-image-memory-barriers, image memory barrier>> is an
image created with this flag the application can: chain a
slink:VkSampleLocationsInfoEXT structure to the pname:pNext chain of
ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
slink:VkImageMemoryBarrier2 or
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]
slink:VkImageMemoryBarrier to specify the sample locations to use during any
image layout transition.

If the sname:VkSampleLocationsInfoEXT structure does not match the sample
location state last used to render to the image subresource range specified
by pname:subresourceRange, or if no sname:VkSampleLocationsInfoEXT structure
is present, then the contents of the given image subresource range becomes
undefined: as if pname:oldLayout would equal
ename:VK_IMAGE_LAYOUT_UNDEFINED.

endif::VK_EXT_sample_locations[]


[[synchronization-pipeline-stages]]
=== Pipeline Stages

The work performed by an <<fundamentals-queueoperation-command-types, action
command>> consists of multiple operations, which are performed as a sequence
of logically independent steps known as _pipeline stages_.
The exact pipeline stages executed depend on the particular command that is
used, and current command buffer state when the command was recorded.

[NOTE]
.Note
====
Operations performed by synchronization commands (e.g.
<<synchronization-dependencies-available-and-visible, availability and
visibility operations>>) are not executed by a defined pipeline stage.
However other commands can still synchronize with them by using the
<<synchronization-dependencies-scopes, synchronization scopes>> to create a
<<synchronization-dependencies-chains, dependency chain>>.
====

Execution of operations across pipeline stages must: adhere to
<<synchronization-implicit, implicit ordering guarantees>>, particularly
including <<synchronization-pipeline-stages-order, pipeline stage order>>.
Otherwise, execution across pipeline stages may: overlap or execute out of
order with regards to other stages, unless otherwise enforced by an
execution dependency.

Several of the synchronization commands include pipeline stage parameters,
restricting the <<synchronization-dependencies-scopes, synchronization
scopes>> for that command to just those stages.
This allows fine grained control over the exact execution dependencies and
accesses performed by action commands.
Implementations should: use these pipeline stages to avoid unnecessary
stalls or cache flushing.

ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
[open,refpage='VkPipelineStageFlagBits2',desc='Pipeline stage flags for VkPipelineStageFlags2',type='enums',alias='VkPipelineStageFlagBits2KHR']
--
Bits which can: be set in a tlink:VkPipelineStageFlags2 mask, specifying
stages of execution, are:

ifdef::editing-notes[]
[NOTE]
.editing-note
====
The many places pipeline stage flags are used are not currently listed here.
====
endif::editing-notes[]

include::{generated}/api/enums/VkPipelineStageFlagBits2.adoc[]

ifdef::VK_KHR_synchronization2[]
or the equivalent

include::{generated}/api/enums/VkPipelineStageFlagBits2KHR.adoc[]
endif::VK_KHR_synchronization2[]

  * ename:VK_PIPELINE_STAGE_2_NONE specifies no stages of execution.
  * ename:VK_PIPELINE_STAGE_2_DRAW_INDIRECT_BIT specifies the stage of the
    pipeline where indirect command parameters are consumed.
ifdef::VK_NV_device_generated_commands[]
    This stage also includes reading commands written by
    flink:vkCmdPreprocessGeneratedCommandsNV.
endif::VK_NV_device_generated_commands[]
ifdef::VK_NV_mesh_shader,VK_EXT_mesh_shader[]
  * ename:VK_PIPELINE_STAGE_2_TASK_SHADER_BIT_EXT specifies the task shader
    stage.
  * ename:VK_PIPELINE_STAGE_2_MESH_SHADER_BIT_EXT specifies the mesh shader
    stage.
endif::VK_NV_mesh_shader,VK_EXT_mesh_shader[]
  * ename:VK_PIPELINE_STAGE_2_INDEX_INPUT_BIT specifies the stage of the
    pipeline where index buffers are consumed.
  * ename:VK_PIPELINE_STAGE_2_VERTEX_ATTRIBUTE_INPUT_BIT specifies the stage
    of the pipeline where vertex buffers are consumed.
  * ename:VK_PIPELINE_STAGE_2_VERTEX_INPUT_BIT is equivalent to the logical
    OR of:
include::{generated}/sync/flagDefinitions/VK_PIPELINE_STAGE_2_VERTEX_INPUT_BIT.adoc[]
  * ename:VK_PIPELINE_STAGE_2_VERTEX_SHADER_BIT specifies the vertex shader
    stage.
  * ename:VK_PIPELINE_STAGE_2_TESSELLATION_CONTROL_SHADER_BIT specifies the
    tessellation control shader stage.
  * ename:VK_PIPELINE_STAGE_2_TESSELLATION_EVALUATION_SHADER_BIT specifies
    the tessellation evaluation shader stage.
  * ename:VK_PIPELINE_STAGE_2_GEOMETRY_SHADER_BIT specifies the geometry
    shader stage.
  * ename:VK_PIPELINE_STAGE_2_PRE_RASTERIZATION_SHADERS_BIT is equivalent to
    specifying all supported
    <<pipelines-graphics-subsets-pre-rasterization,pre-rasterization shader
    stages>>:
include::{generated}/sync/flagDefinitions/VK_PIPELINE_STAGE_2_PRE_RASTERIZATION_SHADERS_BIT.adoc[]
  * ename:VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT specifies the fragment
    shader stage.
  * ename:VK_PIPELINE_STAGE_2_EARLY_FRAGMENT_TESTS_BIT specifies the stage
    of the pipeline where early fragment tests (depth and stencil tests
    before fragment shading) are performed.
    This stage also includes <<renderpass-load-operations, render pass load
    operations>> for framebuffer attachments with a depth/stencil format.
  * ename:VK_PIPELINE_STAGE_2_LATE_FRAGMENT_TESTS_BIT specifies the stage of
    the pipeline where late fragment tests (depth and stencil tests after
    fragment shading) are performed.
    This stage also includes <<renderpass-store-operations, render pass
    store operations>> for framebuffer attachments with a depth/stencil
    format.
  * ename:VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT specifies the
    stage of the pipeline where final color values are output from the
    pipeline.
    This stage includes <<framebuffer-blending, blending>>,
    <<framebuffer-logicop, logic operations>>, render pass
    <<renderpass-load-operations, load>> and <<renderpass-store-operations,
    store>> operations for color attachments,
    <<renderpass-resolve-operations, render pass multisample resolve
    operations>>, and flink:vkCmdClearAttachments.
  * ename:VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT specifies the compute
    shader stage.
  * ename:VK_PIPELINE_STAGE_2_HOST_BIT specifies a pseudo-stage indicating
    execution on the host of reads/writes of device memory.
    This stage is not invoked by any commands recorded in a command buffer.
  * ename:VK_PIPELINE_STAGE_2_COPY_BIT specifies the execution of all
    <<copies,copy commands>>, including flink:vkCmdCopyQueryPoolResults.
  * ename:VK_PIPELINE_STAGE_2_BLIT_BIT specifies the execution of
    flink:vkCmdBlitImage.
  * ename:VK_PIPELINE_STAGE_2_RESOLVE_BIT specifies the execution of
    flink:vkCmdResolveImage.
  * ename:VK_PIPELINE_STAGE_2_CLEAR_BIT specifies the execution of
    <<clears,clear commands>>, with the exception of
    flink:vkCmdClearAttachments.
  * ename:VK_PIPELINE_STAGE_2_ALL_TRANSFER_BIT is equivalent to specifying
    all of:
include::{generated}/sync/flagDefinitions/VK_PIPELINE_STAGE_2_ALL_TRANSFER_BIT.adoc[]
ifdef::VK_KHR_ray_tracing_pipeline,VK_NV_ray_tracing[]
  * ename:VK_PIPELINE_STAGE_2_RAY_TRACING_SHADER_BIT_KHR specifies the
    execution of the ray tracing shader stages.
endif::VK_KHR_ray_tracing_pipeline,VK_NV_ray_tracing[]
ifdef::VK_KHR_acceleration_structure,VK_NV_ray_tracing[]
  * ename:VK_PIPELINE_STAGE_2_ACCELERATION_STRUCTURE_BUILD_BIT_KHR specifies
    the execution of <<acceleration-structure, acceleration structure
    commands>> or <<acceleration-structure-copying, acceleration structure
    copy commands>>.
ifdef::VK_KHR_ray_tracing_maintenance1[]
  * ename:VK_PIPELINE_STAGE_2_ACCELERATION_STRUCTURE_COPY_BIT_KHR specifies
    the execution of <<acceleration-structure-copying, acceleration
    structure copy commands>>.
endif::VK_KHR_ray_tracing_maintenance1[]
endif::VK_KHR_acceleration_structure,VK_NV_ray_tracing[]
  * ename:VK_PIPELINE_STAGE_2_ALL_GRAPHICS_BIT specifies the execution of
    all graphics pipeline stages, and is equivalent to the logical OR of:
include::{generated}/sync/flagDefinitions/VK_PIPELINE_STAGE_2_ALL_GRAPHICS_BIT.adoc[]
  * ename:VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT specifies all operations
    performed by all commands supported on the queue it is used with.
ifdef::VK_EXT_conditional_rendering[]
  * ename:VK_PIPELINE_STAGE_2_CONDITIONAL_RENDERING_BIT_EXT specifies the
    stage of the pipeline where the predicate of conditional rendering is
    consumed.
endif::VK_EXT_conditional_rendering[]
ifdef::VK_EXT_transform_feedback[]
  * ename:VK_PIPELINE_STAGE_2_TRANSFORM_FEEDBACK_BIT_EXT specifies the stage
    of the pipeline where vertex attribute output values are written to the
    transform feedback buffers.
endif::VK_EXT_transform_feedback[]
ifdef::VK_NV_device_generated_commands[]
  * ename:VK_PIPELINE_STAGE_2_COMMAND_PREPROCESS_BIT_NV specifies the stage
    of the pipeline where device-side generation of commands via
    flink:vkCmdPreprocessGeneratedCommandsNV is handled.
endif::VK_NV_device_generated_commands[]
ifdef::VK_KHR_fragment_shading_rate,VK_NV_shading_rate_image[]
  * ename:VK_PIPELINE_STAGE_2_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR
    specifies the stage of the pipeline where the
ifdef::VK_KHR_fragment_shading_rate[]
    <<primsrast-fragment-shading-rate-attachment, fragment shading rate
    attachment>>
endif::VK_KHR_fragment_shading_rate[]
ifdef::VK_KHR_fragment_shading_rate+VK_NV_shading_rate_image[or]
ifdef::VK_NV_shading_rate_image[]
    <<primsrast-shading-rate-image, shading rate image>>
endif::VK_NV_shading_rate_image[]
    is read to determine the fragment shading rate for portions of a
    rasterized primitive.
endif::VK_KHR_fragment_shading_rate,VK_NV_shading_rate_image[]
ifdef::VK_EXT_fragment_density_map[]
  * ename:VK_PIPELINE_STAGE_2_FRAGMENT_DENSITY_PROCESS_BIT_EXT specifies the
    stage of the pipeline where the fragment density map is read to
    <<fragmentdensitymapops,generate the fragment areas>>.
endif::VK_EXT_fragment_density_map[]
ifdef::VK_HUAWEI_invocation_mask[]
  * ename:VK_PIPELINE_STAGE_2_INVOCATION_MASK_BIT_HUAWEI specifies the stage
    of the pipeline where the invocation mask image is read by the
    implementation to optimize the ray dispatch.
endif::VK_HUAWEI_invocation_mask[]
ifdef::VK_KHR_video_decode_queue[]
  * ename:VK_PIPELINE_STAGE_2_VIDEO_DECODE_BIT_KHR specifies the execution
    of <<video-decode-operations, video decode operations>>.
endif::VK_KHR_video_decode_queue[]
ifdef::VK_KHR_video_encode_queue[]
  * ename:VK_PIPELINE_STAGE_2_VIDEO_ENCODE_BIT_KHR specifies the execution
    of <<video-encode-operations, video encode operations>>.
endif::VK_KHR_video_encode_queue[]
ifdef::VK_NV_optical_flow[]
  * ename:VK_PIPELINE_STAGE_2_OPTICAL_FLOW_BIT_NV specifies the stage of the
    pipeline where <<opticalflow-operations, optical flow operation>> are
    performed.
endif::VK_NV_optical_flow[]
ifdef::VK_HUAWEI_subpass_shading[]
  * ename:VK_PIPELINE_STAGE_2_SUBPASS_SHADER_BIT_HUAWEI specifies the
    subpass shading shader stage.
endif::VK_HUAWEI_subpass_shading[]
ifdef::VK_EXT_opacity_micromap[]
  * ename:VK_PIPELINE_STAGE_2_MICROMAP_BUILD_BIT_EXT specifies the execution
    of <<micromap, micromap commands>>.
endif::VK_EXT_opacity_micromap[]
ifdef::VK_HUAWEI_cluster_culling_shader[]
  * ename:VK_PIPELINE_STAGE_2_CLUSTER_CULLING_SHADER_BIT_HUAWEI specifies
    the cluster culling shader stage.
endif::VK_HUAWEI_cluster_culling_shader[]
  * ename:VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT is equivalent to
    ename:VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT with tlink:VkAccessFlags2 set
    to `0` when specified in the second synchronization scope, but
    equivalent to ename:VK_PIPELINE_STAGE_2_NONE in the first scope.
  * ename:VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT is equivalent to
    ename:VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT with tlink:VkAccessFlags2 set
    to `0` when specified in the first synchronization scope, but equivalent
    to ename:VK_PIPELINE_STAGE_2_NONE in the second scope.

[NOTE]
.Note
====
The etext:TOP and etext:BOTTOM pipeline stages are deprecated, and
applications should prefer ename:VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT and
ename:VK_PIPELINE_STAGE_2_NONE.
====

[NOTE]
.Note
====
The tname:VkPipelineStageFlags2 bitmask goes beyond the 31 individual bit
flags allowable within a C99 enum, which is how
elink:VkPipelineStageFlagBits is defined.
The first 31 values are common to both, and are interchangeable.
====
--

[open,refpage='VkPipelineStageFlags2',desc='64-bit mask of pipeline stage flags',type='flags',alias='VkPipelineStageFlags2KHR']
--
tname:VkPipelineStageFlags2 is a bitmask type for setting a mask of zero or
more elink:VkPipelineStageFlagBits2 flags:

include::{generated}/api/flags/VkPipelineStageFlags2.adoc[]

ifdef::VK_KHR_synchronization2[]
or the equivalent

include::{generated}/api/flags/VkPipelineStageFlags2KHR.adoc[]
endif::VK_KHR_synchronization2[]
--
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]

[open,refpage='VkPipelineStageFlagBits',desc='Bitmask specifying pipeline stages',type='enums']
--
Bits which can: be set in a tlink:VkPipelineStageFlags mask, specifying
stages of execution, are:

include::{generated}/api/enums/VkPipelineStageFlagBits.adoc[]

ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
These values all have the same meaning as the equivalently named values for
tlink:VkPipelineStageFlags2.
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]

ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
  * ename:VK_PIPELINE_STAGE_NONE specifies no stages of execution.
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]
  * ename:VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT specifies the stage of the
    pipeline where stext:VkDrawIndirect* / stext:VkDispatchIndirect* /
    stext:VkTraceRaysIndirect* data structures are consumed.
ifdef::VK_NV_device_generated_commands[]
    This stage also includes reading commands written by
    flink:vkCmdExecuteGeneratedCommandsNV.
endif::VK_NV_device_generated_commands[]
ifdef::VK_NV_mesh_shader,VK_EXT_mesh_shader[]
  * ename:VK_PIPELINE_STAGE_TASK_SHADER_BIT_EXT specifies the task shader
    stage.
  * ename:VK_PIPELINE_STAGE_MESH_SHADER_BIT_EXT specifies the mesh shader
    stage.
endif::VK_NV_mesh_shader,VK_EXT_mesh_shader[]
  * ename:VK_PIPELINE_STAGE_VERTEX_INPUT_BIT specifies the stage of the
    pipeline where vertex and index buffers are consumed.
  * ename:VK_PIPELINE_STAGE_VERTEX_SHADER_BIT specifies the vertex shader
    stage.
  * ename:VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT specifies the
    tessellation control shader stage.
  * ename:VK_PIPELINE_STAGE_TESSELLATION_EVALUATION_SHADER_BIT specifies the
    tessellation evaluation shader stage.
  * ename:VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT specifies the geometry
    shader stage.
  * ename:VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT specifies the fragment
    shader stage.
  * ename:VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT specifies the stage of
    the pipeline where early fragment tests (depth and stencil tests before
    fragment shading) are performed.
    This stage also includes <<renderpass-load-operations, render pass load
    operations>> for framebuffer attachments with a depth/stencil format.
  * ename:VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT specifies the stage of
    the pipeline where late fragment tests (depth and stencil tests after
    fragment shading) are performed.
    This stage also includes <<renderpass-store-operations, render pass
    store operations>> for framebuffer attachments with a depth/stencil
    format.
  * ename:VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT specifies the stage
    of the pipeline after blending where the final color values are output
    from the pipeline.
    This stage includes <<framebuffer-blending, blending>>,
    <<framebuffer-logicop, logic operations>>, render pass
    <<renderpass-load-operations, load>> and <<renderpass-store-operations,
    store>> operations for color attachments,
    <<renderpass-resolve-operations, render pass multisample resolve
    operations>>, and flink:vkCmdClearAttachments.
  * ename:VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT specifies the execution of a
    compute shader.
  * [[synchronization-pipeline-stages-transfer]]
    ename:VK_PIPELINE_STAGE_TRANSFER_BIT specifies the following commands:
  ** All <<copies,copy commands>>, including flink:vkCmdCopyQueryPoolResults
ifndef::VK_VERSION_1_3,VK_KHR_copy_commands2[]
  ** flink:vkCmdBlitImage
  ** flink:vkCmdResolveImage
endif::VK_VERSION_1_3,VK_KHR_copy_commands2[]
ifdef::VK_VERSION_1_3,VK_KHR_copy_commands2[]
  ** flink:vkCmdBlitImage2 and flink:vkCmdBlitImage
  ** flink:vkCmdResolveImage2 and flink:vkCmdResolveImage
endif::VK_VERSION_1_3,VK_KHR_copy_commands2[]
  ** All <<clears,clear commands>>, with the exception of
     flink:vkCmdClearAttachments
  * ename:VK_PIPELINE_STAGE_HOST_BIT specifies a pseudo-stage indicating
    execution on the host of reads/writes of device memory.
    This stage is not invoked by any commands recorded in a command buffer.
ifdef::VK_NV_ray_tracing,VK_KHR_acceleration_structure[]
  * ename:VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR specifies
    the execution of
ifdef::VK_NV_ray_tracing[]
    flink:vkCmdBuildAccelerationStructureNV,
    flink:vkCmdCopyAccelerationStructureNV,
    flink:vkCmdWriteAccelerationStructuresPropertiesNV
endif::VK_NV_ray_tracing[]
ifdef::VK_NV_ray_tracing+VK_KHR_acceleration_structure[,]
ifdef::VK_KHR_acceleration_structure[]
    flink:vkCmdBuildAccelerationStructuresKHR,
    flink:vkCmdBuildAccelerationStructuresIndirectKHR,
    flink:vkCmdCopyAccelerationStructureKHR,
    flink:vkCmdCopyAccelerationStructureToMemoryKHR,
    flink:vkCmdCopyMemoryToAccelerationStructureKHR, and
    flink:vkCmdWriteAccelerationStructuresPropertiesKHR.
endif::VK_KHR_acceleration_structure[]
endif::VK_NV_ray_tracing,VK_KHR_acceleration_structure[]
ifdef::VK_NV_ray_tracing,VK_KHR_ray_tracing_pipeline[]
  * ename:VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR specifies the
    execution of the ray tracing shader stages, via
ifdef::VK_NV_ray_tracing[flink:vkCmdTraceRaysNV]
ifdef::VK_NV_ray_tracing+VK_KHR_ray_tracing_pipeline[,]
ifdef::VK_KHR_ray_tracing_pipeline[flink:vkCmdTraceRaysKHR, or flink:vkCmdTraceRaysIndirectKHR]
endif::VK_NV_ray_tracing,VK_KHR_ray_tracing_pipeline[]
  * ename:VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT specifies the execution of all
    graphics pipeline stages, and is equivalent to the logical OR of:
  ** ename:VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT
ifdef::VK_NV_mesh_shader,VK_EXT_mesh_shader[]
  ** ename:VK_PIPELINE_STAGE_TASK_SHADER_BIT_EXT
  ** ename:VK_PIPELINE_STAGE_MESH_SHADER_BIT_EXT
endif::VK_NV_mesh_shader,VK_EXT_mesh_shader[]
  ** ename:VK_PIPELINE_STAGE_VERTEX_INPUT_BIT
  ** ename:VK_PIPELINE_STAGE_VERTEX_SHADER_BIT
  ** ename:VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT
  ** ename:VK_PIPELINE_STAGE_TESSELLATION_EVALUATION_SHADER_BIT
  ** ename:VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT
  ** ename:VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
  ** ename:VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
  ** ename:VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT
  ** ename:VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
ifdef::VK_EXT_conditional_rendering[]
  ** ename:VK_PIPELINE_STAGE_CONDITIONAL_RENDERING_BIT_EXT
endif::VK_EXT_conditional_rendering[]
ifdef::VK_EXT_transform_feedback[]
  ** ename:VK_PIPELINE_STAGE_TRANSFORM_FEEDBACK_BIT_EXT
endif::VK_EXT_transform_feedback[]
ifdef::VK_KHR_fragment_shading_rate,VK_NV_shading_rate_image[]
  ** ename:VK_PIPELINE_STAGE_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR
endif::VK_KHR_fragment_shading_rate,VK_NV_shading_rate_image[]
ifdef::VK_EXT_fragment_density_map[]
  ** ename:VK_PIPELINE_STAGE_FRAGMENT_DENSITY_PROCESS_BIT_EXT
endif::VK_EXT_fragment_density_map[]
  * ename:VK_PIPELINE_STAGE_ALL_COMMANDS_BIT specifies all operations
    performed by all commands supported on the queue it is used with.
ifdef::VK_EXT_conditional_rendering[]
  * ename:VK_PIPELINE_STAGE_CONDITIONAL_RENDERING_BIT_EXT specifies the
    stage of the pipeline where the predicate of conditional rendering is
    consumed.
endif::VK_EXT_conditional_rendering[]
ifdef::VK_EXT_transform_feedback[]
  * ename:VK_PIPELINE_STAGE_TRANSFORM_FEEDBACK_BIT_EXT specifies the stage
    of the pipeline where vertex attribute output values are written to the
    transform feedback buffers.
endif::VK_EXT_transform_feedback[]
ifdef::VK_NV_device_generated_commands[]
  * ename:VK_PIPELINE_STAGE_COMMAND_PREPROCESS_BIT_NV specifies the stage of
    the pipeline where device-side preprocessing for generated commands via
    flink:vkCmdPreprocessGeneratedCommandsNV is handled.
endif::VK_NV_device_generated_commands[]
ifdef::VK_KHR_fragment_shading_rate,VK_NV_shading_rate_image[]
  * ename:VK_PIPELINE_STAGE_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR
    specifies the stage of the pipeline where the
ifdef::VK_KHR_fragment_shading_rate[]
    <<primsrast-fragment-shading-rate-attachment, fragment shading rate
    attachment>>
endif::VK_KHR_fragment_shading_rate[]
ifdef::VK_KHR_fragment_shading_rate+VK_NV_shading_rate_image[or]
ifdef::VK_NV_shading_rate_image[]
    <<primsrast-shading-rate-image, shading rate image>>
endif::VK_NV_shading_rate_image[]
    is read to determine the fragment shading rate for portions of a
    rasterized primitive.
endif::VK_KHR_fragment_shading_rate,VK_NV_shading_rate_image[]
ifdef::VK_EXT_fragment_density_map[]
  * ename:VK_PIPELINE_STAGE_FRAGMENT_DENSITY_PROCESS_BIT_EXT specifies the
    stage of the pipeline where the fragment density map is read to
    <<fragmentdensitymapops,generate the fragment areas>>.
endif::VK_EXT_fragment_density_map[]
  * ename:VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT is equivalent to
    ename:VK_PIPELINE_STAGE_ALL_COMMANDS_BIT with tlink:VkAccessFlags set to
    `0` when specified in the second synchronization scope, but specifies no
    stage of execution when specified in the first scope.
  * ename:VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT is equivalent to
    ename:VK_PIPELINE_STAGE_ALL_COMMANDS_BIT with tlink:VkAccessFlags set to
    `0` when specified in the first synchronization scope, but specifies no
    stage of execution when specified in the second scope.
--

[open,refpage='VkPipelineStageFlags',desc='Bitmask of VkPipelineStageFlagBits',type='flags']
--
include::{generated}/api/flags/VkPipelineStageFlags.adoc[]

tname:VkPipelineStageFlags is a bitmask type for setting a mask of zero or
more elink:VkPipelineStageFlagBits.
--

[[synchronization-pipeline-stages-masks]]
If a synchronization command includes a source stage mask, its first
<<synchronization-dependencies-scopes, synchronization scope>> only includes
execution of the pipeline stages specified in that mask and any
<<synchronization-pipeline-stages-order, logically earlier>> stages.
Its first <<synchronization-dependencies-access-scopes, access scope>> only
includes memory accesses performed by pipeline stages explicitly specified
in the source stage mask.

If a synchronization command includes a destination stage mask, its second
<<synchronization-dependencies-scopes, synchronization scope>> only includes
execution of the pipeline stages specified in that mask and any
<<synchronization-pipeline-stages-order, logically later>> stages.
Its second <<synchronization-dependencies-access-scopes, access scope>> only
includes memory accesses performed by pipeline stages explicitly specified
in the destination stage mask.

[NOTE]
.Note
====
Note that <<synchronization-dependencies-access-scopes, access scopes>> do
not interact with the logically earlier or later stages for either scope -
only the stages the app specifies are considered part of each access scope.
====

Certain pipeline stages are only available on queues that support a
particular set of operations.
The following table lists, for each pipeline stage flag, which queue
capability flag must: be supported by the queue.
When multiple flags are enumerated in the second column of the table, it
means that the pipeline stage is supported on the queue if it supports any
of the listed capability flags.
For further details on queue capabilities see
<<devsandqueues-physical-device-enumeration,Physical Device Enumeration>>
and <<devsandqueues-queues,Queues>>.

[[synchronization-pipeline-stages-supported]]
.Supported pipeline stage flags
[cols="70%,30%",options="header"]
|====
|Pipeline stage flag                                          | Required queue capability flag
include::{generated}/sync/supportedPipelineStages.adoc[]
|====

[[synchronization-pipeline-stages-order]]
Pipeline stages that execute as a result of a command logically complete
execution in a specific order, such that completion of a logically later
pipeline stage must: not happen-before completion of a logically earlier
stage.
This means that including any stage in the source stage mask for a
particular synchronization command also implies that any logically earlier
stages are included in *Scope~1st~* for that command.

Similarly, initiation of a logically earlier pipeline stage must: not
happen-after initiation of a logically later pipeline stage.
Including any given stage in the destination stage mask for a particular
synchronization command also implies that any logically later stages are
included in *Scope~2nd~* for that command.

[NOTE]
.Note
====
Implementations may: not support synchronization at every pipeline stage for
every synchronization operation.
If a pipeline stage that an implementation does not support synchronization
for appears in a source stage mask, it may: substitute any logically later
stage in its place for the first synchronization scope.
If a pipeline stage that an implementation does not support synchronization
for appears in a destination stage mask, it may: substitute any logically
earlier stage in its place for the second synchronization scope.

For example, if an implementation is unable to signal an event immediately
after vertex shader execution is complete, it may: instead signal the event
after color attachment output has completed.

If an implementation makes such a substitution, it must: not affect the
semantics of execution or memory dependencies or image and buffer memory
barriers.
====

[[synchronization-pipeline-stages-types]][[synchronization-pipeline-graphics]]
<<pipelines-graphics, Graphics pipelines>> are executable on queues
supporting ename:VK_QUEUE_GRAPHICS_BIT.
Stages executed by graphics pipelines can: only be specified in commands
recorded for queues supporting ename:VK_QUEUE_GRAPHICS_BIT.

The graphics
ifdef::VK_NV_mesh_shader,VK_EXT_mesh_shader[]
primitive
endif::VK_NV_mesh_shader,VK_EXT_mesh_shader[]
pipeline executes the following stages, with the logical ordering of the
stages matching the order specified here:

include::{generated}/sync/pipelineOrders/graphics_primitive.adoc[]

ifdef::VK_NV_mesh_shader,VK_EXT_mesh_shader[]
The graphics mesh pipeline executes the following stages, with the logical
ordering of the stages matching the order specified here:

include::{generated}/sync/pipelineOrders/graphics_mesh.adoc[]
endif::VK_NV_mesh_shader,VK_EXT_mesh_shader[]

For the compute pipeline, the following stages occur in this order:

include::{generated}/sync/pipelineOrders/compute.adoc[]

ifdef::VK_HUAWEI_subpass_shading[]
For the subpass shading pipeline, the following stages occur in this order:

include::{generated}/sync/pipelineOrders/subpass_shading.adoc[]
endif::VK_HUAWEI_subpass_shading[]

ifdef::VK_EXT_fragment_density_map[]
For graphics pipeline commands executing in a render pass with a fragment
density map attachment, the following pipeline stage where the fragment
density map read happens has no particular order relative to the other
stages, except that it is logically earlier than
ename:VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT:

  * ename:VK_PIPELINE_STAGE_FRAGMENT_DENSITY_PROCESS_BIT_EXT
  * ename:VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
endif::VK_EXT_fragment_density_map[]

ifdef::VK_EXT_conditional_rendering[]
The conditional rendering stage is formally part of both the graphics, and
the compute pipeline.
The pipeline stage where the predicate read happens has unspecified order
relative to other stages of these pipelines:

  * ename:VK_PIPELINE_STAGE_CONDITIONAL_RENDERING_BIT_EXT
endif::VK_EXT_conditional_rendering[]

For the transfer pipeline, the following stages occur in this order:

include::{generated}/sync/pipelineOrders/transfer.adoc[]

For host operations, only one pipeline stage occurs, so no order is
guaranteed:

include::{generated}/sync/pipelineOrders/host.adoc[]

ifdef::VK_NV_device_generated_commands[]
For the command preprocessing pipeline, the following stages occur in this
order:

include::{generated}/sync/pipelineOrders/command_preprocessing.adoc[]
endif::VK_NV_device_generated_commands[]

ifdef::VK_NV_ray_tracing,VK_KHR_acceleration_structure[]
For acceleration structure build operations, only one pipeline stage occurs,
so no order is guaranteed:

include::{generated}/sync/pipelineOrders/acceleration_structure_build.adoc[]

For acceleration structure copy operations, only one pipeline stage occurs,
so no order is guaranteed:

include::{generated}/sync/pipelineOrders/acceleration_structure_copy.adoc[]
endif::VK_NV_ray_tracing,VK_KHR_acceleration_structure[]

ifdef::VK_EXT_opacity_micromap[]
For opacity micromap build operations, only one pipeline stage occurs, so no
order is guaranteed:

include::{generated}/sync/pipelineOrders/opacity_micromap.adoc[]
endif::VK_EXT_opacity_micromap[]

ifdef::VK_NV_ray_tracing,VK_KHR_ray_tracing_pipeline[]
For the ray tracing pipeline, the following stages occur in this order:

include::{generated}/sync/pipelineOrders/ray_tracing.adoc[]
endif::VK_NV_ray_tracing,VK_KHR_ray_tracing_pipeline[]

ifdef::VK_KHR_video_decode_queue[]
For the video decode pipeline, the following stages occur in this order:

include::{generated}/sync/pipelineOrders/video_decode.adoc[]
endif::VK_KHR_video_decode_queue[]

ifdef::VK_KHR_video_encode_queue[]
For the video encode pipeline, the following stages occur in this order:

include::{generated}/sync/pipelineOrders/video_encode.adoc[]
endif::VK_KHR_video_encode_queue[]

[[synchronization-access-types]]
=== Access Types

Memory in Vulkan can: be accessed from within shader invocations and via
some fixed-function stages of the pipeline.
The _access type_ is a function of the <<descriptorsets, descriptor type>>
used, or how a fixed-function stage accesses memory.

[[synchronization-access-masks]]
Some synchronization commands take sets of access types as parameters to
define the <<synchronization-dependencies-access-scopes, access scopes>> of
a memory dependency.
If a synchronization command includes a _source access mask_, its first
<<synchronization-dependencies-access-scopes, access scope>> only includes
accesses via the access types specified in that mask.
Similarly, if a synchronization command includes a _destination access
mask_, its second <<synchronization-dependencies-access-scopes, access
scope>> only includes accesses via the access types specified in that mask.

ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
[open,refpage='VkAccessFlagBits2',desc='Access flags for VkAccessFlags2',type='enums',alias='VkAccessFlagBits2KHR']
--
Bits which can: be set in the pname:srcAccessMask and pname:dstAccessMask
members of slink:VkMemoryBarrier2KHR, slink:VkImageMemoryBarrier2KHR, and
slink:VkBufferMemoryBarrier2KHR, specifying access behavior, are:

include::{generated}/api/enums/VkAccessFlagBits2.adoc[]

ifdef::VK_KHR_synchronization2[]
or the equivalent

include::{generated}/api/enums/VkAccessFlagBits2KHR.adoc[]
endif::VK_KHR_synchronization2[]

  * ename:VK_ACCESS_2_NONE specifies no accesses.
  * ename:VK_ACCESS_2_MEMORY_READ_BIT specifies all read accesses.
    It is always valid in any access mask, and is treated as equivalent to
    setting all etext:READ access flags that are valid where it is used.
  * ename:VK_ACCESS_2_MEMORY_WRITE_BIT specifies all write accesses.
    It is always valid in any access mask, and is treated as equivalent to
    setting all etext:WRITE access flags that are valid where it is used.
  * ename:VK_ACCESS_2_INDIRECT_COMMAND_READ_BIT specifies read access to
    command data read from indirect buffers as part of an indirect
ifdef::VK_KHR_acceleration_structure[build,]
ifdef::VK_KHR_ray_tracing_pipeline[trace,]
    drawing or dispatch command.
    Such access occurs in the ename:VK_PIPELINE_STAGE_2_DRAW_INDIRECT_BIT
    pipeline stage.
  * ename:VK_ACCESS_2_INDEX_READ_BIT specifies read access to an index
    buffer as part of an indexed drawing command, bound by
ifdef::VK_KHR_maintenance5[flink:vkCmdBindIndexBuffer2KHR and]
    flink:vkCmdBindIndexBuffer.
    Such access occurs in the ename:VK_PIPELINE_STAGE_2_INDEX_INPUT_BIT
    pipeline stage.
  * ename:VK_ACCESS_2_VERTEX_ATTRIBUTE_READ_BIT specifies read access to a
    vertex buffer as part of a drawing command, bound by
    flink:vkCmdBindVertexBuffers.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_2_VERTEX_ATTRIBUTE_INPUT_BIT pipeline stage.
  * ename:VK_ACCESS_2_UNIFORM_READ_BIT specifies read access to a
    <<descriptorsets-uniformbuffer, uniform buffer>> in any shader pipeline
    stage.
  * ename:VK_ACCESS_2_INPUT_ATTACHMENT_READ_BIT specifies read access to an
    <<renderpass, input attachment>> within a render pass during
ifdef::VK_HUAWEI_subpass_shading[]
    subpass shading or
endif::VK_HUAWEI_subpass_shading[]
    fragment shading.
    Such access occurs in the
ifdef::VK_HUAWEI_subpass_shading[]
    ename:VK_PIPELINE_STAGE_2_SUBPASS_SHADER_BIT_HUAWEI or
endif::VK_HUAWEI_subpass_shading[]
    ename:VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT pipeline stage.
  * ename:VK_ACCESS_2_SHADER_SAMPLED_READ_BIT specifies read access to a
    <<descriptorsets-uniformtexelbuffer, uniform texel buffer>> or
    <<descriptorsets-sampledimage, sampled image>> in any shader pipeline
    stage.
  * ename:VK_ACCESS_2_SHADER_STORAGE_READ_BIT specifies read access to a
    <<descriptorsets-storagebuffer, storage buffer>>,
ifdef::VK_VERSION_1_2,VK_EXT_buffer_device_address,VK_buffer_device_address[]
    <<descriptorsets-physical-storage-buffer, physical storage buffer>>,
endif::VK_VERSION_1_2,VK_EXT_buffer_device_address,VK_buffer_device_address[]
    <<descriptorsets-storagetexelbuffer, storage texel buffer>>, or
    <<descriptorsets-storageimage, storage image>> in any shader pipeline
    stage.
ifdef::VK_KHR_ray_tracing_maintenance1+VK_KHR_ray_tracing_pipeline[]
  * ename:VK_ACCESS_2_SHADER_BINDING_TABLE_READ_BIT_KHR specifies read
    access to a <<shader-binding-table, shader binding table>> in any shader
    pipeline stage.
endif::VK_KHR_ray_tracing_maintenance1+VK_KHR_ray_tracing_pipeline[]
  * ename:VK_ACCESS_2_SHADER_READ_BIT
ifndef::VK_KHR_ray_tracing_maintenance1[]
ifdef::VK_NV_ray_tracing,VK_KHR_ray_tracing_pipeline[]
    specifies read access to a <<shader-binding-table, shader binding
    table>> in any shader pipeline.
    In addition, it
endif::VK_NV_ray_tracing,VK_KHR_ray_tracing_pipeline[]
endif::VK_KHR_ray_tracing_maintenance1[]
    is equivalent to the logical OR of:
include::{generated}/sync/flagDefinitions/VK_ACCESS_2_SHADER_READ_BIT.adoc[]
  * ename:VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT specifies write access to a
    <<descriptorsets-storagebuffer, storage buffer>>,
ifdef::VK_VERSION_1_2,VK_EXT_buffer_device_address,VK_buffer_device_address[]
    <<descriptorsets-physical-storage-buffer, physical storage buffer>>,
endif::VK_VERSION_1_2,VK_EXT_buffer_device_address,VK_buffer_device_address[]
    <<descriptorsets-storagetexelbuffer, storage texel buffer>>, or
    <<descriptorsets-storageimage, storage image>> in any shader pipeline
    stage.
  * ename:VK_ACCESS_2_SHADER_WRITE_BIT is equivalent to
    ename:VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT.
  * ename:VK_ACCESS_2_COLOR_ATTACHMENT_READ_BIT specifies read access to a
    <<renderpass, color attachment>>, such as via
ifndef::VK_EXT_blend_operation_advanced[<<framebuffer-blending, blending>>,]
ifdef::VK_EXT_blend_operation_advanced[]
    <<framebuffer-blending, blending>> (other than
    <<framebuffer-blend-advanced, advanced blend operations>>),
endif::VK_EXT_blend_operation_advanced[]
    <<framebuffer-logicop, logic operations>> or certain
ifndef::VK_EXT_shader_tile_image[]
    <<renderpass-load-operations, render pass load operations>>.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT pipeline stage.
endif::VK_EXT_shader_tile_image[]
ifdef::VK_EXT_shader_tile_image[]
    <<renderpass-load-operations, render pass load operations>> in the
    ename:VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT pipeline stage or
    via <<fragops-shader-tileimage-reads, fragment shader tile image reads>>
    in the ename:VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT pipeline stage.
endif::VK_EXT_shader_tile_image[]
  * ename:VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT specifies write access to a
    <<renderpass, color attachment>> during a <<renderpass, render pass>> or
    via certain render pass <<renderpass-load-operations, load>>,
    <<renderpass-store-operations, store>>, and
    <<renderpass-resolve-operations, multisample resolve>> operations.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT pipeline stage.
  * ename:VK_ACCESS_2_DEPTH_STENCIL_ATTACHMENT_READ_BIT specifies read
    access to a <<renderpass, depth/stencil attachment>>, via
    <<fragops-ds-state, depth or stencil operations>> or certain
ifndef::VK_EXT_shader_tile_image[]
    <<renderpass-load-operations, render pass load operations>>.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_2_EARLY_FRAGMENT_TESTS_BIT or
    ename:VK_PIPELINE_STAGE_2_LATE_FRAGMENT_TESTS_BIT pipeline stages.
endif::VK_EXT_shader_tile_image[]
ifdef::VK_EXT_shader_tile_image[]
    <<renderpass-load-operations, render pass load operations>> in the
    ename:VK_PIPELINE_STAGE_2_EARLY_FRAGMENT_TESTS_BIT or
    ename:VK_PIPELINE_STAGE_2_LATE_FRAGMENT_TESTS_BIT pipeline stages or via
    <<fragops-shader-tileimage-reads, fragment shader tile image reads>> in
    the ename:VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT pipeline stage.
endif::VK_EXT_shader_tile_image[]
  * ename:VK_ACCESS_2_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT specifies write
    access to a <<renderpass, depth/stencil attachment>>, via
    <<fragops-ds-state, depth or stencil operations>> or certain render pass
    <<renderpass-load-operations, load>> and <<renderpass-store-operations,
    store>> operations.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_2_EARLY_FRAGMENT_TESTS_BIT or
    ename:VK_PIPELINE_STAGE_2_LATE_FRAGMENT_TESTS_BIT pipeline stages.
  * ename:VK_ACCESS_2_TRANSFER_READ_BIT specifies read access to an image or
    buffer in a <<copies, copy>> operation.
    Such access occurs in the ename:VK_PIPELINE_STAGE_2_COPY_BIT,
    ename:VK_PIPELINE_STAGE_2_BLIT_BIT, or
    ename:VK_PIPELINE_STAGE_2_RESOLVE_BIT pipeline stages.
  * ename:VK_ACCESS_2_TRANSFER_WRITE_BIT specifies write access to an image
    or buffer in a <<clears, clear>> or <<copies, copy>> operation.
    Such access occurs in the ename:VK_PIPELINE_STAGE_2_COPY_BIT,
    ename:VK_PIPELINE_STAGE_2_BLIT_BIT, ename:VK_PIPELINE_STAGE_2_CLEAR_BIT,
    or ename:VK_PIPELINE_STAGE_2_RESOLVE_BIT pipeline stages.
  * ename:VK_ACCESS_2_HOST_READ_BIT specifies read access by a host
    operation.
    Accesses of this type are not performed through a resource, but directly
    on memory.
    Such access occurs in the ename:VK_PIPELINE_STAGE_2_HOST_BIT pipeline
    stage.
  * ename:VK_ACCESS_2_HOST_WRITE_BIT specifies write access by a host
    operation.
    Accesses of this type are not performed through a resource, but directly
    on memory.
    Such access occurs in the ename:VK_PIPELINE_STAGE_2_HOST_BIT pipeline
    stage.
ifdef::VK_EXT_conditional_rendering[]
  * ename:VK_ACCESS_2_CONDITIONAL_RENDERING_READ_BIT_EXT specifies read
    access to a predicate as part of conditional rendering.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_2_CONDITIONAL_RENDERING_BIT_EXT pipeline stage.
endif::VK_EXT_conditional_rendering[]
ifdef::VK_EXT_transform_feedback[]
  * ename:VK_ACCESS_2_TRANSFORM_FEEDBACK_WRITE_BIT_EXT specifies write
    access to a transform feedback buffer made when transform feedback is
    active.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_2_TRANSFORM_FEEDBACK_BIT_EXT pipeline stage.
  * ename:VK_ACCESS_2_TRANSFORM_FEEDBACK_COUNTER_READ_BIT_EXT specifies read
    access to a transform feedback counter buffer which is read when
    flink:vkCmdBeginTransformFeedbackEXT executes.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_2_TRANSFORM_FEEDBACK_BIT_EXT pipeline stage.
  * ename:VK_ACCESS_2_TRANSFORM_FEEDBACK_COUNTER_WRITE_BIT_EXT specifies
    write access to a transform feedback counter buffer which is written
    when flink:vkCmdEndTransformFeedbackEXT executes.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_2_TRANSFORM_FEEDBACK_BIT_EXT pipeline stage.
endif::VK_EXT_transform_feedback[]
ifdef::VK_NV_device_generated_commands[]
  * ename:VK_ACCESS_2_COMMAND_PREPROCESS_READ_BIT_NV specifies reads from
    buffer inputs to flink:vkCmdPreprocessGeneratedCommandsNV.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_2_COMMAND_PREPROCESS_BIT_NV pipeline stage.
  * ename:VK_ACCESS_2_COMMAND_PREPROCESS_WRITE_BIT_NV specifies writes to
    the target command buffer preprocess outputs.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_2_COMMAND_PREPROCESS_BIT_NV pipeline stage.
endif::VK_NV_device_generated_commands[]
ifdef::VK_EXT_blend_operation_advanced[]
  * ename:VK_ACCESS_2_COLOR_ATTACHMENT_READ_NONCOHERENT_BIT_EXT specifies
    read access to <<renderpass, color attachments>>, including
    <<framebuffer-blend-advanced,advanced blend operations>>.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT pipeline stage.
endif::VK_EXT_blend_operation_advanced[]
ifdef::VK_HUAWEI_invocation_mask[]
  * ename:VK_ACCESS_2_INVOCATION_MASK_READ_BIT_HUAWEI specifies read access
    to a invocation mask image in the
    ename:VK_PIPELINE_STAGE_2_INVOCATION_MASK_BIT_HUAWEI pipeline stage.
endif::VK_HUAWEI_invocation_mask[]
ifdef::VK_KHR_acceleration_structure,VK_NV_ray_tracing[]
  * ename:VK_ACCESS_2_ACCELERATION_STRUCTURE_READ_BIT_KHR specifies read
    access to an acceleration structure as part of a trace, build, or copy
    command, or to an <<acceleration-structure-scratch, acceleration
    structure scratch buffer>> as part of a build command.
    Such access occurs in the
ifdef::VK_KHR_ray_tracing_pipeline[]
    ename:VK_PIPELINE_STAGE_2_RAY_TRACING_SHADER_BIT_KHR pipeline stage or
endif::VK_KHR_ray_tracing_pipeline[]
    ename:VK_PIPELINE_STAGE_2_ACCELERATION_STRUCTURE_BUILD_BIT_KHR pipeline
    stage.
  * ename:VK_ACCESS_2_ACCELERATION_STRUCTURE_WRITE_BIT_KHR specifies write
    access to an acceleration structure or <<acceleration-structure-scratch,
    acceleration structure scratch buffer>> as part of a build or copy
    command.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_2_ACCELERATION_STRUCTURE_BUILD_BIT_KHR pipeline
    stage.
endif::VK_KHR_acceleration_structure,VK_NV_ray_tracing[]
ifdef::VK_EXT_fragment_density_map[]
  * ename:VK_ACCESS_2_FRAGMENT_DENSITY_MAP_READ_BIT_EXT specifies read
    access to a <<renderpass-fragmentdensitymapattachment, fragment density
    map attachment>> during dynamic <<fragmentdensitymapops, fragment
    density map operations>>.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_2_FRAGMENT_DENSITY_PROCESS_BIT_EXT pipeline
    stage.
endif::VK_EXT_fragment_density_map[]
ifdef::VK_KHR_fragment_shading_rate[]
  * ename:VK_ACCESS_2_FRAGMENT_SHADING_RATE_ATTACHMENT_READ_BIT_KHR
    specifies read access to a fragment shading rate attachment during
    rasterization.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_2_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR
    pipeline stage.
endif::VK_KHR_fragment_shading_rate[]
ifdef::VK_NV_shading_rate_image[]
  * ename:VK_ACCESS_2_SHADING_RATE_IMAGE_READ_BIT_NV specifies read access
    to a shading rate image during rasterization.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_2_SHADING_RATE_IMAGE_BIT_NV pipeline stage.
ifdef::VK_KHR_fragment_shading_rate[]
    It is equivalent to
    ename:VK_ACCESS_2_FRAGMENT_SHADING_RATE_ATTACHMENT_READ_BIT_KHR.
endif::VK_KHR_fragment_shading_rate[]
endif::VK_NV_shading_rate_image[]
ifdef::VK_KHR_video_decode_queue[]
  * ename:VK_ACCESS_2_VIDEO_DECODE_READ_BIT_KHR specifies read access to an
    image or buffer resource in a <<video-decode-operations, video decode
    operation>>.
    Such access occurs in the ename:VK_PIPELINE_STAGE_2_VIDEO_DECODE_BIT_KHR
    pipeline stage.
  * ename:VK_ACCESS_2_VIDEO_DECODE_WRITE_BIT_KHR specifies write access to
    an image or buffer resource in a <<video-decode-operations, video decode
    operation>>.
    Such access occurs in the ename:VK_PIPELINE_STAGE_2_VIDEO_DECODE_BIT_KHR
    pipeline stage.
endif::VK_KHR_video_decode_queue[]
ifdef::VK_KHR_video_encode_queue[]
  * ename:VK_ACCESS_2_VIDEO_ENCODE_READ_BIT_KHR specifies read access to an
    image or buffer resource in a <<video-encode-operations, video encode
    operation>>.
    Such access occurs in the ename:VK_PIPELINE_STAGE_2_VIDEO_ENCODE_BIT_KHR
    pipeline stage.
  * ename:VK_ACCESS_2_VIDEO_ENCODE_WRITE_BIT_KHR specifies write access to
    an image or buffer resource in a <<video-encode-operations, video encode
    operation>>.
    Such access occurs in the ename:VK_PIPELINE_STAGE_2_VIDEO_ENCODE_BIT_KHR
    pipeline stage.
endif::VK_KHR_video_encode_queue[]
ifdef::VK_EXT_descriptor_buffer[]
  * ename:VK_ACCESS_2_DESCRIPTOR_BUFFER_READ_BIT_EXT specifies read access
    to a <<descriptorbuffers, descriptor buffer>> in any shader pipeline
    stage.
endif::VK_EXT_descriptor_buffer[]
ifdef::VK_NV_optical_flow[]
  * ename:VK_ACCESS_2_OPTICAL_FLOW_READ_BIT_NV specifies read access to an
    image or buffer resource as part of a <<opticalflow-operations, optical
    flow operation>>.
    Such access occurs in the ename:VK_PIPELINE_STAGE_2_OPTICAL_FLOW_BIT_NV
    pipeline stage.
  * ename:VK_ACCESS_2_OPTICAL_FLOW_WRITE_BIT_NV specifies write access to an
    image or buffer resource as part of a <<opticalflow-operations, optical
    flow operation>>.
    Such access occurs in the ename:VK_PIPELINE_STAGE_2_OPTICAL_FLOW_BIT_NV
    pipeline stage.
endif::VK_NV_optical_flow[]
ifdef::VK_EXT_opacity_micromap[]
  * ename:VK_ACCESS_2_MICROMAP_WRITE_BIT_EXT specifies write access to a
    micromap object.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_2_MICROMAP_BUILD_BIT_EXT pipeline stage.
  * ename:VK_ACCESS_2_MICROMAP_READ_BIT_EXT specifies read access to a
    micromap object.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_2_MICROMAP_BUILD_BIT_EXT and
    ename:VK_PIPELINE_STAGE_2_ACCELERATION_STRUCTURE_BUILD_BIT_KHR pipeline
    stages.
endif::VK_EXT_opacity_micromap[]

[NOTE]
.Note
====
In situations where an application wishes to select all access types for a
given set of pipeline stages, ename:VK_ACCESS_2_MEMORY_READ_BIT or
ename:VK_ACCESS_2_MEMORY_WRITE_BIT can be used.
This is particularly useful when specifying stages that only have a single
access type.
====

[NOTE]
.Note
====
The tname:VkAccessFlags2 bitmask goes beyond the 31 individual bit flags
allowable within a C99 enum, which is how elink:VkAccessFlagBits is defined.
The first 31 values are common to both, and are interchangeable.
====
--

[open,refpage='VkAccessFlags2',desc='64-bit mask of access flags',type='flags',alias='VkAccessFlags2KHR']
--
tname:VkAccessFlags2 is a bitmask type for setting a mask of zero or more
elink:VkAccessFlagBits2:

include::{generated}/api/flags/VkAccessFlags2.adoc[]

ifdef::VK_KHR_synchronization2[]
or the equivalent

include::{generated}/api/flags/VkAccessFlags2KHR.adoc[]
endif::VK_KHR_synchronization2[]
--
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]

[open,refpage='VkAccessFlagBits',desc='Bitmask specifying memory access types that will participate in a memory dependency',type='enums']
--
Bits which can: be set in the pname:srcAccessMask and pname:dstAccessMask
members of slink:VkSubpassDependency,
ifdef::VK_KHR_synchronization2[slink:VkSubpassDependency2,]
slink:VkMemoryBarrier, slink:VkBufferMemoryBarrier, and
slink:VkImageMemoryBarrier, specifying access behavior, are:

include::{generated}/api/enums/VkAccessFlagBits.adoc[]

ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
These values all have the same meaning as the equivalently named values for
tlink:VkAccessFlags2.

  * ename:VK_ACCESS_NONE specifies no accesses.
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]
  * ename:VK_ACCESS_MEMORY_READ_BIT specifies all read accesses.
    It is always valid in any access mask, and is treated as equivalent to
    setting all etext:READ access flags that are valid where it is used.
  * ename:VK_ACCESS_MEMORY_WRITE_BIT specifies all write accesses.
    It is always valid in any access mask, and is treated as equivalent to
    setting all etext:WRITE access flags that are valid where it is used.
  * ename:VK_ACCESS_INDIRECT_COMMAND_READ_BIT specifies read access to
    indirect command data read as part of an indirect
ifdef::VK_KHR_acceleration_structure[build,]
ifdef::VK_KHR_ray_tracing_pipeline[trace,]
    drawing or dispatching command.
    Such access occurs in the ename:VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT
    pipeline stage.
  * ename:VK_ACCESS_INDEX_READ_BIT specifies read access to an index buffer
    as part of an indexed drawing command, bound by
ifdef::VK_KHR_maintenance5[flink:vkCmdBindIndexBuffer2KHR and]
    flink:vkCmdBindIndexBuffer.
    Such access occurs in the ename:VK_PIPELINE_STAGE_VERTEX_INPUT_BIT
    pipeline stage.
  * ename:VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT specifies read access to a
    vertex buffer as part of a drawing command, bound by
    flink:vkCmdBindVertexBuffers.
    Such access occurs in the ename:VK_PIPELINE_STAGE_VERTEX_INPUT_BIT
    pipeline stage.
  * ename:VK_ACCESS_UNIFORM_READ_BIT specifies read access to a
    <<descriptorsets-uniformbuffer, uniform buffer>> in any shader pipeline
    stage.
  * ename:VK_ACCESS_INPUT_ATTACHMENT_READ_BIT specifies read access to an
    <<renderpass, input attachment>> within a render pass during
ifdef::VK_HUAWEI_subpass_shading[]
    subpass shading or
endif::VK_HUAWEI_subpass_shading[]
    fragment shading.
    Such access occurs in the
ifdef::VK_HUAWEI_subpass_shading[]
    ename:VK_PIPELINE_STAGE_2_SUBPASS_SHADER_BIT_HUAWEI or
endif::VK_HUAWEI_subpass_shading[]
    ename:VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT pipeline stage.
  * ename:VK_ACCESS_SHADER_READ_BIT specifies read access to a
    <<descriptorsets-uniformtexelbuffer, uniform texel buffer>>,
    <<descriptorsets-sampledimage, sampled image>>,
    <<descriptorsets-storagebuffer, storage buffer>>,
ifdef::VK_VERSION_1_2,VK_EXT_buffer_device_address,VK_KHR_buffer_device_address[]
    <<descriptorsets-physical-storage-buffer, physical storage buffer>>,
endif::VK_VERSION_1_2,VK_EXT_buffer_device_address,VK_KHR_buffer_device_address[]
ifdef::VK_NV_ray_tracing,VK_KHR_ray_tracing_pipeline[]
    <<shader-binding-table, shader binding table>>,
endif::VK_NV_ray_tracing,VK_KHR_ray_tracing_pipeline[]
    <<descriptorsets-storagetexelbuffer, storage texel buffer>>, or
    <<descriptorsets-storageimage, storage image>> in any shader pipeline
    stage.
  * ename:VK_ACCESS_SHADER_WRITE_BIT specifies write access to a
    <<descriptorsets-storagebuffer, storage buffer>>,
ifdef::VK_VERSION_1_2,VK_EXT_buffer_device_address,VK_KHR_buffer_device_address[]
    <<descriptorsets-physical-storage-buffer, physical storage buffer>>,
endif::VK_VERSION_1_2,VK_EXT_buffer_device_address,VK_KHR_buffer_device_address[]
    <<descriptorsets-storagetexelbuffer, storage texel buffer>>, or
    <<descriptorsets-storageimage, storage image>> in any shader pipeline
    stage.
  * ename:VK_ACCESS_COLOR_ATTACHMENT_READ_BIT specifies read access to a
    <<renderpass, color attachment>>, such as via
ifndef::VK_EXT_blend_operation_advanced[<<framebuffer-blending, blending>>,]
ifdef::VK_EXT_blend_operation_advanced[]
    <<framebuffer-blending, blending>> (other than
    <<framebuffer-blend-advanced, advanced blend operations>>),
endif::VK_EXT_blend_operation_advanced[]
    <<framebuffer-logicop, logic operations>> or certain
ifndef::VK_EXT_shader_tile_image[]
    <<renderpass-load-operations, render pass load operations>>.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT pipeline stage.
endif::VK_EXT_shader_tile_image[]
ifdef::VK_EXT_shader_tile_image[]
    <<renderpass-load-operations, render pass load operations>> in the
    ename:VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT pipeline stage or
    via <<fragops-shader-tileimage-reads, fragment shader tile image reads>>
    in the ename:VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT pipeline stage.
endif::VK_EXT_shader_tile_image[]
  * ename:VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT specifies write access to a
ifndef::VK_VERSION_1_2,VK_KHR_depth_stencil_resolve[]
    <<renderpass, color or resolve attachment>>
endif::VK_VERSION_1_2,VK_KHR_depth_stencil_resolve[]
ifdef::VK_VERSION_1_2,VK_KHR_depth_stencil_resolve[]
    <<renderpass, color, resolve, or depth/stencil resolve attachment>>
endif::VK_VERSION_1_2,VK_KHR_depth_stencil_resolve[]
    during a <<renderpass, render pass>> or via certain render pass
    <<renderpass-load-operations, load>> and <<renderpass-store-operations,
    store>> operations.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT pipeline stage.
  * ename:VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT specifies read access
    to a <<renderpass, depth/stencil attachment>>, via <<fragops-ds-state,
    depth or stencil operations>> or certain
ifndef::VK_EXT_shader_tile_image[]
    <<renderpass-load-operations, render pass load operations>>.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT or
    ename:VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT pipeline stages.
endif::VK_EXT_shader_tile_image[]
ifdef::VK_EXT_shader_tile_image[]
    <<renderpass-load-operations, render pass load operations>> in the
    ename:VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT or
    ename:VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT pipeline stages or via
    <<fragops-shader-tileimage-reads, fragment shader tile image reads>> in
    the ename:VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT pipeline stage.
endif::VK_EXT_shader_tile_image[]
  * ename:VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT specifies write
    access to a <<renderpass, depth/stencil attachment>>, via
    <<fragops-ds-state, depth or stencil operations>> or certain render pass
    <<renderpass-load-operations, load>> and <<renderpass-store-operations,
    store>> operations.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT or
    ename:VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT pipeline stages.
  * ename:VK_ACCESS_TRANSFER_READ_BIT specifies read access to an image or
    buffer in a <<copies, copy>> operation.
ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
    Such access occurs in the ename:VK_PIPELINE_STAGE_2_ALL_TRANSFER_BIT
    pipeline stage.
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]
  * ename:VK_ACCESS_TRANSFER_WRITE_BIT specifies write access to an image or
    buffer in a <<clears, clear>> or <<copies, copy>> operation.
ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
    Such access occurs in the ename:VK_PIPELINE_STAGE_2_ALL_TRANSFER_BIT
    pipeline stage.
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]
  * ename:VK_ACCESS_HOST_READ_BIT specifies read access by a host operation.
    Accesses of this type are not performed through a resource, but directly
    on memory.
    Such access occurs in the ename:VK_PIPELINE_STAGE_HOST_BIT pipeline
    stage.
  * ename:VK_ACCESS_HOST_WRITE_BIT specifies write access by a host
    operation.
    Accesses of this type are not performed through a resource, but directly
    on memory.
    Such access occurs in the ename:VK_PIPELINE_STAGE_HOST_BIT pipeline
    stage.
ifdef::VK_EXT_conditional_rendering[]
  * ename:VK_ACCESS_CONDITIONAL_RENDERING_READ_BIT_EXT specifies read access
    to a predicate as part of conditional rendering.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_CONDITIONAL_RENDERING_BIT_EXT pipeline stage.
endif::VK_EXT_conditional_rendering[]
ifdef::VK_EXT_transform_feedback[]
  * ename:VK_ACCESS_TRANSFORM_FEEDBACK_WRITE_BIT_EXT specifies write access
    to a transform feedback buffer made when transform feedback is active.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_TRANSFORM_FEEDBACK_BIT_EXT pipeline stage.
  * ename:VK_ACCESS_TRANSFORM_FEEDBACK_COUNTER_READ_BIT_EXT specifies read
    access to a transform feedback counter buffer which is read when
    fname:vkCmdBeginTransformFeedbackEXT executes.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_TRANSFORM_FEEDBACK_BIT_EXT pipeline stage.
  * ename:VK_ACCESS_TRANSFORM_FEEDBACK_COUNTER_WRITE_BIT_EXT specifies write
    access to a transform feedback counter buffer which is written when
    fname:vkCmdEndTransformFeedbackEXT executes.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_TRANSFORM_FEEDBACK_BIT_EXT pipeline stage.
endif::VK_EXT_transform_feedback[]
ifdef::VK_NV_device_generated_commands[]
  * ename:VK_ACCESS_COMMAND_PREPROCESS_READ_BIT_NV specifies reads from
    buffer inputs to flink:vkCmdPreprocessGeneratedCommandsNV.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_COMMAND_PREPROCESS_BIT_NV pipeline stage.
  * ename:VK_ACCESS_COMMAND_PREPROCESS_WRITE_BIT_NV specifies writes to the
    target command buffer preprocess outputs in
    flink:vkCmdPreprocessGeneratedCommandsNV.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_COMMAND_PREPROCESS_BIT_NV pipeline stage.
endif::VK_NV_device_generated_commands[]
ifdef::VK_EXT_blend_operation_advanced[]
  * ename:VK_ACCESS_COLOR_ATTACHMENT_READ_NONCOHERENT_BIT_EXT specifies read
    access to <<renderpass, color attachments>>, including
    <<framebuffer-blend-advanced,advanced blend operations>>.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT pipeline stage.
endif::VK_EXT_blend_operation_advanced[]
ifdef::VK_KHR_acceleration_structure,VK_NV_ray_tracing[]
ifdef::VK_HUAWEI_invocation_mask[]
  * ename:VK_ACCESS_2_INVOCATION_MASK_READ_BIT_HUAWEI specifies read access
    to a invocation mask image in the
    ename:VK_PIPELINE_STAGE_2_INVOCATION_MASK_BIT_HUAWEI pipeline stage.
endif::VK_HUAWEI_invocation_mask[]
  * ename:VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_KHR specifies read
    access to an acceleration structure as part of a trace, build, or copy
    command, or to an <<acceleration-structure-scratch, acceleration
    structure scratch buffer>> as part of a build command.
    Such access occurs in the
ifdef::VK_KHR_ray_tracing_pipeline[]
    ename:VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR pipeline stage or
endif::VK_KHR_ray_tracing_pipeline[]
    ename:VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR pipeline
    stage.
  * ename:VK_ACCESS_ACCELERATION_STRUCTURE_WRITE_BIT_KHR specifies write
    access to an acceleration structure or <<acceleration-structure-scratch,
    acceleration structure scratch buffer>> as part of a build or copy
    command.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR pipeline
    stage.
endif::VK_KHR_acceleration_structure,VK_NV_ray_tracing[]
ifdef::VK_EXT_fragment_density_map[]
  * ename:VK_ACCESS_FRAGMENT_DENSITY_MAP_READ_BIT_EXT specifies read access
    to a <<renderpass-fragmentdensitymapattachment, fragment density map
    attachment>> during dynamic <<fragmentdensitymapops, fragment density
    map operations>> Such access occurs in the
    ename:VK_PIPELINE_STAGE_FRAGMENT_DENSITY_PROCESS_BIT_EXT pipeline stage.
endif::VK_EXT_fragment_density_map[]
ifdef::VK_KHR_fragment_shading_rate[]
  * ename:VK_ACCESS_FRAGMENT_SHADING_RATE_ATTACHMENT_READ_BIT_KHR specifies
    read access to a fragment shading rate attachment during rasterization.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR
    pipeline stage.
endif::VK_KHR_fragment_shading_rate[]
ifdef::VK_NV_shading_rate_image[]
  * ename:VK_ACCESS_SHADING_RATE_IMAGE_READ_BIT_NV specifies read access to
    a shading rate image during rasterization.
    Such access occurs in the
    ename:VK_PIPELINE_STAGE_SHADING_RATE_IMAGE_BIT_NV pipeline stage.
ifdef::VK_KHR_fragment_shading_rate[]
    It is equivalent to
    ename:VK_PIPELINE_STAGE_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR.
endif::VK_KHR_fragment_shading_rate[]
endif::VK_NV_shading_rate_image[]

Certain access types are only performed by a subset of pipeline stages.
Any synchronization command that takes both stage masks and access masks
uses both to define the <<synchronization-dependencies-access-scopes, access
scopes>> - only the specified access types performed by the specified stages
are included in the access scope.
An application must: not specify an access flag in a synchronization command
if it does not include a pipeline stage in the corresponding stage mask that
is able to perform accesses of that type.
The following table lists, for each access flag, which pipeline stages can:
perform that type of access.

[[synchronization-access-types-supported]]
.Supported access types
[cols="50,50",options="header"]
|====
|Access flag                                                  | Supported pipeline stages
include::{generated}/sync/supportedAccessTypes.adoc[]
|====
--

[open,refpage='VkAccessFlags',desc='Bitmask of VkAccessFlagBits',type='flags']
--
include::{generated}/api/flags/VkAccessFlags.adoc[]

tname:VkAccessFlags is a bitmask type for setting a mask of zero or more
elink:VkAccessFlagBits.
--


[[synchronization-host-access-types]]
If a memory object does not have the
ename:VK_MEMORY_PROPERTY_HOST_COHERENT_BIT property, then
flink:vkFlushMappedMemoryRanges must: be called in order to guarantee that
writes to the memory object from the host are made available to the host
domain, where they can: be further made available to the device domain via a
domain operation.
Similarly, flink:vkInvalidateMappedMemoryRanges must: be called to guarantee
that writes which are available to the host domain are made visible to host
operations.

If the memory object does have the
ename:VK_MEMORY_PROPERTY_HOST_COHERENT_BIT property flag, writes to the
memory object from the host are automatically made available to the host
domain.
Similarly, writes made available to the host domain are automatically made
visible to the host.

[NOTE]
.Note
====
<<devsandqueues-submission, Queue submission commands>> automatically
perform a <<synchronization-submission-host-writes,domain operation from
host to device>> for all writes performed before the command executes, so in
most cases an explicit memory barrier is not needed for this case.
In the few circumstances where a submit does not occur between the host
write and the device read access, writes can: be made available by using an
explicit memory barrier.
====


[[synchronization-framebuffer-regions]]
=== Framebuffer Region Dependencies

<<synchronization-pipeline-stages, Pipeline stages>> that operate on, or
with respect to, the framebuffer are collectively the _framebuffer-space_
pipeline stages.
These stages are:

  * ename:VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
  * ename:VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
  * ename:VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT
  * ename:VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT

For these pipeline stages, an execution or memory dependency from the first
set of operations to the second set can: either be a single
_framebuffer-global_ dependency, or split into multiple _framebuffer-local_
dependencies.
A dependency with non-framebuffer-space pipeline stages is neither
framebuffer-global nor framebuffer-local.

ifndef::VK_QCOM_render_pass_shader_resolve,VK_EXT_rasterization_order_attachment_access,VK_ARM_rasterization_order_attachment_access[]
A _framebuffer region_ is a set of sample (x, y, layer, sample) coordinates
that is a subset of the entire framebuffer.
endif::VK_QCOM_render_pass_shader_resolve,VK_EXT_rasterization_order_attachment_access,VK_ARM_rasterization_order_attachment_access[]
ifdef::VK_QCOM_render_pass_shader_resolve,VK_EXT_rasterization_order_attachment_access,VK_ARM_rasterization_order_attachment_access[]
A _framebuffer region_ is a subset of the entire framebuffer, and can:
either be:

  * A _sample region_, which is set of sample (x, y, layer, sample)
    coordinates that is a subset of the entire framebuffer, or
  * A _fragment region_, which is a set of fragment (x, y, layer)
    coordinates that is a subset of the entire framebuffer.
endif::VK_QCOM_render_pass_shader_resolve,VK_EXT_rasterization_order_attachment_access,VK_ARM_rasterization_order_attachment_access[]

Both <<synchronization-dependencies-scopes, synchronization scopes>> of a
framebuffer-local dependency include only the operations performed within
corresponding framebuffer regions (as defined below).
No ordering guarantees are made between different framebuffer regions for a
framebuffer-local dependency.

Both <<synchronization-dependencies-scopes, synchronization scopes>> of a
framebuffer-global dependency include operations on all framebuffer-regions.

If the first synchronization scope includes operations on pixels/fragments
with N samples and the second synchronization scope includes operations on
pixels/fragments with M samples, where N does not equal M, then a
framebuffer region containing all samples at a given (x, y, layer)
coordinate in the first synchronization scope corresponds to a region
containing all samples at the same coordinate in the second synchronization
scope.
ifndef::VK_QCOM_render_pass_shader_resolve[]
In other words, it is a pixel granularity dependency.
endif::VK_QCOM_render_pass_shader_resolve[]
ifdef::VK_QCOM_render_pass_shader_resolve[]
In other words, the framebuffer region is a fragment region and it is a
pixel granularity dependency.
endif::VK_QCOM_render_pass_shader_resolve[]
If N equals M,
ifdef::VK_QCOM_render_pass_shader_resolve[]
and if the sname:VkSubpassDescription::pname:flags does not specify the
ename:VK_SUBPASS_DESCRIPTION_FRAGMENT_REGION_BIT_QCOM flag,
endif::VK_QCOM_render_pass_shader_resolve[]
then a framebuffer region containing a single (x, y, layer, sample)
coordinate in the first synchronization scope corresponds to a region
containing the same sample at the same coordinate in the second
synchronization scope.
ifndef::VK_QCOM_render_pass_shader_resolve[]
In other words, it is a sample granularity dependency.
endif::VK_QCOM_render_pass_shader_resolve[]
ifdef::VK_QCOM_render_pass_shader_resolve[]
In other words, the framebuffer region is a sample region and it is a sample
granularity dependency.
endif::VK_QCOM_render_pass_shader_resolve[]

ifdef::VK_EXT_rasterization_order_attachment_access,VK_ARM_rasterization_order_attachment_access[]
If the pipeline performing the operation was created with
ename:VK_PIPELINE_COLOR_BLEND_STATE_CREATE_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_BIT_EXT,
ename:VK_PIPELINE_DEPTH_STENCIL_STATE_CREATE_RASTERIZATION_ORDER_ATTACHMENT_DEPTH_ACCESS_BIT_EXT,
or
ename:VK_PIPELINE_DEPTH_STENCIL_STATE_CREATE_RASTERIZATION_ORDER_ATTACHMENT_STENCIL_ACCESS_BIT_EXT,
the framebuffer region is a fragment region and it is a pixel granularity
dependency.
endif::VK_EXT_rasterization_order_attachment_access,VK_ARM_rasterization_order_attachment_access[]

[NOTE]
.Note
====
Since fragment shader invocations are not specified to run in any particular
groupings, the size of a framebuffer region is implementation-dependent, not
known to the application, and must: be assumed to be no larger than
specified above.
====

[NOTE]
.Note
====
Practically, the pixel vs. sample granularity dependency means that if an
input attachment has a different number of samples than the pipeline's
pname:rasterizationSamples, then a fragment can: access any sample in the
input attachment's pixel even if it only uses framebuffer-local
dependencies.
If the input attachment has the same number of samples, then the fragment
can: only access the covered samples in its input code:SampleMask (i.e. the
fragment operations happen-after a framebuffer-local dependency for each
sample the fragment covers).
To access samples that are not covered,
ifdef::VK_QCOM_render_pass_shader_resolve[]
either the sname:VkSubpassDescription::pname:flags
ename:VK_SUBPASS_DESCRIPTION_FRAGMENT_REGION_BIT_QCOM flag is required, or
endif::VK_QCOM_render_pass_shader_resolve[]
a framebuffer-global dependency is required.
====

If a synchronization command includes a pname:dependencyFlags parameter, and
specifies the ename:VK_DEPENDENCY_BY_REGION_BIT flag, then it defines
framebuffer-local dependencies for the framebuffer-space pipeline stages in
that synchronization command, for all framebuffer regions.
If no pname:dependencyFlags parameter is included, or the
ename:VK_DEPENDENCY_BY_REGION_BIT flag is not specified, then a
framebuffer-global dependency is specified for those stages.
The ename:VK_DEPENDENCY_BY_REGION_BIT flag does not affect the dependencies
between non-framebuffer-space pipeline stages, nor does it affect the
dependencies between framebuffer-space and non-framebuffer-space pipeline
stages.

[NOTE]
.Note
====
Framebuffer-local dependencies are more efficient for most architectures;
particularly tile-based architectures - which can keep framebuffer-regions
entirely in on-chip registers and thus avoid external bandwidth across such
a dependency.
Including a framebuffer-global dependency in your rendering will usually
force all implementations to flush data to memory, or to a higher level
cache, breaking any potential locality optimizations.
====


ifdef::VK_VERSION_1_1,VK_KHR_multiview[]
[[synchronization-view-local-dependencies]]
=== View-Local Dependencies

In a render pass instance that has <<renderpass-multiview,multiview>>
enabled, dependencies can: be either view-local or view-global.

A view-local dependency only includes operations from a single
<<renderpass-multiview-view-local,source view>> from the source subpass in
the first synchronization scope, and only includes operations from a single
<<renderpass-multiview-view-local,destination view>> from the destination
subpass in the second synchronization scope.
A view-global dependency includes all views in the view mask of the source
and destination subpasses in the corresponding synchronization scopes.

If a synchronization command includes a pname:dependencyFlags parameter and
specifies the ename:VK_DEPENDENCY_VIEW_LOCAL_BIT flag, then it defines
view-local dependencies for that synchronization command, for all views.
If no pname:dependencyFlags parameter is included or the
ename:VK_DEPENDENCY_VIEW_LOCAL_BIT flag is not specified, then a view-global
dependency is specified.
endif::VK_VERSION_1_1,VK_KHR_multiview[]


ifdef::VK_VERSION_1_1,VK_KHR_device_group[]
[[synchronization-device-local-dependencies]]
=== Device-Local Dependencies

Dependencies can: be either device-local or non-device-local.
A device-local dependency acts as multiple separate dependencies, one for
each physical device that executes the synchronization command, where each
dependency only includes operations from that physical device in both
synchronization scopes.
A non-device-local dependency is a single dependency where both
synchronization scopes include operations from all physical devices that
participate in the synchronization command.
For subpass dependencies, all physical devices in the
slink:VkDeviceGroupRenderPassBeginInfo::pname:deviceMask participate in the
dependency, and for pipeline barriers all physical devices that are set in
the command buffer's current device mask participate in the dependency.

If a synchronization command includes a pname:dependencyFlags parameter and
specifies the ename:VK_DEPENDENCY_DEVICE_GROUP_BIT flag, then it defines a
non-device-local dependency for that synchronization command.
If no pname:dependencyFlags parameter is included or the
ename:VK_DEPENDENCY_DEVICE_GROUP_BIT flag is not specified, then it defines
device-local dependencies for that synchronization command, for all
participating physical devices.

Semaphore and event dependencies are device-local and only execute on the
one physical device that performs the dependency.
endif::VK_VERSION_1_1,VK_KHR_device_group[]


[[synchronization-implicit]]
== Implicit Synchronization Guarantees

A small number of implicit ordering guarantees are provided by Vulkan,
ensuring that the order in which commands are submitted is meaningful, and
avoiding unnecessary complexity in common operations.

[[synchronization-submission-order]]
_Submission order_ is a fundamental ordering in Vulkan, giving meaning to
the order in which <<fundamentals-queueoperation-command-types, action and
synchronization commands>> are recorded and submitted to a single queue.
Explicit and implicit ordering guarantees between commands in Vulkan all
work on the premise that this ordering is meaningful.
This order does not itself define any execution or memory dependencies;
synchronization commands and other orderings within the API use this
ordering to define their scopes.

Submission order for any given set of commands is based on the order in
which they were recorded to command buffers and then submitted.
This order is determined as follows:

  . The initial order is determined by the order in which
    flink:vkQueueSubmit
ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
    and flink:vkQueueSubmit2
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]
    commands are executed on the host, for a single queue, from first to
    last.
  . The order in which slink:VkSubmitInfo structures are specified in the
    pname:pSubmits parameter of flink:vkQueueSubmit,
ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
    or in which slink:VkSubmitInfo2 structures are specified in the
    pname:pSubmits parameter of flink:vkQueueSubmit2,
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]
    from lowest index to highest.
  . The order in which command buffers are specified in the
    pname:pCommandBuffers member of slink:VkSubmitInfo
ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
    or slink:VkSubmitInfo2
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]
    from lowest index to highest.
  . The order in which commands were recorded to a command buffer on the
    host, from first to last:
  ** For commands recorded outside a render pass, this includes all other
     commands recorded outside a render pass, including
     flink:vkCmdBeginRenderPass and flink:vkCmdEndRenderPass commands; it
     does not directly include commands inside a render pass.
  ** For commands recorded inside a render pass, this includes all other
     commands recorded inside the same subpass, including the
     flink:vkCmdBeginRenderPass and flink:vkCmdEndRenderPass commands that
     delimit the same render pass instance; it does not include commands
     recorded to other subpasses.
<<fundamentals-queueoperation-command-types, State commands>> do not execute
any operations on the device, instead they set the state of the command
buffer when they execute on the host, in the order that they are recorded.
<<fundamentals-queueoperation-command-types, Action commands>> consume the
current state of the command buffer when they are recorded, and will execute
state changes on the device as required to match the recorded state.

<<drawing-primitive-order, The order of primitives passing through the
graphics pipeline>> and
<<synchronization-image-barrier-layout-transition-order, image layout
transitions as part of an image memory barrier>> provide additional
guarantees based on submission order.

Execution of <<synchronization-pipeline-stages-order, pipeline stages>>
within a given command also has a loose ordering, dependent only on a single
command.

[[synchronization-signal-operation-order]]
_Signal operation order_ is a fundamental ordering in Vulkan, giving meaning
to the order in which semaphore and fence signal operations occur when
submitted to a single queue.
The signal operation order for queue operations is determined as follows:

  . The initial order is determined by the order in which
    flink:vkQueueSubmit
ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
    and flink:vkQueueSubmit2
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]
    commands are executed on the host, for a single queue, from first to
    last.
  . The order in which slink:VkSubmitInfo structures are specified in the
    pname:pSubmits parameter of flink:vkQueueSubmit,
ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
    or in which slink:VkSubmitInfo2 structures are specified in the
    pname:pSubmits parameter of flink:vkQueueSubmit2,
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]
    from lowest index to highest.
  . The fence signal operation defined by the pname:fence parameter of a
    flink:vkQueueSubmit
ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[or flink:vkQueueSubmit2]
ifndef::VKSC_VERSION_1_0[or flink:vkQueueBindSparse]
    command is ordered after all semaphore signal operations defined by that
    command.

Semaphore signal operations defined by a single slink:VkSubmitInfo
ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[or slink:VkSubmitInfo2]
ifndef::VKSC_VERSION_1_0[or slink:VkBindSparseInfo]
structure are unordered with respect to other semaphore signal operations
defined within the same structure.

ifdef::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
The flink:vkSignalSemaphore command does not execute on a queue but instead
performs the signal operation from the host.
The semaphore signal operation defined by executing a
flink:vkSignalSemaphore command happens-after the flink:vkSignalSemaphore
command is invoked and happens-before the command returns.

[NOTE]
.Note
====
When signaling timeline semaphores, it is the responsibility of the
application to ensure that they are ordered such that the semaphore value is
strictly increasing.
Because the first synchronization scope for a semaphore signal operation
contains all semaphore signal operations which occur earlier in submission
order, all semaphore signal operations contained in any given batch are
guaranteed to happen-after all semaphore signal operations contained in any
previous batches.
However, no ordering guarantee is provided between the semaphore signal
operations defined within a single batch.
This, combined with the requirement that timeline semaphore values strictly
increase, means that it is invalid to signal the same timeline semaphore
twice within a single batch.

If an application wishes to ensure that some semaphore signal operation
happens-after some other semaphore signal operation, it can submit a
separate batch containing only semaphore signal operations, which will
happen-after the semaphore signal operations in any earlier batches.

When signaling a semaphore from the host, the only ordering guarantee is
that the signal operation happens-after when flink:vkSignalSemaphore is
called and happens-before it returns.
Therefore, it is invalid to call fname:vkSignalSemaphore while there are any
outstanding signal operations on that semaphore from any queue submissions
unless those queue submissions have some dependency which ensures that they
happen-after the host signal operation.
One example of this would be if the pending signal operation is, itself,
waiting on the same semaphore at a lower value and the call to
fname:vkSignalSemaphore signals that lower value.
Furthermore, if there are two or more processes or threads signaling the
same timeline semaphore from the host, the application must ensure that the
fname:vkSignalSemaphore with the lower semaphore value returns before
fname:vkSignalSemaphore is called with the higher value.
====
endif::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]


[[synchronization-fences]]
== Fences

[open,refpage='VkFence',desc='Opaque handle to a fence object',type='handles']
--
Fences are a synchronization primitive that can: be used to insert a
dependency from a queue to the host.
Fences have two states - signaled and unsignaled.
A fence can: be signaled as part of the execution of a
<<devsandqueues-submission, queue submission>> command.
Fences can: be unsignaled on the host with flink:vkResetFences.
Fences can: be waited on by the host with the flink:vkWaitForFences command,
and the current state can: be queried with flink:vkGetFenceStatus.

ifdef::VK_VERSION_1_1,VK_KHR_external_fence[]
[[synchronization-fences-payloads]]
The internal data of a fence may: include a reference to any resources and
pending work associated with signal or unsignal operations performed on that
fence object, collectively referred to as the fence's _payload_.
Mechanisms to import and export that internal data to and from fences are
provided <<VkExportFenceCreateInfo, below>>.
These mechanisms indirectly enable applications to share fence state between
two or more fences and other synchronization primitives across process and
API boundaries.

endif::VK_VERSION_1_1,VK_KHR_external_fence[]

Fences are represented by sname:VkFence handles:

include::{generated}/api/handles/VkFence.adoc[]
--

[open,refpage='vkCreateFence',desc='Create a new fence object',type='protos']
--
:refpage: vkCreateFence
:objectnameplural: fences
:objectnamecamelcase: fence
:objectcount: 1

To create a fence, call:

include::{generated}/api/protos/vkCreateFence.adoc[]

  * pname:device is the logical device that creates the fence.
  * pname:pCreateInfo is a pointer to a slink:VkFenceCreateInfo structure
    containing information about how the fence is to be created.
  * pname:pAllocator controls host memory allocation as described in the
    <<memory-allocation, Memory Allocation>> chapter.
  * pname:pFence is a pointer to a handle in which the resulting fence
    object is returned.

include::{chapters}/commonvalidity/no_dynamic_allocations_common.adoc[]

ifdef::VKSC_VERSION_1_0,VK_NV_external_sci_sync,VK_NV_external_sci_sync2[]
.Valid Usage
****
include::{chapters}/commonvalidity/memory_reservation_request_count_common.adoc[]
ifdef::VK_NV_external_sci_sync,VK_NV_external_sci_sync2[]
  * [[VUID-vkCreateFence-pNext-05106]]
    If the pname:pNext chain of slink:VkFenceCreateInfo includes
    slink:VkExportFenceSciSyncInfoNV, then
    slink:VkFenceCreateInfo::pname:flags must: not include
    ename:VK_FENCE_CREATE_SIGNALED_BIT
endif::VK_NV_external_sci_sync,VK_NV_external_sci_sync2[]
****
endif::VKSC_VERSION_1_0,VK_NV_external_sci_sync,VK_NV_external_sci_sync2[]

include::{generated}/validity/protos/vkCreateFence.adoc[]
--

[open,refpage='VkFenceCreateInfo',desc='Structure specifying parameters of a newly created fence',type='structs']
--
The sname:VkFenceCreateInfo structure is defined as:

include::{generated}/api/structs/VkFenceCreateInfo.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:flags is a bitmask of elink:VkFenceCreateFlagBits specifying the
    initial state and behavior of the fence.

include::{generated}/validity/structs/VkFenceCreateInfo.adoc[]
--

[open,refpage='VkFenceCreateFlagBits',desc='Bitmask specifying initial state and behavior of a fence',type='enums']
--
include::{generated}/api/enums/VkFenceCreateFlagBits.adoc[]

  * ename:VK_FENCE_CREATE_SIGNALED_BIT specifies that the fence object is
    created in the signaled state.
    Otherwise, it is created in the unsignaled state.
--

[open,refpage='VkFenceCreateFlags',desc='Bitmask of VkFenceCreateFlagBits',type='flags']
--
include::{generated}/api/flags/VkFenceCreateFlags.adoc[]

tname:VkFenceCreateFlags is a bitmask type for setting a mask of zero or
more elink:VkFenceCreateFlagBits.
--

ifdef::VK_VERSION_1_1,VK_KHR_external_fence[]
[open,refpage='VkExportFenceCreateInfo',desc='Structure specifying handle types that can be exported from a fence',type='structs']
--
To create a fence whose payload can: be exported to external handles, add a
slink:VkExportFenceCreateInfo structure to the pname:pNext chain of the
slink:VkFenceCreateInfo structure.
The sname:VkExportFenceCreateInfo structure is defined as:

include::{generated}/api/structs/VkExportFenceCreateInfo.adoc[]

ifdef::VK_KHR_external_fence[]
or the equivalent

include::{generated}/api/structs/VkExportFenceCreateInfoKHR.adoc[]
endif::VK_KHR_external_fence[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:handleTypes is a bitmask of
    elink:VkExternalFenceHandleTypeFlagBits specifying one or more fence
    handle types the application can: export from the resulting fence.
    The application can: request multiple handle types for the same fence.

.Valid Usage
****
  * [[VUID-VkExportFenceCreateInfo-handleTypes-01446]]
    The bits in pname:handleTypes must: be supported and compatible, as
    reported by slink:VkExternalFenceProperties
ifdef::VK_NV_external_sci_sync,VK_NV_external_sci_sync2[]
  * [[VUID-VkExportFenceCreateInfo-pNext-05107]]
    If the pname:pNext chain includes a slink:VkExportFenceSciSyncInfoNV
    structure,
    slink:VkPhysicalDeviceExternalSciSyncFeaturesNV::pname:sciSyncFence and
    slink:VkPhysicalDeviceExternalSciSyncFeaturesNV::pname:sciSyncExport, or
    slink:VkPhysicalDeviceExternalSciSync2FeaturesNV::pname:sciSyncFence and
    slink:VkPhysicalDeviceExternalSciSync2FeaturesNV::pname:sciSyncExport
    must: be enabled
endif::VK_NV_external_sci_sync,VK_NV_external_sci_sync2[]
****

include::{generated}/validity/structs/VkExportFenceCreateInfo.adoc[]
--
endif::VK_VERSION_1_1,VK_KHR_external_fence[]

ifdef::VK_KHR_external_fence_win32[]
[open,refpage='VkExportFenceWin32HandleInfoKHR',desc='Structure specifying additional attributes of Windows handles exported from a fence',type='structs']
--
To specify additional attributes of NT handles exported from a fence, add a
slink:VkExportFenceWin32HandleInfoKHR structure to the pname:pNext chain of
the slink:VkFenceCreateInfo structure.
The sname:VkExportFenceWin32HandleInfoKHR structure is defined as:

include::{generated}/api/structs/VkExportFenceWin32HandleInfoKHR.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:pAttributes is a pointer to a Windows code:SECURITY_ATTRIBUTES
    structure specifying security attributes of the handle.
  * pname:dwAccess is a code:DWORD specifying access rights of the handle.
  * pname:name is a null-terminated UTF-16 string to associate with the
    underlying synchronization primitive referenced by NT handles exported
    from the created fence.

If slink:VkExportFenceCreateInfo is not included in the same pname:pNext
chain, this structure is ignored.

If slink:VkExportFenceCreateInfo is included in the pname:pNext chain of
slink:VkFenceCreateInfo with a Windows pname:handleType, but either
sname:VkExportFenceWin32HandleInfoKHR is not included in the pname:pNext
chain, or it is included but pname:pAttributes is set to `NULL`, default
security descriptor values will be used, and child processes created by the
application will not inherit the handle, as described in the MSDN
documentation for "`Synchronization Object Security and Access Rights`"^1^.
Further, if the structure is not present, the access rights will be

code:DXGI_SHARED_RESOURCE_READ | code:DXGI_SHARED_RESOURCE_WRITE

for handles of the following types:

ename:VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_BIT

1::
    https://docs.microsoft.com/en-us/windows/win32/sync/synchronization-object-security-and-access-rights

.Valid Usage
****
  * [[VUID-VkExportFenceWin32HandleInfoKHR-handleTypes-01447]]
    If slink:VkExportFenceCreateInfo::pname:handleTypes does not include
    ename:VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_BIT, a
    sname:VkExportFenceWin32HandleInfoKHR structure must: not be included in
    the pname:pNext chain of slink:VkFenceCreateInfo
****

include::{generated}/validity/structs/VkExportFenceWin32HandleInfoKHR.adoc[]
--

[open,refpage='vkGetFenceWin32HandleKHR',desc='Get a Windows HANDLE for a fence',type='protos']
--
To export a Windows handle representing the state of a fence, call:

include::{generated}/api/protos/vkGetFenceWin32HandleKHR.adoc[]

  * pname:device is the logical device that created the fence being
    exported.
  * pname:pGetWin32HandleInfo is a pointer to a
    slink:VkFenceGetWin32HandleInfoKHR structure containing parameters of
    the export operation.
  * pname:pHandle will return the Windows handle representing the fence
    state.

For handle types defined as NT handles, the handles returned by
fname:vkGetFenceWin32HandleKHR are owned by the application.
To avoid leaking resources, the application must: release ownership of them
using the code:CloseHandle system call when they are no longer needed.

Exporting a Windows handle from a fence may: have side effects depending on
the transference of the specified handle type, as described in
<<synchronization-fences-importing,Importing Fence Payloads>>.

include::{generated}/validity/protos/vkGetFenceWin32HandleKHR.adoc[]
--

[open,refpage='VkFenceGetWin32HandleInfoKHR',desc='Structure describing a Win32 handle fence export operation',type='structs']
--
The sname:VkFenceGetWin32HandleInfoKHR structure is defined as:

include::{generated}/api/structs/VkFenceGetWin32HandleInfoKHR.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:fence is the fence from which state will be exported.
  * pname:handleType is a elink:VkExternalFenceHandleTypeFlagBits value
    specifying the type of handle requested.

The properties of the handle returned depend on the value of
pname:handleType.
See elink:VkExternalFenceHandleTypeFlagBits for a description of the
properties of the defined external fence handle types.

.Valid Usage
****
  * [[VUID-VkFenceGetWin32HandleInfoKHR-handleType-01448]]
    pname:handleType must: have been included in
    slink:VkExportFenceCreateInfo::pname:handleTypes when the pname:fence's
    current payload was created
  * [[VUID-VkFenceGetWin32HandleInfoKHR-handleType-01449]]
    If pname:handleType is defined as an NT handle,
    flink:vkGetFenceWin32HandleKHR must: be called no more than once for
    each valid unique combination of pname:fence and pname:handleType
  * [[VUID-VkFenceGetWin32HandleInfoKHR-fence-01450]]
    pname:fence must: not currently have its payload replaced by an imported
    payload as described below in
    <<synchronization-fences-importing,Importing Fence Payloads>> unless
    that imported payload's handle type was included in
    slink:VkExternalFenceProperties::pname:exportFromImportedHandleTypes for
    pname:handleType
  * [[VUID-VkFenceGetWin32HandleInfoKHR-handleType-01451]]
    If pname:handleType refers to a handle type with copy payload
    transference semantics, pname:fence must: be signaled, or have an
    associated <<synchronization-fences-signaling,fence signal operation>>
    pending execution
  * [[VUID-VkFenceGetWin32HandleInfoKHR-handleType-01452]]
    pname:handleType must: be defined as an NT handle or a global share
    handle
****

include::{generated}/validity/structs/VkFenceGetWin32HandleInfoKHR.adoc[]
--
endif::VK_KHR_external_fence_win32[]

ifdef::VK_KHR_external_fence_fd[]
[open,refpage='vkGetFenceFdKHR',desc='Get a POSIX file descriptor handle for a fence',type='protos']
--
:refpage: vkGetFenceFdKHR

To export a POSIX file descriptor representing the payload of a fence, call:

include::{generated}/api/protos/vkGetFenceFdKHR.adoc[]

  * pname:device is the logical device that created the fence being
    exported.
  * pname:pGetFdInfo is a pointer to a slink:VkFenceGetFdInfoKHR structure
    containing parameters of the export operation.
  * pname:pFd will return the file descriptor representing the fence
    payload.

Each call to fname:vkGetFenceFdKHR must: create a new file descriptor and
transfer ownership of it to the application.
To avoid leaking resources, the application must: release ownership of the
file descriptor when it is no longer needed.

[NOTE]
.Note
====
Ownership can be released in many ways.
For example, the application can call code:close() on the file descriptor,
or transfer ownership back to Vulkan by using the file descriptor to import
a fence payload.
====

If pname:pGetFdInfo->handleType is
ename:VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT and the fence is signaled at
the time fname:vkGetFenceFdKHR is called, pname:pFd may: return the value
`-1` instead of a valid file descriptor.

Where supported by the operating system, the implementation must: set the
file descriptor to be closed automatically when an code:execve system call
is made.

Exporting a file descriptor from a fence may: have side effects depending on
the transference of the specified handle type, as described in
<<synchronization-fences-importing,Importing Fence State>>.

include::{chapters}/commonvalidity/no_dynamic_allocations_common.adoc[]

include::{generated}/validity/protos/vkGetFenceFdKHR.adoc[]
--

[open,refpage='VkFenceGetFdInfoKHR',desc='Structure describing a POSIX FD fence export operation',type='structs']
--
The sname:VkFenceGetFdInfoKHR structure is defined as:

include::{generated}/api/structs/VkFenceGetFdInfoKHR.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:fence is the fence from which state will be exported.
  * pname:handleType is a elink:VkExternalFenceHandleTypeFlagBits value
    specifying the type of handle requested.

The properties of the file descriptor returned depend on the value of
pname:handleType.
See elink:VkExternalFenceHandleTypeFlagBits for a description of the
properties of the defined external fence handle types.

.Valid Usage
****
  * [[VUID-VkFenceGetFdInfoKHR-handleType-01453]]
    pname:handleType must: have been included in
    slink:VkExportFenceCreateInfo::pname:handleTypes when pname:fence's
    current payload was created
  * [[VUID-VkFenceGetFdInfoKHR-handleType-01454]]
    If pname:handleType refers to a handle type with copy payload
    transference semantics, pname:fence must: be signaled, or have an
    associated <<synchronization-fences-signaling,fence signal operation>>
    pending execution
  * [[VUID-VkFenceGetFdInfoKHR-fence-01455]]
    pname:fence must: not currently have its payload replaced by an imported
    payload as described below in
    <<synchronization-fences-importing,Importing Fence Payloads>> unless
    that imported payload's handle type was included in
    slink:VkExternalFenceProperties::pname:exportFromImportedHandleTypes for
    pname:handleType
  * [[VUID-VkFenceGetFdInfoKHR-handleType-01456]]
    pname:handleType must: be defined as a POSIX file descriptor handle
****

include::{generated}/validity/structs/VkFenceGetFdInfoKHR.adoc[]
--
endif::VK_KHR_external_fence_fd[]

ifdef::VK_NV_external_sci_sync,VK_NV_external_sci_sync2[]
[open,refpage='VkExportFenceSciSyncInfoNV',desc='Structure specifying additional attributes SciSync handles exported from a fence',type='structs']
--
To specify additional attributes of stext:NvSciSync handles exported from a
fence, add a slink:VkExportFenceSciSyncInfoNV structure to the pname:pNext
chain of the slink:VkFenceCreateInfo structure.
The sname:VkExportFenceSciSyncInfoNV structure is defined as:

include::{generated}/api/structs/VkExportFenceSciSyncInfoNV.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:pAttributes is an opaque sname:NvSciSyncAttrList describing the
    attributes of the NvSciSync object that will be exported.

If slink:VkExportFenceCreateInfo is not present in the same pname:pNext
chain, this structure is ignored.
If the pname:pNext chain of slink:VkFenceCreateInfo includes a
slink:VkExportFenceCreateInfo structure with a NvSciSync pname:handleType,
but either slink:VkExportFenceSciSyncInfoNV is not included in the
pname:pNext chain, or it is included but pname:pAttributes is set to `NULL`,
flink:vkCreateFence will return ename:VK_ERROR_INITIALIZATION_FAILED.

The pname:pAttributes must: be a reconciled sname:NvSciSyncAttrList.
Before exporting the NvSciSync handles, applications must: use the
flink:vkGetPhysicalDeviceSciSyncAttributesNV command to get the unreconciled
sname:NvSciSyncAttrList and then use the NvSciSync API to reconcile it.

.Valid Usage
****
  * [[VUID-VkExportFenceSciSyncInfoNV-pAttributes-05108]]
    pname:pAttributes must: be a reconciled stext:NvSciSyncAttrList
****

include::{generated}/validity/structs/VkExportFenceSciSyncInfoNV.adoc[]
--

[open,refpage='vkGetPhysicalDeviceSciSyncAttributesNV',desc='Get the implementation-specific NvSciSync attributes',type='protos']
--

To obtain the implementation-specific NvSciSync attributes in an
unreconciled sname:NvSciSyncAttrList, call:

include::{generated}/api/protos/vkGetPhysicalDeviceSciSyncAttributesNV.adoc[]

  * pname:physicalDevice is the handle to the physical device that will be
    used to determine the attributes.
  * pname:pSciSyncAttributesInfo is a pointer to a
    slink:VkSciSyncAttributesInfoNV structure containing information about
    how the attributes are to be filled.
  * pname:pAttributes is an opaque stext:NvSciSyncAttrList in which the
    implementation will set the requested attributes.

On success, pname:pAttributes will contain an unreconciled
stext:NvSciSyncAttrList whose private attributes and some public attributes
are filled in by the implementation.
If the attributes of pname:physicalDevice could not be obtained,
ename:VK_ERROR_INITIALIZATION_FAILED is returned.

.Valid Usage
****
  * [[VUID-vkGetPhysicalDeviceSciSyncAttributesNV-pSciSyncAttributesInfo-05109]]
    If pname:pSciSyncAttributesInfo->primitiveType is
    ename:VK_SCI_SYNC_PRIMITIVE_TYPE_FENCE_NV then
    slink:VkPhysicalDeviceExternalSciSyncFeaturesNV::pname:sciSyncFence or
    slink:VkPhysicalDeviceExternalSciSync2FeaturesNV::pname:sciSyncFence
    must: be enabled
  * [[VUID-vkGetPhysicalDeviceSciSyncAttributesNV-pSciSyncAttributesInfo-05110]]
    If pname:pSciSyncAttributesInfo->primitiveType is
    ename:VK_SCI_SYNC_PRIMITIVE_TYPE_SEMAPHORE_NV then
    slink:VkPhysicalDeviceExternalSciSyncFeaturesNV::pname:sciSyncSemaphore
    or
    slink:VkPhysicalDeviceExternalSciSync2FeaturesNV::pname:sciSyncSemaphore2
    must: be enabled
  * [[VUID-vkGetPhysicalDeviceSciSyncAttributesNV-pAttributes-05111]]
    pname:pAttributes must: be a valid stext:NvSciSyncAttrList and must: not
    be `NULL`
****

include::{generated}/validity/protos/vkGetPhysicalDeviceSciSyncAttributesNV.adoc[]
--

[open,refpage='VkSciSyncAttributesInfoNV',desc='Structure describing SciSync attribute information',type='structs']
--
The sname:VkSciSyncAttributesInfoNV structure is defined as:

include::{generated}/api/structs/VkSciSyncAttributesInfoNV.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:clientType is the permission type of client.
  * pname:primitiveType is the synchronization primitive type.

NvSciSync disallows multi-signalers, therefore clients must: specify their
permission types as one of signaler, waiter or signaler_waiter.
In addition, NvSciSync requires clients to specify which primitive type is
to be used in synchronization, hence clients also need to provide the
primitive type (slink:VkFence or slink:VkSemaphore) that will be used.

include::{generated}/validity/structs/VkSciSyncAttributesInfoNV.adoc[]
--

[open,refpage='VkSciSyncClientTypeNV',desc='Enums specifying client permission types',type='enums']
--
The ename:VkSciSyncClientTypeNV enum is defined as:

include::{generated}/api/enums/VkSciSyncClientTypeNV.adoc[]

  * ename:VK_SCI_SYNC_CLIENT_TYPE_SIGNALER_NV specifies the permission of
    the client as signaler.
    It indicates that the client can only signal the created fence or
    semaphore and disallows waiting on it.
  * ename:VK_SCI_SYNC_CLIENT_TYPE_WAITER_NV specifies the permission of the
    client as waiter.
    It indicates that the client can only wait on the imported fence or
    semaphore and disallows signalling it.
    This type of permission is only used when the client imports NvSciSync
    handles, and export is not allowed.
  * ename:VK_SCI_SYNC_CLIENT_TYPE_SIGNALER_WAITER_NV specifies the
    permission of client as both signaler and waiter.
    It indicates that the client can: signal and wait on the created fence
    or semaphore.
--

[open,refpage='VkSciSyncPrimitiveTypeNV',desc='Enums specifying the primitive types',type='enums']
--
The ename:VkSciSyncPrimitiveTypeNV enum is defined as:

include::{generated}/api/enums/VkSciSyncPrimitiveTypeNV.adoc[]

  * ename:VK_SCI_SYNC_PRIMITIVE_TYPE_FENCE_NV specifies that the
    synchronization primitive type the client will create is a
    slink:VkFence.
  * ename:VK_SCI_SYNC_PRIMITIVE_TYPE_SEMAPHORE_NV specifies that the
    synchronization primitive type the client will create is a
    slink:VkSemaphore.
--

[open,refpage='vkGetFenceSciSyncFenceNV',desc='Get a stext:NvSciSyncFence handle for a fence',type='protos']
--
To export a stext:NvSciSyncFence handle representing the payload of a fence,
call:

include::{generated}/api/protos/vkGetFenceSciSyncFenceNV.adoc[]

  * pname:device is the logical device that created the fence being
    exported.
  * pname:pGetSciSyncHandleInfo is a pointer to a
    slink:VkFenceGetSciSyncInfoNV structure containing parameters of the
    export operation.
  * pname:pHandle is a pointer to a stext:NvSciSyncFence which will contain
    the fence payload on return.

Each call to fname:vkGetFenceSciSyncFenceNV will duplicate the underlying
stext:NvSciSyncFence handle and transfer the ownership of the
stext:NvSciSyncFence handle to the application.
To avoid leaking resources, the application must: release of the ownership
of the stext:NvSciSyncFence handle when it is no longer needed.

.Valid Usage
****
  * [[VUID-vkGetFenceSciSyncFenceNV-pGetSciSyncHandleInfo-05112]]
    pname:pGetSciSyncHandleInfo->handleType must: be
    ename:VK_EXTERNAL_FENCE_HANDLE_TYPE_SCI_SYNC_FENCE_BIT_NV
  * [[VUID-vkGetFenceSciSyncFenceNV-sciSyncFence-05113]]
    slink:VkPhysicalDeviceExternalSciSyncFeaturesNV::pname:sciSyncFence or
    slink:VkPhysicalDeviceExternalSciSync2FeaturesNV::pname:sciSyncFence
    must: be enabled
****

include::{generated}/validity/protos/vkGetFenceSciSyncFenceNV.adoc[]
--

[open,refpage='vkGetFenceSciSyncObjNV',desc='Get a stext:NvSciSyncObj handle for a fence',type='protos']
--
To export a stext:NvSciSyncObj handle representing the payload of a fence,
call:

include::{generated}/api/protos/vkGetFenceSciSyncObjNV.adoc[]

  * pname:device is the logical device that created the fence being
    exported.
  * pname:pGetSciSyncHandleInfo is a pointer to a
    slink:VkFenceGetSciSyncInfoNV structure containing parameters of the
    export operation.
  * pname:pHandle will return the stext:NvSciSyncObj handle representing the
    fence payload.

Each call to fname:vkGetFenceSciSyncObjNV will duplicate the underlying
stext:NvSciSyncObj handle and transfer the ownership of the
stext:NvSciSyncObj handle to the application.
To avoid leaking resources, the application must: release of the ownership
of the stext:NvSciSyncObj handle when it is no longer needed.

.Valid Usage
****
  * [[VUID-vkGetFenceSciSyncObjNV-pGetSciSyncHandleInfo-05114]]
    pname:pGetSciSyncHandleInfo->handleType must: be
    ename:VK_EXTERNAL_FENCE_HANDLE_TYPE_SCI_SYNC_OBJ_BIT_NV
  * [[VUID-vkGetFenceSciSyncObjNV-sciSyncFence-05115]]
    slink:VkPhysicalDeviceExternalSciSyncFeaturesNV::pname:sciSyncFence or
    slink:VkPhysicalDeviceExternalSciSync2FeaturesNV::pname:sciSyncFence
    must: be enabled
****

include::{generated}/validity/protos/vkGetFenceSciSyncObjNV.adoc[]
--

[open,refpage='VkFenceGetSciSyncInfoNV',desc='Structure describing a slink:VkFence export operation to NvSciSync',type='structs']
--
The sname:VkFenceGetSciSyncInfoNV structure is defined as:

include::{generated}/api/structs/VkFenceGetSciSyncInfoNV.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:fence is the fence from which state will be exported.
  * pname:handleType is the type of NvSciSync handle (stext:NvSciSyncObj or
    stext:NvSciSyncFence) representing the fence payload that will be
    exported.

If pname:handleType is
ename:VK_EXTERNAL_FENCE_HANDLE_TYPE_SCI_SYNC_OBJ_BIT_NV, a
stext:NvSciSyncObj will be exported.
If pname:handleType is
ename:VK_EXTERNAL_FENCE_HANDLE_TYPE_SCI_SYNC_FENCE_BIT_NV, a
stext:NvSciSyncFence will be exported.

include::{generated}/validity/structs/VkFenceGetSciSyncInfoNV.adoc[]
--
endif::VK_NV_external_sci_sync,VK_NV_external_sci_sync2[]

[open,refpage='vkDestroyFence',desc='Destroy a fence object',type='protos']
--
To destroy a fence, call:

include::{generated}/api/protos/vkDestroyFence.adoc[]

  * pname:device is the logical device that destroys the fence.
  * pname:fence is the handle of the fence to destroy.
  * pname:pAllocator controls host memory allocation as described in the
    <<memory-allocation, Memory Allocation>> chapter.

.Valid Usage
****
  * [[VUID-vkDestroyFence-fence-01120]]
    All <<devsandqueues-submission, queue submission>> commands that refer
    to pname:fence must: have completed execution
ifndef::VKSC_VERSION_1_0[]
  * [[VUID-vkDestroyFence-fence-01121]]
    If sname:VkAllocationCallbacks were provided when pname:fence was
    created, a compatible set of callbacks must: be provided here
  * [[VUID-vkDestroyFence-fence-01122]]
    If no sname:VkAllocationCallbacks were provided when pname:fence was
    created, pname:pAllocator must: be `NULL`
endif::VKSC_VERSION_1_0[]
****

include::{generated}/validity/protos/vkDestroyFence.adoc[]
--

[open,refpage='vkGetFenceStatus',desc='Return the status of a fence',type='protos']
--
:refpage: vkGetFenceStatus

To query the status of a fence from the host, call:

include::{generated}/api/protos/vkGetFenceStatus.adoc[]

  * pname:device is the logical device that owns the fence.
  * pname:fence is the handle of the fence to query.

Upon success, fname:vkGetFenceStatus returns the status of the fence object,
with the following return codes:

.Fence Object Status Codes
[width="80%",options="header"]
|====
| Status | Meaning
| ename:VK_SUCCESS | The fence specified by pname:fence is signaled.
| ename:VK_NOT_READY | The fence specified by pname:fence is unsignaled.
| ename:VK_ERROR_DEVICE_LOST | The device has been lost.  See <<devsandqueues-lost-device,Lost Device>>.
|====

If a <<devsandqueues-submission, queue submission>> command is pending
execution, then the value returned by this command may: immediately be out
of date.

If the device has been lost (see <<devsandqueues-lost-device,Lost Device>>),
fname:vkGetFenceStatus may: return any of the above status codes.
If the device has been lost and fname:vkGetFenceStatus is called repeatedly,
it will eventually return either ename:VK_SUCCESS or
ename:VK_ERROR_DEVICE_LOST.

include::{chapters}/commonvalidity/no_dynamic_allocations_common.adoc[]

include::{generated}/validity/protos/vkGetFenceStatus.adoc[]
--

[[synchronization-fences-unsignaling]]
[open,refpage='vkResetFences',desc='Resets one or more fence objects',type='protos']
--
To set the state of fences to unsignaled from the host, call:

include::{generated}/api/protos/vkResetFences.adoc[]

  * pname:device is the logical device that owns the fences.
  * pname:fenceCount is the number of fences to reset.
  * pname:pFences is a pointer to an array of fence handles to reset.

ifdef::VK_VERSION_1_1,VK_KHR_external_fence[]

If any member of pname:pFences currently has its
<<synchronization-fences-importing, payload imported>> with temporary
permanence, that fence's prior permanent payload is first restored.
The remaining operations described therefore operate on the restored
payload.

endif::VK_VERSION_1_1,VK_KHR_external_fence[]

When flink:vkResetFences is executed on the host, it defines a _fence
unsignal operation_ for each fence, which resets the fence to the unsignaled
state.

If any member of pname:pFences is already in the unsignaled state when
flink:vkResetFences is executed, then flink:vkResetFences has no effect on
that fence.

.Valid Usage
****
  * [[VUID-vkResetFences-pFences-01123]]
    Each element of pname:pFences must: not be currently associated with any
    queue command that has not yet completed execution on that queue
****

include::{generated}/validity/protos/vkResetFences.adoc[]
--

[[synchronization-fences-signaling]]
When a fence is submitted to a queue as part of a
<<devsandqueues-submission, queue submission>> command, it defines a memory
dependency on the batches that were submitted as part of that command, and
defines a _fence signal operation_ which sets the fence to the signaled
state.

The first <<synchronization-dependencies-scopes, synchronization scope>>
includes every batch submitted in the same <<devsandqueues-submission, queue
submission>> command.
Fence signal operations that are defined by flink:vkQueueSubmit
ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[or flink:vkQueueSubmit2]
additionally include in the first synchronization scope all commands that
occur earlier in <<synchronization-submission-order,submission order>>.
Fence signal operations that are defined by flink:vkQueueSubmit
ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[or flink:vkQueueSubmit2]
ifndef::VKSC_VERSION_1_0[or flink:vkQueueBindSparse]
additionally include in the first synchronization scope any semaphore and
fence signal operations that occur earlier in
<<synchronization-signal-operation-order,signal operation order>>.

The second <<synchronization-dependencies-scopes, synchronization scope>>
only includes the fence signal operation.

The first <<synchronization-dependencies-access-scopes, access scope>>
includes all memory access performed by the device.

The second <<synchronization-dependencies-access-scopes, access scope>> is
empty.

[open,refpage='vkWaitForFences',desc='Wait for one or more fences to become signaled',type='protos']
--
:refpage: vkWaitForFences

To wait for one or more fences to enter the signaled state on the host,
call:

include::{generated}/api/protos/vkWaitForFences.adoc[]

  * pname:device is the logical device that owns the fences.
  * pname:fenceCount is the number of fences to wait on.
  * pname:pFences is a pointer to an array of pname:fenceCount fence
    handles.
  * pname:waitAll is the condition that must: be satisfied to successfully
    unblock the wait.
    If pname:waitAll is ename:VK_TRUE, then the condition is that all fences
    in pname:pFences are signaled.
    Otherwise, the condition is that at least one fence in pname:pFences is
    signaled.
  * pname:timeout is the timeout period in units of nanoseconds.
    pname:timeout is adjusted to the closest value allowed by the
    implementation-dependent timeout accuracy, which may: be substantially
    longer than one nanosecond, and may: be longer than the requested
    period.

If the condition is satisfied when fname:vkWaitForFences is called, then
fname:vkWaitForFences returns immediately.
If the condition is not satisfied at the time fname:vkWaitForFences is
called, then fname:vkWaitForFences will block and wait until the condition
is satisfied or the pname:timeout has expired, whichever is sooner.

If pname:timeout is zero, then fname:vkWaitForFences does not wait, but
simply returns the current state of the fences.
ename:VK_TIMEOUT will be returned in this case if the condition is not
satisfied, even though no actual wait was performed.

If the condition is satisfied before the pname:timeout has expired,
fname:vkWaitForFences returns ename:VK_SUCCESS.
Otherwise, fname:vkWaitForFences returns ename:VK_TIMEOUT after the
pname:timeout has expired.

If device loss occurs (see <<devsandqueues-lost-device,Lost Device>>) before
the timeout has expired, fname:vkWaitForFences must: return in finite time
with either ename:VK_SUCCESS or ename:VK_ERROR_DEVICE_LOST.

[NOTE]
.Note
====
While we guarantee that fname:vkWaitForFences must: return in finite time,
no guarantees are made that it returns immediately upon device loss.
However, the client can reasonably expect that the delay will be on the
order of seconds and that calling fname:vkWaitForFences will not result in a
permanently (or seemingly permanently) dead process.
====

include::{chapters}/commonvalidity/no_dynamic_allocations_common.adoc[]

include::{generated}/validity/protos/vkWaitForFences.adoc[]
--

[[synchronization-fences-waiting]]
An execution dependency is defined by waiting for a fence to become
signaled, either via flink:vkWaitForFences or by polling on
flink:vkGetFenceStatus.

The first <<synchronization-dependencies-scopes, synchronization scope>>
includes only the fence signal operation.

The second <<synchronization-dependencies-scopes, synchronization scope>>
includes the host operations of flink:vkWaitForFences or
flink:vkGetFenceStatus indicating that the fence has become signaled.

[NOTE]
.Note
====
Signaling a fence and waiting on the host does not guarantee that the
results of memory accesses will be visible to the host, as the access scope
of a memory dependency defined by a fence only includes device access.
A <<synchronization-memory-barriers, memory barrier>> or other memory
dependency must: be used to guarantee this.
See the description of <<synchronization-host-access-types, host access
types>> for more information.
====

ifdef::VK_EXT_display_control[]
include::{chapters}/VK_EXT_display_control/fence_events.adoc[]
endif::VK_EXT_display_control[]


ifdef::VK_VERSION_1_1,VK_KHR_external_fence[]
[[synchronization-fences-importing]]
=== Importing Fence Payloads

Applications can: import a fence payload into an existing fence using an
external fence handle.
The effects of the import operation will be either temporary or permanent,
as specified by the application.
If the import is temporary, the fence will be _restored_ to its permanent
state the next time that fence is passed to flink:vkResetFences.

[NOTE]
.Note
====
Restoring a fence to its prior permanent payload is a distinct operation
from resetting a fence payload.
See flink:vkResetFences for more detail.
====

Performing a subsequent temporary import on a fence before resetting it has
no effect on this requirement; the next unsignal of the fence must: still
restore its last permanent state.
A permanent payload import behaves as if the target fence was destroyed, and
a new fence was created with the same handle but the imported payload.
Because importing a fence payload temporarily or permanently detaches the
existing payload from a fence, similar usage restrictions to those applied
to fname:vkDestroyFence are applied to any command that imports a fence
payload.
Which of these import types is used is referred to as the import operation's
_permanence_.
Each handle type supports either one or both types of permanence.

The implementation must: perform the import operation by either referencing
or copying the payload referred to by the specified external fence handle,
depending on the handle's type.
The import method used is referred to as the handle type's _transference_.
When using handle types with reference transference, importing a payload to
a fence adds the fence to the set of all fences sharing that payload.
This set includes the fence from which the payload was exported.
Fence signaling, waiting, and resetting operations performed on any fence in
the set must: behave as if the set were a single fence.
Importing a payload using handle types with copy transference creates a
duplicate copy of the payload at the time of import, but makes no further
reference to it.
Fence signaling, waiting, and resetting operations performed on the target
of copy imports must: not affect any other fence or payload.

Export operations have the same transference as the specified handle type's
import operations.
Additionally, exporting a fence payload to a handle with copy transference
has the same side effects on the source fence's payload as executing a fence
reset operation.
If the fence was using a temporarily imported payload, the fence's prior
permanent payload will be restored.

ifdef::VK_KHR_external_fence_win32,VK_KHR_external_fence_fd[]
[NOTE]
.Note
====
The
ifdef::VK_KHR_external_fence_win32+VK_KHR_external_fence_fd[tables]
ifndef::VK_KHR_external_fence_win32+VK_KHR_external_fence_fd[table]
ifdef::VK_KHR_external_fence_win32[]
<<synchronization-fence-handletypes-win32,Handle Types Supported by
sname:VkImportFenceWin32HandleInfoKHR>>
endif::VK_KHR_external_fence_win32[]
ifdef::VK_KHR_external_fence_win32+VK_KHR_external_fence_fd[and]
ifdef::VK_KHR_external_fence_fd[]
<<synchronization-fence-handletypes-fd,Handle Types Supported by
sname:VkImportFenceFdInfoKHR>>
endif::VK_KHR_external_fence_fd[]
ifdef::VK_KHR_external_fence_win32+VK_KHR_external_fence_fd[define]
ifndef::VK_KHR_external_fence_win32+VK_KHR_external_fence_fd[defines]
the permanence and transference of each handle type.
====
endif::VK_KHR_external_fence_win32,VK_KHR_external_fence_fd[]

<<fundamentals-threadingbehavior,External synchronization>> allows
implementations to modify an object's internal state, i.e. payload, without
internal synchronization.
However, for fences sharing a payload across processes, satisfying the
external synchronization requirements of sname:VkFence parameters as if all
fences in the set were the same object is sometimes infeasible.
Satisfying valid usage constraints on the state of a fence would similarly
require impractical coordination or levels of trust between processes.
Therefore, these constraints only apply to a specific fence handle, not to
its payload.
For distinct fence objects which share a payload:

  * If multiple commands which queue a signal operation, or which unsignal a
    fence, are called concurrently, behavior will be as if the commands were
    called in an arbitrary sequential order.
  * If a queue submission command is called with a fence that is sharing a
    payload, and the payload is already associated with another queue
    command that has not yet completed execution, either one or both of the
    commands will cause the fence to become signaled when they complete
    execution.
  * If a fence payload is reset while it is associated with a queue command
    that has not yet completed execution, the payload will become
    unsignaled, but may: become signaled again when the command completes
    execution.
  * In the preceding cases, any of the devices associated with the fences
    sharing the payload may: be lost, or any of the queue submission or
    fence reset commands may: return ename:VK_ERROR_INITIALIZATION_FAILED.

Other than these non-deterministic results, behavior is well defined.
In particular:

  * The implementation must: not crash or enter an internally inconsistent
    state where future valid Vulkan commands might cause undefined: results,
  * Timeouts on future wait commands on fences sharing the payload must: be
    effective.

[NOTE]
.Note
====
These rules allow processes to synchronize access to shared memory without
trusting each other.
However, such processes must still be cautious not to use the shared fence
for more than synchronizing access to the shared memory.
For example, a process should not use a fence with shared payload to tell
when commands it submitted to a queue have completed and objects used by
those commands may be destroyed, since the other process can accidentally or
maliciously cause the fence to signal before the commands actually complete.
====

When a fence is using an imported payload, its
slink:VkExportFenceCreateInfo::pname:handleTypes value is specified when
creating the fence from which the payload was exported, rather than
specified when creating the fence.
Additionally,
slink:VkExternalFenceProperties::pname:exportFromImportedHandleTypes
restricts which handle types can: be exported from such a fence based on the
specific handle type used to import the current payload.
ifdef::VK_KHR_swapchain[]
Passing a fence to flink:vkAcquireNextImageKHR is equivalent to temporarily
importing a fence payload to that fence.

[NOTE]
.Note
====
Because the exportable handle types of an imported fence correspond to its
current imported payload, and flink:vkAcquireNextImageKHR behaves the same
as a temporary import operation for which the source fence is opaque to the
application, applications have no way of determining whether any external
handle types can: be exported from a fence in this state.
Therefore, applications must: not attempt to export handles from fences
using a temporarily imported payload from flink:vkAcquireNextImageKHR.
====
endif::VK_KHR_swapchain[]

When importing a fence payload, it is the responsibility of the application
to ensure the external handles meet all valid usage requirements.
However, implementations must: perform sufficient validation of external
handles to ensure that the operation results in a valid fence which will not
cause program termination, device loss, queue stalls, host thread stalls, or
corruption of other resources when used as allowed according to its import
parameters.
If the external handle provided does not meet these requirements, the
implementation must: fail the fence payload import operation with the error
code ename:VK_ERROR_INVALID_EXTERNAL_HANDLE.
endif::VK_VERSION_1_1,VK_KHR_external_fence[]

ifdef::VK_KHR_external_fence_win32[]
[open,refpage='vkImportFenceWin32HandleKHR',desc='Import a fence from a Windows HANDLE',type='protos']
--
To import a fence payload from a Windows handle, call:

include::{generated}/api/protos/vkImportFenceWin32HandleKHR.adoc[]

  * pname:device is the logical device that created the fence.
  * pname:pImportFenceWin32HandleInfo is a pointer to a
    slink:VkImportFenceWin32HandleInfoKHR structure specifying the fence and
    import parameters.

Importing a fence payload from Windows handles does not transfer ownership
of the handle to the Vulkan implementation.
For handle types defined as NT handles, the application must: release
ownership using the code:CloseHandle system call when the handle is no
longer needed.

Applications can: import the same fence payload into multiple instances of
Vulkan, into the same instance from which it was exported, and multiple
times into a given Vulkan instance.

.Valid Usage
****
  * [[VUID-vkImportFenceWin32HandleKHR-fence-04448]]
    pname:fence must: not be associated with any queue command that has not
    yet completed execution on that queue
****

include::{generated}/validity/protos/vkImportFenceWin32HandleKHR.adoc[]
--

[open,refpage='VkImportFenceWin32HandleInfoKHR',desc='(None)',type='structs']
--
The sname:VkImportFenceWin32HandleInfoKHR structure is defined as:

include::{generated}/api/structs/VkImportFenceWin32HandleInfoKHR.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:fence is the fence into which the state will be imported.
  * pname:flags is a bitmask of elink:VkFenceImportFlagBits specifying
    additional parameters for the fence payload import operation.
  * pname:handleType is a elink:VkExternalFenceHandleTypeFlagBits value
    specifying the type of pname:handle.
  * pname:handle is `NULL` or the external handle to import.
  * pname:name is `NULL` or a null-terminated UTF-16 string naming the
    underlying synchronization primitive to import.

The handle types supported by pname:handleType are:

[[synchronization-fence-handletypes-win32]]
.Handle Types Supported by sname:VkImportFenceWin32HandleInfoKHR
[width="80%",options="header"]
|====
| Handle Type                                                  | Transference | Permanence Supported
| ename:VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_BIT     | Reference    | Temporary,Permanent
| ename:VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT | Reference    | Temporary,Permanent
|====

.Valid Usage
****
  * [[VUID-VkImportFenceWin32HandleInfoKHR-handleType-01457]]
    pname:handleType must: be a value included in the
    <<synchronization-fence-handletypes-win32, Handle Types Supported by
    sname:VkImportFenceWin32HandleInfoKHR>> table
  * [[VUID-VkImportFenceWin32HandleInfoKHR-handleType-01459]]
    If pname:handleType is not
    ename:VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_BIT, pname:name must:
    be `NULL`
  * [[VUID-VkImportFenceWin32HandleInfoKHR-handleType-01460]]
    If pname:handle is `NULL`, pname:name must: name a valid synchronization
    primitive of the type specified by pname:handleType
  * [[VUID-VkImportFenceWin32HandleInfoKHR-handleType-01461]]
    If pname:name is `NULL`, pname:handle must: be a valid handle of the
    type specified by pname:handleType
  * [[VUID-VkImportFenceWin32HandleInfoKHR-handle-01462]]
    If pname:handle is not `NULL`, pname:name must: be `NULL`
  * [[VUID-VkImportFenceWin32HandleInfoKHR-handle-01539]]
    If pname:handle is not `NULL`, it must: obey any requirements listed for
    pname:handleType in <<external-fence-handle-types-compatibility,external
    fence handle types compatibility>>
  * [[VUID-VkImportFenceWin32HandleInfoKHR-name-01540]]
    If pname:name is not `NULL`, it must: obey any requirements listed for
    pname:handleType in <<external-fence-handle-types-compatibility,external
    fence handle types compatibility>>
****

include::{generated}/validity/structs/VkImportFenceWin32HandleInfoKHR.adoc[]
--
endif::VK_KHR_external_fence_win32[]

ifdef::VK_KHR_external_fence_fd[]
[open,refpage='vkImportFenceFdKHR',desc='Import a fence from a POSIX file descriptor',type='protos']
--
:refpage: vkImportFenceFdKHR

To import a fence payload from a POSIX file descriptor, call:

include::{generated}/api/protos/vkImportFenceFdKHR.adoc[]

  * pname:device is the logical device that created the fence.
  * pname:pImportFenceFdInfo is a pointer to a slink:VkImportFenceFdInfoKHR
    structure specifying the fence and import parameters.

Importing a fence payload from a file descriptor transfers ownership of the
file descriptor from the application to the Vulkan implementation.
The application must: not perform any operations on the file descriptor
after a successful import.

Applications can: import the same fence payload into multiple instances of
Vulkan, into the same instance from which it was exported, and multiple
times into a given Vulkan instance.

include::{chapters}/commonvalidity/no_dynamic_allocations_common.adoc[]

.Valid Usage
****
  * [[VUID-vkImportFenceFdKHR-fence-01463]]
    pname:fence must: not be associated with any queue command that has not
    yet completed execution on that queue
****

include::{generated}/validity/protos/vkImportFenceFdKHR.adoc[]
--

[open,refpage='VkImportFenceFdInfoKHR',desc='(None)',type='structs']
--
The sname:VkImportFenceFdInfoKHR structure is defined as:

include::{generated}/api/structs/VkImportFenceFdInfoKHR.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:fence is the fence into which the payload will be imported.
  * pname:flags is a bitmask of elink:VkFenceImportFlagBits specifying
    additional parameters for the fence payload import operation.
  * pname:handleType is a elink:VkExternalFenceHandleTypeFlagBits value
    specifying the type of pname:fd.
  * pname:fd is the external handle to import.

The handle types supported by pname:handleType are:

[[synchronization-fence-handletypes-fd]]
.Handle Types Supported by sname:VkImportFenceFdInfoKHR
[width="80%",options="header"]
|====
| Handle Type                                           | Transference | Permanence Supported
| ename:VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT | Reference    | Temporary,Permanent
| ename:VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT   | Copy         | Temporary
|====

.Valid Usage
****
  * [[VUID-VkImportFenceFdInfoKHR-handleType-01464]]
    pname:handleType must: be a value included in the
    <<synchronization-fence-handletypes-fd, Handle Types Supported by
    sname:VkImportFenceFdInfoKHR>> table
  * [[VUID-VkImportFenceFdInfoKHR-fd-01541]]
    pname:fd must: obey any requirements listed for pname:handleType in
    <<external-fence-handle-types-compatibility,external fence handle types
    compatibility>>
  * [[VUID-VkImportFenceFdInfoKHR-handleType-07306]]
    If pname:handleType refers to a handle type with copy payload
    transference semantics, pname:flags must: contain
    ename:VK_FENCE_IMPORT_TEMPORARY_BIT
****

If pname:handleType is ename:VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT, the
special value `-1` for pname:fd is treated like a valid sync file descriptor
referring to an object that has already signaled.
The import operation will succeed and the sname:VkFence will have a
temporarily imported payload as if a valid file descriptor had been
provided.

[NOTE]
.Note
====
This special behavior for importing an invalid sync file descriptor allows
easier interoperability with other system APIs which use the convention that
an invalid sync file descriptor represents work that has already completed
and does not need to be waited for.
It is consistent with the option for implementations to return a `-1` file
descriptor when exporting a ename:VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
from a sname:VkFence which is signaled.
====

include::{generated}/validity/structs/VkImportFenceFdInfoKHR.adoc[]
--
endif::VK_KHR_external_fence_fd[]

ifdef::VK_NV_external_sci_sync,VK_NV_external_sci_sync2[]
[open,refpage='vkImportFenceSciSyncFenceNV',desc='Import a fence from a stext:NvSciSyncFence handle',type='protos']
--
To import a fence payload from a stext:NvSciSyncFence handle, call:

include::{generated}/api/protos/vkImportFenceSciSyncFenceNV.adoc[]

  * pname:device is the logical device that created the fence.
  * pname:pImportFenceSciSyncInfo is a pointer to a
    slink:VkImportFenceSciSyncInfoNV structure containing parameters of the
    import operation

Importing a fence payload from stext:NvSciSyncFence does not transfer
ownership of the handle to the Vulkan implementation.
Vulkan will make a copy of stext:NvSciSyncFence when importing it.
The application must: release ownership using the NvSciSync API when the
handle is no longer needed.

.Valid Usage
****
  * [[VUID-vkImportFenceSciSyncFenceNV-sciSyncImport-05140]]
    slink:VkPhysicalDeviceExternalSciSyncFeaturesNV::pname:sciSyncImport and
    slink:VkPhysicalDeviceExternalSciSyncFeaturesNV::pname:sciSyncFence, or
    slink:VkPhysicalDeviceExternalSciSync2FeaturesNV::pname:sciSyncImport
    and slink:VkPhysicalDeviceExternalSciSync2FeaturesNV::pname:sciSyncFence
    must: be enabled
  * [[VUID-vkImportFenceSciSyncFenceNV-fence-05141]]
    pname:fence must: not be associated with any queue command that has not
    yet completed execution on that queue
  * [[VUID-vkImportFenceSciSyncFenceNV-pImportFenceSciSyncInfo-05142]]
    pname:pImportFenceSciSyncInfo->handleType must: be
    ename:VK_EXTERNAL_FENCE_HANDLE_TYPE_SCI_SYNC_FENCE_BIT_NV
****

include::{generated}/validity/protos/vkImportFenceSciSyncFenceNV.adoc[]
--

[open,refpage='vkImportFenceSciSyncObjNV',desc='Import a fence from a stext:NvSciSyncObj handle',type='protos']
--
To import a fence payload from a stext:NvSciSyncObj handle, call:

include::{generated}/api/protos/vkImportFenceSciSyncObjNV.adoc[]

  * pname:device is the logical device that created the fence.
  * pname:pImportFenceSciSyncInfo is a pointer to a
    slink:VkImportFenceSciSyncInfoNV structure containing parameters of the
    import operation

Importing a fence payload from a stext:NvSciSyncObj does not transfer
ownership of the handle to the Vulkan implementation.
Vulkan will make a new reference to the stext:NvSciSyncObj object when
importing it.
The application must: release ownership using the NvSciSync API when the
handle is no longer needed.

The application must: not import the same stext:NvSciSyncObj with signaler
access permissions into multiple instances of slink:VkFence, and must: not
import into the same instance from which it was exported.

.Valid Usage
****
  * [[VUID-vkImportFenceSciSyncObjNV-sciSyncImport-05143]]
    slink:VkPhysicalDeviceExternalSciSyncFeaturesNV::pname:sciSyncImport and
    slink:VkPhysicalDeviceExternalSciSyncFeaturesNV::pname:sciSyncFence, or
    slink:VkPhysicalDeviceExternalSciSync2FeaturesNV::pname:sciSyncImport
    and slink:VkPhysicalDeviceExternalSciSync2FeaturesNV::pname:sciSyncFence
    must: be enabled
  * [[VUID-vkImportFenceSciSyncObjNV-fence-05144]]
    pname:fence must: not be associated with any queue command that has not
    yet completed execution on that queue
  * [[VUID-vkImportFenceSciSyncObjNV-pImportFenceSciSyncInfo-05145]]
    pname:pImportFenceSciSyncInfo->handleType must: be
    ename:VK_EXTERNAL_FENCE_HANDLE_TYPE_SCI_SYNC_OBJ_BIT_NV
****

include::{generated}/validity/protos/vkImportFenceSciSyncObjNV.adoc[]
--


[open,refpage='VkImportFenceSciSyncInfoNV',desc='Structure specifying attributes for importing a SciSync handle as a fence',type='structs']
--
The sname:VkImportFenceSciSyncInfoNV structure is defined as:

include::{generated}/api/structs/VkImportFenceSciSyncInfoNV.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:fence is the fence into which the state will be imported.
  * pname:handleType specifies the type of stext:handle.
  * pname:handle is the external handle to import.

The handle types supported by pname:handleType are:

[[synchronization-fence-handletypes-sci-sync]]
.Handle Types Supported by sname:VkImportFenceSciSyncInfoNV
[width="80%",options="header"]
|====
| Handle Type                                           | Transference | Permanence Supported
| ename:VK_EXTERNAL_FENCE_HANDLE_TYPE_SCI_SYNC_OBJ_BIT_NV   | Reference | Permanent
| ename:VK_EXTERNAL_FENCE_HANDLE_TYPE_SCI_SYNC_FENCE_BIT_NV | Copy      | Temporary
|====

include::{generated}/validity/structs/VkImportFenceSciSyncInfoNV.adoc[]
--
endif::VK_NV_external_sci_sync,VK_NV_external_sci_sync2[]

ifdef::VK_VERSION_1_1,VK_KHR_external_fence[]
ifdef::VK_KHR_external_fence_win32,VK_KHR_external_fence_fd[]
[open,refpage='VkFenceImportFlagBits',desc='Bitmask specifying additional parameters of fence payload import',type='enums']
--
Bits which can: be set in

ifdef::VK_KHR_external_fence_win32[]
  * slink:VkImportFenceWin32HandleInfoKHR::pname:flags
endif::VK_KHR_external_fence_win32[]
ifdef::VK_KHR_external_fence_fd[]
  * slink:VkImportFenceFdInfoKHR::pname:flags
endif::VK_KHR_external_fence_fd[]

specifying additional parameters of a fence import operation are:

include::{generated}/api/enums/VkFenceImportFlagBits.adoc[]

ifdef::VK_KHR_external_fence[]
or the equivalent

include::{generated}/api/enums/VkFenceImportFlagBitsKHR.adoc[]
endif::VK_KHR_external_fence[]

  * ename:VK_FENCE_IMPORT_TEMPORARY_BIT specifies that the fence payload
    will be imported only temporarily, as described in
    <<synchronization-fences-importing,Importing Fence Payloads>>,
    regardless of the permanence of pname:handleType.
--

[open,refpage='VkFenceImportFlags',desc='Bitmask of VkFenceImportFlagBits',type='flags']
--
include::{generated}/api/flags/VkFenceImportFlags.adoc[]

ifdef::VK_KHR_external_fence[]
or the equivalent

include::{generated}/api/flags/VkFenceImportFlagsKHR.adoc[]
endif::VK_KHR_external_fence[]

tname:VkFenceImportFlags is a bitmask type for setting a mask of zero or
more elink:VkFenceImportFlagBits.
--
endif::VK_KHR_external_fence_win32,VK_KHR_external_fence_fd[]
endif::VK_VERSION_1_1,VK_KHR_external_fence[]


[[synchronization-semaphores]]
== Semaphores

[open,refpage='VkSemaphore',desc='Opaque handle to a semaphore object',type='handles']
--
Semaphores are a synchronization primitive that can: be used to insert a
dependency
ifndef::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
between queue operations.
Semaphores have two states - signaled and unsignaled.
endif::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
ifdef::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
between queue operations or between a queue operation and the host.
<<glossary, Binary semaphores>> have two states - signaled and unsignaled.
<<glossary, Timeline semaphores>> have a strictly increasing 64-bit unsigned
integer payload and are signaled with respect to a particular reference
value.
endif::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
A semaphore can: be signaled after execution of a queue operation is
completed, and a queue operation can: wait for a semaphore to become
signaled before it begins execution.
ifdef::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
A timeline semaphore can: additionally be signaled from the host with the
flink:vkSignalSemaphore command and waited on from the host with the
flink:vkWaitSemaphores command.
endif::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]

ifdef::VK_VERSION_1_1,VK_KHR_external_semaphore[]
[[synchronization-semaphores-payloads]]
The internal data of a semaphore may: include a reference to any resources
and pending work associated with signal or unsignal operations performed on
that semaphore object, collectively referred to as the semaphore's
_payload_.
Mechanisms to import and export that internal data to and from semaphores
are provided <<VkExportSemaphoreCreateInfo, below>>.
These mechanisms indirectly enable applications to share semaphore state
between two or more semaphores and other synchronization primitives across
process and API boundaries.

endif::VK_VERSION_1_1,VK_KHR_external_semaphore[]

Semaphores are represented by sname:VkSemaphore handles:

include::{generated}/api/handles/VkSemaphore.adoc[]
--

[open,refpage='vkCreateSemaphore',desc='Create a new queue semaphore object',type='protos']
--
:refpage: vkCreateSemaphore
:objectnameplural: semaphores
:objectnamecamelcase: semaphore
:objectcount: 1

To create a semaphore, call:

include::{generated}/api/protos/vkCreateSemaphore.adoc[]

  * pname:device is the logical device that creates the semaphore.
  * pname:pCreateInfo is a pointer to a slink:VkSemaphoreCreateInfo
    structure containing information about how the semaphore is to be
    created.
  * pname:pAllocator controls host memory allocation as described in the
    <<memory-allocation, Memory Allocation>> chapter.
  * pname:pSemaphore is a pointer to a handle in which the resulting
    semaphore object is returned.

ifndef::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
This command creates a _binary semaphore_ that has a boolean payload
indicating whether the semaphore is currently signaled or unsignaled.
When created, the semaphore is in the unsignaled state.
endif::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]

include::{chapters}/commonvalidity/no_dynamic_allocations_common.adoc[]

ifdef::VKSC_VERSION_1_0[]
.Valid Usage
****
include::{chapters}/commonvalidity/memory_reservation_request_count_common.adoc[]
****
endif::VKSC_VERSION_1_0[]

include::{generated}/validity/protos/vkCreateSemaphore.adoc[]
--

[open,refpage='VkSemaphoreCreateInfo',desc='Structure specifying parameters of a newly created semaphore',type='structs']
--
The sname:VkSemaphoreCreateInfo structure is defined as:

include::{generated}/api/structs/VkSemaphoreCreateInfo.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:flags is reserved for future use.

ifdef::VK_EXT_metal_objects,VK_NV_external_sci_sync,VK_NV_external_sci_sync2[]
.Valid Usage
****
ifdef::VK_EXT_metal_objects[]
  * [[VUID-VkSemaphoreCreateInfo-pNext-06789]]
    If the pname:pNext chain includes a
    slink:VkExportMetalObjectCreateInfoEXT structure, its
    pname:exportObjectType member must: be
    ename:VK_EXPORT_METAL_OBJECT_TYPE_METAL_SHARED_EVENT_BIT_EXT
endif::VK_EXT_metal_objects[]
ifdef::VK_NV_external_sci_sync[]
  * [[VUID-VkSemaphoreCreateInfo-pNext-05118]]
    If the pname:pNext chain includes slink:VkExportSemaphoreSciSyncInfoNV,
    it must: also include slink:VkSemaphoreTypeCreateInfo with a
    slink:VkSemaphoreTypeCreateInfo::pname:semaphoreType of
    ename:VK_SEMAPHORE_TYPE_TIMELINE
endif::VK_NV_external_sci_sync[]
ifdef::VK_NV_external_sci_sync2[]
  * [[VUID-VkSemaphoreCreateInfo-pNext-05146]]
    If the pname:pNext chain includes slink:VkSemaphoreSciSyncCreateInfoNV,
    it must: also include slink:VkSemaphoreTypeCreateInfo with a
    slink:VkSemaphoreTypeCreateInfo::pname:semaphoreType of
    ename:VK_SEMAPHORE_TYPE_TIMELINE
endif::VK_NV_external_sci_sync2[]
****
endif::VK_EXT_metal_objects,VK_NV_external_sci_sync,VK_NV_external_sci_sync2[]

include::{generated}/validity/structs/VkSemaphoreCreateInfo.adoc[]
--

[open,refpage='VkSemaphoreCreateFlags',desc='Reserved for future use',type='flags']
--
include::{generated}/api/flags/VkSemaphoreCreateFlags.adoc[]

tname:VkSemaphoreCreateFlags is a bitmask type for setting a mask, but is
currently reserved for future use.
--

ifdef::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
[open,refpage='VkSemaphoreTypeCreateInfo',desc='Structure specifying the type of a newly created semaphore',type='structs',alias='VkSemaphoreTypeCreateInfoKHR']
--
The sname:VkSemaphoreTypeCreateInfo structure is defined as:

include::{generated}/api/structs/VkSemaphoreTypeCreateInfo.adoc[]

ifdef::VK_KHR_timeline_semaphore[]
or the equivalent

include::{generated}/api/structs/VkSemaphoreTypeCreateInfoKHR.adoc[]
endif::VK_KHR_timeline_semaphore[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:semaphoreType is a elink:VkSemaphoreType value specifying the type
    of the semaphore.
  * pname:initialValue is the initial payload value if pname:semaphoreType
    is ename:VK_SEMAPHORE_TYPE_TIMELINE.

To create a semaphore of a specific type, add a
sname:VkSemaphoreTypeCreateInfo structure to the
slink:VkSemaphoreCreateInfo::pname:pNext chain.

If no sname:VkSemaphoreTypeCreateInfo structure is included in the
pname:pNext chain of slink:VkSemaphoreCreateInfo, then the created semaphore
will have a default elink:VkSemaphoreType of ename:VK_SEMAPHORE_TYPE_BINARY.

ifdef::VK_NV_external_sci_sync2[]
If slink:VkSemaphoreSciSyncCreateInfoNV structure is included in the
pname:pNext chain of sname:VkSemaphoreTypeCreateInfo, pname:initialValue is
ignored.
endif::VK_NV_external_sci_sync2[]

.Valid Usage
****
  * [[VUID-VkSemaphoreTypeCreateInfo-timelineSemaphore-03252]]
    If the <<features-timelineSemaphore, pname:timelineSemaphore>> feature
    is not enabled, pname:semaphoreType must: not equal
    ename:VK_SEMAPHORE_TYPE_TIMELINE
  * [[VUID-VkSemaphoreTypeCreateInfo-semaphoreType-03279]]
    If pname:semaphoreType is ename:VK_SEMAPHORE_TYPE_BINARY,
    pname:initialValue must: be zero
ifdef::VK_NV_external_sci_sync[]
  * [[VUID-VkSemaphoreTypeCreateInfo-pNext-05119]]
    If the pname:pNext chain includes slink:VkExportSemaphoreSciSyncInfoNV,
    pname:initialValue must: be zero.
endif::VK_NV_external_sci_sync[]
****

include::{generated}/validity/structs/VkSemaphoreTypeCreateInfo.adoc[]
--

[open,refpage='VkSemaphoreType',desc='Specifies the type of a semaphore object',type='enums',alias='VkSemaphoreTypeKHR']
--
Possible values of slink:VkSemaphoreTypeCreateInfo::pname:semaphoreType,
specifying the type of a semaphore, are:

include::{generated}/api/enums/VkSemaphoreType.adoc[]

ifdef::VK_KHR_timeline_semaphore[]
or the equivalent

include::{generated}/api/enums/VkSemaphoreTypeKHR.adoc[]
endif::VK_KHR_timeline_semaphore[]

  * ename:VK_SEMAPHORE_TYPE_BINARY specifies a _binary semaphore_ type that
    has a boolean payload indicating whether the semaphore is currently
    signaled or unsignaled.
    When created, the semaphore is in the unsignaled state.
  * ename:VK_SEMAPHORE_TYPE_TIMELINE specifies a _timeline semaphore_ type
    that has a strictly increasing 64-bit unsigned integer payload
    indicating whether the semaphore is signaled with respect to a
    particular reference value.
    When created, the semaphore payload has the value given by the
    pname:initialValue field of slink:VkSemaphoreTypeCreateInfo.
--
endif::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]

ifdef::VK_VERSION_1_1,VK_KHR_external_semaphore[]
[open,refpage='VkExportSemaphoreCreateInfo',desc='Structure specifying handle types that can be exported from a semaphore',type='structs']
--
To create a semaphore whose payload can: be exported to external handles,
add a slink:VkExportSemaphoreCreateInfo structure to the pname:pNext chain
of the slink:VkSemaphoreCreateInfo structure.
The sname:VkExportSemaphoreCreateInfo structure is defined as:

include::{generated}/api/structs/VkExportSemaphoreCreateInfo.adoc[]

ifdef::VK_KHR_external_semaphore[]
or the equivalent

include::{generated}/api/structs/VkExportSemaphoreCreateInfoKHR.adoc[]
endif::VK_KHR_external_semaphore[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:handleTypes is a bitmask of
    elink:VkExternalSemaphoreHandleTypeFlagBits specifying one or more
    semaphore handle types the application can: export from the resulting
    semaphore.
    The application can: request multiple handle types for the same
    semaphore.

.Valid Usage
****
  * [[VUID-VkExportSemaphoreCreateInfo-handleTypes-01124]]
    The bits in pname:handleTypes must: be supported and compatible, as
    reported by slink:VkExternalSemaphoreProperties
ifdef::VK_NV_external_sci_sync[]
  * [[VUID-VkExportSemaphoreCreateInfo-pNext-05120]]
    If the pname:pNext chain includes a sname:VkExportSemaphoreSciSyncInfoNV
    structure,
    slink:VkPhysicalDeviceExternalSciSyncFeaturesNV::pname:sciSyncSemapore
    and slink:VkPhysicalDeviceExternalSciSyncFeaturesNV::pname:sciSyncExport
    must: be enabled
endif::VK_NV_external_sci_sync[]
****

include::{generated}/validity/structs/VkExportSemaphoreCreateInfo.adoc[]
--
endif::VK_VERSION_1_1,VK_KHR_external_semaphore[]

ifdef::VK_KHR_external_semaphore_win32[]
[open,refpage='VkExportSemaphoreWin32HandleInfoKHR',desc='Structure specifying additional attributes of Windows handles exported from a semaphore',type='structs']
--
To specify additional attributes of NT handles exported from a semaphore,
add a sname:VkExportSemaphoreWin32HandleInfoKHR structure to the pname:pNext
chain of the slink:VkSemaphoreCreateInfo structure.
The sname:VkExportSemaphoreWin32HandleInfoKHR structure is defined as:

include::{generated}/api/structs/VkExportSemaphoreWin32HandleInfoKHR.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:pAttributes is a pointer to a Windows code:SECURITY_ATTRIBUTES
    structure specifying security attributes of the handle.
  * pname:dwAccess is a code:DWORD specifying access rights of the handle.
  * pname:name is a null-terminated UTF-16 string to associate with the
    underlying synchronization primitive referenced by NT handles exported
    from the created semaphore.

If slink:VkExportSemaphoreCreateInfo is not included in the same pname:pNext
chain, this structure is ignored.

If slink:VkExportSemaphoreCreateInfo is included in the pname:pNext chain of
slink:VkSemaphoreCreateInfo with a Windows pname:handleType, but either
sname:VkExportSemaphoreWin32HandleInfoKHR is not included in the pname:pNext
chain, or it is included but pname:pAttributes is set to `NULL`, default
security descriptor values will be used, and child processes created by the
application will not inherit the handle, as described in the MSDN
documentation for "`Synchronization Object Security and Access Rights`"^1^.
Further, if the structure is not present, the access rights used depend on
the handle type.

For handles of the following types:

ename:VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT

The implementation must: ensure the access rights allow both signal and wait
operations on the semaphore.

For handles of the following types:

ename:VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE_BIT

The access rights must: be:

code:GENERIC_ALL

1::
    https://docs.microsoft.com/en-us/windows/win32/sync/synchronization-object-security-and-access-rights

.Valid Usage
****
  * [[VUID-VkExportSemaphoreWin32HandleInfoKHR-handleTypes-01125]]
    If slink:VkExportSemaphoreCreateInfo::pname:handleTypes does not include
    ename:VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT or
    ename:VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE_BIT,
    sname:VkExportSemaphoreWin32HandleInfoKHR must: not be included in the
    pname:pNext chain of slink:VkSemaphoreCreateInfo
****

include::{generated}/validity/structs/VkExportSemaphoreWin32HandleInfoKHR.adoc[]
--

[open,refpage='vkGetSemaphoreWin32HandleKHR',desc='Get a Windows HANDLE for a semaphore',type='protos']
--
To export a Windows handle representing the payload of a semaphore, call:

include::{generated}/api/protos/vkGetSemaphoreWin32HandleKHR.adoc[]

  * pname:device is the logical device that created the semaphore being
    exported.
  * pname:pGetWin32HandleInfo is a pointer to a
    slink:VkSemaphoreGetWin32HandleInfoKHR structure containing parameters
    of the export operation.
  * pname:pHandle will return the Windows handle representing the semaphore
    state.

For handle types defined as NT handles, the handles returned by
fname:vkGetSemaphoreWin32HandleKHR are owned by the application.
To avoid leaking resources, the application must: release ownership of them
using the code:CloseHandle system call when they are no longer needed.

Exporting a Windows handle from a semaphore may: have side effects depending
on the transference of the specified handle type, as described in
<<synchronization-semaphores-importing,Importing Semaphore Payloads>>.

include::{generated}/validity/protos/vkGetSemaphoreWin32HandleKHR.adoc[]
--

[open,refpage='VkSemaphoreGetWin32HandleInfoKHR',desc='Structure describing a Win32 handle semaphore export operation',type='structs']
--
The sname:VkSemaphoreGetWin32HandleInfoKHR structure is defined as:

include::{generated}/api/structs/VkSemaphoreGetWin32HandleInfoKHR.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:semaphore is the semaphore from which state will be exported.
  * pname:handleType is a elink:VkExternalSemaphoreHandleTypeFlagBits value
    specifying the type of handle requested.

The properties of the handle returned depend on the value of
pname:handleType.
See elink:VkExternalSemaphoreHandleTypeFlagBits for a description of the
properties of the defined external semaphore handle types.

.Valid Usage
****
  * [[VUID-VkSemaphoreGetWin32HandleInfoKHR-handleType-01126]]
    pname:handleType must: have been included in
    slink:VkExportSemaphoreCreateInfo::pname:handleTypes when the
    pname:semaphore's current payload was created
  * [[VUID-VkSemaphoreGetWin32HandleInfoKHR-handleType-01127]]
    If pname:handleType is defined as an NT handle,
    flink:vkGetSemaphoreWin32HandleKHR must: be called no more than once for
    each valid unique combination of pname:semaphore and pname:handleType
  * [[VUID-VkSemaphoreGetWin32HandleInfoKHR-semaphore-01128]]
    pname:semaphore must: not currently have its payload replaced by an
    imported payload as described below in
    <<synchronization-semaphores-importing,Importing Semaphore Payloads>>
    unless that imported payload's handle type was included in
    slink:VkExternalSemaphoreProperties::pname:exportFromImportedHandleTypes
    for pname:handleType
  * [[VUID-VkSemaphoreGetWin32HandleInfoKHR-handleType-01129]]
    If pname:handleType refers to a handle type with copy payload
    transference semantics, as defined below in
    <<synchronization-semaphores-importing,Importing Semaphore Payloads>>,
    there must: be no queue waiting on pname:semaphore
  * [[VUID-VkSemaphoreGetWin32HandleInfoKHR-handleType-01130]]
    If pname:handleType refers to a handle type with copy payload
    transference semantics, pname:semaphore must: be signaled, or have an
    associated <<synchronization-semaphores-signaling,semaphore signal
    operation>> pending execution
  * [[VUID-VkSemaphoreGetWin32HandleInfoKHR-handleType-01131]]
    pname:handleType must: be defined as an NT handle or a global share
    handle
****

include::{generated}/validity/structs/VkSemaphoreGetWin32HandleInfoKHR.adoc[]
--
endif::VK_KHR_external_semaphore_win32[]


ifdef::VK_NV_low_latency[]
[open,refpage='VkQueryLowLatencySupportNV',desc='Structure used for NVIDIA Reflex Support',type='structs']
--
The sname:VkQueryLowLatencySupportNV structure is defined as:

include::{generated}/api/structs/VkQueryLowLatencySupportNV.adoc[]

This structure describes the following feature:

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:pQueriedLowLatencyData is used for NVIDIA Reflex Support.

include::{generated}/validity/structs/VkQueryLowLatencySupportNV.adoc[]
--
endif::VK_NV_low_latency[]

ifdef::VK_KHR_external_semaphore_fd[]
[open,refpage='vkGetSemaphoreFdKHR',desc='Get a POSIX file descriptor handle for a semaphore',type='protos']
--
:refpage: vkGetSemaphoreFdKHR

To export a POSIX file descriptor representing the payload of a semaphore,
call:

include::{generated}/api/protos/vkGetSemaphoreFdKHR.adoc[]

  * pname:device is the logical device that created the semaphore being
    exported.
  * pname:pGetFdInfo is a pointer to a slink:VkSemaphoreGetFdInfoKHR
    structure containing parameters of the export operation.
  * pname:pFd will return the file descriptor representing the semaphore
    payload.

Each call to fname:vkGetSemaphoreFdKHR must: create a new file descriptor
and transfer ownership of it to the application.
To avoid leaking resources, the application must: release ownership of the
file descriptor when it is no longer needed.

[NOTE]
.Note
====
Ownership can be released in many ways.
For example, the application can call code:close() on the file descriptor,
or transfer ownership back to Vulkan by using the file descriptor to import
a semaphore payload.
====
Where supported by the operating system, the implementation must: set the
file descriptor to be closed automatically when an code:execve system call
is made.

Exporting a file descriptor from a semaphore may: have side effects
depending on the transference of the specified handle type, as described in
<<synchronization-semaphores-importing,Importing Semaphore State>>.

include::{chapters}/commonvalidity/no_dynamic_allocations_common.adoc[]

include::{generated}/validity/protos/vkGetSemaphoreFdKHR.adoc[]
--

[open,refpage='VkSemaphoreGetFdInfoKHR',desc='Structure describing a POSIX FD semaphore export operation',type='structs']
--
The sname:VkSemaphoreGetFdInfoKHR structure is defined as:

include::{generated}/api/structs/VkSemaphoreGetFdInfoKHR.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:semaphore is the semaphore from which state will be exported.
  * pname:handleType is a elink:VkExternalSemaphoreHandleTypeFlagBits value
    specifying the type of handle requested.

The properties of the file descriptor returned depend on the value of
pname:handleType.
See elink:VkExternalSemaphoreHandleTypeFlagBits for a description of the
properties of the defined external semaphore handle types.

.Valid Usage
****
  * [[VUID-VkSemaphoreGetFdInfoKHR-handleType-01132]]
    pname:handleType must: have been included in
    slink:VkExportSemaphoreCreateInfo::pname:handleTypes when
    pname:semaphore's current payload was created
  * [[VUID-VkSemaphoreGetFdInfoKHR-semaphore-01133]]
    pname:semaphore must: not currently have its payload replaced by an
    imported payload as described below in
    <<synchronization-semaphores-importing,Importing Semaphore Payloads>>
    unless that imported payload's handle type was included in
    slink:VkExternalSemaphoreProperties::pname:exportFromImportedHandleTypes
    for pname:handleType
  * [[VUID-VkSemaphoreGetFdInfoKHR-handleType-01134]]
    If pname:handleType refers to a handle type with copy payload
    transference semantics, as defined below in
    <<synchronization-semaphores-importing,Importing Semaphore Payloads>>,
    there must: be no queue waiting on pname:semaphore
  * [[VUID-VkSemaphoreGetFdInfoKHR-handleType-01135]]
    If pname:handleType refers to a handle type with copy payload
    transference semantics, pname:semaphore must: be signaled, or have an
    associated <<synchronization-semaphores-signaling,semaphore signal
    operation>> pending execution
  * [[VUID-VkSemaphoreGetFdInfoKHR-handleType-01136]]
    pname:handleType must: be defined as a POSIX file descriptor handle
ifdef::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
  * [[VUID-VkSemaphoreGetFdInfoKHR-handleType-03253]]
    If pname:handleType refers to a handle type with copy payload
    transference semantics, pname:semaphore must: have been created with a
    elink:VkSemaphoreType of ename:VK_SEMAPHORE_TYPE_BINARY
  * [[VUID-VkSemaphoreGetFdInfoKHR-handleType-03254]]
    If pname:handleType refers to a handle type with copy payload
    transference semantics, pname:semaphore must: have an associated
    semaphore signal operation that has been submitted for execution and any
    semaphore signal operations on which it depends must: have also been
    submitted for execution
endif::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
****

include::{generated}/validity/structs/VkSemaphoreGetFdInfoKHR.adoc[]
--
endif::VK_KHR_external_semaphore_fd[]

ifdef::VK_FUCHSIA_external_semaphore[]
[open,refpage='vkGetSemaphoreZirconHandleFUCHSIA',desc='Get a Zircon event handle for a semaphore',type='protos']
--
To export a Zircon event handle representing the payload of a semaphore,
call:

include::{generated}/api/protos/vkGetSemaphoreZirconHandleFUCHSIA.adoc[]

  * pname:device is the logical device that created the semaphore being
    exported.
  * pname:pGetZirconHandleInfo is a pointer to a
    slink:VkSemaphoreGetZirconHandleInfoFUCHSIA structure containing
    parameters of the export operation.
  * pname:pZirconHandle will return the Zircon event handle representing the
    semaphore payload.

Each call to fname:vkGetSemaphoreZirconHandleFUCHSIA must: create a Zircon
event handle and transfer ownership of it to the application.
To avoid leaking resources, the application must: release ownership of the
Zircon event handle when it is no longer needed.

[NOTE]
.Note
====
Ownership can be released in many ways.
For example, the application can call zx_handle_close() on the file
descriptor, or transfer ownership back to Vulkan by using the file
descriptor to import a semaphore payload.
====

Exporting a Zircon event handle from a semaphore may: have side effects
depending on the transference of the specified handle type, as described in
<<synchronization-semaphores-importing,Importing Semaphore State>>.

include::{generated}/validity/protos/vkGetSemaphoreZirconHandleFUCHSIA.adoc[]
--

[open,refpage='VkSemaphoreGetZirconHandleInfoFUCHSIA',desc='Structure describing a Zircon event handle semaphore export operation',type='structs']
--
The sname:VkSemaphoreGetZirconHandleInfoFUCHSIA structure is defined as:

include::{generated}/api/structs/VkSemaphoreGetZirconHandleInfoFUCHSIA.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:semaphore is the semaphore from which state will be exported.
  * pname:handleType is a elink:VkExternalSemaphoreHandleTypeFlagBits value
    specifying the type of handle requested.

The properties of the Zircon event handle returned depend on the value of
pname:handleType.
See elink:VkExternalSemaphoreHandleTypeFlagBits for a description of the
properties of the defined external semaphore handle types.

.Valid Usage
****
  * [[VUID-VkSemaphoreGetZirconHandleInfoFUCHSIA-handleType-04758]]
    pname:handleType must: have been included in
    slink:VkExportSemaphoreCreateInfo::pname:handleTypes when
    pname:semaphore's current payload was created
  * [[VUID-VkSemaphoreGetZirconHandleInfoFUCHSIA-semaphore-04759]]
    pname:semaphore must: not currently have its payload replaced by an
    imported payload as described below in
    <<synchronization-semaphores-importing,Importing Semaphore Payloads>>
    unless that imported payload's handle type was included in
    slink:VkExternalSemaphoreProperties::pname:exportFromImportedHandleTypes
    for pname:handleType
  * [[VUID-VkSemaphoreGetZirconHandleInfoFUCHSIA-handleType-04760]]
    If pname:handleType refers to a handle type with copy payload
    transference semantics, as defined below in
    <<synchronization-semaphores-importing,Importing Semaphore Payloads>>,
    there must: be no queue waiting on pname:semaphore
  * [[VUID-VkSemaphoreGetZirconHandleInfoFUCHSIA-handleType-04761]]
    If pname:handleType refers to a handle type with copy payload
    transference semantics, pname:semaphore must: be signaled, or have an
    associated <<synchronization-semaphores-signaling,semaphore signal
    operation>> pending execution
  * [[VUID-VkSemaphoreGetZirconHandleInfoFUCHSIA-handleType-04762]]
    pname:handleType must: be defined as a Zircon event handle
  * [[VUID-VkSemaphoreGetZirconHandleInfoFUCHSIA-semaphore-04763]]
    pname:semaphore must: have been created with a elink:VkSemaphoreType of
    ename:VK_SEMAPHORE_TYPE_BINARY
****

include::{generated}/validity/structs/VkSemaphoreGetZirconHandleInfoFUCHSIA.adoc[]
--
endif::VK_FUCHSIA_external_semaphore[]

ifdef::VK_NV_external_sci_sync[]
[open,refpage='VkExportSemaphoreSciSyncInfoNV',desc='Structure specifying additional attributes of NvSciSync handles exported from a semaphore',type='structs']
--
To specify additional attributes of NvSciSync handles exported from a
semaphore, add a sname:VkExportSemaphoreSciSyncInfoNV structure to the
pname:pNext chain of the slink:VkSemaphoreCreateInfo structure.
The sname:VkExportSemaphoreSciSyncInfoNV structure is defined as:

include::{generated}/api/structs/VkExportSemaphoreSciSyncInfoNV.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:pAttributes is an opaque sname:NvSciSyncAttrList describing the
    attributes of the NvSciSync object that will be exported.

If slink:VkExportSemaphoreCreateInfo is not present in the same pname:pNext
chain, this structure is ignored.
If the pname:pNext chain of slink:VkSemaphoreCreateInfo includes a
slink:VkExportSemaphoreCreateInfo structure with a NvSciSync
pname:handleType, but either slink:VkExportSemaphoreSciSyncInfoNV is not
included in the pname:pNext chain, or it is included but pname:pAttributes
is set to `NULL`, flink:vkCreateSemaphore will return
ename:VK_ERROR_INITIALIZATION_FAILED.

The pname:pAttributes must: be a reconciled sname:NvSciSyncAttrList.
Before exporting a NvSciSync handle, the application must: use the
flink:vkGetPhysicalDeviceSciSyncAttributesNV command to obtain the
unreconciled sname:NvSciSyncAttrList and then use the NvSciSync API to
reconcile it.

.Valid Usage
****
  * [[VUID-VkExportSemaphoreSciSyncInfoNV-pAttributes-05121]]
    pname:pAttributes must: be a reconciled stext:NvSciSyncAttrList
****

include::{generated}/validity/structs/VkExportSemaphoreSciSyncInfoNV.adoc[]
--

[open,refpage='vkGetSemaphoreSciSyncObjNV',desc='Get a stext:NvSciSyncObj handle for a semaphore',type='protos']
--

To export a stext:NvSciSyncObj handle representing the payload of a
semaphore, call:

include::{generated}/api/protos/vkGetSemaphoreSciSyncObjNV.adoc[]

  * pname:device is the logical device that created the semaphore being
    exported.
  * pname:pGetSciSyncInfo is a pointer to a
    slink:VkSemaphoreGetSciSyncInfoNV structure containing parameters of the
    export operation.
  * pname:pHandle will return the stext:NvSciSyncObj representing the
    semaphore payload.

Each call to fname:vkGetSemaphoreSciSyncObjNV will duplicate the underlying
stext:NvSciSyncObj and transfer the ownership of the stext:NvSciSyncObj
handle to the application.
To avoid leaking resources, the application must: release ownership of the
stext:NvSciSyncObj when it is no longer needed.

.Valid Usage
****
  * [[VUID-vkGetSemaphoreSciSyncObjNV-sciSyncSemaphore-05147]]
    slink:VkPhysicalDeviceExternalSciSyncFeaturesNV::pname:sciSyncSemaphore
    must: be enabled
****

include::{generated}/validity/protos/vkGetSemaphoreSciSyncObjNV.adoc[]
--

[open,refpage='VkSemaphoreGetSciSyncInfoNV',desc='Structure describing a slink:VkSemaphore export operation to NvSciSync',type='structs']
--

The sname:VkSemaphoreGetSciSyncInfoNV structure is defined as:

include::{generated}/api/structs/VkSemaphoreGetSciSyncInfoNV.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:semaphore is the semaphore from which state will be exported.
  * pname:handleType is the type of NvSciSync handle (stext:NvSciSyncObj)
    representing the semaphore that will be exported.

.Valid Usage
****
  * [[VUID-VkSemaphoreGetSciSyncInfoNV-handleType-05122]]
    pname:handleType must: be
    ename:VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SCI_SYNC_OBJ_BIT_NV
  * [[VUID-VkSemaphoreGetSciSyncInfoNV-semaphore-05123]]
    pname:semaphore must: have been created with a elink:VkSemaphoreType of
    ename:VK_SEMAPHORE_TYPE_TIMELINE
  * [[VUID-VkSemaphoreGetSciSyncInfoNV-semaphore-05129]]
    pname:semaphore must: have been created with
    slink:VkExportSemaphoreSciSyncInfoNV included pname:pNext chain of
    slink:VkSemaphoreCreateInfo, or previously imported by
    flink:vkImportSemaphoreSciSyncObjNV
****

include::{generated}/validity/structs/VkSemaphoreGetSciSyncInfoNV.adoc[]
--
endif::VK_NV_external_sci_sync[]

ifdef::VK_NV_external_sci_sync2[]
[open,refpage='VkSemaphoreSciSyncCreateInfoNV',desc='Structure to create a semaphore from a semaphore SciSync pool',type='structs']
--
The sname:VkSemaphoreSciSyncCreateInfoNV structure is defined as:

include::{generated}/api/structs/VkSemaphoreSciSyncCreateInfoNV.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:semaphorePool is a slink:VkSemaphoreSciSyncPoolNV handle.
  * pname:pFence is a pointer to a stext:NvSciSyncFence.

When slink:VkSemaphoreSciSyncCreateInfoNV is included in
slink:VkSemaphoreCreateInfo::pname:pNext chain, the semaphore is created
from the slink:VkSemaphoreSciSyncPoolNV handle that represents a
stext:NvSciSyncObj with one or more primitives.
The slink:VkSemaphoreSciSyncCreateInfoNV::pname:pFence parameter provides
the information to select the corresponding primitive represented by this
semaphore.
When a stext:NvSciSyncObj with signaler permissions is imported to
slink:VkSemaphoreSciSyncPoolNV, it only supports one primitive and
slink:VkSemaphoreSciSyncCreateInfoNV::pname:pFence must: be in the cleared
state.

.Valid Usage
****
  * [[VUID-VkSemaphoreSciSyncCreateInfoNV-sciSyncSemaphore2-05148]]
    The <<features-sciSyncSemaphore2,
    slink:VkPhysicalDeviceExternalSciSync2FeaturesNV::pname:sciSyncSemaphore2>>
    feature must: be enabled
****

include::{generated}/validity/structs/VkSemaphoreSciSyncCreateInfoNV.adoc[]
--
endif::VK_NV_external_sci_sync2[]


[open,refpage='vkDestroySemaphore',desc='Destroy a semaphore object',type='protos']
--
To destroy a semaphore, call:

include::{generated}/api/protos/vkDestroySemaphore.adoc[]

  * pname:device is the logical device that destroys the semaphore.
  * pname:semaphore is the handle of the semaphore to destroy.
  * pname:pAllocator controls host memory allocation as described in the
    <<memory-allocation, Memory Allocation>> chapter.

ifdef::VK_NV_external_sci_sync2[]
If pname:semaphore was created with slink:VkSemaphoreSciSyncCreateInfoNV
present in the slink:VkSemaphoreCreateInfo::pname:pNext chain,
pname:semaphore can: be destroyed immediately after all batches that refer
to it are submitted.
Otherwise, all submitted batches that refer to pname:semaphore must: have
completed execution before it can be destroyed.
endif::VK_NV_external_sci_sync2[]

.Valid Usage
****
  * [[VUID-vkDestroySemaphore-semaphore-05149]]
ifdef::VK_NV_external_sci_sync2[]
    If pname:semaphore was not created with
    slink:VkSemaphoreSciSyncCreateInfoNV present in the
    slink:VkSemaphoreCreateInfo::pname:pNext chain when it was created, all
endif::VK_NV_external_sci_sync2[]
ifndef::VK_NV_external_sci_sync2[All]
    submitted batches that refer to pname:semaphore must: have completed
    execution
ifndef::VKSC_VERSION_1_0[]
  * [[VUID-vkDestroySemaphore-semaphore-01138]]
    If sname:VkAllocationCallbacks were provided when pname:semaphore was
    created, a compatible set of callbacks must: be provided here
  * [[VUID-vkDestroySemaphore-semaphore-01139]]
    If no sname:VkAllocationCallbacks were provided when pname:semaphore was
    created, pname:pAllocator must: be `NULL`
endif::VKSC_VERSION_1_0[]
****

include::{generated}/validity/protos/vkDestroySemaphore.adoc[]
--

ifdef::VK_NV_external_sci_sync2[]
=== Semaphore SciSync Pools

A semaphore SciSync pool is used to represent a stext:NvSciSyncObj with one
or more primitives.

[open,refpage='VkSemaphoreSciSyncPoolNV',desc='Opaque handle to a semaphore SciSync pool',type='handles']
--
Semaphore SciSync pools are represented by sname:VkSemaphoreSciSyncPoolNV
handles:

include::{generated}/api/handles/VkSemaphoreSciSyncPoolNV.adoc[]
--

To import a stext:NvSciSyncObj with multiple primitives, use
flink:vkCreateSemaphoreSciSyncPoolNV to reserve a semaphore pool to map the
multiple semaphores allocated by stext:NvSciSyncObj.
Then create a slink:VkSemaphore from the semaphore pool using the index
provided by the stext:NvSciSyncFence when chaining the
slink:VkSemaphoreSciSyncCreateInfoNV structure to
slink:VkSemaphoreCreateInfo.

[open,refpage='vkCreateSemaphoreSciSyncPoolNV',desc='Create a slink:VkSemaphoreSciSyncPoolNV object',type='protos']
--
:refpage: vkCreateSemaphoreSciSyncPoolNV

To create a sname:VkSemaphoreSciSyncPoolNV, call:

include::{generated}/api/protos/vkCreateSemaphoreSciSyncPoolNV.adoc[]

  * pname:device is the logical device that creates the semaphore pool.
  * pname:pCreateInfo is a pointer to a
    slink:VkSemaphoreSciSyncPoolCreateInfoNV structure containing
    information about the semaphore SciSync pool being created.
  * pname:pAllocator controls host memory allocation as described in the
    <<memory-allocation, Memory Allocation>> chapter.
  * pname:pSemaphorePool is a pointer to a handle in which the resulting
    semaphore pool object is returned.

include::{chapters}/commonvalidity/no_dynamic_allocations_common.adoc[]

.Valid Usage
****
ifdef::VKSC_VERSION_1_0[]
  * [[VUID-vkCreateSemaphoreSciSyncPoolNV-device-05150]]
    The number of semaphore pools currently allocated from pname:device plus
    1 must: be less than or equal to the total number of semaphore pools
    requested via
    slink:VkDeviceSemaphoreSciSyncPoolReservationCreateInfoNV::pname:semaphoreSciSyncPoolRequestCount
    specified when pname:device was created
endif::VKSC_VERSION_1_0[]
  * [[VUID-vkCreateSemaphoreSciSyncPoolNV-sciSyncSemaphore2-05151]]
    The <<features-sciSyncSemaphore2,
    slink:VkPhysicalDeviceExternalSciSync2FeaturesNV::pname:sciSyncSemaphore2>>
    feature must: be enabled
****

include::{generated}/validity/protos/vkCreateSemaphoreSciSyncPoolNV.adoc[]
--

[open,refpage='VkSemaphoreSciSyncPoolCreateInfoNV',desc='Structure describing the creation parameters for a SciSync pool',type='structs']
--
The sname:VkSemaphoreSciSyncPoolCreateInfoNV structure is defined as:

include::{generated}/api/structs/VkSemaphoreSciSyncPoolCreateInfoNV.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:handle is an external stext:NvSciSyncObj to import.

During flink:vkCreateSemaphoreSciSyncPoolNV, the external stext:NvSciSyncObj
is imported to sname:VkSemaphoreSciSyncPoolNV.
The import does not transfer the ownership of the stext:NvSciSyncObj to the
implementation, but will increment the reference count of that object.
ifndef::VKSC_VERSION_1_0[]
flink:vkDestroySemaphoreSciSyncPoolNV will decrement the reference count of
that object.
endif::VKSC_VERSION_1_0[]
The application must: delete other references of the original
stext:NvSciSyncObj using <<NvSciSync2-extension-page, NvSciSync APIs>> when
it is no longer needed.

Applications must: not import the same stext:NvSciSyncObj with signaler
access permissions to multiple instances of sname:VkSemaphoreSciSyncPoolNV.

.Valid Usage
****
  * [[VUID-VkSemaphoreSciSyncPoolCreateInfoNV-handle-05152]]
    pname:handle must: be a valid stext:NvSciSyncObj
****

include::{generated}/validity/structs/VkSemaphoreSciSyncPoolCreateInfoNV.adoc[]
--

ifdef::VKSC_VERSION_1_0[]
ifdef::hidden[]
// tag::scremoved[]
ifdef::VK_NV_external_sci_sync2[]
  * fname:vkDestroySemaphoreSciSyncPoolNV <<SCID-4>>
endif::VK_NV_external_sci_sync2[]
// end::scremoved[]
endif::hidden[]

Semaphore SciSync pools cannot: be freed <<SCID-4>>.
If
slink:VkPhysicalDeviceVulkanSC10Properties::<<limits-deviceDestroyFreesMemory,pname:deviceDestroyFreesMemory>>
is ename:VK_TRUE, the memory is returned to the system and the reference to
the stext:NvSciSyncObj that was imported is releasd when the device is
destroyed.
endif::VKSC_VERSION_1_0[]

ifndef::VKSC_VERSION_1_0[]
[open,refpage='vkDestroySemaphoreSciSyncPoolNV',desc='Destroy a slink:VkSemaphoreSciSyncPoolNV object',type='protos']
--
To destroy a slink:VkSemaphoreSciSyncPoolNV, call:

include::{generated}/api/protos/vkDestroySemaphoreSciSyncPoolNV.adoc[]

  * pname:device is the logical device that destroys the semaphore SciSync
    pool.
  * pname:semaphorePool is the handle of the semaphore SciSync pool to
    destroy.
  * pname:pAllocator controls host memory allocation as described in the
    <<memory-allocation, Memory Allocation>> chapter.

.Valid Usage
****
  * [[VUID-vkDestroySemaphoreSciSyncPoolNV-semaphorePool-05153]]
    All submitted batches that refer to a semaphore created from
    pname:semaphorePool must: have completed execution
  * [[VUID-vkDestroySemaphoreSciSyncPoolNV-sciSyncSemaphore2-05154]]
    The <<features-sciSyncSemaphore2,
    slink:VkPhysicalDeviceExternalSciSync2FeaturesNV::pname:sciSyncSemaphore2>>
    feature must: be enabled
****

include::{generated}/validity/protos/vkDestroySemaphoreSciSyncPoolNV.adoc[]
--
endif::VKSC_VERSION_1_0[]
endif::VK_NV_external_sci_sync2[]


[[synchronization-semaphores-signaling]]
=== Semaphore Signaling

When a batch is submitted to a queue via a <<devsandqueues-submission, queue
submission>>, and it includes semaphores to be signaled, it defines a memory
dependency on the batch, and defines _semaphore signal operations_ which set
the semaphores to the signaled state.

ifdef::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
In case of semaphores created with a elink:VkSemaphoreType of
ename:VK_SEMAPHORE_TYPE_TIMELINE the semaphore is considered signaled with
respect to the counter value set to be signaled as specified in
slink:VkTimelineSemaphoreSubmitInfo or slink:VkSemaphoreSignalInfo.
endif::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]

The first <<synchronization-dependencies-scopes, synchronization scope>>
includes every command submitted in the same batch.
ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
In the case of flink:vkQueueSubmit2, the first synchronization scope is
limited to the pipeline stage specified by
slink:VkSemaphoreSubmitInfo::pname:stageMask.
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]
Semaphore signal operations that are defined by flink:vkQueueSubmit
ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
or flink:vkQueueSubmit2
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]
additionally include all commands that occur earlier in
<<synchronization-submission-order,submission order>>.
Semaphore signal operations that are defined by flink:vkQueueSubmit
ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[or flink:vkQueueSubmit2]
ifndef::VKSC_VERSION_1_0[or flink:vkQueueBindSparse]
additionally include in the first synchronization scope any semaphore and
fence signal operations that occur earlier in
<<synchronization-signal-operation-order,signal operation order>>.

The second <<synchronization-dependencies-scopes, synchronization scope>>
includes only the semaphore signal operation.

The first <<synchronization-dependencies-access-scopes, access scope>>
includes all memory access performed by the device.

The second <<synchronization-dependencies-access-scopes, access scope>> is
empty.


[[synchronization-semaphores-waiting]]
=== Semaphore Waiting

When a batch is submitted to a queue via a <<devsandqueues-submission, queue
submission>>, and it includes semaphores to be waited on, it defines a
memory dependency between prior semaphore signal operations and the batch,
and defines _semaphore wait operations_.

Such semaphore wait operations set the semaphores
ifdef::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
created with a elink:VkSemaphoreType of ename:VK_SEMAPHORE_TYPE_BINARY
endif::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
to the unsignaled state.
ifdef::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
In case of semaphores created with a elink:VkSemaphoreType of
ename:VK_SEMAPHORE_TYPE_TIMELINE a prior semaphore signal operation defines
a memory dependency with a semaphore wait operation if the value the
semaphore is signaled with is greater than or equal to the value the
semaphore is waited with, thus the semaphore will continue to be considered
signaled with respect to the counter value waited on as specified in
slink:VkTimelineSemaphoreSubmitInfo.
endif::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]

The first synchronization scope includes all semaphore signal operations
that operate on semaphores waited on in the same batch, and that
happen-before the wait completes.

The second <<synchronization-dependencies-scopes, synchronization scope>>
includes every command submitted in the same batch.
In the case of flink:vkQueueSubmit, the second synchronization scope is
limited to operations on the pipeline stages determined by the
<<synchronization-pipeline-stages-masks, destination stage mask>> specified
by the corresponding element of pname:pWaitDstStageMask.
ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
In the case of flink:vkQueueSubmit2, the second synchronization scope is
limited to the pipeline stage specified by
slink:VkSemaphoreSubmitInfo::pname:stageMask.
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]
Also, in the case of
ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
either flink:vkQueueSubmit2 or
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]
flink:vkQueueSubmit, the second synchronization scope additionally includes
all commands that occur later in
<<synchronization-submission-order,submission order>>.

The first <<synchronization-dependencies-access-scopes, access scope>> is
empty.

The second <<synchronization-dependencies-access-scopes, access scope>>
includes all memory access performed by the device.

The semaphore wait operation happens-after the first set of operations in
the execution dependency, and happens-before the second set of operations in
the execution dependency.

[NOTE]
.Note
====
Unlike
ifdef::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
timeline semaphores,
endif::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
fences or events, the act of waiting for a binary semaphore also unsignals
that semaphore.
Applications must: ensure that between two such wait operations, the
semaphore is signaled again, with execution dependencies used to ensure
these occur in order.
Binary semaphore waits and signals should thus occur in discrete 1:1 pairs.
====

ifdef::VK_KHR_swapchain[]
[NOTE]
.Note
====
A common scenario for using pname:pWaitDstStageMask with values other than
ename:VK_PIPELINE_STAGE_ALL_COMMANDS_BIT is when synchronizing a window
system presentation operation against subsequent command buffers which
render the next frame.
In this case, a presentation image must: not be overwritten until the
presentation operation completes, but other pipeline stages can: execute
without waiting.
A mask of ename:VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT prevents
subsequent color attachment writes from executing until the semaphore
signals.
Some implementations may: be able to execute transfer operations and/or
pre-rasterization work before the semaphore is signaled.

If an image layout transition needs to be performed on a presentable image
before it is used in a framebuffer, that can: be performed as the first
operation submitted to the queue after acquiring the image, and should: not
prevent other work from overlapping with the presentation operation.
For example, a sname:VkImageMemoryBarrier could use:

  * pname:srcStageMask = ename:VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
  * pname:srcAccessMask = 0
  * pname:dstStageMask = ename:VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
  * pname:dstAccessMask = ename:VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
    ename:VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT.
  * pname:oldLayout = ename:VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
  * pname:newLayout = ename:VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL

Alternatively, pname:oldLayout can: be ename:VK_IMAGE_LAYOUT_UNDEFINED, if
the image's contents need not be preserved.

This barrier accomplishes a dependency chain between previous presentation
operations and subsequent color attachment output operations, with the
layout transition performed in between, and does not introduce a dependency
between previous work and any
<<pipelines-graphics-subsets-pre-rasterization,pre-rasterization shader
stage>>s.
More precisely, the semaphore signals after the presentation operation
completes, the semaphore wait stalls the
ename:VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT stage, and there is a
dependency from that same stage to itself with the layout transition
performed in between.
====
endif::VK_KHR_swapchain[]


[[synchronization-semaphores-waiting-state]]
=== Semaphore State Requirements for Wait Operations

Before waiting on a semaphore, the application must: ensure the semaphore is
in a valid state for a wait operation.
Specifically, when a <<synchronization-semaphores-waiting,semaphore wait
operation>> is submitted to a queue:

  * A binary semaphore must: be signaled, or have an associated
    <<synchronization-semaphores-signaling,semaphore signal operation>> that
    is pending execution.
  * Any <<synchronization-semaphores-signaling,semaphore signal operations>>
    on which the pending binary semaphore signal operation depends must:
    also be completed or pending execution.
  * There must: be no other queue waiting on the same binary semaphore when
    the operation executes.


ifdef::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
[[synchronization-semaphores-hostops]]
=== Host Operations on Semaphores

In addition to <<synchronization-semaphores-signaling,semaphore signal
operations>> and <<synchronization-semaphores-waiting,semaphore wait
operations>> submitted to device queues, timeline semaphores support the
following host operations:

  * Query the current counter value of the semaphore using the
    flink:vkGetSemaphoreCounterValue command.
  * Wait for a set of semaphores to reach particular counter values using
    the flink:vkWaitSemaphores command.
  * Signal the semaphore with a particular counter value from the host using
    the flink:vkSignalSemaphore command.

[open,refpage='vkGetSemaphoreCounterValue',desc='Query the current state of a timeline semaphore',type='protos',alias='vkGetSemaphoreCounterValueKHR']
--
:refpage: vkGetSemaphoreCounterValue

To query the current counter value of a semaphore created with a
elink:VkSemaphoreType of ename:VK_SEMAPHORE_TYPE_TIMELINE from the host,
call:

ifdef::VK_VERSION_1_2[]
include::{generated}/api/protos/vkGetSemaphoreCounterValue.adoc[]
endif::VK_VERSION_1_2[]

ifdef::VK_VERSION_1_2+VK_KHR_timeline_semaphore[or the equivalent command]

ifdef::VK_KHR_timeline_semaphore[]
include::{generated}/api/protos/vkGetSemaphoreCounterValueKHR.adoc[]
endif::VK_KHR_timeline_semaphore[]

  * pname:device is the logical device that owns the semaphore.
  * pname:semaphore is the handle of the semaphore to query.
  * pname:pValue is a pointer to a 64-bit integer value in which the current
    counter value of the semaphore is returned.

[NOTE]
.Note
====
If a <<devsandqueues-submission, queue submission>> command is pending
execution, then the value returned by this command may: immediately be out
of date.
====

include::{chapters}/commonvalidity/no_dynamic_allocations_common.adoc[]

.Valid Usage
****
  * [[VUID-vkGetSemaphoreCounterValue-semaphore-03255]]
    pname:semaphore must: have been created with a elink:VkSemaphoreType of
    ename:VK_SEMAPHORE_TYPE_TIMELINE
****

include::{generated}/validity/protos/vkGetSemaphoreCounterValue.adoc[]
--

[open,refpage='vkWaitSemaphores',desc='Wait for timeline semaphores on the host',type='protos',alias='vkWaitSemaphoresKHR']
--
:refpage: vkWaitSemaphores

To wait for a set of semaphores created with a elink:VkSemaphoreType of
ename:VK_SEMAPHORE_TYPE_TIMELINE to reach particular counter values on the
host, call:

ifdef::VK_VERSION_1_2[]
include::{generated}/api/protos/vkWaitSemaphores.adoc[]
endif::VK_VERSION_1_2[]

ifdef::VK_VERSION_1_2+VK_KHR_timeline_semaphore[or the equivalent command]

ifdef::VK_KHR_timeline_semaphore[]
include::{generated}/api/protos/vkWaitSemaphoresKHR.adoc[]
endif::VK_KHR_timeline_semaphore[]

  * pname:device is the logical device that owns the semaphores.
  * pname:pWaitInfo is a pointer to a slink:VkSemaphoreWaitInfo structure
    containing information about the wait condition.
  * pname:timeout is the timeout period in units of nanoseconds.
    pname:timeout is adjusted to the closest value allowed by the
    implementation-dependent timeout accuracy, which may: be substantially
    longer than one nanosecond, and may: be longer than the requested
    period.

If the condition is satisfied when fname:vkWaitSemaphores is called, then
fname:vkWaitSemaphores returns immediately.
If the condition is not satisfied at the time fname:vkWaitSemaphores is
called, then fname:vkWaitSemaphores will block and wait until the condition
is satisfied or the pname:timeout has expired, whichever is sooner.

If pname:timeout is zero, then fname:vkWaitSemaphores does not wait, but
simply returns information about the current state of the semaphores.
ename:VK_TIMEOUT will be returned in this case if the condition is not
satisfied, even though no actual wait was performed.

If the condition is satisfied before the pname:timeout has expired,
fname:vkWaitSemaphores returns ename:VK_SUCCESS.
Otherwise, fname:vkWaitSemaphores returns ename:VK_TIMEOUT after the
pname:timeout has expired.

If device loss occurs (see <<devsandqueues-lost-device,Lost Device>>) before
the timeout has expired, fname:vkWaitSemaphores must: return in finite time
with either ename:VK_SUCCESS or ename:VK_ERROR_DEVICE_LOST.

include::{chapters}/commonvalidity/no_dynamic_allocations_common.adoc[]

include::{generated}/validity/protos/vkWaitSemaphores.adoc[]
--

[open,refpage='VkSemaphoreWaitInfo',desc='Structure containing information about the semaphore wait condition',type='structs',alias='VkSemaphoreWaitInfoKHR']
--
The sname:VkSemaphoreWaitInfo structure is defined as:

include::{generated}/api/structs/VkSemaphoreWaitInfo.adoc[]

ifdef::VK_KHR_timeline_semaphore[]
or the equivalent

include::{generated}/api/structs/VkSemaphoreWaitInfoKHR.adoc[]
endif::VK_KHR_timeline_semaphore[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:flags is a bitmask of elink:VkSemaphoreWaitFlagBits specifying
    additional parameters for the semaphore wait operation.
  * pname:semaphoreCount is the number of semaphores to wait on.
  * pname:pSemaphores is a pointer to an array of pname:semaphoreCount
    semaphore handles to wait on.
  * pname:pValues is a pointer to an array of pname:semaphoreCount timeline
    semaphore values.

.Valid Usage
****
  * [[VUID-VkSemaphoreWaitInfo-pSemaphores-03256]]
    All of the elements of pname:pSemaphores must: reference a semaphore
    that was created with a elink:VkSemaphoreType of
    ename:VK_SEMAPHORE_TYPE_TIMELINE
ifdef::VK_NV_external_sci_sync,VK_NV_external_sci_sync2[]
  * [[VUID-VkSemaphoreWaitInfo-pSemaphores-05124]]
    If any of the semaphores in pname:pSemaphores have stext:NvSciSyncObj as
    payload, application must: calculate the corresponding timeline
    semaphore values in pname:pValues by calling
    <<NvSciSync2-extension-page, NvSciSync APIs>>.
endif::VK_NV_external_sci_sync,VK_NV_external_sci_sync2[]
****

include::{generated}/validity/structs/VkSemaphoreWaitInfo.adoc[]
--

[open,refpage='VkSemaphoreWaitFlagBits',desc='Bitmask specifying additional parameters of a semaphore wait operation',type='enums',alias='VkSemaphoreWaitFlagBitsKHR']
--
Bits which can: be set in slink:VkSemaphoreWaitInfo::pname:flags, specifying
additional parameters of a semaphore wait operation, are:

include::{generated}/api/enums/VkSemaphoreWaitFlagBits.adoc[]

ifdef::VK_KHR_timeline_semaphore[]
or the equivalent

include::{generated}/api/enums/VkSemaphoreWaitFlagBitsKHR.adoc[]
endif::VK_KHR_timeline_semaphore[]

  * ename:VK_SEMAPHORE_WAIT_ANY_BIT specifies that the semaphore wait
    condition is that at least one of the semaphores in
    sname:VkSemaphoreWaitInfo::pname:pSemaphores has reached the value
    specified by the corresponding element of
    sname:VkSemaphoreWaitInfo::pname:pValues.
    If ename:VK_SEMAPHORE_WAIT_ANY_BIT is not set, the semaphore wait
    condition is that all of the semaphores in
    sname:VkSemaphoreWaitInfo::pname:pSemaphores have reached the value
    specified by the corresponding element of
    sname:VkSemaphoreWaitInfo::pname:pValues.
--

[open,refpage='VkSemaphoreWaitFlags',desc='Bitmask of VkSemaphoreWaitFlagBits',type='flags',alias='VkSemaphoreWaitFlagsKHR']
--
include::{generated}/api/flags/VkSemaphoreWaitFlags.adoc[]

ifdef::VK_KHR_timeline_semaphore[]
or the equivalent

include::{generated}/api/flags/VkSemaphoreWaitFlagsKHR.adoc[]
endif::VK_KHR_timeline_semaphore[]

tname:VkSemaphoreWaitFlags is a bitmask type for setting a mask of zero or
more elink:VkSemaphoreWaitFlagBits.
--

[open,refpage='vkSignalSemaphore',desc='Signal a timeline semaphore on the host',type='protos',alias='vkSignalSemaphoreKHR']
--
:refpage: vkSignalSemaphore

To signal a semaphore created with a elink:VkSemaphoreType of
ename:VK_SEMAPHORE_TYPE_TIMELINE with a particular counter value, on the
host, call:

ifdef::VK_VERSION_1_2[]
include::{generated}/api/protos/vkSignalSemaphore.adoc[]
endif::VK_VERSION_1_2[]

ifdef::VK_VERSION_1_2+VK_KHR_timeline_semaphore[or the equivalent command]

ifdef::VK_KHR_timeline_semaphore[]
include::{generated}/api/protos/vkSignalSemaphoreKHR.adoc[]
endif::VK_KHR_timeline_semaphore[]

  * pname:device is the logical device that owns the semaphore.
  * pname:pSignalInfo is a pointer to a slink:VkSemaphoreSignalInfo
    structure containing information about the signal operation.

When fname:vkSignalSemaphore is executed on the host, it defines and
immediately executes a <<synchronization-semaphores-signaling,_semaphore
signal operation_>> which sets the timeline semaphore to the given value.

The first synchronization scope is defined by the host execution model, but
includes execution of fname:vkSignalSemaphore on the host and anything that
happened-before it.

The second synchronization scope is empty.

include::{chapters}/commonvalidity/no_dynamic_allocations_common.adoc[]

include::{generated}/validity/protos/vkSignalSemaphore.adoc[]
--

[open,refpage='VkSemaphoreSignalInfo',desc='Structure containing information about a semaphore signal operation',type='structs',alias='VkSemaphoreSignalInfoKHR']
--
The sname:VkSemaphoreSignalInfo structure is defined as:

include::{generated}/api/structs/VkSemaphoreSignalInfo.adoc[]

ifdef::VK_KHR_timeline_semaphore[]
or the equivalent

include::{generated}/api/structs/VkSemaphoreSignalInfoKHR.adoc[]
endif::VK_KHR_timeline_semaphore[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:semaphore is the handle of the semaphore to signal.
  * pname:value is the value to signal.

.Valid Usage
****
  * [[VUID-VkSemaphoreSignalInfo-semaphore-03257]]
    pname:semaphore must: have been created with a elink:VkSemaphoreType of
    ename:VK_SEMAPHORE_TYPE_TIMELINE
  * [[VUID-VkSemaphoreSignalInfo-value-03258]]
    pname:value must: have a value greater than the current value of the
    semaphore
  * [[VUID-VkSemaphoreSignalInfo-value-03259]]
    pname:value must: be less than the value of any pending semaphore signal
    operations
  * [[VUID-VkSemaphoreSignalInfo-value-03260]]
    pname:value must: have a value which does not differ from the current
    value of the semaphore or the value of any outstanding semaphore wait or
    signal operation on pname:semaphore by more than
    <<limits-maxTimelineSemaphoreValueDifference,
    pname:maxTimelineSemaphoreValueDifference>>
ifdef::VK_NV_external_sci_sync,VK_NV_external_sci_sync2[]
  * [[VUID-VkSemaphoreSignalInfo-semaphores-05125]]
    If pname:semaphores has stext:NvSciSyncObj as payload, application must:
    calculate the corresponding timeline semaphore value in pname:value by
    calling <<NvSciSync2-extension-page, NvSciSync APIs>>.
endif::VK_NV_external_sci_sync,VK_NV_external_sci_sync2[]
****

include::{generated}/validity/structs/VkSemaphoreSignalInfo.adoc[]
--
endif::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]


ifdef::VK_VERSION_1_1,VK_KHR_external_semaphore[]
[[synchronization-semaphores-importing]]
=== Importing Semaphore Payloads

Applications can: import a semaphore payload into an existing semaphore
using an external semaphore handle.
The effects of the import operation will be either temporary or permanent,
as specified by the application.
If the import is temporary, the implementation must: restore the semaphore
to its prior permanent state after submitting the next semaphore wait
operation.
Performing a subsequent temporary import on a semaphore before performing a
semaphore wait has no effect on this requirement; the next wait submitted on
the semaphore must: still restore its last permanent state.
A permanent payload import behaves as if the target semaphore was destroyed,
and a new semaphore was created with the same handle but the imported
payload.
Because importing a semaphore payload temporarily or permanently detaches
the existing payload from a semaphore, similar usage restrictions to those
applied to fname:vkDestroySemaphore are applied to any command that imports
a semaphore payload.
Which of these import types is used is referred to as the import operation's
_permanence_.
Each handle type supports either one or both types of permanence.

The implementation must: perform the import operation by either referencing
or copying the payload referred to by the specified external semaphore
handle, depending on the handle's type.
The import method used is referred to as the handle type's _transference_.
When using handle types with reference transference, importing a payload to
a semaphore adds the semaphore to the set of all semaphores sharing that
payload.
This set includes the semaphore from which the payload was exported.
Semaphore signaling and waiting operations performed on any semaphore in the
set must: behave as if the set were a single semaphore.
Importing a payload using handle types with copy transference creates a
duplicate copy of the payload at the time of import, but makes no further
reference to it.
Semaphore signaling and waiting operations performed on the target of copy
imports must: not affect any other semaphore or payload.

Export operations have the same transference as the specified handle type's
import operations.
Additionally, exporting a semaphore payload to a handle with copy
transference has the same side effects on the source semaphore's payload as
executing a semaphore wait operation.
If the semaphore was using a temporarily imported payload, the semaphore's
prior permanent payload will be restored.

ifdef::VK_KHR_external_semaphore_win32,VK_KHR_external_semaphore_fd,VK_FUCHSIA_external_semaphore[]
[NOTE]
.Note
====
The permanence and transference of handle types can be found in:

ifdef::VK_KHR_external_semaphore_win32[]
  * <<synchronization-semaphore-handletypes-win32,Handle Types Supported by
    sname:VkImportSemaphoreWin32HandleInfoKHR>>
endif::VK_KHR_external_semaphore_win32[]
ifdef::VK_KHR_external_semaphore_fd[]
  * <<synchronization-semaphore-handletypes-fd,Handle Types Supported by
    sname:VkImportSemaphoreFdInfoKHR>>
endif::VK_KHR_external_semaphore_fd[]
ifdef::VK_FUCHSIA_external_semaphore[]
  * <<synchronization-semaphore-handletypes-fuchsia,Handle Types Supported
    by sname:VkImportSemaphoreZirconHandleInfoFUCHSIA>>
endif::VK_FUCHSIA_external_semaphore[]
====
endif::VK_KHR_external_semaphore_win32,VK_KHR_external_semaphore_fd,VK_FUCHSIA_external_semaphore[]

<<fundamentals-threadingbehavior,External synchronization>> allows
implementations to modify an object's internal state, i.e. payload, without
internal synchronization.
However, for semaphores sharing a payload across processes, satisfying the
external synchronization requirements of sname:VkSemaphore parameters as if
all semaphores in the set were the same object is sometimes infeasible.
Satisfying the <<synchronization-semaphores-waiting-state,wait operation
state requirements>> would similarly require impractical coordination or
levels of trust between processes.
Therefore, these constraints only apply to a specific semaphore handle, not
to its payload.
For distinct semaphore objects which share a payload, if the semaphores are
passed to separate queue submission commands concurrently, behavior will be
as if the commands were called in an arbitrary sequential order.
If the <<synchronization-semaphores-waiting-state,wait operation state
requirements>> are violated for the shared payload by a queue submission
command, or if a signal operation is queued for a shared payload that is
already signaled or has a pending signal operation, effects must: be limited
to one or more of the following:

  * Returning ename:VK_ERROR_INITIALIZATION_FAILED from the command which
    resulted in the violation.
  * Losing the logical device on which the violation occurred immediately or
    at a future time, resulting in a ename:VK_ERROR_DEVICE_LOST error from
    subsequent commands, including the one causing the violation.
  * Continuing execution of the violating command or operation as if the
    semaphore wait completed successfully after an implementation-dependent
    timeout.
    In this case, the state of the payload becomes undefined:, and future
    operations on semaphores sharing the payload will be subject to these
    same rules.
    The semaphore must: be destroyed or have its payload replaced by an
    import operation to again have a well-defined state.

[NOTE]
.Note
====
These rules allow processes to synchronize access to shared memory without
trusting each other.
However, such processes must still be cautious not to use the shared
semaphore for more than synchronizing access to the shared memory.
For example, a process should not use a shared semaphore as part of an
execution dependency chain that, when complete, leads to objects being
destroyed, if it does not trust other processes sharing the semaphore
payload.
====

When a semaphore is using an imported payload, its
slink:VkExportSemaphoreCreateInfo::pname:handleTypes value is specified when
creating the semaphore from which the payload was exported, rather than
specified when creating the semaphore.
Additionally,
slink:VkExternalSemaphoreProperties::pname:exportFromImportedHandleTypes
restricts which handle types can: be exported from such a semaphore based on
the specific handle type used to import the current payload.
ifdef::VK_KHR_swapchain[]
Passing a semaphore to flink:vkAcquireNextImageKHR is equivalent to
temporarily importing a semaphore payload to that semaphore.

[NOTE]
.Note
====
Because the exportable handle types of an imported semaphore correspond to
its current imported payload, and flink:vkAcquireNextImageKHR behaves the
same as a temporary import operation for which the source semaphore is
opaque to the application, applications have no way of determining whether
any external handle types can: be exported from a semaphore in this state.
Therefore, applications must: not attempt to export external handles from
semaphores using a temporarily imported payload from
flink:vkAcquireNextImageKHR.
====
endif::VK_KHR_swapchain[]

When importing a semaphore payload, it is the responsibility of the
application to ensure the external handles meet all valid usage
requirements.
However, implementations must: perform sufficient validation of external
handles to ensure that the operation results in a valid semaphore which will
not cause program termination, device loss, queue stalls, or corruption of
other resources when used as allowed according to its import parameters, and
excepting those side effects allowed for violations of the
<<synchronization-semaphores-waiting-state,valid semaphore state for wait
operations>> rules.
If the external handle provided does not meet these requirements, the
implementation must: fail the semaphore payload import operation with the
error code ename:VK_ERROR_INVALID_EXTERNAL_HANDLE.

ifdef::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
In addition, when importing a semaphore payload that is not compatible with
the payload type corresponding to the elink:VkSemaphoreType the semaphore
was created with, the implementation may: fail the semaphore payload import
operation with the error code ename:VK_ERROR_INVALID_EXTERNAL_HANDLE.

[NOTE]
.Note
====
As the introduction of the external semaphore handle type
ename:VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE_BIT predates that of
timeline semaphores, support for importing semaphore payloads from external
handles of that type into semaphores created (implicitly or explicitly) with
a elink:VkSemaphoreType of ename:VK_SEMAPHORE_TYPE_BINARY is preserved for
backwards compatibility.
However, applications should: prefer importing such handle types into
semaphores created with a elink:VkSemaphoreType of
ename:VK_SEMAPHORE_TYPE_TIMELINE.
====
endif::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
endif::VK_VERSION_1_1,VK_KHR_external_semaphore[]

ifdef::VK_KHR_external_semaphore_win32[]
[open,refpage='vkImportSemaphoreWin32HandleKHR',desc='Import a semaphore from a Windows HANDLE',type='protos']
--
To import a semaphore payload from a Windows handle, call:

include::{generated}/api/protos/vkImportSemaphoreWin32HandleKHR.adoc[]

  * pname:device is the logical device that created the semaphore.
  * pname:pImportSemaphoreWin32HandleInfo is a pointer to a
    slink:VkImportSemaphoreWin32HandleInfoKHR structure specifying the
    semaphore and import parameters.

Importing a semaphore payload from Windows handles does not transfer
ownership of the handle to the Vulkan implementation.
For handle types defined as NT handles, the application must: release
ownership using the code:CloseHandle system call when the handle is no
longer needed.

Applications can: import the same semaphore payload into multiple instances
of Vulkan, into the same instance from which it was exported, and multiple
times into a given Vulkan instance.

include::{generated}/validity/protos/vkImportSemaphoreWin32HandleKHR.adoc[]
--

[open,refpage='VkImportSemaphoreWin32HandleInfoKHR',desc='Structure specifying Windows handle to import to a semaphore',type='structs']
--
The sname:VkImportSemaphoreWin32HandleInfoKHR structure is defined as:

include::{generated}/api/structs/VkImportSemaphoreWin32HandleInfoKHR.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:semaphore is the semaphore into which the payload will be
    imported.
  * pname:flags is a bitmask of elink:VkSemaphoreImportFlagBits specifying
    additional parameters for the semaphore payload import operation.
  * pname:handleType is a elink:VkExternalSemaphoreHandleTypeFlagBits value
    specifying the type of pname:handle.
  * pname:handle is `NULL` or the external handle to import.
  * pname:name is `NULL` or a null-terminated UTF-16 string naming the
    underlying synchronization primitive to import.

The handle types supported by pname:handleType are:

[[synchronization-semaphore-handletypes-win32]]
.Handle Types Supported by sname:VkImportSemaphoreWin32HandleInfoKHR
[width="80%",options="header"]
|====
| Handle Type                                                      | Transference | Permanence Supported
| ename:VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT     | Reference    | Temporary,Permanent
| ename:VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT | Reference    | Temporary,Permanent
| ename:VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE_BIT      | Reference    | Temporary,Permanent
|====

.Valid Usage
****
  * [[VUID-VkImportSemaphoreWin32HandleInfoKHR-handleType-01140]]
    pname:handleType must: be a value included in the
    <<synchronization-semaphore-handletypes-win32,Handle Types Supported by
    sname:VkImportSemaphoreWin32HandleInfoKHR>> table
  * [[VUID-VkImportSemaphoreWin32HandleInfoKHR-handleType-01466]]
    If pname:handleType is not
    ename:VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT or
    ename:VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE_BIT, pname:name
    must: be `NULL`
  * [[VUID-VkImportSemaphoreWin32HandleInfoKHR-handleType-01467]]
    If pname:handle is `NULL`, pname:name must: name a valid synchronization
    primitive of the type specified by pname:handleType
  * [[VUID-VkImportSemaphoreWin32HandleInfoKHR-handleType-01468]]
    If pname:name is `NULL`, pname:handle must: be a valid handle of the
    type specified by pname:handleType
  * [[VUID-VkImportSemaphoreWin32HandleInfoKHR-handle-01469]]
    If pname:handle is not `NULL`, pname:name must: be `NULL`
  * [[VUID-VkImportSemaphoreWin32HandleInfoKHR-handle-01542]]
    If pname:handle is not `NULL`, it must: obey any requirements listed for
    pname:handleType in
    <<external-semaphore-handle-types-compatibility,external semaphore
    handle types compatibility>>
  * [[VUID-VkImportSemaphoreWin32HandleInfoKHR-name-01543]]
    If pname:name is not `NULL`, it must: obey any requirements listed for
    pname:handleType in
    <<external-semaphore-handle-types-compatibility,external semaphore
    handle types compatibility>>
  * [[VUID-VkImportSemaphoreWin32HandleInfoKHR-handleType-03261]]
    If pname:handleType is
    ename:VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT or
    ename:VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT, the
    slink:VkSemaphoreCreateInfo::pname:flags field must: match that of the
    semaphore from which pname:handle or pname:name was exported
ifdef::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
  * [[VUID-VkImportSemaphoreWin32HandleInfoKHR-handleType-03262]]
    If pname:handleType is
    ename:VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT or
    ename:VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT, the
    slink:VkSemaphoreTypeCreateInfo::pname:semaphoreType field must: match
    that of the semaphore from which pname:handle or pname:name was exported
  * [[VUID-VkImportSemaphoreWin32HandleInfoKHR-flags-03322]]
    If pname:flags contains ename:VK_SEMAPHORE_IMPORT_TEMPORARY_BIT, the
    slink:VkSemaphoreTypeCreateInfo::pname:semaphoreType field of the
    semaphore from which pname:handle or pname:name was exported must: not
    be ename:VK_SEMAPHORE_TYPE_TIMELINE
endif::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
****

include::{generated}/validity/structs/VkImportSemaphoreWin32HandleInfoKHR.adoc[]
--
endif::VK_KHR_external_semaphore_win32[]

ifdef::VK_KHR_external_semaphore_fd[]
[open,refpage='vkImportSemaphoreFdKHR',desc='Import a semaphore from a POSIX file descriptor',type='protos']
--
:refpage: vkImportSemaphoreFdKHR

To import a semaphore payload from a POSIX file descriptor, call:

include::{generated}/api/protos/vkImportSemaphoreFdKHR.adoc[]

  * pname:device is the logical device that created the semaphore.
  * pname:pImportSemaphoreFdInfo is a pointer to a
    slink:VkImportSemaphoreFdInfoKHR structure specifying the semaphore and
    import parameters.

Importing a semaphore payload from a file descriptor transfers ownership of
the file descriptor from the application to the Vulkan implementation.
The application must: not perform any operations on the file descriptor
after a successful import.

Applications can: import the same semaphore payload into multiple instances
of Vulkan, into the same instance from which it was exported, and multiple
times into a given Vulkan instance.

include::{chapters}/commonvalidity/no_dynamic_allocations_common.adoc[]

.Valid Usage
****
  * [[VUID-vkImportSemaphoreFdKHR-semaphore-01142]]
    pname:semaphore must: not be associated with any queue command that has
    not yet completed execution on that queue
****

include::{generated}/validity/protos/vkImportSemaphoreFdKHR.adoc[]
--

[open,refpage='VkImportSemaphoreFdInfoKHR',desc='Structure specifying POSIX file descriptor to import to a semaphore',type='structs']
--
The sname:VkImportSemaphoreFdInfoKHR structure is defined as:

include::{generated}/api/structs/VkImportSemaphoreFdInfoKHR.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:semaphore is the semaphore into which the payload will be
    imported.
  * pname:flags is a bitmask of elink:VkSemaphoreImportFlagBits specifying
    additional parameters for the semaphore payload import operation.
  * pname:handleType is a elink:VkExternalSemaphoreHandleTypeFlagBits value
    specifying the type of pname:fd.
  * pname:fd is the external handle to import.

The handle types supported by pname:handleType are:

[[synchronization-semaphore-handletypes-fd]]
.Handle Types Supported by sname:VkImportSemaphoreFdInfoKHR
[width="80%",options="header"]
|====
| Handle Type                                               | Transference | Permanence Supported
| ename:VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT | Reference    | Temporary,Permanent
| ename:VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT   | Copy         | Temporary
|====

.Valid Usage
****
  * [[VUID-VkImportSemaphoreFdInfoKHR-handleType-01143]]
    pname:handleType must: be a value included in the
    <<synchronization-semaphore-handletypes-fd,Handle Types Supported by
    sname:VkImportSemaphoreFdInfoKHR>> table
  * [[VUID-VkImportSemaphoreFdInfoKHR-fd-01544]]
    pname:fd must: obey any requirements listed for pname:handleType in
    <<external-semaphore-handle-types-compatibility,external semaphore
    handle types compatibility>>
  * [[VUID-VkImportSemaphoreFdInfoKHR-handleType-03263]]
    If pname:handleType is
    ename:VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT, the
    slink:VkSemaphoreCreateInfo::pname:flags field must: match that of the
    semaphore from which pname:fd was exported
  * [[VUID-VkImportSemaphoreFdInfoKHR-handleType-07307]]
    If pname:handleType refers to a handle type with copy payload
    transference semantics, pname:flags must: contain
    ename:VK_SEMAPHORE_IMPORT_TEMPORARY_BIT
ifdef::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
  * [[VUID-VkImportSemaphoreFdInfoKHR-handleType-03264]]
    If pname:handleType is
    ename:VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT, the
    slink:VkSemaphoreTypeCreateInfo::pname:semaphoreType field must: match
    that of the semaphore from which pname:fd was exported
  * [[VUID-VkImportSemaphoreFdInfoKHR-flags-03323]]
    If pname:flags contains ename:VK_SEMAPHORE_IMPORT_TEMPORARY_BIT, the
    slink:VkSemaphoreTypeCreateInfo::pname:semaphoreType field of the
    semaphore from which pname:fd was exported must: not be
    ename:VK_SEMAPHORE_TYPE_TIMELINE
endif::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
****

If pname:handleType is ename:VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT,
the special value `-1` for pname:fd is treated like a valid sync file
descriptor referring to an object that has already signaled.
The import operation will succeed and the sname:VkSemaphore will have a
temporarily imported payload as if a valid file descriptor had been
provided.

[NOTE]
.Note
====
This special behavior for importing an invalid sync file descriptor allows
easier interoperability with other system APIs which use the convention that
an invalid sync file descriptor represents work that has already completed
and does not need to be waited for.
It is consistent with the option for implementations to return a `-1` file
descriptor when exporting a
ename:VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT from a sname:VkSemaphore
which is signaled.
====

include::{generated}/validity/structs/VkImportSemaphoreFdInfoKHR.adoc[]
--
endif::VK_KHR_external_semaphore_fd[]

ifdef::VK_FUCHSIA_external_semaphore[]
[open,refpage='vkImportSemaphoreZirconHandleFUCHSIA',desc='Import a semaphore from a Zircon event handle',type='protos']
--
To import a semaphore payload from a Zircon event handle, call:

include::{generated}/api/protos/vkImportSemaphoreZirconHandleFUCHSIA.adoc[]

  * pname:device is the logical device that created the semaphore.
  * pname:pImportSemaphoreZirconHandleInfo is a pointer to a
    slink:VkImportSemaphoreZirconHandleInfoFUCHSIA structure specifying the
    semaphore and import parameters.

Importing a semaphore payload from a Zircon event handle transfers ownership
of the handle from the application to the Vulkan implementation.
The application must: not perform any operations on the handle after a
successful import.

Applications can: import the same semaphore payload into multiple instances
of Vulkan, into the same instance from which it was exported, and multiple
times into a given Vulkan instance.

.Valid Usage
****
  * [[VUID-vkImportSemaphoreZirconHandleFUCHSIA-semaphore-04764]]
    pname:semaphore must: not be associated with any queue command that has
    not yet completed execution on that queue
****

include::{generated}/validity/protos/vkImportSemaphoreZirconHandleFUCHSIA.adoc[]
--

[open,refpage='VkImportSemaphoreZirconHandleInfoFUCHSIA',desc='Structure specifying Zircon event handle to import to a semaphore',type='structs']
--
The sname:VkImportSemaphoreZirconHandleInfoFUCHSIA structure is defined as:

include::{generated}/api/structs/VkImportSemaphoreZirconHandleInfoFUCHSIA.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:semaphore is the semaphore into which the payload will be
    imported.
  * pname:flags is a bitmask of elink:VkSemaphoreImportFlagBits specifying
    additional parameters for the semaphore payload import operation.
  * pname:handleType is a elink:VkExternalSemaphoreHandleTypeFlagBits value
    specifying the type of pname:zirconHandle.
  * pname:zirconHandle is the external handle to import.

The handle types supported by pname:handleType are:

[[synchronization-semaphore-handletypes-fuchsia]]
.Handle Types Supported by sname:VkImportSemaphoreZirconHandleInfoFUCHSIA
[width="80%",options="header"]
|====
| Handle Type                                               | Transference | Permanence Supported
| ename:VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_ZIRCON_EVENT_BIT_FUCHSIA   | Reference         | Temporary,Permanent
|====

.Valid Usage
****
  * [[VUID-VkImportSemaphoreZirconHandleInfoFUCHSIA-handleType-04765]]
    pname:handleType must: be a value included in the
    <<synchronization-semaphore-handletypes-fuchsia,Handle Types Supported
    by sname:VkImportSemaphoreZirconHandleInfoFUCHSIA>> table
  * [[VUID-VkImportSemaphoreZirconHandleInfoFUCHSIA-zirconHandle-04766]]
    pname:zirconHandle must: obey any requirements listed for
    pname:handleType in
    <<external-semaphore-handle-types-compatibility,external semaphore
    handle types compatibility>>
  * [[VUID-VkImportSemaphoreZirconHandleInfoFUCHSIA-zirconHandle-04767]]
    pname:zirconHandle must: have code:ZX_RIGHTS_BASIC and
    code:ZX_RIGHTS_SIGNAL rights
ifdef::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
  * [[VUID-VkImportSemaphoreZirconHandleInfoFUCHSIA-semaphoreType-04768]]
    The slink:VkSemaphoreTypeCreateInfo::pname:semaphoreType field must: not
    be ename:VK_SEMAPHORE_TYPE_TIMELINE
endif::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
****

include::{generated}/validity/structs/VkImportSemaphoreZirconHandleInfoFUCHSIA.adoc[]
--
endif::VK_FUCHSIA_external_semaphore[]

ifdef::VK_NV_external_sci_sync[]
[open,refpage='vkImportSemaphoreSciSyncObjNV',desc='Import a semaphore from a SciSync handle',type='protos']
--
To import a semaphore payload from a stext:NvSciSyncObj, call:

include::{generated}/api/protos/vkImportSemaphoreSciSyncObjNV.adoc[]

  * pname:device is the logical device that created the semaphore.
  * pname:pImportSemaphoreSciSyncInfo is a pointer to a
    slink:VkImportSemaphoreSciSyncInfoNV structure containing parameters of
    the import operation

Importing a semaphore payload from stext:NvSciSyncObj does not transfer
ownership of the handle to the Vulkan implementation.
When importing stext:NvSciSyncObj, Vulkan will make a new reference to that
object, the application must: release its ownership using
<<NvSciSync-extension-page, NvSciSync APIs>> when that ownership is no
longer needed.

Application must: not import the same stext:NvSciSyncObj with signaler
access permissions into multiple instances of VkSemaphore, and must: not
import into the same instance from which it was exported.

.Valid Usage
****
  * [[VUID-vkImportSemaphoreSciSyncObjNV-sciSyncImport-05155]]
    slink:VkPhysicalDeviceExternalSciSyncFeaturesNV::pname:sciSyncImport and
    slink:VkPhysicalDeviceExternalSciSyncFeaturesNV::pname:sciSyncSemaphore
    must: be enabled
****

include::{generated}/validity/protos/vkImportSemaphoreSciSyncObjNV.adoc[]
--

[open,refpage='VkImportSemaphoreSciSyncInfoNV',desc='Structure specifying SciSync handle to import to a semaphore',type='structs']
--
The sname:VkImportSemaphoreSciSyncInfoNV structure is defined as:

include::{generated}/api/structs/VkImportSemaphoreSciSyncInfoNV.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:semaphore is the semaphore into which the payload will be
    imported.
  * pname:handleType specifies the type of stext:handle.
  * pname:handle is the external handle to import.

The handle types supported by pname:handleType are:

[[synchronization-semaphore-handletypes-sci-sync]]
.Handle Types Supported by sname:VkImportSemaphoreSciSyncInfoNV
[width="80%",options="header"]
|====
| Handle Type                                           | Transference | Permanence Supported
| ename:VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SCI_SYNC_OBJ_BIT_NV   | Reference | Permanent
|====

.Valid Usage
****
  * [[VUID-VkImportSemaphoreSciSyncInfoNV-handleType-05126]]
    pname:handleType must: be a value included in the
    <<synchronization-semaphore-handletypes-sci-sync, Handle Types Supported
    by sname:VkImportSemaphoreSciSyncInfoNV>> table
  * [[VUID-VkImportSemaphoreSciSyncInfoNV-semaphore-05127]]
    pname:semaphore must: have been created with a elink:VkSemaphoreType of
    ename:VK_SEMAPHORE_TYPE_TIMELINE
  * [[VUID-VkImportSemaphoreSciSyncInfoNV-semaphore-05128]]
    pname:semaphore must: not be associated with any queue command that has
    not yet completed execution on that queue
****

include::{generated}/validity/structs/VkImportSemaphoreSciSyncInfoNV.adoc[]
--
endif::VK_NV_external_sci_sync[]

ifdef::VK_VERSION_1_1,VK_KHR_external_semaphore[]
ifdef::VK_KHR_external_semaphore_win32,VK_KHR_external_semaphore_fd,VK_FUCHSIA_external_semaphore[]
[open,refpage='VkSemaphoreImportFlagBits',desc='Bitmask specifying additional parameters of semaphore payload import',type='enums']
--
Bits which can: be set in

ifdef::VK_KHR_external_semaphore_win32[]
  * slink:VkImportSemaphoreWin32HandleInfoKHR::pname:flags
endif::VK_KHR_external_semaphore_win32[]
ifdef::VK_KHR_external_semaphore_fd[]
  * slink:VkImportSemaphoreFdInfoKHR::pname:flags
endif::VK_KHR_external_semaphore_fd[]
ifdef::VK_FUCHSIA_external_semaphore[]
  * slink:VkImportSemaphoreZirconHandleInfoFUCHSIA::pname:flags
endif::VK_FUCHSIA_external_semaphore[]

specifying additional parameters of a semaphore import operation are:

include::{generated}/api/enums/VkSemaphoreImportFlagBits.adoc[]

ifdef::VK_KHR_external_semaphore[]
or the equivalent

include::{generated}/api/enums/VkSemaphoreImportFlagBitsKHR.adoc[]
endif::VK_KHR_external_semaphore[]

These bits have the following meanings:

  * ename:VK_SEMAPHORE_IMPORT_TEMPORARY_BIT specifies that the semaphore
    payload will be imported only temporarily, as described in
    <<synchronization-semaphores-importing,Importing Semaphore Payloads>>,
    regardless of the permanence of pname:handleType.
--

[open,refpage='VkSemaphoreImportFlags',desc='Bitmask of VkSemaphoreImportFlagBits',type='flags']
--
include::{generated}/api/flags/VkSemaphoreImportFlags.adoc[]

ifdef::VK_KHR_external_semaphore[]
or the equivalent

include::{generated}/api/flags/VkSemaphoreImportFlagsKHR.adoc[]
endif::VK_KHR_external_semaphore[]

tname:VkSemaphoreImportFlags is a bitmask type for setting a mask of zero or
more elink:VkSemaphoreImportFlagBits.
--
endif::VK_KHR_external_semaphore_win32,VK_KHR_external_semaphore_fd,VK_FUCHSIA_external_semaphore[]
endif::VK_VERSION_1_1,VK_KHR_external_semaphore[]


[[synchronization-events]]
== Events

[open,refpage='VkEvent',desc='Opaque handle to an event object',type='handles']
--
Events are a synchronization primitive that can: be used to insert a
fine-grained dependency between commands submitted to the same queue, or
between the host and a queue.
Events must: not be used to insert a dependency between commands submitted
to different queues.
Events have two states - signaled and unsignaled.
An application can: signal or unsignal an event either on the host or on the
device.
A device can: be made to wait for an event to become signaled before
executing further operations.
No command exists to wait for an event to become signaled on the host, but
the current state of an event can: be queried.

Events are represented by sname:VkEvent handles:

include::{generated}/api/handles/VkEvent.adoc[]
--

[open,refpage='vkCreateEvent',desc='Create a new event object',type='protos']
--
:refpage: vkCreateEvent
:objectnameplural: events
:objectnamecamelcase: event
:objectcount: 1

To create an event, call:

include::{generated}/api/protos/vkCreateEvent.adoc[]

  * pname:device is the logical device that creates the event.
  * pname:pCreateInfo is a pointer to a slink:VkEventCreateInfo structure
    containing information about how the event is to be created.
  * pname:pAllocator controls host memory allocation as described in the
    <<memory-allocation, Memory Allocation>> chapter.
  * pname:pEvent is a pointer to a handle in which the resulting event
    object is returned.

When created, the event object is in the unsignaled state.

include::{chapters}/commonvalidity/no_dynamic_allocations_common.adoc[]

.Valid Usage
****
ifdef::VK_KHR_portability_subset[]
  * [[VUID-vkCreateEvent-events-04468]]
    If the `apiext:VK_KHR_portability_subset` extension is enabled, and
    slink:VkPhysicalDevicePortabilitySubsetFeaturesKHR::pname:events is
    ename:VK_FALSE, then the implementation does not support
    <<synchronization-events, events>>, and flink:vkCreateEvent must: not be
    used
endif::VK_KHR_portability_subset[]
include::{chapters}/commonvalidity/memory_reservation_request_count_common.adoc[]
****

include::{generated}/validity/protos/vkCreateEvent.adoc[]
--

[open,refpage='VkEventCreateInfo',desc='Structure specifying parameters of a newly created event',type='structs']
--
The sname:VkEventCreateInfo structure is defined as:

include::{generated}/api/structs/VkEventCreateInfo.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:flags is a bitmask of elink:VkEventCreateFlagBits defining
    additional creation parameters.

ifdef::VK_EXT_metal_objects[]
.Valid Usage
****
  * [[VUID-VkEventCreateInfo-pNext-06790]]
    If the pname:pNext chain includes a
    slink:VkExportMetalObjectCreateInfoEXT structure, its
    pname:exportObjectType member must: be
    ename:VK_EXPORT_METAL_OBJECT_TYPE_METAL_SHARED_EVENT_BIT_EXT
****
endif::VK_EXT_metal_objects[]

include::{generated}/validity/structs/VkEventCreateInfo.adoc[]
--

[open,refpage='VkEventCreateFlagBits',desc='Event creation flag bits',type='enums']
--
include::{generated}/api/enums/VkEventCreateFlagBits.adoc[]

ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
  * ename:VK_EVENT_CREATE_DEVICE_ONLY_BIT specifies that host event commands
    will not be used with this event.
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]

ifndef::VK_VERSION_1_3,VK_KHR_synchronization2[]
[NOTE]
.Note
====
All bits for this type are defined by extensions, and none of those
extensions are enabled in this build of the specification.
====
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]
--

[open,refpage='VkEventCreateFlags',desc='Bitmask of event creation flag bits',type='flags']
--
include::{generated}/api/flags/VkEventCreateFlags.adoc[]

tname:VkEventCreateFlags is a bitmask type for setting a mask of
elink:VkEventCreateFlagBits.
--

[open,refpage='vkDestroyEvent',desc='Destroy an event object',type='protos']
--
To destroy an event, call:

include::{generated}/api/protos/vkDestroyEvent.adoc[]

  * pname:device is the logical device that destroys the event.
  * pname:event is the handle of the event to destroy.
  * pname:pAllocator controls host memory allocation as described in the
    <<memory-allocation, Memory Allocation>> chapter.

.Valid Usage
****
  * [[VUID-vkDestroyEvent-event-01145]]
    All submitted commands that refer to pname:event must: have completed
    execution
ifndef::VKSC_VERSION_1_0[]
  * [[VUID-vkDestroyEvent-event-01146]]
    If sname:VkAllocationCallbacks were provided when pname:event was
    created, a compatible set of callbacks must: be provided here
  * [[VUID-vkDestroyEvent-event-01147]]
    If no sname:VkAllocationCallbacks were provided when pname:event was
    created, pname:pAllocator must: be `NULL`
endif::VKSC_VERSION_1_0[]
****

include::{generated}/validity/protos/vkDestroyEvent.adoc[]
--

[open,refpage='vkGetEventStatus',desc='Retrieve the status of an event object',type='protos']
--
:refpage: vkGetEventStatus

To query the state of an event from the host, call:

include::{generated}/api/protos/vkGetEventStatus.adoc[]

  * pname:device is the logical device that owns the event.
  * pname:event is the handle of the event to query.

Upon success, fname:vkGetEventStatus returns the state of the event object
with the following return codes:

.Event Object Status Codes
[width="80%",options="header"]
|====
| Status | Meaning
| ename:VK_EVENT_SET | The event specified by pname:event is signaled.
| ename:VK_EVENT_RESET | The event specified by pname:event is unsignaled.
|====

If a fname:vkCmdSetEvent or fname:vkCmdResetEvent command is in a command
buffer that is in the <<commandbuffers-lifecycle, pending state>>, then the
value returned by this command may: immediately be out of date.

The state of an event can: be updated by the host.
The state of the event is immediately changed, and subsequent calls to
fname:vkGetEventStatus will return the new state.
If an event is already in the requested state, then updating it to the same
state has no effect.

include::{chapters}/commonvalidity/no_dynamic_allocations_common.adoc[]

ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
.Valid Usage
****
  * [[VUID-vkGetEventStatus-event-03940]]
    pname:event must: not have been created with
    ename:VK_EVENT_CREATE_DEVICE_ONLY_BIT
****
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]

include::{generated}/validity/protos/vkGetEventStatus.adoc[]
--

[[synchronization-events-signaling-host]]
[open,refpage='vkSetEvent',desc='Set an event to signaled state',type='protos']
--
:refpage: vkSetEvent

To set the state of an event to signaled from the host, call:

include::{generated}/api/protos/vkSetEvent.adoc[]

  * pname:device is the logical device that owns the event.
  * pname:event is the event to set.

When flink:vkSetEvent is executed on the host, it defines an _event signal
operation_ which sets the event to the signaled state.

If pname:event is already in the signaled state when flink:vkSetEvent is
executed, then flink:vkSetEvent has no effect, and no event signal operation
occurs.

[NOTE]
.Note
====
If a command buffer is waiting for an event to be signaled from the host,
the application must signal the event before submitting the command buffer,
as described in the <<commandbuffers-submission-progress, queue forward
progress>> section.
====

include::{chapters}/commonvalidity/no_dynamic_allocations_common.adoc[]

ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
.Valid Usage
****
  * [[VUID-vkSetEvent-event-03941]]
    pname:event must: not have been created with
    ename:VK_EVENT_CREATE_DEVICE_ONLY_BIT
  * [[VUID-vkSetEvent-event-09543]]
    pname:event must: not be waited on by a command buffer in the
    <<commandbuffers-lifecycle, pending state>>
****
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]

include::{generated}/validity/protos/vkSetEvent.adoc[]
--

[[synchronization-events-unsignaling-host]]
[open,refpage='vkResetEvent',desc='Reset an event to non-signaled state',type='protos']
--
To set the state of an event to unsignaled from the host, call:

include::{generated}/api/protos/vkResetEvent.adoc[]

  * pname:device is the logical device that owns the event.
  * pname:event is the event to reset.

When flink:vkResetEvent is executed on the host, it defines an _event
unsignal operation_ which resets the event to the unsignaled state.

If pname:event is already in the unsignaled state when flink:vkResetEvent is
executed, then flink:vkResetEvent has no effect, and no event unsignal
operation occurs.

.Valid Usage
****
  * [[VUID-vkResetEvent-event-03821]]
    There must: be an execution dependency between fname:vkResetEvent and
    the execution of any flink:vkCmdWaitEvents that includes pname:event in
    its pname:pEvents parameter
ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
  * [[VUID-vkResetEvent-event-03822]]
    There must: be an execution dependency between fname:vkResetEvent and
    the execution of any flink:vkCmdWaitEvents2 that includes pname:event in
    its pname:pEvents parameter
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]
ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
  * [[VUID-vkResetEvent-event-03823]]
    pname:event must: not have been created with
    ename:VK_EVENT_CREATE_DEVICE_ONLY_BIT
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]
****

include::{generated}/validity/protos/vkResetEvent.adoc[]
--

The state of an event can: also be updated on the device by commands
inserted in command buffers.

[[synchronization-events-signaling-device]]
ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
[open,refpage='vkCmdSetEvent2',desc='Set an event object to signaled state',type='protos',alias='vkCmdSetEvent2KHR']
--
To signal an event from a device, call:

ifdef::VK_VERSION_1_3[]
include::{generated}/api/protos/vkCmdSetEvent2.adoc[]
endif::VK_VERSION_1_3[]

ifdef::VK_VERSION_1_3+VK_KHR_synchronization2[or the equivalent command]

ifdef::VK_KHR_synchronization2[]
include::{generated}/api/protos/vkCmdSetEvent2KHR.adoc[]
endif::VK_KHR_synchronization2[]

  * pname:commandBuffer is the command buffer into which the command is
    recorded.
  * pname:event is the event that will be signaled.
  * pname:pDependencyInfo is a pointer to a slink:VkDependencyInfo structure
    defining the first scopes of this operation.

When flink:vkCmdSetEvent2 is submitted to a queue, it defines the first half
of memory dependencies defined by pname:pDependencyInfo, as well as an event
signal operation which sets the event to the signaled state.
A memory dependency is defined between the event signal operation and
commands that occur earlier in submission order.

The first <<synchronization-dependencies-scopes, synchronization scope>> and
<<synchronization-dependencies-access-scopes, access scope>> are defined by
the union of all the memory dependencies defined by pname:pDependencyInfo,
and are applied to all operations that occur earlier in
<<synchronization-submission-order,submission order>>.
<<synchronization-queue-transfers, Queue family ownership transfers>> and
<<synchronization-image-layout-transitions, image layout transitions>>
defined by pname:pDependencyInfo are also included in the first scopes.

The second <<synchronization-dependencies-scopes, synchronization scope>>
includes only the event signal operation, and any
<<synchronization-queue-transfers, queue family ownership transfers>> and
<<synchronization-image-layout-transitions, image layout transitions>>
defined by pname:pDependencyInfo.

The second <<synchronization-dependencies-access-scopes, access scope>>
includes only <<synchronization-queue-transfers, queue family ownership
transfers>> and <<synchronization-image-layout-transitions, image layout
transitions>>.

Future flink:vkCmdWaitEvents2 commands rely on all values of each element in
pname:pDependencyInfo matching exactly with those used to signal the
corresponding event.
flink:vkCmdWaitEvents must: not be used to wait on the result of a signal
operation defined by fname:vkCmdSetEvent2.

[NOTE]
.Note
====
The extra information provided by flink:vkCmdSetEvent2 compared to
flink:vkCmdSetEvent allows implementations to more efficiently schedule the
operations required to satisfy the requested dependencies.
With flink:vkCmdSetEvent, the full dependency information is not known until
flink:vkCmdWaitEvents is recorded, forcing implementations to insert the
required operations at that point and not before.
====

If pname:event is already in the signaled state when flink:vkCmdSetEvent2 is
executed on the device, then flink:vkCmdSetEvent2 has no effect, no event
signal operation occurs, and no dependency is generated.

.Valid Usage
****
  * [[VUID-vkCmdSetEvent2-synchronization2-03824]]
    The <<features-synchronization2, pname:synchronization2>> feature must:
    be enabled
  * [[VUID-vkCmdSetEvent2-dependencyFlags-03825]]
    The pname:dependencyFlags member of pname:pDependencyInfo must: be `0`
  * [[VUID-vkCmdSetEvent2-srcStageMask-09391]]
    The pname:srcStageMask member of any element of the
    pname:pMemoryBarriers, pname:pBufferMemoryBarriers, or
    pname:pImageMemoryBarriers members of pname:pDependencyInfo must: not
    include ename:VK_PIPELINE_STAGE_2_HOST_BIT
  * [[VUID-vkCmdSetEvent2-dstStageMask-09392]]
    The pname:dstStageMask member of any element of the
    pname:pMemoryBarriers, pname:pBufferMemoryBarriers, or
    pname:pImageMemoryBarriers members of pname:pDependencyInfo must: not
    include ename:VK_PIPELINE_STAGE_2_HOST_BIT
ifdef::VK_VERSION_1_1,VK_KHR_device_group[]
  * [[VUID-vkCmdSetEvent2-commandBuffer-03826]]
    The current device mask of pname:commandBuffer must: include exactly one
    physical device
endif::VK_VERSION_1_1,VK_KHR_device_group[]
  * [[VUID-vkCmdSetEvent2-srcStageMask-03827]]
    The pname:srcStageMask member of any element of the
    pname:pMemoryBarriers, pname:pBufferMemoryBarriers, or
    pname:pImageMemoryBarriers members of pname:pDependencyInfo must: only
    include pipeline stages valid for the queue family that was used to
    create the command pool that pname:commandBuffer was allocated from
  * [[VUID-vkCmdSetEvent2-dstStageMask-03828]]
    The pname:dstStageMask member of any element of the
    pname:pMemoryBarriers, pname:pBufferMemoryBarriers, or
    pname:pImageMemoryBarriers members of pname:pDependencyInfo must: only
    include pipeline stages valid for the queue family that was used to
    create the command pool that pname:commandBuffer was allocated from
****

include::{generated}/validity/protos/vkCmdSetEvent2.adoc[]
--

[open,refpage='VkDependencyInfo',desc='Structure specifying dependency information for a synchronization command',type='structs',alias='VkDependencyInfoKHR']
--
The sname:VkDependencyInfo structure is defined as:

include::{generated}/api/structs/VkDependencyInfo.adoc[]

ifdef::VK_KHR_synchronization2[]
or the equivalent

include::{generated}/api/structs/VkDependencyInfoKHR.adoc[]
endif::VK_KHR_synchronization2[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:dependencyFlags is a bitmask of elink:VkDependencyFlagBits
    specifying how execution and memory dependencies are formed.
  * pname:memoryBarrierCount is the length of the pname:pMemoryBarriers
    array.
  * pname:pMemoryBarriers is a pointer to an array of slink:VkMemoryBarrier2
    structures defining memory dependencies between any memory accesses.
  * pname:bufferMemoryBarrierCount is the length of the
    pname:pBufferMemoryBarriers array.
  * pname:pBufferMemoryBarriers is a pointer to an array of
    slink:VkBufferMemoryBarrier2 structures defining memory dependencies
    between buffer ranges.
  * pname:imageMemoryBarrierCount is the length of the
    pname:pImageMemoryBarriers array.
  * pname:pImageMemoryBarriers is a pointer to an array of
    slink:VkImageMemoryBarrier2 structures defining memory dependencies
    between image subresources.

This structure defines a set of <<synchronization-dependencies-memory,
memory dependencies>>, as well as <<synchronization-queue-transfers, queue
family transfer operations>> and <<synchronization-image-layout-transitions,
image layout transitions>>.

Each member of pname:pMemoryBarriers, pname:pBufferMemoryBarriers, and
pname:pImageMemoryBarriers defines a separate
<<synchronization-dependencies-memory, memory dependency>>.

include::{generated}/validity/structs/VkDependencyInfo.adoc[]
--
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]

[open,refpage='vkCmdSetEvent',desc='Set an event object to signaled state',type='protos']
--
:refpage: vkCmdSetEvent

To set the state of an event to signaled from a device, call:

include::{generated}/api/protos/vkCmdSetEvent.adoc[]

  * pname:commandBuffer is the command buffer into which the command is
    recorded.
  * pname:event is the event that will be signaled.
  * pname:stageMask specifies the <<synchronization-pipeline-stages,source
    stage mask>> used to determine the first
    <<synchronization-dependencies-scopes, synchronization scope>>.


ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
fname:vkCmdSetEvent behaves identically to flink:vkCmdSetEvent2, except that
it does not define an access scope, and must: only be used with
flink:vkCmdWaitEvents, not flink:vkCmdWaitEvents2.
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]

ifndef::VK_VERSION_1_3,VK_KHR_synchronization2[]
When flink:vkCmdSetEvent is submitted to a queue, it defines an execution
dependency on commands that were submitted before it, and defines an event
signal operation which sets the event to the signaled state.

The first <<synchronization-dependencies-scopes, synchronization scope>>
includes all commands that occur earlier in
<<synchronization-submission-order,submission order>>.
The synchronization scope is limited to operations on the pipeline stages
determined by the <<synchronization-pipeline-stages-masks, source stage
mask>> specified by pname:stageMask.

The second <<synchronization-dependencies-scopes, synchronization scope>>
includes only the event signal operation.

If pname:event is already in the signaled state when flink:vkCmdSetEvent is
executed on the device, then flink:vkCmdSetEvent has no effect, no event
signal operation occurs, and no execution dependency is generated.
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]

.Valid Usage
****
:stageMaskName: stageMask
include::{chapters}/commonvalidity/stage_mask_common.adoc[]
  * [[VUID-vkCmdSetEvent-stageMask-06457]]
    Any pipeline stage included in pname:stageMask must: be supported by the
    capabilities of the queue family specified by the pname:queueFamilyIndex
    member of the slink:VkCommandPoolCreateInfo structure that was used to
    create the sname:VkCommandPool that pname:commandBuffer was allocated
    from, as specified in the <<synchronization-pipeline-stages-supported,
    table of supported pipeline stages>>
  * [[VUID-vkCmdSetEvent-stageMask-01149]]
    pname:stageMask must: not include ename:VK_PIPELINE_STAGE_HOST_BIT
ifdef::VK_VERSION_1_1,VK_KHR_device_group[]
  * [[VUID-vkCmdSetEvent-commandBuffer-01152]]
    The current device mask of pname:commandBuffer must: include exactly one
    physical device
endif::VK_VERSION_1_1,VK_KHR_device_group[]
****

include::{generated}/validity/protos/vkCmdSetEvent.adoc[]
--

[[synchronization-events-unsignaling-device]]
ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
[open,refpage='vkCmdResetEvent2',desc='Reset an event object to non-signaled state',type='protos',alias='vkCmdResetEvent2KHR']
--
:refpage: vkCmdResetEvent2

To unsignal the event from a device, call:

ifdef::VK_VERSION_1_3[]
include::{generated}/api/protos/vkCmdResetEvent2.adoc[]
endif::VK_VERSION_1_3[]

ifdef::VK_VERSION_1_3+VK_KHR_synchronization2[or the equivalent command]

ifdef::VK_KHR_synchronization2[]
include::{generated}/api/protos/vkCmdResetEvent2KHR.adoc[]
endif::VK_KHR_synchronization2[]

  * pname:commandBuffer is the command buffer into which the command is
    recorded.
  * pname:event is the event that will be unsignaled.
  * pname:stageMask is a tlink:VkPipelineStageFlags2 mask of pipeline stages
    used to determine the first <<synchronization-dependencies-scopes,
    synchronization scope>>.

When flink:vkCmdResetEvent2 is submitted to a queue, it defines an execution
dependency on commands that were submitted before it, and defines an event
unsignal operation which resets the event to the unsignaled state.

The first <<synchronization-dependencies-scopes, synchronization scope>>
includes all commands that occur earlier in
<<synchronization-submission-order,submission order>>.
The synchronization scope is limited to operations by pname:stageMask or
stages that are <<synchronization-pipeline-stages-order,logically earlier>>
than pname:stageMask.

The second <<synchronization-dependencies-scopes, synchronization scope>>
includes only the event unsignal operation.

If pname:event is already in the unsignaled state when
flink:vkCmdResetEvent2 is executed on the device, then this command has no
effect, no event unsignal operation occurs, and no execution dependency is
generated.

.Valid Usage
****
:stageMaskName: stageMask
include::{chapters}/commonvalidity/stage_mask_2_common.adoc[]
  * [[VUID-vkCmdResetEvent2-synchronization2-03829]]
    The <<features-synchronization2, pname:synchronization2>> feature must:
    be enabled
  * [[VUID-vkCmdResetEvent2-stageMask-03830]]
    pname:stageMask must: not include ename:VK_PIPELINE_STAGE_2_HOST_BIT
  * [[VUID-vkCmdResetEvent2-event-03831]]
    There must: be an execution dependency between fname:vkCmdResetEvent2
    and the execution of any flink:vkCmdWaitEvents that includes pname:event
    in its pname:pEvents parameter
  * [[VUID-vkCmdResetEvent2-event-03832]]
    There must: be an execution dependency between fname:vkCmdResetEvent2
    and the execution of any flink:vkCmdWaitEvents2 that includes
    pname:event in its pname:pEvents parameter
ifdef::VK_VERSION_1_1,VK_KHR_device_group[]
  * [[VUID-vkCmdResetEvent2-commandBuffer-03833]]
    pname:commandBuffer's current device mask must: include exactly one
    physical device
endif::VK_VERSION_1_1,VK_KHR_device_group[]
****

include::{generated}/validity/protos/vkCmdResetEvent2.adoc[]
--
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]

[open,refpage='vkCmdResetEvent',desc='Reset an event object to non-signaled state',type='protos']
--
:refpage: vkCmdResetEvent

To set the state of an event to unsignaled from a device, call:

include::{generated}/api/protos/vkCmdResetEvent.adoc[]

  * pname:commandBuffer is the command buffer into which the command is
    recorded.
  * pname:event is the event that will be unsignaled.
  * pname:stageMask is a bitmask of elink:VkPipelineStageFlagBits specifying
    the <<synchronization-pipeline-stages, source stage mask>> used to
    determine when the pname:event is unsignaled.

ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
fname:vkCmdResetEvent behaves identically to flink:vkCmdResetEvent2.
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]

ifndef::VK_VERSION_1_3,VK_KHR_synchronization2[]
When flink:vkCmdResetEvent is submitted to a queue, it defines an execution
dependency on commands that were submitted before it, and defines an event
unsignal operation which resets the event to the unsignaled state.

The first <<synchronization-dependencies-scopes, synchronization scope>>
includes all commands that occur earlier in
<<synchronization-submission-order,submission order>>.
The synchronization scope is limited to operations on the pipeline stages
determined by the <<synchronization-pipeline-stages-masks, source stage
mask>> specified by pname:stageMask.

The second <<synchronization-dependencies-scopes, synchronization scope>>
includes only the event unsignal operation.

If pname:event is already in the unsignaled state when flink:vkCmdResetEvent
is executed on the device, then flink:vkCmdResetEvent has no effect, no
event unsignal operation occurs, and no execution dependency is generated.
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]

.Valid Usage
****
:stageMaskName: stageMask
include::{chapters}/commonvalidity/stage_mask_common.adoc[]
  * [[VUID-vkCmdResetEvent-stageMask-06458]]
    Any pipeline stage included in pname:stageMask must: be supported by the
    capabilities of the queue family specified by the pname:queueFamilyIndex
    member of the slink:VkCommandPoolCreateInfo structure that was used to
    create the sname:VkCommandPool that pname:commandBuffer was allocated
    from, as specified in the <<synchronization-pipeline-stages-supported,
    table of supported pipeline stages>>
  * [[VUID-vkCmdResetEvent-stageMask-01153]]
    pname:stageMask must: not include ename:VK_PIPELINE_STAGE_HOST_BIT
  * [[VUID-vkCmdResetEvent-event-03834]]
    There must: be an execution dependency between fname:vkCmdResetEvent and
    the execution of any flink:vkCmdWaitEvents that includes pname:event in
    its pname:pEvents parameter
ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
  * [[VUID-vkCmdResetEvent-event-03835]]
    There must: be an execution dependency between fname:vkCmdResetEvent and
    the execution of any flink:vkCmdWaitEvents2 that includes pname:event in
    its pname:pEvents parameter
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]
ifdef::VK_VERSION_1_1,VK_KHR_device_group[]
  * [[VUID-vkCmdResetEvent-commandBuffer-01157]]
    pname:commandBuffer's current device mask must: include exactly one
    physical device
endif::VK_VERSION_1_1,VK_KHR_device_group[]
****

include::{generated}/validity/protos/vkCmdResetEvent.adoc[]
--

ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
[open,refpage='vkCmdWaitEvents2',desc='Wait for one or more events',type='protos',alias='vkCmdWaitEvents2KHR']
--
To wait for one or more events to enter the signaled state on a device,
call:

[[synchronization-events-waiting-device]]
ifdef::VK_VERSION_1_3[]
include::{generated}/api/protos/vkCmdWaitEvents2.adoc[]
endif::VK_VERSION_1_3[]

ifdef::VK_VERSION_1_3+VK_KHR_synchronization2[or the equivalent command]

ifdef::VK_KHR_synchronization2[]
include::{generated}/api/protos/vkCmdWaitEvents2KHR.adoc[]
endif::VK_KHR_synchronization2[]

  * pname:commandBuffer is the command buffer into which the command is
    recorded.
  * pname:eventCount is the length of the pname:pEvents array.
  * pname:pEvents is a pointer to an array of pname:eventCount events to
    wait on.
  * pname:pDependencyInfos is a pointer to an array of pname:eventCount
    slink:VkDependencyInfo structures, defining the second
    <<synchronization-dependencies-scopes, synchronization scope>>.

When fname:vkCmdWaitEvents2 is submitted to a queue, it inserts memory
dependencies according to the elements of pname:pDependencyInfos and each
corresponding element of pname:pEvents.
fname:vkCmdWaitEvents2 must: not be used to wait on event signal operations
occurring on other queues, or signal operations executed by
flink:vkCmdSetEvent.

The first <<synchronization-dependencies-scopes, synchronization scope>> and
<<synchronization-dependencies-access-scopes, access scope>> of each memory
dependency defined by any element [eq]#i# of pname:pDependencyInfos are
applied to operations that occurred earlier in
<<synchronization-submission-order,submission order>> than the last event
signal operation on element [eq]#i# of pname:pEvents.

Signal operations for an event at index [eq]#i# are only included if:

  * The event was signaled by a flink:vkCmdSetEvent2 command that occurred
    earlier in <<synchronization-submission-order,submission order>> with a
    pname:dependencyInfo parameter exactly equal to the element of
    pname:pDependencyInfos at index [eq]#i# ; or
  * The event was created without ename:VK_EVENT_CREATE_DEVICE_ONLY_BIT, and
    the first <<synchronization-dependencies-scopes, synchronization scope>>
    defined by the element of pname:pDependencyInfos at index [eq]#i# only
    includes host operations (ename:VK_PIPELINE_STAGE_2_HOST_BIT).

The second <<synchronization-dependencies-scopes, synchronization scope>>
and <<synchronization-dependencies-access-scopes, access scope>> of each
memory dependency defined by any element [eq]#i# of pname:pDependencyInfos
are applied to operations that occurred later in
<<synchronization-submission-order,submission order>> than
fname:vkCmdWaitEvents2.

[NOTE]
.Note
====
flink:vkCmdWaitEvents2 is used with flink:vkCmdSetEvent2 to define a memory
dependency between two sets of action commands, roughly in the same way as
pipeline barriers, but split into two commands such that work between the
two may: execute unhindered.
====

[NOTE]
.Note
====
Applications should be careful to avoid race conditions when using events.
There is no direct ordering guarantee between fname:vkCmdSetEvent2 and
flink:vkCmdResetEvent2, flink:vkCmdResetEvent, or flink:vkCmdSetEvent.
Another execution dependency (e.g. a pipeline barrier or semaphore with
ename:VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT) is needed to prevent such a race
condition.
====

.Valid Usage
****
  * [[VUID-vkCmdWaitEvents2-synchronization2-03836]]
    The <<features-synchronization2, pname:synchronization2>> feature must:
    be enabled
  * [[VUID-vkCmdWaitEvents2-pEvents-03837]]
    Members of pname:pEvents must: not have been signaled by
    flink:vkCmdSetEvent
  * [[VUID-vkCmdWaitEvents2-pEvents-03838]]
    For any element [eq]#i# of pname:pEvents, if that event is signaled by
    flink:vkCmdSetEvent2, that command's pname:dependencyInfo parameter
    must: be exactly equal to the [eq]##i##th element of
    pname:pDependencyInfos
  * [[VUID-vkCmdWaitEvents2-pEvents-03839]]
    For any element [eq]#i# of pname:pEvents, if that event is signaled by
    flink:vkSetEvent, barriers in the [eq]##i##th element of
    pname:pDependencyInfos must: include only host operations in their first
    <<synchronization-dependencies-scopes, synchronization scope>>
  * [[VUID-vkCmdWaitEvents2-pEvents-03840]]
    For any element [eq]#i# of pname:pEvents, if barriers in the [eq]##i##th
    element of pname:pDependencyInfos include only host operations, the
    [eq]##i##th element of pname:pEvents must: be signaled before
    flink:vkCmdWaitEvents2 is executed
  * [[VUID-vkCmdWaitEvents2-pEvents-03841]]
    For any element [eq]#i# of pname:pEvents, if barriers in the [eq]##i##th
    element of pname:pDependencyInfos do not include host operations, the
    [eq]##i##th element of pname:pEvents must: be signaled by a
    corresponding flink:vkCmdSetEvent2 that occurred earlier in
    <<synchronization-submission-order,submission order>>
  * [[VUID-vkCmdWaitEvents2-srcStageMask-03842]]
    The pname:srcStageMask member of any element of the
    pname:pMemoryBarriers, pname:pBufferMemoryBarriers, or
    pname:pImageMemoryBarriers members of pname:pDependencyInfos must:
    either include only pipeline stages valid for the queue family that was
    used to create the command pool that pname:commandBuffer was allocated
    from
  * [[VUID-vkCmdWaitEvents2-dstStageMask-03843]]
    The pname:dstStageMask member of any element of the
    pname:pMemoryBarriers, pname:pBufferMemoryBarriers, or
    pname:pImageMemoryBarriers members of pname:pDependencyInfos must: only
    include pipeline stages valid for the queue family that was used to
    create the command pool that pname:commandBuffer was allocated from
  * [[VUID-vkCmdWaitEvents2-dependencyFlags-03844]]
    If fname:vkCmdWaitEvents2 is being called inside a render pass instance,
    the pname:srcStageMask member of any element of the
    pname:pMemoryBarriers, pname:pBufferMemoryBarriers, or
    pname:pImageMemoryBarriers members of pname:pDependencyInfos must: not
    include ename:VK_PIPELINE_STAGE_2_HOST_BIT
  * [[VUID-vkCmdWaitEvents2-commandBuffer-03846]]
    pname:commandBuffer's current device mask must: include exactly one
    physical device
****

include::{generated}/validity/protos/vkCmdWaitEvents2.adoc[]
--
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]

[open,refpage='vkCmdWaitEvents',desc='Wait for one or more events and insert a set of memory',type='protos']
--
:refpage: vkCmdWaitEvents

To wait for one or more events to enter the signaled state on a device,
call:

[[synchronization-events-waiting-device]]
include::{generated}/api/protos/vkCmdWaitEvents.adoc[]

  * pname:commandBuffer is the command buffer into which the command is
    recorded.
  * pname:eventCount is the length of the pname:pEvents array.
  * pname:pEvents is a pointer to an array of event object handles to wait
    on.
  * pname:srcStageMask is a bitmask of elink:VkPipelineStageFlagBits
    specifying the <<synchronization-pipeline-stages, source stage mask>>.
  * pname:dstStageMask is a bitmask of elink:VkPipelineStageFlagBits
    specifying the <<synchronization-pipeline-stages, destination stage
    mask>>.
  * pname:memoryBarrierCount is the length of the pname:pMemoryBarriers
    array.
  * pname:pMemoryBarriers is a pointer to an array of slink:VkMemoryBarrier
    structures.
  * pname:bufferMemoryBarrierCount is the length of the
    pname:pBufferMemoryBarriers array.
  * pname:pBufferMemoryBarriers is a pointer to an array of
    slink:VkBufferMemoryBarrier structures.
  * pname:imageMemoryBarrierCount is the length of the
    pname:pImageMemoryBarriers array.
  * pname:pImageMemoryBarriers is a pointer to an array of
    slink:VkImageMemoryBarrier structures.

ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
fname:vkCmdWaitEvents is largely similar to flink:vkCmdWaitEvents2, but can:
only wait on signal operations defined by flink:vkCmdSetEvent.
As flink:vkCmdSetEvent does not define any access scopes,
fname:vkCmdWaitEvents defines the first access scope for each event signal
operation in addition to its own access scopes.

[NOTE]
.Note
====
Since flink:vkCmdSetEvent does not have any dependency information beyond a
stage mask, implementations do not have the same opportunity to perform
<<synchronization-dependencies-available-and-visible, availability and
visibility operations>> or <<synchronization-image-layout-transitions, image
layout transitions>> in advance as they do with flink:vkCmdSetEvent2 and
flink:vkCmdWaitEvents2.
====
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]

When fname:vkCmdWaitEvents is submitted to a queue, it defines a memory
dependency between prior event signal operations on the same queue or the
host, and subsequent commands.
fname:vkCmdWaitEvents must: not be used to wait on event signal operations
occurring on other queues.

The first synchronization scope only includes event signal operations that
operate on members of pname:pEvents, and the operations that happened-before
the event signal operations.
Event signal operations performed by flink:vkCmdSetEvent that occur earlier
in <<synchronization-submission-order,submission order>> are included in the
first synchronization scope, if the <<synchronization-pipeline-stages-order,
logically latest>> pipeline stage in their pname:stageMask parameter is
<<synchronization-pipeline-stages-order, logically earlier>> than or equal
to the <<synchronization-pipeline-stages-order, logically latest>> pipeline
stage in pname:srcStageMask.
Event signal operations performed by flink:vkSetEvent are only included in
the first synchronization scope if ename:VK_PIPELINE_STAGE_HOST_BIT is
included in pname:srcStageMask.

The second <<synchronization-dependencies-scopes, synchronization scope>>
includes all commands that occur later in
<<synchronization-submission-order,submission order>>.
The second synchronization scope is limited to operations on the pipeline
stages determined by the <<synchronization-pipeline-stages-masks,
destination stage mask>> specified by pname:dstStageMask.

The first <<synchronization-dependencies-access-scopes, access scope>> is
limited to accesses in the pipeline stages determined by the
<<synchronization-pipeline-stages-masks, source stage mask>> specified by
pname:srcStageMask.
Within that, the first access scope only includes the first access scopes
defined by elements of the pname:pMemoryBarriers,
pname:pBufferMemoryBarriers and pname:pImageMemoryBarriers arrays, which
each define a set of <<synchronization-memory-barriers, memory barriers>>.
If no memory barriers are specified, then the first access scope includes no
accesses.

The second <<synchronization-dependencies-access-scopes, access scope>> is
limited to accesses in the pipeline stages determined by the
<<synchronization-pipeline-stages-masks, destination stage mask>> specified
by pname:dstStageMask.
Within that, the second access scope only includes the second access scopes
defined by elements of the pname:pMemoryBarriers,
pname:pBufferMemoryBarriers and pname:pImageMemoryBarriers arrays, which
each define a set of <<synchronization-memory-barriers, memory barriers>>.
If no memory barriers are specified, then the second access scope includes
no accesses.

ifndef::VK_VERSION_1_3,VK_KHR_synchronization2[]
[NOTE]
.Note
====
flink:vkCmdWaitEvents is used with flink:vkCmdSetEvent to define a memory
dependency between two sets of action commands, roughly in the same way as
pipeline barriers, but split into two commands such that work between the
two may: execute unhindered.

Unlike flink:vkCmdPipelineBarrier, a <<synchronization-queue-transfers,
queue family ownership transfer>> cannot: be performed using
flink:vkCmdWaitEvents.
====

[NOTE]
.Note
====
Applications should be careful to avoid race conditions when using events.
There is no direct ordering guarantee between flink:vkCmdWaitEvents and
ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[flink:vkCmdResetEvent2,]
flink:vkCmdResetEvent, or flink:vkCmdSetEvent.
Another execution dependency (e.g. a pipeline barrier or semaphore with
ename:VK_PIPELINE_STAGE_ALL_COMMANDS_BIT) is needed to prevent such a race
condition.
====
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]

.Valid Usage
****
:stageMaskName: srcStageMask
:accessMaskName: srcAccessMask
include::{chapters}/commonvalidity/stage_mask_common.adoc[]
include::{chapters}/commonvalidity/access_mask_common.adoc[]

:stageMaskName: dstStageMask
:accessMaskName: dstAccessMask
include::{chapters}/commonvalidity/stage_mask_common.adoc[]
include::{chapters}/commonvalidity/access_mask_common.adoc[]
include::{chapters}/commonvalidity/fine_sync_commands_common.adoc[]
  * [[VUID-vkCmdWaitEvents-srcStageMask-06459]]
    Any pipeline stage included in pname:srcStageMask must: be supported by
    the capabilities of the queue family specified by the
    pname:queueFamilyIndex member of the slink:VkCommandPoolCreateInfo
    structure that was used to create the sname:VkCommandPool that
    pname:commandBuffer was allocated from, as specified in the
    <<synchronization-pipeline-stages-supported, table of supported pipeline
    stages>>
  * [[VUID-vkCmdWaitEvents-dstStageMask-06460]]
    Any pipeline stage included in pname:dstStageMask must: be supported by
    the capabilities of the queue family specified by the
    pname:queueFamilyIndex member of the slink:VkCommandPoolCreateInfo
    structure that was used to create the sname:VkCommandPool that
    pname:commandBuffer was allocated from, as specified in the
    <<synchronization-pipeline-stages-supported, table of supported pipeline
    stages>>
  * [[VUID-vkCmdWaitEvents-srcStageMask-01158]]
    pname:srcStageMask must: be the bitwise OR of the pname:stageMask
    parameter used in previous calls to fname:vkCmdSetEvent with any of the
    elements of pname:pEvents and ename:VK_PIPELINE_STAGE_HOST_BIT if any of
    the elements of pname:pEvents was set using fname:vkSetEvent
  * [[VUID-vkCmdWaitEvents-srcStageMask-07308]]
    If fname:vkCmdWaitEvents is being called inside a render pass instance,
    pname:srcStageMask must: not include ename:VK_PIPELINE_STAGE_HOST_BIT
  * [[VUID-vkCmdWaitEvents-srcQueueFamilyIndex-02803]]
    The pname:srcQueueFamilyIndex and pname:dstQueueFamilyIndex members of
    any element of pname:pBufferMemoryBarriers or pname:pImageMemoryBarriers
    must: be equal
ifdef::VK_VERSION_1_1,VK_KHR_device_group[]
  * [[VUID-vkCmdWaitEvents-commandBuffer-01167]]
    pname:commandBuffer's current device mask must: include exactly one
    physical device
endif::VK_VERSION_1_1,VK_KHR_device_group[]
ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
  * [[VUID-vkCmdWaitEvents-pEvents-03847]]
    Elements of pname:pEvents must: not have been signaled by
    flink:vkCmdSetEvent2
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]
****

include::{generated}/validity/protos/vkCmdWaitEvents.adoc[]
--


[[synchronization-pipeline-barriers]]
== Pipeline Barriers

ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
[open,refpage='vkCmdPipelineBarrier2',desc='Insert a memory dependency',type='protos',alias='vkCmdPipelineBarrier2KHR']
--
:refpage: vkCmdPipelineBarrier2

To record a pipeline barrier, call:

ifdef::VK_VERSION_1_3[]
include::{generated}/api/protos/vkCmdPipelineBarrier2.adoc[]
endif::VK_VERSION_1_3[]

ifdef::VK_VERSION_1_3+VK_KHR_synchronization2[or the equivalent command]

ifdef::VK_KHR_synchronization2[]
include::{generated}/api/protos/vkCmdPipelineBarrier2KHR.adoc[]
endif::VK_KHR_synchronization2[]

  * pname:commandBuffer is the command buffer into which the command is
    recorded.
  * pname:pDependencyInfo is a pointer to a slink:VkDependencyInfo structure
    defining the scopes of this operation.

When flink:vkCmdPipelineBarrier2 is submitted to a queue, it defines memory
dependencies between commands that were submitted to the same queue before
it, and those submitted to the same queue after it.

The first <<synchronization-dependencies-scopes, synchronization scope>> and
<<synchronization-dependencies-access-scopes, access scope>> of each memory
dependency defined by pname:pDependencyInfo are applied to operations that
occurred earlier in <<synchronization-submission-order,submission order>>.

The second <<synchronization-dependencies-scopes, synchronization scope>>
and <<synchronization-dependencies-access-scopes, access scope>> of each
memory dependency defined by pname:pDependencyInfo are applied to operations
that occurred later in <<synchronization-submission-order,submission
order>>.

If fname:vkCmdPipelineBarrier2 is recorded within a render pass instance,
the synchronization scopes are limited to a subset of operations within the
same subpass or render pass instance.

.Valid Usage
****
include::{chapters}/commonvalidity/pipeline_barrier_common.adoc[]
  * [[VUID-vkCmdPipelineBarrier2-synchronization2-03848]]
    The <<features-synchronization2, pname:synchronization2>> feature must:
    be enabled
  * [[VUID-vkCmdPipelineBarrier2-srcStageMask-03849]]
    The pname:srcStageMask member of any element of the
    pname:pMemoryBarriers, pname:pBufferMemoryBarriers, or
    pname:pImageMemoryBarriers members of pname:pDependencyInfo must: only
    include pipeline stages valid for the queue family that was used to
    create the command pool that pname:commandBuffer was allocated from
  * [[VUID-vkCmdPipelineBarrier2-dstStageMask-03850]]
    The pname:dstStageMask member of any element of the
    pname:pMemoryBarriers, pname:pBufferMemoryBarriers, or
    pname:pImageMemoryBarriers members of pname:pDependencyInfo must: only
    include pipeline stages valid for the queue family that was used to
    create the command pool that pname:commandBuffer was allocated from
****

include::{generated}/validity/protos/vkCmdPipelineBarrier2.adoc[]
--
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]

[open,refpage='vkCmdPipelineBarrier',desc='Insert a memory dependency',type='protos']
--
:refpage: vkCmdPipelineBarrier

To record a pipeline barrier, call:

include::{generated}/api/protos/vkCmdPipelineBarrier.adoc[]

  * pname:commandBuffer is the command buffer into which the command is
    recorded.
  * pname:srcStageMask is a bitmask of elink:VkPipelineStageFlagBits
    specifying the <<synchronization-pipeline-stages-masks,source stages>>.
  * pname:dstStageMask is a bitmask of elink:VkPipelineStageFlagBits
    specifying the <<synchronization-pipeline-stages-masks,destination
    stages>>.
  * pname:dependencyFlags is a bitmask of elink:VkDependencyFlagBits
    specifying how execution and memory dependencies are formed.
  * pname:memoryBarrierCount is the length of the pname:pMemoryBarriers
    array.
  * pname:pMemoryBarriers is a pointer to an array of slink:VkMemoryBarrier
    structures.
  * pname:bufferMemoryBarrierCount is the length of the
    pname:pBufferMemoryBarriers array.
  * pname:pBufferMemoryBarriers is a pointer to an array of
    slink:VkBufferMemoryBarrier structures.
  * pname:imageMemoryBarrierCount is the length of the
    pname:pImageMemoryBarriers array.
  * pname:pImageMemoryBarriers is a pointer to an array of
    slink:VkImageMemoryBarrier structures.

ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
fname:vkCmdPipelineBarrier operates almost identically to
flink:vkCmdPipelineBarrier2, except that the scopes and barriers are defined
as direct parameters rather than being defined by a slink:VkDependencyInfo.
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]

When flink:vkCmdPipelineBarrier is submitted to a queue, it defines a memory
dependency between commands that were submitted to the same queue before it,
and those submitted to the same queue after it.

If flink:vkCmdPipelineBarrier was recorded outside a render pass instance,
the first <<synchronization-dependencies-scopes, synchronization scope>>
includes all commands that occur earlier in
<<synchronization-submission-order,submission order>>.
If flink:vkCmdPipelineBarrier was recorded inside a render pass instance,
the first synchronization scope includes only commands that occur earlier in
<<synchronization-submission-order,submission order>> within the same
subpass.
In either case, the first synchronization scope is limited to operations on
the pipeline stages determined by the
<<synchronization-pipeline-stages-masks, source stage mask>> specified by
pname:srcStageMask.

If flink:vkCmdPipelineBarrier was recorded outside a render pass instance,
the second <<synchronization-dependencies-scopes, synchronization scope>>
includes all commands that occur later in
<<synchronization-submission-order,submission order>>.
If flink:vkCmdPipelineBarrier was recorded inside a render pass instance,
the second synchronization scope includes only commands that occur later in
<<synchronization-submission-order,submission order>> within the same
subpass.
In either case, the second synchronization scope is limited to operations on
the pipeline stages determined by the
<<synchronization-pipeline-stages-masks, destination stage mask>> specified
by pname:dstStageMask.

The first <<synchronization-dependencies-access-scopes, access scope>> is
limited to accesses in the pipeline stages determined by the
<<synchronization-pipeline-stages-masks, source stage mask>> specified by
pname:srcStageMask.
Within that, the first access scope only includes the first access scopes
defined by elements of the pname:pMemoryBarriers,
pname:pBufferMemoryBarriers and pname:pImageMemoryBarriers arrays, which
each define a set of <<synchronization-memory-barriers, memory barriers>>.
If no memory barriers are specified, then the first access scope includes no
accesses.

The second <<synchronization-dependencies-access-scopes, access scope>> is
limited to accesses in the pipeline stages determined by the
<<synchronization-pipeline-stages-masks, destination stage mask>> specified
by pname:dstStageMask.
Within that, the second access scope only includes the second access scopes
defined by elements of the pname:pMemoryBarriers,
pname:pBufferMemoryBarriers and pname:pImageMemoryBarriers arrays, which
each define a set of <<synchronization-memory-barriers, memory barriers>>.
If no memory barriers are specified, then the second access scope includes
no accesses.

If pname:dependencyFlags includes ename:VK_DEPENDENCY_BY_REGION_BIT, then
any dependency between <<synchronization-framebuffer-regions,
framebuffer-space>> pipeline stages is
<<synchronization-framebuffer-regions, framebuffer-local>> - otherwise it is
<<synchronization-framebuffer-regions, framebuffer-global>>.

.Valid Usage
****
:stageMaskName: srcStageMask
:accessMaskName: srcAccessMask
include::{chapters}/commonvalidity/stage_mask_common.adoc[]
include::{chapters}/commonvalidity/access_mask_common.adoc[]

:stageMaskName: dstStageMask
:accessMaskName: dstAccessMask
include::{chapters}/commonvalidity/stage_mask_common.adoc[]
include::{chapters}/commonvalidity/access_mask_common.adoc[]
include::{chapters}/commonvalidity/fine_sync_commands_common.adoc[]
include::{chapters}/commonvalidity/pipeline_barrier_common.adoc[]
  * [[VUID-vkCmdPipelineBarrier-srcStageMask-06461]]
    Any pipeline stage included in pname:srcStageMask must: be supported by
    the capabilities of the queue family specified by the
    pname:queueFamilyIndex member of the slink:VkCommandPoolCreateInfo
    structure that was used to create the sname:VkCommandPool that
    pname:commandBuffer was allocated from, as specified in the
    <<synchronization-pipeline-stages-supported, table of supported pipeline
    stages>>
  * [[VUID-vkCmdPipelineBarrier-dstStageMask-06462]]
    Any pipeline stage included in pname:dstStageMask must: be supported by
    the capabilities of the queue family specified by the
    pname:queueFamilyIndex member of the slink:VkCommandPoolCreateInfo
    structure that was used to create the sname:VkCommandPool that
    pname:commandBuffer was allocated from, as specified in the
    <<synchronization-pipeline-stages-supported, table of supported pipeline
    stages>>
****

include::{generated}/validity/protos/vkCmdPipelineBarrier.adoc[]
--

[open,refpage='VkDependencyFlagBits',desc='Bitmask specifying how execution and memory dependencies are formed',type='enums']
--
Bits which can: be set in fname:vkCmdPipelineBarrier::pname:dependencyFlags,
specifying how execution and memory dependencies are formed, are:

include::{generated}/api/enums/VkDependencyFlagBits.adoc[]

  * ename:VK_DEPENDENCY_BY_REGION_BIT specifies that dependencies will be
    <<synchronization-framebuffer-regions, framebuffer-local>>.
ifdef::VK_VERSION_1_1,VK_KHR_multiview[]
  * ename:VK_DEPENDENCY_VIEW_LOCAL_BIT specifies that dependencies will be
    <<synchronization-view-local-dependencies, view-local>>.
endif::VK_VERSION_1_1,VK_KHR_multiview[]
ifdef::VK_VERSION_1_1,VK_KHR_device_group[]
  * ename:VK_DEPENDENCY_DEVICE_GROUP_BIT specifies that dependencies are
    <<synchronization-device-local-dependencies, non-device-local>>.
endif::VK_VERSION_1_1,VK_KHR_device_group[]
ifdef::VK_EXT_attachment_feedback_loop_layout[]
  * ename:VK_DEPENDENCY_FEEDBACK_LOOP_BIT_EXT specifies that the render pass
    will write to and read from the same image using the
    ename:VK_IMAGE_LAYOUT_ATTACHMENT_FEEDBACK_LOOP_OPTIMAL_EXT layout.
endif::VK_EXT_attachment_feedback_loop_layout[]
--

[open,refpage='VkDependencyFlags',desc='Bitmask of VkDependencyFlagBits',type='flags']
--
include::{generated}/api/flags/VkDependencyFlags.adoc[]

tname:VkDependencyFlags is a bitmask type for setting a mask of zero or more
elink:VkDependencyFlagBits.
--

[[synchronization-memory-barriers]]
== Memory Barriers

_Memory barriers_ are used to explicitly control access to buffer and image
subresource ranges.
Memory barriers are used to <<synchronization-queue-transfers, transfer
ownership between queue families>>,
<<synchronization-image-layout-transitions, change image layouts>>, and
define <<synchronization-dependencies-available-and-visible, availability
and visibility operations>>.
They explicitly define the <<synchronization-access-types, access types>>
and buffer and image subresource ranges that are included in the
<<synchronization-dependencies-access-scopes, access scopes>> of a memory
dependency that is created by a synchronization command that includes them.


[[synchronization-global-memory-barriers]]
=== Global Memory Barriers

Global memory barriers apply to memory accesses involving all memory objects
that exist at the time of its execution.

ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
[open,refpage='VkMemoryBarrier2',desc='Structure specifying a global memory barrier',type='structs',alias='VkMemoryBarrier2KHR']
--
:refpage: VkMemoryBarrier2

The sname:VkMemoryBarrier2 structure is defined as:

include::{generated}/api/structs/VkMemoryBarrier2.adoc[]

ifdef::VK_KHR_synchronization2[]
or the equivalent

include::{generated}/api/structs/VkMemoryBarrier2KHR.adoc[]
endif::VK_KHR_synchronization2[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:srcStageMask is a tlink:VkPipelineStageFlags2 mask of pipeline
    stages to be included in the <<synchronization-dependencies-scopes,
    first synchronization scope>>.
  * pname:srcAccessMask is a tlink:VkAccessFlags2 mask of access flags to be
    included in the <<synchronization-dependencies-access-scopes, first
    access scope>>.
  * pname:dstStageMask is a tlink:VkPipelineStageFlags2 mask of pipeline
    stages to be included in the <<synchronization-dependencies-scopes,
    second synchronization scope>>.
  * pname:dstAccessMask is a tlink:VkAccessFlags2 mask of access flags to be
    included in the <<synchronization-dependencies-access-scopes, second
    access scope>>.

This structure defines a <<synchronization-dependencies-memory, memory
dependency>> affecting all device memory.

The first <<synchronization-dependencies-scopes, synchronization scope>> and
<<synchronization-dependencies-access-scopes, access scope>> described by
this structure include only operations and memory accesses specified by
pname:srcStageMask and pname:srcAccessMask.

The second <<synchronization-dependencies-scopes, synchronization scope>>
and <<synchronization-dependencies-access-scopes, access scope>> described
by this structure include only operations and memory accesses specified by
pname:dstStageMask and pname:dstAccessMask.

.Valid Usage
****
:stageMaskName: srcStageMask
:accessMaskName: srcAccessMask
include::{chapters}/commonvalidity/stage_mask_2_common.adoc[]
include::{chapters}/commonvalidity/access_mask_2_common.adoc[]

:stageMaskName: dstStageMask
:accessMaskName: dstAccessMask
include::{chapters}/commonvalidity/stage_mask_2_common.adoc[]
include::{chapters}/commonvalidity/access_mask_2_common.adoc[]
****

include::{generated}/validity/structs/VkMemoryBarrier2.adoc[]
--
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]

[open,refpage='VkMemoryBarrier',desc='Structure specifying a global memory barrier',type='structs']
--
The sname:VkMemoryBarrier structure is defined as:

include::{generated}/api/structs/VkMemoryBarrier.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:srcAccessMask is a bitmask of elink:VkAccessFlagBits specifying a
    <<synchronization-access-masks, source access mask>>.
  * pname:dstAccessMask is a bitmask of elink:VkAccessFlagBits specifying a
    <<synchronization-access-masks, destination access mask>>.

The first <<synchronization-dependencies-access-scopes, access scope>> is
limited to access types in the <<synchronization-access-masks, source access
mask>> specified by pname:srcAccessMask.

The second <<synchronization-dependencies-access-scopes, access scope>> is
limited to access types in the <<synchronization-access-masks, destination
access mask>> specified by pname:dstAccessMask.

include::{generated}/validity/structs/VkMemoryBarrier.adoc[]
--


[[synchronization-buffer-memory-barriers]]
=== Buffer Memory Barriers

Buffer memory barriers only apply to memory accesses involving a specific
buffer range.
That is, a memory dependency formed from a buffer memory barrier is
<<synchronization-dependencies-access-scopes, scoped>> to access via the
specified buffer range.
Buffer memory barriers can: also be used to define a
<<synchronization-queue-transfers, queue family ownership transfer>> for the
specified buffer range.

ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
[open,refpage='VkBufferMemoryBarrier2',desc='Structure specifying a buffer memory barrier',type='structs',alias='VkBufferMemoryBarrier2KHR']
--
:refpage: VkBufferMemoryBarrier2

The sname:VkBufferMemoryBarrier2 structure is defined as:

include::{generated}/api/structs/VkBufferMemoryBarrier2.adoc[]

ifdef::VK_KHR_synchronization2[]
or the equivalent

include::{generated}/api/structs/VkBufferMemoryBarrier2KHR.adoc[]
endif::VK_KHR_synchronization2[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:srcStageMask is a tlink:VkPipelineStageFlags2 mask of pipeline
    stages to be included in the <<synchronization-dependencies-scopes,
    first synchronization scope>>.
  * pname:srcAccessMask is a tlink:VkAccessFlags2 mask of access flags to be
    included in the <<synchronization-dependencies-access-scopes, first
    access scope>>.
  * pname:dstStageMask is a tlink:VkPipelineStageFlags2 mask of pipeline
    stages to be included in the <<synchronization-dependencies-scopes,
    second synchronization scope>>.
  * pname:dstAccessMask is a tlink:VkAccessFlags2 mask of access flags to be
    included in the <<synchronization-dependencies-access-scopes, second
    access scope>>.
  * pname:srcQueueFamilyIndex is the source queue family for a
    <<synchronization-queue-transfers, queue family ownership transfer>>.
  * pname:dstQueueFamilyIndex is the destination queue family for a
    <<synchronization-queue-transfers, queue family ownership transfer>>.
  * pname:buffer is a handle to the buffer whose backing memory is affected
    by the barrier.
  * pname:offset is an offset in bytes into the backing memory for
    pname:buffer; this is relative to the base offset as bound to the buffer
    (see flink:vkBindBufferMemory).
  * pname:size is a size in bytes of the affected area of backing memory for
    pname:buffer, or ename:VK_WHOLE_SIZE to use the range from pname:offset
    to the end of the buffer.

This structure defines a <<synchronization-dependencies-memory, memory
dependency>> limited to a range of a buffer, and can: define a
<<synchronization-queue-transfers, queue family transfer operation>> for
that range.

The first <<synchronization-dependencies-scopes, synchronization scope>> and
<<synchronization-dependencies-access-scopes, access scope>> described by
this structure include only operations and memory accesses specified by
pname:srcStageMask and pname:srcAccessMask.

The second <<synchronization-dependencies-scopes, synchronization scope>>
and <<synchronization-dependencies-access-scopes, access scope>> described
by this structure include only operations and memory accesses specified by
pname:dstStageMask and pname:dstAccessMask.

Both <<synchronization-dependencies-access-scopes, access scopes>> are
limited to only memory accesses to pname:buffer in the range defined by
pname:offset and pname:size.

If pname:buffer was created with ename:VK_SHARING_MODE_EXCLUSIVE, and
pname:srcQueueFamilyIndex is not equal to pname:dstQueueFamilyIndex, this
memory barrier defines a <<synchronization-queue-transfers, queue family
transfer operation>>.
When executed on a queue in the family identified by
pname:srcQueueFamilyIndex, this barrier defines a
<<synchronization-queue-transfers-release, queue family release operation>>
for the specified buffer range, and the second synchronization and access
scopes do not synchronize operations on that queue.
When executed on a queue in the family identified by
pname:dstQueueFamilyIndex, this barrier defines a
<<synchronization-queue-transfers-acquire, queue family acquire operation>>
for the specified buffer range, and the first synchronization and access
scopes do not synchronize operations on that queue.

ifdef::VK_VERSION_1_1,VK_KHR_external_memory[]
A <<synchronization-queue-transfers, queue family transfer operation>> is
also defined if the values are not equal, and either is one of the special
queue family values reserved for external memory ownership transfers, as
described in <<synchronization-queue-transfers>>.
A <<synchronization-queue-transfers-release, queue family release
operation>> is defined when pname:dstQueueFamilyIndex is one of those
values, and a <<synchronization-queue-transfers-acquire, queue family
acquire operation>> is defined when pname:srcQueueFamilyIndex is one of
those values.
endif::VK_VERSION_1_1,VK_KHR_external_memory[]


.Valid Usage
****

:stageMaskName: srcStageMask
:accessMaskName: srcAccessMask
include::{chapters}/commonvalidity/stage_mask_2_common.adoc[]
include::{chapters}/commonvalidity/access_mask_2_common.adoc[]

:stageMaskName: dstStageMask
:accessMaskName: dstAccessMask
include::{chapters}/commonvalidity/stage_mask_2_common.adoc[]
include::{chapters}/commonvalidity/access_mask_2_common.adoc[]
include::{chapters}/commonvalidity/buffer_memory_barrier_common.adoc[]
  * [[VUID-VkBufferMemoryBarrier2-srcStageMask-03851]]
    If either pname:srcStageMask or pname:dstStageMask includes
    ename:VK_PIPELINE_STAGE_2_HOST_BIT, pname:srcQueueFamilyIndex and
    pname:dstQueueFamilyIndex must: be equal
****

include::{generated}/validity/structs/VkBufferMemoryBarrier2.adoc[]
--
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]

[open,refpage='VkBufferMemoryBarrier',desc='Structure specifying a buffer memory barrier',type='structs']
--
:refpage: VkBufferMemoryBarrier

The sname:VkBufferMemoryBarrier structure is defined as:

include::{generated}/api/structs/VkBufferMemoryBarrier.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:srcAccessMask is a bitmask of elink:VkAccessFlagBits specifying a
    <<synchronization-access-masks, source access mask>>.
  * pname:dstAccessMask is a bitmask of elink:VkAccessFlagBits specifying a
    <<synchronization-access-masks, destination access mask>>.
  * pname:srcQueueFamilyIndex is the source queue family for a
    <<synchronization-queue-transfers, queue family ownership transfer>>.
  * pname:dstQueueFamilyIndex is the destination queue family for a
    <<synchronization-queue-transfers, queue family ownership transfer>>.
  * pname:buffer is a handle to the buffer whose backing memory is affected
    by the barrier.
  * pname:offset is an offset in bytes into the backing memory for
    pname:buffer; this is relative to the base offset as bound to the buffer
    (see flink:vkBindBufferMemory).
  * pname:size is a size in bytes of the affected area of backing memory for
    pname:buffer, or ename:VK_WHOLE_SIZE to use the range from pname:offset
    to the end of the buffer.

The first <<synchronization-dependencies-access-scopes, access scope>> is
limited to access to memory through the specified buffer range, via access
types in the <<synchronization-access-masks, source access mask>> specified
by pname:srcAccessMask.
If pname:srcAccessMask includes ename:VK_ACCESS_HOST_WRITE_BIT, a
<<synchronization-dependencies-available-and-visible, memory domain
operation>> is performed where available memory in the host domain is also
made available to the device domain.

The second <<synchronization-dependencies-access-scopes, access scope>> is
limited to access to memory through the specified buffer range, via access
types in the <<synchronization-access-masks, destination access mask>>
specified by pname:dstAccessMask.
If pname:dstAccessMask includes ename:VK_ACCESS_HOST_WRITE_BIT or
ename:VK_ACCESS_HOST_READ_BIT, a
<<synchronization-dependencies-available-and-visible, memory domain
operation>> is performed where available memory in the device domain is also
made available to the host domain.

[NOTE]
.Note
====
When ename:VK_MEMORY_PROPERTY_HOST_COHERENT_BIT is used, available memory in
host domain is automatically made visible to host domain, and any host write
is automatically made available to host domain.
====

If pname:srcQueueFamilyIndex is not equal to pname:dstQueueFamilyIndex, and
pname:srcQueueFamilyIndex is equal to the current queue family, then the
memory barrier defines a <<synchronization-queue-transfers-release, queue
family release operation>> for the specified buffer range, and the second
access scope includes no access, as if pname:dstAccessMask was `0`.

If pname:dstQueueFamilyIndex is not equal to pname:srcQueueFamilyIndex, and
pname:dstQueueFamilyIndex is equal to the current queue family, then the
memory barrier defines a <<synchronization-queue-transfers-acquire, queue
family acquire operation>> for the specified buffer range, and the first
access scope includes no access, as if pname:srcAccessMask was `0`.

.Valid Usage
****
include::{chapters}/commonvalidity/buffer_memory_barrier_common.adoc[]
ifdef::VK_VERSION_1_1,VK_KHR_external_memory[]
  * [[VUID-VkBufferMemoryBarrier-None-09049]]
    If
ifdef::VK_KHR_synchronization2[]
    the <<features-synchronization2, pname:synchronization2>> feature is not
    enabled, and
endif::VK_KHR_synchronization2[]
    pname:buffer was created with a sharing mode of
    ename:VK_SHARING_MODE_CONCURRENT, at least one of
    pname:srcQueueFamilyIndex and pname:dstQueueFamilyIndex must: be
    ename:VK_QUEUE_FAMILY_IGNORED
endif::VK_VERSION_1_1,VK_KHR_external_memory[]
  * [[VUID-VkBufferMemoryBarrier-None-09050]]
    If
ifdef::VK_KHR_synchronization2[]
    the <<features-synchronization2, pname:synchronization2>> feature is not
    enabled, and
endif::VK_KHR_synchronization2[]
    pname:buffer was created with a sharing mode of
    ename:VK_SHARING_MODE_CONCURRENT, pname:srcQueueFamilyIndex must: be
    ename:VK_QUEUE_FAMILY_IGNORED
ifdef::VK_VERSION_1_1,VK_KHR_external_memory[]
    or ename:VK_QUEUE_FAMILY_EXTERNAL
endif::VK_VERSION_1_1,VK_KHR_external_memory[]
  * [[VUID-VkBufferMemoryBarrier-None-09051]]
    If
ifdef::VK_KHR_synchronization2[]
    the <<features-synchronization2, pname:synchronization2>> feature is not
    enabled, and
endif::VK_KHR_synchronization2[]
    pname:buffer was created with a sharing mode of
    ename:VK_SHARING_MODE_CONCURRENT, pname:dstQueueFamilyIndex must: be
    ename:VK_QUEUE_FAMILY_IGNORED
ifdef::VK_VERSION_1_1,VK_KHR_external_memory[]
    or ename:VK_QUEUE_FAMILY_EXTERNAL
endif::VK_VERSION_1_1,VK_KHR_external_memory[]
****

include::{generated}/validity/structs/VkBufferMemoryBarrier.adoc[]
--

[open,refpage='VK_WHOLE_SIZE',desc='Sentinel value to use entire remaining array length',type='consts']
--
ename:VK_WHOLE_SIZE is a special value indicating that the entire remaining
length of a buffer following a given pname:offset should be used.
It can: be specified for slink:VkBufferMemoryBarrier::pname:size and other
structures.

include::{generated}/api/enums/VK_WHOLE_SIZE.adoc[]
--


[[synchronization-image-memory-barriers]]
=== Image Memory Barriers

Image memory barriers only apply to memory accesses involving a specific
image subresource range.
That is, a memory dependency formed from an image memory barrier is
<<synchronization-dependencies-access-scopes, scoped>> to access via the
specified image subresource range.
Image memory barriers can: also be used to define
<<synchronization-image-layout-transitions, image layout transitions>> or a
<<synchronization-queue-transfers, queue family ownership transfer>> for the
specified image subresource range.

ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
[open,refpage='VkImageMemoryBarrier2',desc='Structure specifying an image memory barrier',type='structs',alias='VkImageMemoryBarrier2KHR']
--
:refpage: VkImageMemoryBarrier2

The sname:VkImageMemoryBarrier2 structure is defined as:

include::{generated}/api/structs/VkImageMemoryBarrier2.adoc[]

ifdef::VK_KHR_synchronization2[]
or the equivalent

include::{generated}/api/structs/VkImageMemoryBarrier2KHR.adoc[]
endif::VK_KHR_synchronization2[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:srcStageMask is a tlink:VkPipelineStageFlags2 mask of pipeline
    stages to be included in the <<synchronization-dependencies-scopes,
    first synchronization scope>>.
  * pname:srcAccessMask is a tlink:VkAccessFlags2 mask of access flags to be
    included in the <<synchronization-dependencies-access-scopes, first
    access scope>>.
  * pname:dstStageMask is a tlink:VkPipelineStageFlags2 mask of pipeline
    stages to be included in the <<synchronization-dependencies-scopes,
    second synchronization scope>>.
  * pname:dstAccessMask is a tlink:VkAccessFlags2 mask of access flags to be
    included in the <<synchronization-dependencies-access-scopes, second
    access scope>>.
  * pname:oldLayout is the old layout in an
    <<synchronization-image-layout-transitions, image layout transition>>.
  * pname:newLayout is the new layout in an
    <<synchronization-image-layout-transitions, image layout transition>>.
  * pname:srcQueueFamilyIndex is the source queue family for a
    <<synchronization-queue-transfers, queue family ownership transfer>>.
  * pname:dstQueueFamilyIndex is the destination queue family for a
    <<synchronization-queue-transfers, queue family ownership transfer>>.
  * pname:image is a handle to the image affected by this barrier.
  * pname:subresourceRange describes the <<resources-image-views, image
    subresource range>> within pname:image that is affected by this barrier.

This structure defines a <<synchronization-dependencies-memory, memory
dependency>> limited to an image subresource range, and can: define a
<<synchronization-queue-transfers, queue family transfer operation>> and
<<synchronization-image-layout-transitions, image layout transition>> for
that subresource range.

The first <<synchronization-dependencies-scopes, synchronization scope>> and
<<synchronization-dependencies-access-scopes, access scope>> described by
this structure include only operations and memory accesses specified by
pname:srcStageMask and pname:srcAccessMask.

The second <<synchronization-dependencies-scopes, synchronization scope>>
and <<synchronization-dependencies-access-scopes, access scope>> described
by this structure include only operations and memory accesses specified by
pname:dstStageMask and pname:dstAccessMask.

Both <<synchronization-dependencies-access-scopes, access scopes>> are
limited to only memory accesses to pname:image in the subresource range
defined by pname:subresourceRange.

If pname:image was created with ename:VK_SHARING_MODE_EXCLUSIVE, and
pname:srcQueueFamilyIndex is not equal to pname:dstQueueFamilyIndex, this
memory barrier defines a <<synchronization-queue-transfers, queue family
transfer operation>>.
When executed on a queue in the family identified by
pname:srcQueueFamilyIndex, this barrier defines a
<<synchronization-queue-transfers-release, queue family release operation>>
for the specified image subresource range, and the second synchronization
and access scopes do not synchronize operations on that queue.
When executed on a queue in the family identified by
pname:dstQueueFamilyIndex, this barrier defines a
<<synchronization-queue-transfers-acquire, queue family acquire operation>>
for the specified image subresource range, and the first synchronization and
access scopes do not synchronize operations on that queue.

ifdef::VK_VERSION_1_1,VK_KHR_external_memory[]
A <<synchronization-queue-transfers, queue family transfer operation>> is
also defined if the values are not equal, and either is one of the special
queue family values reserved for external memory ownership transfers, as
described in <<synchronization-queue-transfers>>.
A <<synchronization-queue-transfers-release, queue family release
operation>> is defined when pname:dstQueueFamilyIndex is one of those
values, and a <<synchronization-queue-transfers-acquire, queue family
acquire operation>> is defined when pname:srcQueueFamilyIndex is one of
those values.
endif::VK_VERSION_1_1,VK_KHR_external_memory[]

If pname:oldLayout is not equal to pname:newLayout, then the memory barrier
defines an <<synchronization-image-layout-transitions, image layout
transition>> for the specified image subresource range.
If this memory barrier defines a <<synchronization-queue-transfers, queue
family transfer operation>>, the layout transition is only executed once
between the queues.

[NOTE]
.Note
====
When the old and new layout are equal, the layout values are ignored - data
is preserved no matter what values are specified, or what layout the image
is currently in.
====

ifdef::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[]

If pname:image has a multi-planar format and the image is _disjoint_, then
including ename:VK_IMAGE_ASPECT_COLOR_BIT in the pname:aspectMask member of
pname:subresourceRange is equivalent to including
ename:VK_IMAGE_ASPECT_PLANE_0_BIT, ename:VK_IMAGE_ASPECT_PLANE_1_BIT, and
(for three-plane formats only) ename:VK_IMAGE_ASPECT_PLANE_2_BIT.

endif::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[]

.Valid Usage
****

:stageMaskName: srcStageMask
:accessMaskName: srcAccessMask
include::{chapters}/commonvalidity/stage_mask_2_common.adoc[]
include::{chapters}/commonvalidity/access_mask_2_common.adoc[]

:stageMaskName: dstStageMask
:accessMaskName: dstAccessMask
include::{chapters}/commonvalidity/stage_mask_2_common.adoc[]
include::{chapters}/commonvalidity/access_mask_2_common.adoc[]
include::{chapters}/commonvalidity/image_memory_barrier_common.adoc[]
include::{chapters}/commonvalidity/image_layout_transition_common.adoc[]
  * [[VUID-VkImageMemoryBarrier2-srcStageMask-03854]]
    If either pname:srcStageMask or pname:dstStageMask includes
    ename:VK_PIPELINE_STAGE_2_HOST_BIT, pname:srcQueueFamilyIndex and
    pname:dstQueueFamilyIndex must: be equal
  * [[VUID-VkImageMemoryBarrier2-srcStageMask-03855]]
    If pname:srcStageMask includes ename:VK_PIPELINE_STAGE_2_HOST_BIT, and
    pname:srcQueueFamilyIndex and pname:dstQueueFamilyIndex define a
    <<synchronization-queue-transfers, queue family ownership transfer>> or
    pname:oldLayout and pname:newLayout define an
    <<synchronization-image-layout-transitions, image layout transition>>,
    pname:oldLayout must: be one of ename:VK_IMAGE_LAYOUT_PREINITIALIZED,
    ename:VK_IMAGE_LAYOUT_UNDEFINED, or ename:VK_IMAGE_LAYOUT_GENERAL
****

include::{generated}/validity/structs/VkImageMemoryBarrier2.adoc[]
--
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]

[open,refpage='VkImageMemoryBarrier',desc='Structure specifying the parameters of an image memory barrier',type='structs']
--
:refpage: VkImageMemoryBarrier

The sname:VkImageMemoryBarrier structure is defined as:

include::{generated}/api/structs/VkImageMemoryBarrier.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:srcAccessMask is a bitmask of elink:VkAccessFlagBits specifying a
    <<synchronization-access-masks, source access mask>>.
  * pname:dstAccessMask is a bitmask of elink:VkAccessFlagBits specifying a
    <<synchronization-access-masks, destination access mask>>.
  * pname:oldLayout is the old layout in an
    <<synchronization-image-layout-transitions, image layout transition>>.
  * pname:newLayout is the new layout in an
    <<synchronization-image-layout-transitions, image layout transition>>.
  * pname:srcQueueFamilyIndex is the source queue family for a
    <<synchronization-queue-transfers, queue family ownership transfer>>.
  * pname:dstQueueFamilyIndex is the destination queue family for a
    <<synchronization-queue-transfers, queue family ownership transfer>>.
  * pname:image is a handle to the image affected by this barrier.
  * pname:subresourceRange describes the <<resources-image-views, image
    subresource range>> within pname:image that is affected by this barrier.

The first <<synchronization-dependencies-access-scopes, access scope>> is
limited to access to memory through the specified image subresource range,
via access types in the <<synchronization-access-masks, source access mask>>
specified by pname:srcAccessMask.
If pname:srcAccessMask includes ename:VK_ACCESS_HOST_WRITE_BIT, memory
writes performed by that access type are also made visible, as that access
type is not performed through a resource.

The second <<synchronization-dependencies-access-scopes, access scope>> is
limited to access to memory through the specified image subresource range,
via access types in the <<synchronization-access-masks, destination access
mask>> specified by pname:dstAccessMask.
If pname:dstAccessMask includes ename:VK_ACCESS_HOST_WRITE_BIT or
ename:VK_ACCESS_HOST_READ_BIT, available memory writes are also made visible
to accesses of those types, as those access types are not performed through
a resource.

If pname:srcQueueFamilyIndex is not equal to pname:dstQueueFamilyIndex, and
pname:srcQueueFamilyIndex is equal to the current queue family, then the
memory barrier defines a <<synchronization-queue-transfers-release, queue
family release operation>> for the specified image subresource range, and
the second access scope includes no access, as if pname:dstAccessMask was
`0`.

If pname:dstQueueFamilyIndex is not equal to pname:srcQueueFamilyIndex, and
pname:dstQueueFamilyIndex is equal to the current queue family, then the
memory barrier defines a <<synchronization-queue-transfers-acquire, queue
family acquire operation>> for the specified image subresource range, and
the first access scope includes no access, as if pname:srcAccessMask was
`0`.

ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
If the <<features-synchronization2, pname:synchronization2>> feature is not
enabled or pname:oldLayout is not equal to pname:newLayout,
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]
pname:oldLayout and pname:newLayout define an
<<synchronization-image-layout-transitions, image layout transition>> for
the specified image subresource range.

ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
[NOTE]
.Note
====
If the <<features-synchronization2, pname:synchronization2>> feature is
enabled, when the old and new layout are equal, the layout values are
ignored - data is preserved no matter what values are specified, or what
layout the image is currently in.
====
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]

ifdef::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[]

If pname:image has a multi-planar format and the image is _disjoint_, then
including ename:VK_IMAGE_ASPECT_COLOR_BIT in the pname:aspectMask member of
pname:subresourceRange is equivalent to including
ename:VK_IMAGE_ASPECT_PLANE_0_BIT, ename:VK_IMAGE_ASPECT_PLANE_1_BIT, and
(for three-plane formats only) ename:VK_IMAGE_ASPECT_PLANE_2_BIT.

endif::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[]

.Valid Usage
****
include::{chapters}/commonvalidity/image_memory_barrier_common.adoc[]
include::{chapters}/commonvalidity/image_layout_transition_common.adoc[]
ifdef::VK_VERSION_1_1,VK_KHR_external_memory[]
  * [[VUID-VkImageMemoryBarrier-None-09052]]
    If
ifdef::VK_KHR_synchronization2[]
    the <<features-synchronization2, pname:synchronization2>> feature is not
    enabled, and
endif::VK_KHR_synchronization2[]
    pname:image was created with a sharing mode of
    ename:VK_SHARING_MODE_CONCURRENT, at least one of
    pname:srcQueueFamilyIndex and pname:dstQueueFamilyIndex must: be
    ename:VK_QUEUE_FAMILY_IGNORED
endif::VK_VERSION_1_1,VK_KHR_external_memory[]
  * [[VUID-VkImageMemoryBarrier-None-09053]]
    If
ifdef::VK_KHR_synchronization2[]
    the <<features-synchronization2, pname:synchronization2>> feature is not
    enabled, and
endif::VK_KHR_synchronization2[]
    pname:image was created with a sharing mode of
    ename:VK_SHARING_MODE_CONCURRENT, pname:srcQueueFamilyIndex must: be
    ename:VK_QUEUE_FAMILY_IGNORED
ifdef::VK_VERSION_1_1,VK_KHR_external_memory[]
    or ename:VK_QUEUE_FAMILY_EXTERNAL
endif::VK_VERSION_1_1,VK_KHR_external_memory[]
  * [[VUID-VkImageMemoryBarrier-None-09054]]
    If
ifdef::VK_KHR_synchronization2[]
    the <<features-synchronization2, pname:synchronization2>> feature is not
    enabled, and
endif::VK_KHR_synchronization2[]
    pname:image was created with a sharing mode of
    ename:VK_SHARING_MODE_CONCURRENT, pname:dstQueueFamilyIndex must: be
    ename:VK_QUEUE_FAMILY_IGNORED
ifdef::VK_VERSION_1_1,VK_KHR_external_memory[]
    or ename:VK_QUEUE_FAMILY_EXTERNAL
endif::VK_VERSION_1_1,VK_KHR_external_memory[]
****

include::{generated}/validity/structs/VkImageMemoryBarrier.adoc[]
--

ifdef::VK_EXT_host_image_copy[]
To facilitate usage of images whose memory is initialized on the host,
Vulkan allows image layout transitions to be performed by the host as well,
albeit supporting limited layouts.

[open,refpage='vkTransitionImageLayoutEXT',desc='Perform an image layout transition on the host',type='protos']
--
To perform an image layout transition on the host, call:

include::{generated}/api/protos/vkTransitionImageLayoutEXT.adoc[]

  * pname:device is the device which owns pname:pTransitions[i].pname:image.
  * pname:transitionCount is the number of image layout transitions to
    perform.
  * pname:pTransitions is a pointer to an array of
    slink:VkHostImageLayoutTransitionInfoEXT structures specifying the image
    and <<resources-image-views, subresource ranges>> within them to
    transition.

include::{generated}/validity/protos/vkTransitionImageLayoutEXT.adoc[]
--

[open,refpage='VkHostImageLayoutTransitionInfoEXT',desc='Structure specifying the parameters of a host-side image layout transition',type='structs']
--
:refpage: VkHostImageLayoutTransitionInfoEXT

The sname:VkHostImageLayoutTransitionInfoEXT structure is defined as:

include::{generated}/api/structs/VkHostImageLayoutTransitionInfoEXT.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:image is a handle to the image affected by this layout transition.
  * pname:oldLayout is the old layout in an
    <<synchronization-image-layout-transitions, image layout transition>>.
  * pname:newLayout is the new layout in an
    <<synchronization-image-layout-transitions, image layout transition>>.
  * pname:subresourceRange describes the <<resources-image-views, image
    subresource range>> within pname:image that is affected by this layout
    transition.

fname:vkTransitionImageLayoutEXT does not check whether the device memory
associated with an image is currently in use before performing the layout
transition.
The application must: guarantee that any previously submitted command that
reads from or writes to this subresource has completed before the host
performs the layout transition.

[NOTE]
.Note
====
Image layout transitions performed on the host do not require queue family
ownership transfers as the physical layout of the image will not vary
between queue families for the layouts supported by this function.
====

.Valid Usage
****
  * [[VUID-VkHostImageLayoutTransitionInfoEXT-image-09055]]
    pname:image must: have been created with
    ename:VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT
include::{chapters}/commonvalidity/image_layout_transition_common.adoc[]
  * [[VUID-VkHostImageLayoutTransitionInfoEXT-oldLayout-09229]]
    pname:oldLayout must: be either ename:VK_IMAGE_LAYOUT_UNDEFINED or the
    current layout of the image subresources as specified in
    pname:subresourceRange
  * [[VUID-VkHostImageLayoutTransitionInfoEXT-oldLayout-09230]]
    If pname:oldLayout is not ename:VK_IMAGE_LAYOUT_UNDEFINED or
    ename:VK_IMAGE_LAYOUT_PREINITIALIZED, it must: be one of the layouts in
    slink:VkPhysicalDeviceHostImageCopyPropertiesEXT::pname:pCopySrcLayouts
  * [[VUID-VkHostImageLayoutTransitionInfoEXT-newLayout-09057]]
    pname:newLayout must: be one of the layouts in
    slink:VkPhysicalDeviceHostImageCopyPropertiesEXT::pname:pCopyDstLayouts
****

include::{generated}/validity/structs/VkHostImageLayoutTransitionInfoEXT.adoc[]
--
endif::VK_EXT_host_image_copy[]

[[synchronization-queue-transfers]]
=== Queue Family Ownership Transfer

Resources created with a elink:VkSharingMode of
ename:VK_SHARING_MODE_EXCLUSIVE must: have their ownership explicitly
transferred from one queue family to another in order to access their
content in a well-defined manner on a queue in a different queue family.

[open,refpage='VK_QUEUE_FAMILY_IGNORED',desc='Ignored queue family index sentinel',type='consts']
--
The special queue family index ename:VK_QUEUE_FAMILY_IGNORED indicates that
a queue family parameter or member is ignored.

include::{generated}/api/enums/VK_QUEUE_FAMILY_IGNORED.adoc[]
--

ifdef::VK_VERSION_1_1,VK_KHR_external_memory[]
Resources shared with external APIs or instances using external memory must:
also explicitly manage ownership transfers between local and external queues
(or equivalent constructs in external APIs) regardless of the
elink:VkSharingMode specified when creating them.

[open,refpage='VK_QUEUE_FAMILY_EXTERNAL',desc='External queue family index sentinel',type='consts',alias='VK_QUEUE_FAMILY_EXTERNAL_KHR']
--
The special queue family index ename:VK_QUEUE_FAMILY_EXTERNAL represents any
queue external to the resource's current Vulkan instance, as long as the
queue uses the same underlying
ifdef::VK_VERSION_1_1,VK_KHR_device_group[device group or]
physical device, and the same driver version as the resource's
slink:VkDevice, as indicated by
slink:VkPhysicalDeviceIDProperties::pname:deviceUUID and
slink:VkPhysicalDeviceIDProperties::pname:driverUUID.

include::{generated}/api/enums/VK_QUEUE_FAMILY_EXTERNAL.adoc[]

ifdef::VK_KHR_external_memory[]
or the equivalent

include::{generated}/api/enums/VK_QUEUE_FAMILY_EXTERNAL_KHR.adoc[]
endif::VK_KHR_external_memory[]
--

ifdef::VK_EXT_queue_family_foreign[]
[open,refpage='VK_QUEUE_FAMILY_FOREIGN_EXT',desc='Foreign queue family index sentinel',type='consts']
--
The special queue family index ename:VK_QUEUE_FAMILY_FOREIGN_EXT represents
any queue external to the resource's current Vulkan instance, regardless of
the queue's underlying physical device or driver version.
This includes, for example, queues for fixed-function image processing
devices, media codec devices, and display devices, as well as all queues
that use the same underlying
ifdef::VK_VERSION_1_1,VK_KHR_device_group[device group or]
physical device, and the same driver version as the resource's
slink:VkDevice.

include::{generated}/api/enums/VK_QUEUE_FAMILY_FOREIGN_EXT.adoc[]
--
endif::VK_EXT_queue_family_foreign[]
endif::VK_VERSION_1_1,VK_KHR_external_memory[]

If memory dependencies are correctly expressed between uses of such a
resource between two queues in different families, but no ownership transfer
is defined, the contents of that resource are undefined: for any read
accesses performed by the second queue family.

[NOTE]
.Note
====
If an application does not need the contents of a resource to remain valid
when transferring from one queue family to another, then the ownership
transfer should: be skipped.
====

ifdef::VK_EXT_queue_family_foreign[]
[NOTE]
.Note
====
Applications should expect transfers to/from
ename:VK_QUEUE_FAMILY_FOREIGN_EXT to be more expensive than transfers
to/from ename:VK_QUEUE_FAMILY_EXTERNAL_KHR.
====
endif::VK_EXT_queue_family_foreign[]

A queue family ownership transfer consists of two distinct parts:

  . Release exclusive ownership from the source queue family
  . Acquire exclusive ownership for the destination queue family

An application must: ensure that these operations occur in the correct order
by defining an execution dependency between them, e.g. using a semaphore.

[[synchronization-queue-transfers-release]] A _release operation_ is used to
release exclusive ownership of a range of a buffer or image subresource
range.
A release operation is defined by executing a
<<synchronization-buffer-memory-barriers, buffer memory barrier>> (for a
buffer range) or an <<synchronization-image-memory-barriers, image memory
barrier>> (for an image subresource range) using a pipeline barrier command,
on a queue from the source queue family.
The pname:srcQueueFamilyIndex parameter of the barrier must: be set to the
source queue family index, and the pname:dstQueueFamilyIndex parameter to
the destination queue family index.
pname:dstAccessMask is ignored for such a barrier, such that no visibility
operation is executed - the value of this mask does not affect the validity
of the barrier.
The release operation happens-after the availability operation, and
happens-before operations specified in the second synchronization scope of
the calling command.

[[synchronization-queue-transfers-acquire]] An _acquire operation_ is used
to acquire exclusive ownership of a range of a buffer or image subresource
range.
An acquire operation is defined by executing a
<<synchronization-buffer-memory-barriers, buffer memory barrier>> (for a
buffer range) or an <<synchronization-image-memory-barriers, image memory
barrier>> (for an image subresource range) using a pipeline barrier command,
on a queue from the destination queue family.
The buffer range or image subresource range specified in an acquire
operation must: match exactly that of a previous release operation.
The pname:srcQueueFamilyIndex parameter of the barrier must: be set to the
source queue family index, and the pname:dstQueueFamilyIndex parameter to
the destination queue family index.
pname:srcAccessMask is ignored for such a barrier, such that no availability
operation is executed - the value of this mask does not affect the validity
of the barrier.
The acquire operation happens-after operations in the first synchronization
scope of the calling command, and happens-before the visibility operation.

[NOTE]
.Note
====
Whilst it is not invalid to provide destination or source access masks for
memory barriers used for release or acquire operations, respectively, they
have no practical effect.
Access after a release operation has undefined: results, and so visibility
for those accesses has no practical effect.
Similarly, write access before an acquire operation will produce undefined:
results for future access, so availability of those writes has no practical
use.
In an earlier version of the specification, these were required to match on
both sides - but this was subsequently relaxed.
These masks should: be set to 0.
====

If the transfer is via an image memory barrier, and an
<<synchronization-image-layout-transitions, image layout transition>> is
desired, then the values of pname:oldLayout and pname:newLayout in the
_release operation_'s memory barrier must: be equal to values of
pname:oldLayout and pname:newLayout in the _acquire operation_'s memory
barrier.
Although the image layout transition is submitted twice, it will only be
executed once.
A layout transition specified in this way happens-after the _release
operation_ and happens-before the _acquire operation_.

If the values of pname:srcQueueFamilyIndex and pname:dstQueueFamilyIndex are
equal, no ownership transfer is performed, and the barrier operates as if
they were both set to ename:VK_QUEUE_FAMILY_IGNORED.

Queue family ownership transfers may: perform read and write accesses on all
memory bound to the image subresource or buffer range, so applications must:
ensure that all memory writes have been made
<<synchronization-dependencies-available-and-visible, available>> before a
queue family ownership transfer is executed.
Available memory is automatically made visible to queue family release and
acquire operations, and writes performed by those operations are
automatically made available.

Once a queue family has acquired ownership of a buffer range or image
subresource range of a ename:VK_SHARING_MODE_EXCLUSIVE resource, its
contents are undefined: to other queue families unless ownership is
transferred.
The contents of any portion of another resource which aliases memory that is
bound to the transferred buffer or image subresource range are undefined:
after a release or acquire operation.

[NOTE]
.Note
====
Because <<synchronization-events, events>> cannot: be used directly for
inter-queue synchronization, and because flink:vkCmdSetEvent does not have
the queue family index or memory barrier parameters needed by a _release
operation_, the release and acquire operations of a queue family ownership
transfer can: only be performed using flink:vkCmdPipelineBarrier.
====

ifdef::VK_EXT_external_memory_acquire_unmodified[]
[open,refpage='VkExternalMemoryAcquireUnmodifiedEXT',desc='Structure specifying that external memory has remained unmodified since releasing ownership',type='structs']
--
An _acquire operation_ may: have a performance penalty when acquiring
ownership of a subresource range from one of the special queue families
reserved for external memory ownership transfers described above.
The application can: reduce the performance penalty in some cases by adding
a slink:VkExternalMemoryAcquireUnmodifiedEXT structure to the pname:pNext
chain of the _acquire operation_'s memory barrier structure.

The sname:VkExternalMemoryAcquireUnmodifiedEXT structure is defined as:

include::{generated}/api/structs/VkExternalMemoryAcquireUnmodifiedEXT.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:acquireUnmodifiedMemory specifies, if ename:VK_TRUE, that no range
    of slink:VkDeviceMemory bound to the resource of the memory barrier's
    subresource range was modified at any time since the resource's most
    recent release of ownership to the queue family specified by the memory
    barrier's pname:srcQueueFamilyIndex.
    If ename:VK_FALSE, it specifies nothing.

If the application releases ownership of the subresource range to one of the
special queue families reserved for external memory ownership transfers with
a memory barrier structure, and later re-acquires ownership from the same
queue family with a memory barrier structure, and if no range of
slink:VkDeviceMemory bound to the resource was modified at any time between
the _release operation_ and the _acquire operation_, then the application
should: add a slink:VkExternalMemoryAcquireUnmodifiedEXT structure to the
pname:pNext chain of the _acquire operation_'s memory barrier structure
because this may: reduce the performance penalty.

This struct is ignored if pname:acquireUnmodifiedMemory is ename:VK_FALSE.
In particular, ename:VK_FALSE does _not_ specify that memory was modified.

This struct is ignored if the memory barrier's pname:srcQueueFamilyIndex is
not a special queue family reserved for external memory ownership transfers.

[NOTE]
.Note
====
The method by which the application determines whether memory was modified
between the _release operation_ and _acquire operation_ is outside the scope
of Vulkan.

For any Vulkan operation that accesses a resource, the application must: not
assume the implementation accesses the resource's memory as read-only, even
for _apparently_ read-only operations such as transfer commands and shader
reads.

The validity of
slink:VkExternalMemoryAcquireUnmodifiedEXT::pname:acquireUnmodifiedMemory is
independent of memory ranges outside the ranges of slink:VkDeviceMemory
bound to the resource.
In particular, it is independent of any implementation-private memory
associated with the resource.
====

.Valid Usage
****
  * [[VUID-VkExternalMemoryAcquireUnmodifiedEXT-acquireUnmodifiedMemory-08922]]
    If pname:acquireUnmodifiedMemory is ename:VK_TRUE, and the memory
    barrier's pname:srcQueueFamilyIndex is a special queue family reserved
    for external memory ownership transfers (as described in
    <<synchronization-queue-transfers>>), then each range of
    slink:VkDeviceMemory bound to the resource must: have remained
    unmodified during all time since the resource's most recent release of
    ownership to the queue family.
****

include::{generated}/validity/structs/VkExternalMemoryAcquireUnmodifiedEXT.adoc[]
--
endif::VK_EXT_external_memory_acquire_unmodified[]

[[synchronization-wait-idle]]
== Wait Idle Operations

[open,refpage='vkQueueWaitIdle',desc='Wait for a queue to become idle',type='protos']
--
:refpage: vkQueueWaitIdle

To wait on the host for the completion of outstanding queue operations for a
given queue, call:

include::{generated}/api/protos/vkQueueWaitIdle.adoc[]

  * pname:queue is the queue on which to wait.

fname:vkQueueWaitIdle is equivalent to having submitted a valid fence to
every previously executed <<devsandqueues-submission,queue submission
command>> that accepts a fence, then waiting for all of those fences to
signal using flink:vkWaitForFences with an infinite timeout and
pname:waitAll set to ename:VK_TRUE.

include::{chapters}/commonvalidity/no_dynamic_allocations_common.adoc[]

include::{generated}/validity/protos/vkQueueWaitIdle.adoc[]
--

[open,refpage='vkDeviceWaitIdle',desc='Wait for a device to become idle',type='protos']
--
:refpage: vkDeviceWaitIdle

To wait on the host for the completion of outstanding queue operations for
all queues on a given logical device, call:

include::{generated}/api/protos/vkDeviceWaitIdle.adoc[]

  * pname:device is the logical device to idle.

fname:vkDeviceWaitIdle is equivalent to calling fname:vkQueueWaitIdle for
all queues owned by pname:device.

include::{chapters}/commonvalidity/no_dynamic_allocations_common.adoc[]

include::{generated}/validity/protos/vkDeviceWaitIdle.adoc[]
--


[[synchronization-submission-host-writes]]
== Host Write Ordering Guarantees

When batches of command buffers are submitted to a queue via a
<<devsandqueues-submission, queue submission command>>, it defines a memory
dependency with prior host operations, and execution of command buffers
submitted to the queue.

The first <<synchronization-dependencies-scopes, synchronization scope>>
includes execution of flink:vkQueueSubmit on the host and anything that
happened-before it, as defined by the host memory model.

[NOTE]
.Note
====
Some systems allow writes that do not directly integrate with the host
memory model; these have to be synchronized by the application manually.
One example of this is non-temporal store instructions on x86; to ensure
these happen-before submission, applications should call `_mm_sfence()`.
====

The second <<synchronization-dependencies-scopes, synchronization scope>>
includes all commands submitted in the same <<devsandqueues-submission,
queue submission>>, and all commands that occur later in
<<synchronization-submission-order,submission order>>.

The first <<synchronization-dependencies-access-scopes, access scope>>
includes all host writes to mappable device memory that are available to the
host memory domain.

The second <<synchronization-dependencies-access-scopes, access scope>>
includes all memory access performed by the device.

ifdef::VK_VERSION_1_1,VK_KHR_device_group[]
[[synchronization-device-group]]
== Synchronization and Multiple Physical Devices

If a logical device includes more than one physical device, then fences,
semaphores, and events all still have a single instance of the signaled
state.

A fence becomes signaled when all physical devices complete the necessary
queue operations.

Semaphore wait and signal operations all include a device index that is the
sole physical device that performs the operation.
These indices are provided in the slink:VkDeviceGroupSubmitInfo
ifndef::VKSC_VERSION_1_0[and slink:VkDeviceGroupBindSparseInfo]
structures.
Semaphores are not exclusively owned by any physical device.
For example, a semaphore can be signaled by one physical device and then
waited on by a different physical device.

An event can: only be waited on by the same physical device that signaled it
(or the host).
endif::VK_VERSION_1_1,VK_KHR_device_group[]


ifdef::VK_KHR_calibrated_timestamps,VK_EXT_calibrated_timestamps[]
[[calibrated-timestamps]]
== Calibrated Timestamps

[open,refpage='vkGetCalibratedTimestampsKHR',desc='Query calibrated timestamps',type='protos',alias='vkGetCalibratedTimestampsEXT']
--
:refpage: vkGetCalibratedTimestampsKHR

In order to be able to correlate the time a particular operation took place
at on timelines of different time domains (e.g. a device operation vs. a
host operation), Vulkan allows querying calibrated timestamps from multiple
time domains.

To query calibrated timestamps from a set of time domains, call:

ifdef::VK_KHR_calibrated_timestamps[]
include::{generated}/api/protos/vkGetCalibratedTimestampsKHR.adoc[]
endif::VK_KHR_calibrated_timestamps[]

ifdef::VK_KHR_calibrated_timestamps+VK_EXT_calibrated_timestamps[or the equivalent command]

ifdef::VK_EXT_calibrated_timestamps[]
include::{generated}/api/protos/vkGetCalibratedTimestampsEXT.adoc[]
endif::VK_EXT_calibrated_timestamps[]

  * pname:device is the logical device used to perform the query.
  * pname:timestampCount is the number of timestamps to query.
  * pname:pTimestampInfos is a pointer to an array of pname:timestampCount
    slink:VkCalibratedTimestampInfoKHR structures, describing the time
    domains the calibrated timestamps should be captured from.
  * pname:pTimestamps is a pointer to an array of pname:timestampCount
    64-bit unsigned integer values in which the requested calibrated
    timestamp values are returned.
  * pname:pMaxDeviation is a pointer to a 64-bit unsigned integer value in
    which the strictly positive maximum deviation, in nanoseconds, of the
    calibrated timestamp values is returned.

[NOTE]
.Note
====
The maximum deviation may: vary between calls to
fname:vkGetCalibratedTimestampsKHR even for the same set of time domains due
to implementation and platform specific reasons.
It is the application's responsibility to assess whether the returned
maximum deviation makes the timestamp values suitable for any particular
purpose and can: choose to re-issue the timestamp calibration call pursuing
a lower deviation value.
====

Calibrated timestamp values can: be extrapolated to estimate future
coinciding timestamp values, however, depending on the nature of the time
domains and other properties of the platform extrapolating values over a
sufficiently long period of time may: no longer be accurate enough to fit
any particular purpose, so applications are expected to re-calibrate the
timestamps on a regular basis.

.Valid Usage
****
  * [[VUID-vkGetCalibratedTimestampsEXT-timeDomain-09246]]
    The pname:timeDomain value of each slink:VkCalibratedTimestampInfoEXT in
    pname:pTimestampInfos must: be unique
****

include::{chapters}/commonvalidity/no_dynamic_allocations_common.adoc[]

include::{generated}/validity/protos/vkGetCalibratedTimestampsKHR.adoc[]
--

[open,refpage='VkCalibratedTimestampInfoKHR',desc='Structure specifying the input parameters of a calibrated timestamp query',type='structs',alias='VkCalibratedTimestampInfoEXT']
--
The sname:VkCalibratedTimestampInfoKHR structure is defined as:

include::{generated}/api/structs/VkCalibratedTimestampInfoKHR.adoc[]

ifdef::VK_EXT_calibrated_timestamps[]
or the equivalent

include::{generated}/api/structs/VkCalibratedTimestampInfoEXT.adoc[]
endif::VK_EXT_calibrated_timestamps[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:timeDomain is a elink:VkTimeDomainKHR value specifying the time
    domain from which the calibrated timestamp value should be returned.

.Valid Usage
****
  * [[VUID-VkCalibratedTimestampInfoEXT-timeDomain-02354]]
    pname:timeDomain must: be one of the elink:VkTimeDomainKHR values
    returned by flink:vkGetPhysicalDeviceCalibrateableTimeDomainsKHR
****
include::{generated}/validity/structs/VkCalibratedTimestampInfoKHR.adoc[]
--

[open,refpage='VkTimeDomainKHR',desc='Supported time domains',type='enums',alias='VkTimeDomainEXT']
--
The set of supported time domains consists of:

include::{generated}/api/enums/VkTimeDomainKHR.adoc[]

ifdef::VK_EXT_calibrated_timestamps[]
or the equivalent

include::{generated}/api/enums/VkTimeDomainEXT.adoc[]
endif::VK_EXT_calibrated_timestamps[]

  * ename:VK_TIME_DOMAIN_DEVICE_KHR specifies the device time domain.
    Timestamp values in this time domain use the same units and are
    comparable with device timestamp values captured using
    flink:vkCmdWriteTimestamp
ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
    or flink:vkCmdWriteTimestamp2
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]
    and are defined to be incrementing according to the
    <<limits-timestampPeriod, pname:timestampPeriod>> of the device.

  * ename:VK_TIME_DOMAIN_CLOCK_MONOTONIC_KHR specifies the CLOCK_MONOTONIC
    time domain available on POSIX platforms.
    Timestamp values in this time domain are in units of nanoseconds and are
    comparable with platform timestamp values captured using the POSIX
    clock_gettime API as computed by this example:

[NOTE]
.Note
====
An implementation supporting
ifdef::VK_KHR_calibrated_timestamps[`apiext:VK_KHR_calibrated_timestamps`]
ifdef::VK_KHR_calibrated_timestamps+VK_EXT_calibrated_timestamps[or]
ifdef::VK_EXT_calibrated_timestamps[`apiext:VK_EXT_calibrated_timestamps`]
will use the same time domain for all its slink:VkQueue so that timestamp
values reported for ename:VK_TIME_DOMAIN_DEVICE_KHR can be matched to any
timestamp captured through flink:vkCmdWriteTimestamp
ifdef::VK_VERSION_1_3,VK_KHR_synchronization2[]
or flink:vkCmdWriteTimestamp2
endif::VK_VERSION_1_3,VK_KHR_synchronization2[]
.
====

[source,c]
----
struct timespec tv;
clock_gettime(CLOCK_MONOTONIC, &tv);
return tv.tv_nsec + tv.tv_sec*1000000000ull;
----

  * ename:VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_KHR specifies the
    CLOCK_MONOTONIC_RAW time domain available on POSIX platforms.
    Timestamp values in this time domain are in units of nanoseconds and are
    comparable with platform timestamp values captured using the POSIX
    clock_gettime API as computed by this example:

[source,c]
----
struct timespec tv;
clock_gettime(CLOCK_MONOTONIC_RAW, &tv);
return tv.tv_nsec + tv.tv_sec*1000000000ull;
----

  * ename:VK_TIME_DOMAIN_QUERY_PERFORMANCE_COUNTER_KHR specifies the
    performance counter (QPC) time domain available on Windows.
    Timestamp values in this time domain are in the same units as those
    provided by the Windows QueryPerformanceCounter API and are comparable
    with platform timestamp values captured using that API as computed by
    this example:

[source,c]
----
LARGE_INTEGER counter;
QueryPerformanceCounter(&counter);
return counter.QuadPart;
----
--
endif::VK_KHR_calibrated_timestamps,VK_EXT_calibrated_timestamps[]