-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
10767 lines (10302 loc) · 447 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <array>
#include <chrono>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <numeric>
#include <random>
#include <regex>
#include <sstream>
#ifdef _WIN32
# include <windows.h>
# include <intrin.h>
#else
# include <set>
#endif
#include <vulkan/vulkan.hpp>
using namespace std;
// constants
static const string appName = "vkperf";
static const uint32_t appVersion = VK_MAKE_VERSION(0,99,5);
static constexpr const vk::Extent2D defaultFramebufferExtent(1920,1080); // FullHD resultion (allowed values are up to 4096x4096 which are guaranteed by Vulkan; for bigger values, test maxFramebufferWidth and maxFramebufferHeight of vk::PhysicalDeviceLimits)
static constexpr const double longTestTime = 20.;
static constexpr const double standardTestTime = 2.;
static constexpr const uint32_t numTrianglesStandard = uint32_t(1000*1e3);
static constexpr const uint32_t numTrianglesIntegratedGpu = uint32_t(100*1e3);
static constexpr const uint32_t numTrianglesCpu = uint32_t(10*1e3);
static constexpr const uint32_t numTrianglesMinimal = 3000; // three times maxTriStripLength; it needs to be at least 3x because we need sameDMatrixStagingBufferSize to be great enough for transfer tests
static constexpr const size_t transferAmountPerTest = 2*1048576;
static constexpr const size_t maxTransfersPerTest = 10000;
static constexpr const uint32_t indirectRecordStride = 32;
static constexpr const unsigned triangleSize = 0;
static constexpr const uint32_t maxTriStripLength = 1000; // length of triangle strip used during various measurements; some tests are splitting it to various lenght strips, while reusing two previous vertices from the previous strip
// Vulkan instance
// (must be destructed as the last one, at least on Linux, it must be destroyed after display connection)
static vk::UniqueInstance instance;
// Vulkan handles and objects
// (they need to be placed in particular (not arbitrary) order as it gives their destruction order)
static vk::PhysicalDevice physicalDevice;
static vk::PhysicalDeviceProperties physicalDeviceProperties;
static vector<vk::ExtensionProperties> physicalDeviceExtensions;
static uint32_t graphicsQueueFamily;
static uint32_t sparseQueueFamily;
static vk::PhysicalDeviceFeatures enabledFeatures;
static vk::UniqueDevice device;
static vk::Queue graphicsQueue;
static vk::Queue sparseQueue;
static constexpr const vk::Format colorFormat = vk::Format::eR8G8B8A8Srgb;
static vk::Format depthFormat;
static vk::UniqueRenderPass renderPass;
static vk::UniqueShaderModule attributelessConstantOutputVS;
static vk::UniqueShaderModule attributelessInputIndicesVS;
static vk::UniqueShaderModule coordinateAttributeVS;
static vk::UniqueShaderModule coordinate4BufferVS;
static vk::UniqueShaderModule coordinate3BufferVS;
static vk::UniqueShaderModule singleUniformMatrixVS;
static vk::UniqueShaderModule matrixAttributeVS;
static vk::UniqueShaderModule matrixBufferVS;
static vk::UniqueShaderModule twoAttributesVS;
static vk::UniqueShaderModule twoBuffersVS;
static vk::UniqueShaderModule twoBuffer3VS;
static vk::UniqueShaderModule twoInterleavedBuffersVS;
static vk::UniqueShaderModule twoPackedAttributesVS;
static vk::UniqueShaderModule twoPackedBuffersVS;
static vk::UniqueShaderModule twoPackedBuffersUsingStructVS;
static vk::UniqueShaderModule twoPackedBuffersUsingStructSlowVS;
static vk::UniqueShaderModule singlePackedBufferVS;
static vk::UniqueShaderModule twoPackedAttributesAndSingleMatrixVS;
static vk::UniqueShaderModule twoPackedAttributesAndMatrixVS;
static vk::UniqueShaderModule twoPackedBuffersAndMatrixVS;
static vk::UniqueShaderModule fourAttributesVS;
static vk::UniqueShaderModule fourBuffersVS;
static vk::UniqueShaderModule fourBuffer3VS;
static vk::UniqueShaderModule fourInterleavedBuffersVS;
static vk::UniqueShaderModule fourAttributesAndMatrixVS;
static vk::UniqueShaderModule geometryShaderConstantOutputVS;
static vk::UniqueShaderModule geometryShaderConstantOutputGS;
static vk::UniqueShaderModule geometryShaderConstantOutputTwoTrianglesGS;
static vk::UniqueShaderModule geometryShaderNoOutputGS;
static vk::UniqueShaderModule geometryShaderVS;
static vk::UniqueShaderModule geometryShaderGS;
static vk::UniqueShaderModule transformationThreeMatricesVS;
static vk::UniqueShaderModule transformationFiveMatricesVS;
static vk::UniqueShaderModule transformationFiveMatricesPushConstantsVS;
static vk::UniqueShaderModule transformationFiveMatricesSpecializationConstantsVS;
static vk::UniqueShaderModule transformationFiveMatricesConstantsVS;
static vk::UniqueShaderModule transformationFiveMatricesUsingGS;
static vk::UniqueShaderModule transformationFiveMatricesUsingGSAndAttributesVS;
static vk::UniqueShaderModule transformationFiveMatricesUsingGSAndAttributesGS;
static vk::UniqueShaderModule phongTexturedFourAttributesFiveMatricesVS;
static vk::UniqueShaderModule phongTexturedFourAttributesVS;
static vk::UniqueShaderModule phongTexturedVS;
static vk::UniqueShaderModule phongTexturedRowMajorVS;
static vk::UniqueShaderModule phongTexturedMat4x3VS;
static vk::UniqueShaderModule phongTexturedMat4x3RowMajorVS;
static vk::UniqueShaderModule phongTexturedQuat1VS;
static vk::UniqueShaderModule phongTexturedQuat2VS;
static vk::UniqueShaderModule phongTexturedQuat3VS;
static vk::UniqueShaderModule phongTexturedQuat2PrimitiveRestartVS;
static vk::UniqueShaderModule phongTexturedSingleQuat2VS;
static vk::UniqueShaderModule phongTexturedDMatricesOnlyInputVS;
static vk::UniqueShaderModule phongTexturedDMatricesVS;
static vk::UniqueShaderModule phongTexturedDMatricesDVerticesVS;
static vk::UniqueShaderModule phongTexturedInGSDMatricesDVerticesVS;
static vk::UniqueShaderModule phongTexturedInGSDMatricesDVerticesGS;
static vk::UniqueShaderModule constantColorFS;
static vk::UniqueShaderModule phongTexturedDummyFS;
static vk::UniqueShaderModule phongTexturedFS;
static vk::UniqueShaderModule phongTexturedNotPackedFS;
static vk::UniqueShaderModule fullscreenQuadVS;
static vk::UniqueShaderModule fullscreenQuadFourInterpolatorsVS;
static vk::UniqueShaderModule fullscreenQuadFourSmoothInterpolatorsFS;
static vk::UniqueShaderModule fullscreenQuadFourFlatInterpolatorsFS;
static vk::UniqueShaderModule fullscreenQuadTexturedPhongInterpolatorsVS;
static vk::UniqueShaderModule fullscreenQuadTexturedPhongInterpolatorsFS;
static vk::UniqueShaderModule uniformColor4fFS;
static vk::UniqueShaderModule uniformColor4bFS;
static vk::UniqueShaderModule fullscreenQuadTwoVec3InterpolatorsVS;
static vk::UniqueShaderModule phongNoSpecularFS;
static vk::UniqueShaderModule phongNoSpecularSingleUniformFS;
static vk::UniquePipelineCache pipelineCache;
static vk::UniquePipelineLayout simplePipelineLayout;
static vk::UniquePipelineLayout oneUniformVSPipelineLayout;
static vk::UniquePipelineLayout oneUniformFSPipelineLayout;
static vk::UniquePipelineLayout oneBufferPipelineLayout;
static vk::UniquePipelineLayout twoBuffersPipelineLayout;
static vk::UniquePipelineLayout threeBuffersPipelineLayout;
static vk::UniquePipelineLayout fourBuffersPipelineLayout;
static vk::UniquePipelineLayout threeBuffersInGSPipelineLayout;
static vk::UniquePipelineLayout threeUniformFSPipelineLayout;
static vk::UniquePipelineLayout bufferAndUniformPipelineLayout;
static vk::UniquePipelineLayout bufferAndUniformInGSPipelineLayout;
static vk::UniquePipelineLayout twoBuffersAndUniformPipelineLayout;
static vk::UniquePipelineLayout twoBuffersAndPushConstantsPipelineLayout;
static vk::UniquePipelineLayout twoBuffersAndUniformInGSPipelineLayout;
static vk::UniquePipelineLayout fourBuffersAndUniformInGSPipelineLayout;
static vk::UniquePipelineLayout phongTexturedPipelineLayout;
static vk::UniqueDescriptorSetLayout oneUniformVSDescriptorSetLayout;
static vk::UniqueDescriptorSetLayout oneUniformFSDescriptorSetLayout;
static vk::UniqueDescriptorSetLayout oneBufferDescriptorSetLayout;
static vk::UniqueDescriptorSetLayout twoBuffersDescriptorSetLayout;
static vk::UniqueDescriptorSetLayout threeBuffersDescriptorSetLayout;
static vk::UniqueDescriptorSetLayout fourBuffersDescriptorSetLayout;
static vk::UniqueDescriptorSetLayout threeBuffersInGSDescriptorSetLayout;
static vk::UniqueDescriptorSetLayout threeUniformFSDescriptorSetLayout;
static vk::UniqueDescriptorSetLayout bufferAndUniformDescriptorSetLayout;
static vk::UniqueDescriptorSetLayout bufferAndUniformInGSDescriptorSetLayout;
static vk::UniqueDescriptorSetLayout twoBuffersAndUniformDescriptorSetLayout;
static vk::UniqueDescriptorSetLayout twoBuffersAndUniformInGSDescriptorSetLayout;
static vk::UniqueDescriptorSetLayout fourBuffersAndUniformInGSDescriptorSetLayout;
static vk::UniqueDescriptorSetLayout phongTexturedDescriptorSetLayout;
static vk::UniqueBuffer singleMatrixUniformBuffer;
static vk::UniqueBuffer singlePATBuffer;
static vk::UniqueBuffer sameMatrixAttribute; // not used now
static vk::UniqueBuffer sameMatrixBuffer;
static vk::UniqueBuffer sameMatrixRowMajorBuffer;
static vk::UniqueBuffer sameMatrix4x3Buffer;
static vk::UniqueBuffer sameMatrix4x3RowMajorBuffer;
static vk::UniqueBuffer sameDMatrixBuffer;
static vk::UniqueBuffer sameDMatrixStagingBuffer;
static vk::UniqueBuffer samePATBuffer;
static vk::UniqueBuffer transformationMatrixAttribute;
static vk::UniqueBuffer transformationMatrixBuffer;
static vk::UniqueBuffer indirectBuffer;
static vk::UniqueBuffer indirectStrideBuffer;
static vk::UniqueBuffer indirectIndexedBuffer;
static vk::UniqueBuffer indirectIndexedStrideBuffer;
static vk::UniqueBuffer normalMatrix4x3Buffer;
static vk::UniqueBuffer viewAndProjectionMatricesUniformBuffer;
static vk::UniqueBuffer viewAndProjectionDMatricesUniformBuffer;
static vk::UniqueBuffer materialUniformBuffer;
static vk::UniqueBuffer materialNotPackedUniformBuffer;
static vk::UniqueBuffer globalLightUniformBuffer;
static vk::UniqueBuffer lightUniformBuffer;
static vk::UniqueBuffer lightNotPackedUniformBuffer;
static vk::UniqueBuffer allInOneLightingUniformBuffer;
static vk::UniqueDeviceMemory singleMatrixUniformMemory;
static vk::UniqueDeviceMemory singlePATMemory;
static vk::UniqueDeviceMemory sameMatrixAttributeMemory; // not used now
static vk::UniqueDeviceMemory sameMatrixBufferMemory;
static vk::UniqueDeviceMemory sameMatrixRowMajorBufferMemory;
static vk::UniqueDeviceMemory sameMatrix4x3BufferMemory;
static vk::UniqueDeviceMemory sameMatrix4x3RowMajorBufferMemory;
static vk::UniqueDeviceMemory sameDMatrixBufferMemory;
static vk::UniqueDeviceMemory sameDMatrixStagingBufferMemory;
static vk::UniqueDeviceMemory samePATBufferMemory;
static vk::UniqueDeviceMemory transformationMatrixAttributeMemory;
static vk::UniqueDeviceMemory transformationMatrixBufferMemory; // not used now
static vk::UniqueDeviceMemory indirectBufferMemory;
static vk::UniqueDeviceMemory indirectStrideBufferMemory;
static vk::UniqueDeviceMemory indirectIndexedBufferMemory;
static vk::UniqueDeviceMemory indirectIndexedStrideBufferMemory;
static vk::UniqueDeviceMemory normalMatrix4x3Memory;
static vk::UniqueDeviceMemory viewAndProjectionMatricesMemory;
static vk::UniqueDeviceMemory viewAndProjectionDMatricesMemory;
static vk::UniqueDeviceMemory materialUniformBufferMemory;
static vk::UniqueDeviceMemory materialNotPackedUniformBufferMemory;
static vk::UniqueDeviceMemory globalLightUniformBufferMemory;
static vk::UniqueDeviceMemory lightUniformBufferMemory;
static vk::UniqueDeviceMemory lightNotPackedUniformBufferMemory;
static vk::UniqueDeviceMemory allInOneLightingUniformBufferMemory;
static vk::UniqueDescriptorPool descriptorPool;
static vk::DescriptorSet oneUniformVSDescriptorSet;
static vk::DescriptorSet one4fUniformFSDescriptorSet;
static vk::DescriptorSet one4bUniformFSDescriptorSet;
static vk::DescriptorSet coordinate4BufferDescriptorSet;
static vk::DescriptorSet coordinate3BufferDescriptorSet;
static vk::DescriptorSet sameMatrixBufferDescriptorSet;
static vk::DescriptorSet transformationMatrixBufferDescriptorSet;
static vk::DescriptorSet singlePackedBufferDescriptorSet;
static vk::DescriptorSet twoBuffersDescriptorSet;
static vk::DescriptorSet twoBuffer3DescriptorSet;
static vk::DescriptorSet twoInterleavedBuffersDescriptorSet;
static vk::DescriptorSet twoPackedBuffersDescriptorSet;
static vk::DescriptorSet threeBuffersDescriptorSet;
static vk::DescriptorSet fourBuffersDescriptorSet;
static vk::DescriptorSet fourBuffer3DescriptorSet;
static vk::DescriptorSet fourInterleavedBuffersDescriptorSet;
static vk::DescriptorSet threeBuffersInGSDescriptorSet;
static vk::DescriptorSet threeUniformFSDescriptorSet;
static vk::DescriptorSet transformationThreeMatricesDescriptorSet;
static vk::DescriptorSet transformationThreeMatricesRowMajorDescriptorSet;
static vk::DescriptorSet transformationThreeMatrices4x3DescriptorSet;
static vk::DescriptorSet transformationThreeMatrices4x3RowMajorDescriptorSet;
static vk::DescriptorSet transformationThreeDMatricesDescriptorSet;
static vk::DescriptorSet transformationTwoMatricesDescriptorSet;
static vk::DescriptorSet transformationTwoMatricesAndPATDescriptorSet;
static vk::DescriptorSet transformationTwoMatricesAndSinglePATDescriptorSet;
static vk::DescriptorSet transformationFiveMatricesDescriptorSet;
static vk::DescriptorSet transformationFiveMatricesUsingGSDescriptorSet;
static vk::DescriptorSet transformationFiveMatricesUsingGSAndAttributesDescriptorSet;
static vk::DescriptorSet phongTexturedThreeDMatricesUsingGSAndAttributesDescriptorSet;
static vk::DescriptorSet phongTexturedDescriptorSet;
static vk::DescriptorSet phongTexturedNotPackedDescriptorSet;
static vk::DescriptorSet allInOneLightingUniformDescriptorSet;
static vk::UniqueFramebuffer framebuffer;
static vk::UniqueImage colorImage;
static vk::UniqueImage depthImage;
static vk::UniqueDeviceMemory colorImageMemory;
static vk::UniqueDeviceMemory depthImageMemory;
static vk::UniqueImageView colorImageView;
static vk::UniqueImageView depthImageView;
static vk::UniqueFence fence;
static vk::UniquePipeline attributelessConstantOutputPipeline;
static vk::UniquePipeline attributelessConstantOutputTriStripPipeline;
static vk::UniquePipeline attributelessConstantOutputPrimitiveRestartPipeline;
static vk::UniquePipeline attributelessInputIndicesPipeline;
static vk::UniquePipeline attributelessInputIndicesTriStripPipeline;
static vk::UniquePipeline attributelessInputIndicesPrimitiveRestartPipeline;
static vk::UniquePipeline coordinateAttributePipeline;
static vk::UniquePipeline coordinate4BufferPipeline;
static vk::UniquePipeline coordinate3BufferPipeline;
static vk::UniquePipeline singleMatrixUniformPipeline;
static vk::UniquePipeline matrixAttributePipeline;
static vk::UniquePipeline matrixBufferPipeline;
static vk::UniquePipeline twoAttributesPipeline;
static vk::UniquePipeline twoBuffersPipeline;
static vk::UniquePipeline twoBuffer3Pipeline;
static vk::UniquePipeline twoInterleavedAttributesPipeline;
static vk::UniquePipeline twoInterleavedBuffersPipeline;
static vk::UniquePipeline twoPackedAttributesPipeline;
static vk::UniquePipeline twoPackedBuffersPipeline;
static vk::UniquePipeline twoPackedBuffersUsingStructPipeline;
static vk::UniquePipeline twoPackedBuffersUsingStructSlowPipeline;
static vk::UniquePipeline two4F32Two4U8AttributesPipeline;
static vk::UniquePipeline singlePackedBufferPipeline;
static vk::UniquePipeline twoPackedAttributesAndSingleMatrixPipeline;
static vk::UniquePipeline twoPackedAttributesAndMatrixPipeline;
static vk::UniquePipeline twoPackedBuffersAndMatrixPipeline;
static vk::UniquePipeline fourAttributesPipeline;
static vk::UniquePipeline fourBuffersPipeline;
static vk::UniquePipeline fourBuffer3Pipeline;
static vk::UniquePipeline fourInterleavedAttributesPipeline;
static vk::UniquePipeline fourInterleavedBuffersPipeline;
static vk::UniquePipeline fourAttributesAndMatrixPipeline;
static vk::UniquePipeline geometryShaderConstantOutputPipeline;
static vk::UniquePipeline geometryShaderConstantOutputTwoTrianglesPipeline;
static vk::UniquePipeline geometryShaderNoOutputPipeline;
static vk::UniquePipeline geometryShaderPipeline;
static vk::UniquePipeline transformationThreeMatricesPipeline;
static vk::UniquePipeline transformationFiveMatricesPipeline;
static vk::UniquePipeline transformationFiveMatricesPushConstantsPipeline;
static vk::UniquePipeline transformationFiveMatricesSpecializationConstantsPipeline;
static vk::UniquePipeline transformationFiveMatricesConstantsPipeline;
static vk::UniquePipeline transformationFiveMatricesUsingGSPipeline;
static vk::UniquePipeline transformationFiveMatricesUsingGSAndAttributesPipeline;
static vk::UniquePipeline phongTexturedFourAttributesFiveMatricesPipeline;
static vk::UniquePipeline phongTexturedFourAttributesPipeline;
static vk::UniquePipeline phongTexturedPipeline;
static vk::UniquePipeline phongTexturedRowMajorPipeline;
static vk::UniquePipeline phongTexturedMat4x3Pipeline;
static vk::UniquePipeline phongTexturedMat4x3RowMajorPipeline;
static vk::UniquePipeline phongTexturedQuat1Pipeline;
static vk::UniquePipeline phongTexturedQuat2Pipeline;
static vk::UniquePipeline phongTexturedQuat3Pipeline;
static vk::UniquePipeline phongTexturedQuat2PrimitiveRestartPipeline;
static vk::UniquePipeline phongTexturedDMatricesOnlyInputPipeline;
static vk::UniquePipeline phongTexturedDMatricesPipeline;
static vk::UniquePipeline phongTexturedDMatricesDVerticesPipeline;
static vk::UniquePipeline phongTexturedInGSDMatricesDVerticesPipeline;
static vk::UniquePipeline phongTexturedSingleQuat2Pipeline;
static vk::UniquePipeline phongTexturedSingleQuat2TriStripPipeline;
static vk::UniquePipeline phongTexturedSingleQuat2PrimitiveRestartPipeline;
static vk::UniquePipeline fillrateContantColorPipeline;
static vk::UniquePipeline fillrateFourSmoothInterpolatorsPipeline;
static vk::UniquePipeline fillrateFourFlatInterpolatorsPipeline;
static vk::UniquePipeline fillrateTexturedPhongInterpolatorsPipeline;
static vk::UniquePipeline fillrateTexturedPhongPipeline;
static vk::UniquePipeline fillrateTexturedPhongNotPackedPipeline;
static vk::UniquePipeline fillrateUniformColor4fPipeline;
static vk::UniquePipeline fillrateUniformColor4bPipeline;
static vk::UniquePipeline phongNoSpecularPipeline;
static vk::UniquePipeline phongNoSpecularSingleUniformPipeline;
static vk::UniqueCommandPool primaryCommandPool;
static vk::UniqueCommandPool secondaryCommandPool;
static vk::UniqueCommandBuffer primaryCommandBuffer;
static vk::UniqueBuffer coordinate4Attribute;
static vk::UniqueBuffer coordinate4Buffer;
static vk::UniqueBuffer coordinate3Attribute;
static vk::UniqueBuffer coordinate3Buffer;
static vk::UniqueBuffer normalAttribute;
static vk::UniqueBuffer colorAttribute;
static vk::UniqueBuffer texCoordAttribute;
static array<vk::UniqueBuffer,3> vec4Attributes;
static array<vk::UniqueBuffer,3> vec4Buffers;
static array<vk::UniqueBuffer,2> vec4u8Attributes;
static array<vk::UniqueBuffer,3> vec3Buffers;
static vk::UniqueBuffer packedAttribute1;
static vk::UniqueBuffer packedAttribute2;
static vk::UniqueBuffer twoInterleavedAttributes;
static vk::UniqueBuffer twoInterleavedBuffers;
static vk::UniqueBuffer fourInterleavedAttributes;
static vk::UniqueBuffer fourInterleavedBuffers;
static vk::UniqueBuffer packedBuffer1;
static vk::UniqueBuffer packedBuffer2;
static vk::UniqueBuffer singlePackedBuffer;
static vk::UniqueBuffer packedDAttribute1;
static vk::UniqueBuffer packedDAttribute2;
static vk::UniqueBuffer packedDAttribute3;
static vk::UniqueBuffer indexBuffer;
static vk::UniqueBuffer primitiveRestartIndexBuffer;
static vk::UniqueBuffer stripIndexBuffer;
static vk::UniqueBuffer stripPrimitiveRestart3IndexBuffer;
static vk::UniqueBuffer stripPrimitiveRestart4IndexBuffer;
static vk::UniqueBuffer stripPrimitiveRestart7IndexBuffer;
static vk::UniqueBuffer stripPrimitiveRestart10IndexBuffer;
static vk::UniqueBuffer stripPrimitiveRestart1002IndexBuffer;
static vk::UniqueBuffer primitiveRestartMinusOne2IndexBuffer;
static vk::UniqueBuffer primitiveRestartMinusOne5IndexBuffer;
static vk::UniqueBuffer minusOneIndexBuffer;
static vk::UniqueBuffer zeroIndexBuffer;
static vk::UniqueBuffer plusOneIndexBuffer;
static vk::UniqueBuffer stripPackedAttribute1;
static vk::UniqueBuffer stripPackedAttribute2;
static vk::UniqueBuffer sharedVertexPackedAttribute1;
static vk::UniqueBuffer sharedVertexPackedAttribute2;
static vk::UniqueBuffer sameVertexPackedAttribute1;
static vk::UniqueBuffer sameVertexPackedAttribute2;
static vk::UniqueDeviceMemory coordinate4AttributeMemory;
static vk::UniqueDeviceMemory coordinate4BufferMemory;
static vk::UniqueDeviceMemory coordinate3AttributeMemory;
static vk::UniqueDeviceMemory coordinate3BufferMemory;
static vk::UniqueDeviceMemory normalAttributeMemory;
static vk::UniqueDeviceMemory colorAttributeMemory;
static vk::UniqueDeviceMemory texCoordAttributeMemory;
static array<vk::UniqueDeviceMemory,3> vec4AttributeMemory;
static array<vk::UniqueDeviceMemory,2> vec4u8AttributeMemory;
static array<vk::UniqueDeviceMemory,3> vec4BufferMemory;
static array<vk::UniqueDeviceMemory,3> vec3BufferMemory;
static vk::UniqueDeviceMemory packedAttribute1Memory;
static vk::UniqueDeviceMemory packedAttribute2Memory;
static vk::UniqueDeviceMemory twoInterleavedAttributesMemory;
static vk::UniqueDeviceMemory twoInterleavedBuffersMemory;
static vk::UniqueDeviceMemory fourInterleavedAttributesMemory;
static vk::UniqueDeviceMemory fourInterleavedBuffersMemory;
static vk::UniqueDeviceMemory packedBuffer1Memory;
static vk::UniqueDeviceMemory packedBuffer2Memory;
static vk::UniqueDeviceMemory singlePackedBufferMemory;
static vk::UniqueDeviceMemory packedDAttribute1Memory;
static vk::UniqueDeviceMemory packedDAttribute2Memory;
static vk::UniqueDeviceMemory packedDAttribute3Memory;
static vk::UniqueDeviceMemory indexBufferMemory;
static vk::UniqueDeviceMemory primitiveRestartIndexBufferMemory;
static vk::UniqueDeviceMemory stripIndexBufferMemory;
static vk::UniqueDeviceMemory stripPrimitiveRestart3IndexBufferMemory;
static vk::UniqueDeviceMemory stripPrimitiveRestart4IndexBufferMemory;
static vk::UniqueDeviceMemory stripPrimitiveRestart7IndexBufferMemory;
static vk::UniqueDeviceMemory stripPrimitiveRestart10IndexBufferMemory;
static vk::UniqueDeviceMemory stripPrimitiveRestart1002IndexBufferMemory;
static vk::UniqueDeviceMemory primitiveRestartMinusOne2IndexBufferMemory;
static vk::UniqueDeviceMemory primitiveRestartMinusOne5IndexBufferMemory;
static vk::UniqueDeviceMemory minusOneIndexBufferMemory;
static vk::UniqueDeviceMemory zeroIndexBufferMemory;
static vk::UniqueDeviceMemory plusOneIndexBufferMemory;
static vk::UniqueDeviceMemory stripPackedAttribute1Memory;
static vk::UniqueDeviceMemory stripPackedAttribute2Memory;
static vk::UniqueDeviceMemory sharedVertexPackedAttribute1Memory;
static vk::UniqueDeviceMemory sharedVertexPackedAttribute2Memory;
static vk::UniqueDeviceMemory sameVertexPackedAttribute1Memory;
static vk::UniqueDeviceMemory sameVertexPackedAttribute2Memory;
static vk::UniqueImage singleTexelImage;
static vk::UniqueDeviceMemory singleTexelImageMemory;
static vk::UniqueImageView singleTexelImageView;
static vk::UniqueSampler trilinearSampler;
static vk::UniqueQueryPool timestampPool;
static uint32_t timestampValidBits=0;
static float timestampPeriod_ns=0;
static uint32_t numTriangles;
static bool minimalTest=false;
static bool longTest=false;
static bool runAllTests=false;
static bool debug=false;
static vk::Extent2D framebufferExtent(0,0);
static size_t sameDMatrixStagingBufferSize;
static uint32_t numFullscreenQuads=10; // note: if you increase the value, make sure that fullscreenQuad*.vert is still drawing to the clip space (by gl_InstanceIndex)
// sparse memory variables
enum { SPARSE_NONE, SPARSE_BINDING, SPARSE_RESIDENCY, SPARSE_RESIDENCY_ALIASED };
static int sparseMode = SPARSE_NONE;
static size_t memoryBlockSize=~0;
static size_t memoryBlockMask=~0;
static size_t sparseBlockSize=~0;
static vk::BufferCreateFlags bufferCreateFlags = {};
static unsigned bufferSizeMultiplier = 1;
// shader code in SPIR-V binary
static const uint32_t attributelessConstantOutputVS_spirv[]={
#include "attributelessConstantOutput.vert.spv"
};
static const uint32_t attributelessInputIndicesVS_spirv[]={
#include "attributelessInputIndices.vert.spv"
};
static const uint32_t coordinateAttributeVS_spirv[]={
#include "coordinateAttribute.vert.spv"
};
static const uint32_t coordinate4BufferVS_spirv[]={
#include "coordinate4Buffer.vert.spv"
};
static const uint32_t coordinate3BufferVS_spirv[]={
#include "coordinate3Buffer.vert.spv"
};
static const uint32_t singleUniformMatrixVS_spirv[]={
#include "singleUniformMatrix.vert.spv"
};
static const uint32_t matrixAttributeVS_spirv[]={
#include "matrixAttribute.vert.spv"
};
static const uint32_t matrixBufferVS_spirv[]={
#include "matrixBuffer.vert.spv"
};
static const uint32_t twoAttributesVS_spirv[]={
#include "twoAttributes.vert.spv"
};
static const uint32_t twoBuffersVS_spirv[]={
#include "twoBuffers.vert.spv"
};
static const uint32_t twoBuffer3VS_spirv[]={
#include "twoBuffer3.vert.spv"
};
static const uint32_t twoInterleavedBuffersVS_spirv[]={
#include "twoInterleavedBuffers.vert.spv"
};
static const uint32_t twoPackedAttributesVS_spirv[]={
#include "twoPackedAttributes.vert.spv"
};
static const uint32_t twoPackedBuffersVS_spirv[]={
#include "twoPackedBuffers.vert.spv"
};
static const uint32_t twoPackedBuffersUsingStructVS_spirv[]={
#include "twoPackedBuffersUsingStruct.vert.spv"
};
static const uint32_t twoPackedBuffersUsingStructSlowVS_spirv[]={
#include "twoPackedBuffersUsingStructSlow.vert.spv"
};
static const uint32_t singlePackedBufferVS_spirv[]={
#include "singlePackedBuffer.vert.spv"
};
static const uint32_t twoPackedAttributesAndSingleMatrixVS_spirv[]={
#include "twoPackedAttributesAndSingleMatrix.vert.spv"
};
static const uint32_t twoPackedAttributesAndMatrixVS_spirv[]={
#include "twoPackedAttributesAndMatrix.vert.spv"
};
static const uint32_t twoPackedBuffersAndMatrixVS_spirv[]={
#include "twoPackedBuffersAndMatrix.vert.spv"
};
static const uint32_t fourAttributesVS_spirv[]={
#include "fourAttributes.vert.spv"
};
static const uint32_t fourBuffersVS_spirv[]={
#include "fourBuffers.vert.spv"
};
static const uint32_t fourBuffer3VS_spirv[]={
#include "fourBuffer3.vert.spv"
};
static const uint32_t fourInterleavedBuffersVS_spirv[]={
#include "fourInterleavedBuffers.vert.spv"
};
static const uint32_t fourAttributesAndMatrixVS_spirv[]={
#include "fourAttributesAndMatrix.vert.spv"
};
static const uint32_t geometryShaderConstantOutputVS_spirv[]={
#include "geometryShaderConstantOutput.vert.spv"
};
static const uint32_t geometryShaderNoOutputGS_spirv[]={
#include "geometryShaderNoOutput.geom.spv"
};
static const uint32_t geometryShaderConstantOutputGS_spirv[]={
#include "geometryShaderConstantOutput.geom.spv"
};
static const uint32_t geometryShaderConstantOutputTwoTrianglesGS_spirv[]={
#include "geometryShaderConstantOutputTwoTriangles.geom.spv"
};
static const uint32_t geometryShaderVS_spirv[]={
#include "geometryShader.vert.spv"
};
static const uint32_t geometryShaderGS_spirv[]={
#include "geometryShader.geom.spv"
};
static const uint32_t transformationThreeMatricesVS_spirv[]={
#include "transformationThreeMatrices.vert.spv"
};
static const uint32_t transformationFiveMatricesVS_spirv[]={
#include "transformationFiveMatrices.vert.spv"
};
static const uint32_t transformationFiveMatricesPushConstantsVS_spirv[]={
#include "transformationFiveMatrices-pushConstants.vert.spv"
};
static const uint32_t transformationFiveMatricesSpecializationConstantsVS_spirv[]={
#include "transformationFiveMatrices-specializationConstants.vert.spv"
};
static const uint32_t transformationFiveMatricesConstantsVS_spirv[]={
#include "transformationFiveMatrices-constants.vert.spv"
};
static const uint32_t transformationFiveMatricesUsingGS_spirv[]={
#include "transformationFiveMatricesUsingGS.geom.spv"
};
static const uint32_t transformationFiveMatricesUsingGSAndAttributesVS_spirv[]={
#include "transformationFiveMatricesUsingGSAndAttributes.vert.spv"
};
static const uint32_t transformationFiveMatricesUsingGSAndAttributesGS_spirv[]={
#include "transformationFiveMatricesUsingGSAndAttributes.geom.spv"
};
static const uint32_t phongTexturedFourAttributesFiveMatricesVS_spirv[]={
#include "phongTexturedFourAttributesFiveMatrices.vert.spv"
};
static const uint32_t phongTexturedFourAttributesVS_spirv[]={
#include "phongTexturedFourAttributes.vert.spv"
};
static const uint32_t phongTexturedVS_spirv[]={
#include "phongTextured.vert.spv"
};
static const uint32_t phongTexturedRowMajorVS_spirv[]={
#include "phongTexturedRowMajor.vert.spv"
};
static const uint32_t phongTexturedMat4x3VS_spirv[]={
#include "phongTexturedMat4x3.vert.spv"
};
static const uint32_t phongTexturedMat4x3RowMajorVS_spirv[]={
#include "phongTexturedMat4x3RowMajor.vert.spv"
};
static const uint32_t phongTexturedQuat1VS_spirv[]={
#include "phongTexturedQuat1.vert.spv"
};
static const uint32_t phongTexturedQuat2VS_spirv[]={
#include "phongTexturedQuat2.vert.spv"
};
static const uint32_t phongTexturedQuat3VS_spirv[]={
#include "phongTexturedQuat3.vert.spv"
};
static const uint32_t phongTexturedQuat2PrimitiveRestartVS_spirv[]={
#include "phongTexturedQuat2PrimitiveRestart.vert.spv"
};
static const uint32_t phongTexturedSingleQuat2VS_spirv[]={
#include "phongTexturedSingleQuat2.vert.spv"
};
static const uint32_t phongTexturedDMatricesOnlyInputVS_spirv[]={
#include "phongTexturedDMatricesOnlyInput.vert.spv"
};
static const uint32_t phongTexturedDMatricesVS_spirv[]={
#include "phongTexturedDMatrices.vert.spv"
};
static const uint32_t phongTexturedDMatricesDVerticesVS_spirv[]={
#include "phongTexturedDMatricesDVertices.vert.spv"
};
static const uint32_t phongTexturedInGSDMatricesDVerticesVS_spirv[]={
#include "phongTexturedInGSDMatricesDVertices.vert.spv"
};
static const uint32_t phongTexturedInGSDMatricesDVerticesGS_spirv[]={
#include "phongTexturedInGSDMatricesDVertices.geom.spv"
};
static const uint32_t constantColorFS_spirv[]={
#include "constantColor.frag.spv"
};
static const uint32_t phongTexturedDummyFS_spirv[]={
#include "phongTexturedDummy.frag.spv"
};
static const uint32_t phongTexturedFS_spirv[]={
#include "phongTextured.frag.spv"
};
static const uint32_t phongTexturedNotPackedFS_spirv[]={
#include "phongTexturedNotPacked.frag.spv"
};
static const uint32_t fullscreenQuadVS_spirv[]={
#include "fullscreenQuad.vert.spv"
};
static const uint32_t fullscreenQuadFourInterpolatorsVS_spirv[]={
#include "fullscreenQuadFourInterpolators.vert.spv"
};
static const uint32_t fullscreenQuadFourSmoothInterpolatorsFS_spirv[]={
#include "fullscreenQuadFourSmoothInterpolators.frag.spv"
};
static const uint32_t fullscreenQuadFourFlatInterpolatorsFS_spirv[]={
#include "fullscreenQuadFourFlatInterpolators.frag.spv"
};
static const uint32_t fullscreenQuadTexturedPhongInterpolatorsVS_spirv[]={
#include "fullscreenQuadTexturedPhongInterpolators.vert.spv"
};
static const uint32_t fullscreenQuadTexturedPhongInterpolatorsFS_spirv[]={
#include "fullscreenQuadTexturedPhongInterpolators.frag.spv"
};
static const uint32_t uniformColor4fFS_spirv[]={
#include "uniformColor4f.frag.spv"
};
static const uint32_t uniformColor4bFS_spirv[]={
#include "uniformColor4b.frag.spv"
};
static const uint32_t fullscreenQuadTwoVec3InterpolatorsVS_spirv[]={
#include "fullscreenQuadTwoVec3Interpolators.vert.spv"
};
static const uint32_t phongNoSpecularFS_spirv[]={
#include "phongNoSpecular.frag.spv"
};
static const uint32_t phongNoSpecularSingleUniformFS_spirv[]={
#include "phongNoSpecularSingleUniform.frag.spv"
};
struct Test {
vector<uint64_t> renderingTimes;
uint32_t timestampIndex;
const char* groupText = nullptr;
uint32_t groupVariable;
string text;
bool enabled = true;
enum class Type { WarmUp, TriangleThroughput, VertexAndGeometryShader,
AttributesAndBuffers, Transformations, FragmentThroughput, TransferThroughput };
Type type;
double resultMultiplier = 1.;
const char* unitString = nullptr;
union {
double numRenderedItems; // used in FragmentThroughput tests
size_t numTransfers; // used in TransferThroughput tests
};
size_t transferSize;
typedef void (*Func)(vk::CommandBuffer cb, uint32_t timestampIndex, uint32_t groupVariable);
Func func;
vk::UniqueCommandBuffer secondaryCommandBuffer;
Test(const char* text_, Type t, Func func_) : text(text_), type(t), func(func_) {}
Test(const char* text_, Type t, double resultMultiplier_, const char* unitString_, Func func_) : text(text_), type(t), resultMultiplier(resultMultiplier_), unitString(unitString_), func(func_) {}
Test(const char* groupText_, uint32_t groupVariable_, const char* text_, Type t, Func func_) : groupText(groupText_), groupVariable(groupVariable_), text(text_), type(t), func(func_) {}
};
static vector<Test> tests;
static vector<Test*> shuffledTests;
static void beginRenderPass(vk::CommandBuffer cb,
vk::SubpassContents subpassContents = vk::SubpassContents::eSecondaryCommandBuffers)
{
cb.beginRenderPass(
vk::RenderPassBeginInfo(
renderPass.get(), // renderPass
framebuffer.get(), // framebuffer
vk::Rect2D(vk::Offset2D(0,0),framebufferExtent), // renderArea
2, // clearValueCount
array<vk::ClearValue,2>{ // pClearValues
vk::ClearColorValue(array<float,4>{0.f,0.f,0.f,1.f}),
vk::ClearDepthStencilValue(1.f,0)
}.data()
),
subpassContents // contents
);
}
static void endRenderPass(vk::CommandBuffer cb)
{
cb.endRenderPass();
}
static void beginTestBarrier(vk::CommandBuffer cb)
{
cb.pipelineBarrier(
vk::PipelineStageFlagBits::eAllCommands, // srcStageMask
vk::PipelineStageFlagBits::eAllCommands, // dstStageMask
vk::DependencyFlags(), // dependencyFlags
1,
array{ // memoryBarrierCount+pMemoryBarriers
vk::MemoryBarrier(
vk::AccessFlagBits::eMemoryRead|vk::AccessFlagBits::eMemoryWrite, // srcAccessMask
vk::AccessFlagBits::eMemoryRead|vk::AccessFlagBits::eMemoryWrite // dstAccessMask
),
}.data(),
0,nullptr, // bufferMemoryBarrierCount+pBufferMemoryBarriers
0,nullptr // imageMemoryBarrierCount+pImageMemoryBarriers
);
}
static void beginTest(
vk::CommandBuffer cb, vk::Pipeline pipeline, vk::PipelineLayout pipelineLayout, uint32_t& timestampIndex,
const vector<vk::Buffer>& attributes, const vector<vk::DescriptorSet>& descriptorSets)
{
cb.bindPipeline(vk::PipelineBindPoint::eGraphics,pipeline); // bind pipeline
if(descriptorSets.size()>0)
cb.bindDescriptorSets(
vk::PipelineBindPoint::eGraphics, // pipelineBindPoint
pipelineLayout, // layout
0, // firstSet
descriptorSets, // descriptorSets
nullptr // dynamicOffsets
);
if(attributes.size()>0)
cb.bindVertexBuffers(
0, // firstBinding
uint32_t(attributes.size()), // bindingCount
attributes.data(), // pBuffers
vector<vk::DeviceSize>(attributes.size(),0).data() // pOffsets
);
cb.writeTimestamp(
vk::PipelineStageFlagBits::eTopOfPipe, // pipelineStage
timestampPool.get(), // queryPool
timestampIndex++ // query
);
}
static void endTest(vk::CommandBuffer cb, uint32_t& timestampIndex)
{
cb.writeTimestamp(
vk::PipelineStageFlagBits::eColorAttachmentOutput, // pipelineStage
timestampPool.get(), // queryPool
timestampIndex++ // query
);
}
static void initTests()
{
tests.clear();
tests.reserve(200);
tests.emplace_back(
" Test just to warm up GPU. The test shall be invisible to the user.",
Test::Type::WarmUp,
[](vk::CommandBuffer cb, uint32_t timestampIndex, uint32_t)
{
// render something to put GPU out of power saving states
beginTest(cb, coordinateAttributePipeline.get(), simplePipelineLayout.get(), timestampIndex,
vector<vk::Buffer>{ coordinate4Attribute.get() },
vector<vk::DescriptorSet>());
cb.draw(3*numTriangles,1,0,0);
cb.draw(3*numTriangles,1,0,0);
endTest(cb, timestampIndex);
}
);
tests.emplace_back(
" Triangle list (triangle list primitive type,\n"
" single per-scene vkCmdDraw() call, attributeless,\n"
" constant VS output): ",
Test::Type::TriangleThroughput,
1., // resultMultiplier
nullptr,
[](vk::CommandBuffer cb, uint32_t timestampIndex, uint32_t)
{
beginTest(cb, attributelessConstantOutputPipeline.get(), simplePipelineLayout.get(), timestampIndex,
vector<vk::Buffer>(),
vector<vk::DescriptorSet>());
cb.draw(3*numTriangles, 1, 0, 0); // vertexCount, instanceCount, firstVertex, firstInstance
endTest(cb, timestampIndex);
}
);
tests.emplace_back(
" Indexed triangle list (triangle list primitive type, single\n"
" per-scene vkCmdDrawIndexed() call, no vertices shared between triangles,\n"
" attributeless, constant VS output): ",
Test::Type::TriangleThroughput,
1., // resultMultiplier
nullptr,
[](vk::CommandBuffer cb, uint32_t timestampIndex, uint32_t)
{
cb.bindIndexBuffer(indexBuffer.get(), 0, vk::IndexType::eUint32);
beginTest(cb, attributelessConstantOutputPipeline.get(), simplePipelineLayout.get(), timestampIndex,
vector<vk::Buffer>(),
vector<vk::DescriptorSet>());
cb.drawIndexed(3*numTriangles, 1, 0, 0, 0); // indexCount, instanceCount, firstIndex, vertexOffset, firstInstance
endTest(cb, timestampIndex);
}
);
tests.emplace_back(
" Indexed triangle list that reuses two indices of the previous triangle\n"
" (triangle list primitive type, single per-scene vkCmdDrawIndexed() call,\n"
" attributeless, constant VS output): ",
Test::Type::TriangleThroughput,
1., // resultMultiplier
nullptr,
[](vk::CommandBuffer cb, uint32_t timestampIndex, uint32_t)
{
cb.bindIndexBuffer(stripIndexBuffer.get(), 0, vk::IndexType::eUint32);
beginTest(cb, attributelessConstantOutputPipeline.get(), simplePipelineLayout.get(), timestampIndex,
vector<vk::Buffer>(),
vector<vk::DescriptorSet>());
cb.drawIndexed(3*numTriangles, 1, 0, 0, 0); // indexCount, instanceCount, firstIndex, vertexOffset, firstInstance
endTest(cb, timestampIndex);
}
);
const char* triStripPerformanceText =
" Triangle strips of various lengths\n"
" (per-strip vkCmdDraw() call, 1 to 1000 triangles per strip,\n"
" attributeless, constant VS output): ";
for(uint32_t n : array<uint32_t,12>{1,2,5,8,10,20,25,40,50,100,125,maxTriStripLength}) { // numbers in this list needs to be divisible by maxTriStripLength (1000 by default) with reminder zero
tests.emplace_back(
triStripPerformanceText,
n,
[](uint32_t n) {
string s = static_cast<stringstream&&>(stringstream() << " strip length " << n << ": ").str();
s.append(28-s.size(), ' ');
return s;
}(n).c_str(),
Test::Type::TriangleThroughput,
[](vk::CommandBuffer cb, uint32_t timestampIndex, uint32_t n)
{
beginTest(cb, attributelessConstantOutputTriStripPipeline.get(), simplePipelineLayout.get(), timestampIndex,
vector<vk::Buffer>(),
vector<vk::DescriptorSet>());
for(uint32_t i=0,e=(numTriangles/maxTriStripLength)*(2+maxTriStripLength); i<e; i+=2+maxTriStripLength)
for(uint32_t j=i,je=i+maxTriStripLength; j<je; j+=n)
cb.draw(n+2, 1, j, 0); // vertexCount, instanceCount, firstVertex, firstInstance
endTest(cb, timestampIndex);
}
);
}
#if 0 // not needed because it was replaced by the test bellow that uses strips of various lengths
tests.emplace_back(
" VS max throughput for indexed triangle strip\n"
" (per-strip vkCmdDrawIndexed() call, 1000 triangles per strip,\n"
" monotonically increasing indices,\n"
" attributeless, constant VS output): ",
Test::Type::VertexThroughput,
[](vk::CommandBuffer cb, uint32_t timestampIndex, uint32_t)
{
cb.bindIndexBuffer(indexBuffer.get(), 0, vk::IndexType::eUint32);
beginTest(cb, attributelessConstantOutputTriStripPipeline.get(), simplePipelineLayout.get(), timestampIndex,
vector<vk::Buffer>(),
vector<vk::DescriptorSet>());
for(uint32_t i=0,e=(numTriangles/maxTriStripLength)*(2+maxTriStripLength); i<e; i+=2+maxTriStripLength)
cb.drawIndexed(2+maxTriStripLength, 1, i, 0, 0); // indexCount, instanceCount, firstIndex, vertexOffset, firstInstance
endTest(cb, timestampIndex);
}
);
#endif
const char* indexedTriStripPerformanceText =
" Indexed triangle strips of various lengths\n"
" (per-strip vkCmdDrawIndexed() call, 1-1000 triangles per strip,\n"
" no vertices shared between strips, each index used just once,\n"
" attributeless, constant VS output): ";
for(uint32_t n : array<uint32_t,12>{1,2,5,8,10,20,25,40,50,100,125,maxTriStripLength}) { // numbers in this list needs to be divisible by maxTriStripLength (1000 by default) with reminder zero
tests.emplace_back(
indexedTriStripPerformanceText,
n,
[](uint32_t n) {
string s = static_cast<stringstream&&>(stringstream() << " strip length " << n << ": ").str();
s.append(28-s.size(), ' ');
return s;
}(n).c_str(),
Test::Type::TriangleThroughput,
[](vk::CommandBuffer cb, uint32_t timestampIndex, uint32_t n)
{
cb.bindIndexBuffer(indexBuffer.get(), 0, vk::IndexType::eUint32);
beginTest(cb, attributelessConstantOutputTriStripPipeline.get(), simplePipelineLayout.get(), timestampIndex,
vector<vk::Buffer>(),
vector<vk::DescriptorSet>());
for(uint32_t i=0,e=(numTriangles/maxTriStripLength)*(2+maxTriStripLength); i<e; i+=2+maxTriStripLength)
for(uint32_t j=i,je=i+maxTriStripLength; j<je; j+=n)
cb.drawIndexed(n+2, 1, j, 0, 0); // indexCount, instanceCount, firstIndex, vertexOffset, firstInstance
endTest(cb, timestampIndex);
}
);
}
const char* primitiveRestartPerformanceText =
" Primitive restart indexed triangle strips of various lengths\n"
" (single per-scene vkCmdDrawIndexed() call, 1-1000 triangles per strip,\n"
" no vertices shared between strips, each index used just once,\n"
" attributeless, constant VS output): ";
for(uint32_t n : array<uint32_t,5>{1,2,5,8,1000}) { // numbers in this list needs to be divisible by maxTriStripLength (1000 by default) with reminder zero
tests.emplace_back(
primitiveRestartPerformanceText,
n,
[](uint32_t n) {
string s = static_cast<stringstream&&>(stringstream()
<< " strip length " << n << ": ").str();
if(s.size()<28)
s.append(28-s.size(), ' ');
return s;
}(n).c_str(),
Test::Type::TriangleThroughput,
[](vk::CommandBuffer cb, uint32_t timestampIndex, uint32_t triPerStrip)
{
switch(triPerStrip) {
case 1: cb.bindIndexBuffer(stripPrimitiveRestart3IndexBuffer.get(), 0, vk::IndexType::eUint32); break;
case 2: cb.bindIndexBuffer(stripPrimitiveRestart4IndexBuffer.get(), 0, vk::IndexType::eUint32); break;
case 5: cb.bindIndexBuffer(stripPrimitiveRestart7IndexBuffer.get(), 0, vk::IndexType::eUint32); break;
case 8: cb.bindIndexBuffer(stripPrimitiveRestart10IndexBuffer.get(), 0, vk::IndexType::eUint32); break;
case 1000: cb.bindIndexBuffer(stripPrimitiveRestart1002IndexBuffer.get(), 0, vk::IndexType::eUint32); break;
default: assert(0 && "Unhandled triPerStrip parameter."); return;
};
beginTest(cb, attributelessConstantOutputPrimitiveRestartPipeline.get(), simplePipelineLayout.get(), timestampIndex,
vector<vk::Buffer>(),
vector<vk::DescriptorSet>());
uint32_t numIndicesPerStrip = triPerStrip+3;
uint32_t numStrips = numTriangles/triPerStrip;
cb.drawIndexed(numIndicesPerStrip*numStrips, 1, 0, 0, 0); // indexCount, instanceCount, firstIndex, vertexOffset, firstInstance
endTest(cb, timestampIndex);
}
);
}
tests.emplace_back(
" Primitive restart, each triangle is replaced by one -1\n"
" (single per-scene vkCmdDrawIndexed() call,\n"
" no fragments produced): ",
Test::Type::TriangleThroughput,
[](vk::CommandBuffer cb, uint32_t timestampIndex, uint32_t)
{
cb.bindIndexBuffer(minusOneIndexBuffer.get(), 0, vk::IndexType::eUint32);
beginTest(cb, attributelessConstantOutputPrimitiveRestartPipeline.get(),
simplePipelineLayout.get(), timestampIndex,
vector<vk::Buffer>(),
vector<vk::DescriptorSet>());
cb.drawIndexed(numTriangles, 1, 0, 0, 0); // indexCount, instanceCount, firstIndex, vertexOffset, firstInstance
endTest(cb, timestampIndex);
}
);
tests.emplace_back(
" Primitive restart, only zeros in the index buffer\n"
" (single per-scene vkCmdDrawIndexed() call,\n"
" no fragments produced): ",
Test::Type::TriangleThroughput,
[](vk::CommandBuffer cb, uint32_t timestampIndex, uint32_t)
{
cb.bindIndexBuffer(zeroIndexBuffer.get(), 0, vk::IndexType::eUint32);
beginTest(cb, attributelessConstantOutputPrimitiveRestartPipeline.get(),
simplePipelineLayout.get(), timestampIndex,
vector<vk::Buffer>(),
vector<vk::DescriptorSet>());
cb.drawIndexed(numTriangles+2, 1, 0, 0, 0); // indexCount, instanceCount, firstIndex, vertexOffset, firstInstance
endTest(cb, timestampIndex);
}
);
#if 0
if(runAllTests) {
tests.emplace_back(
" VS max throughput for indexed triangle list that reuse two indices from\n"
" the previous triangle, VertexIndex and InstanceIndex used for\n"
" position output (single per-scene vkCmdDrawIndexed() call,\n"
" monotonically increasing indices,\n"
" attributeless, constant VS output): ",
Test::Type::VertexThroughput,
[](vk::CommandBuffer cb, uint32_t timestampIndex, uint32_t)
{
cb.bindIndexBuffer(stripIndexBuffer.get(), 0, vk::IndexType::eUint32);
beginTest(cb, attributelessConstantOutputPipeline.get(), simplePipelineLayout.get(), timestampIndex,
vector<vk::Buffer>(),
vector<vk::DescriptorSet>());
cb.drawIndexed(3*numTriangles, 1, 0, 0, 0); // indexCount, instanceCount, firstIndex, vertexOffset, firstInstance
endTest(cb, timestampIndex);
}
);