forked from SaschaWillems/VulkanCapsViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vulkancapsviewer.cpp
1955 lines (1743 loc) · 80.8 KB
/
vulkancapsviewer.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
/*
*
* Vulkan hardware capability viewer
*
* Copyright (C) 2016-2024 by Sascha Willems (www.saschawillems.de)
*
* This code is free software, you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 3 as published by the Free Software Foundation.
*
* Please review the following information to ensure the GNU Lesser
* General Public License version 3 requirements will be met:
* http://opensource.org/licenses/lgpl-3.0.html
*
* The code is distributed WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU LGPL 3.0 for more details.
*
*/
#include "vulkancapsviewer.h"
#include "vulkanresources.h"
#include "vulkansurfaceinfo.hpp"
#include <typeinfo>
#include <sstream>
#include <iomanip>
#include <type_traits>
#include <QMessageBox>
#include <QFileDialog>
#include <QStyleFactory>
#include <QDesktopServices>
#include <QUrl>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QHttpMultiPart>
#include <QVariant>
#include <QInputDialog>
#include <QSysInfo>
#include <QDebug>
#include <QScroller>
#include <QEasingCurve>
#include <QSet>
#include <QWindow>
#include <QApplication>
#include <qnamespace.h>
#include <assert.h>
#include <settingsDialog.h>
#include "submitDialog.h"
#ifdef _WIN32
#include <windows.h>
#endif
#ifdef __linux__
#include <sys/utsname.h>
#endif
#ifdef VK_USE_PLATFORM_XCB_KHR
#include <QX11Info>
#endif
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
#include <wayland-client.h>
#endif
#ifdef VK_USE_PLATFORM_ANDROID_KHR
#include <QtAndroid>
#include <QAndroidJniEnvironment>
#include <android/native_window.h>
#include <android/native_window_jni.h>
#endif
#ifdef __APPLE__
#include <vulkan/vulkan_metal.h>
#ifdef VK_USE_PLATFORM_METAL_EXT
extern "C" const char *getWorkingFolderForiOS(void);
extern "C" void *makeViewMetalCompatible(void* handle);
#endif
#endif
using std::to_string;
const QString VulkanCapsViewer::version = "3.43";
const QString VulkanCapsViewer::reportVersion = "3.3";
OSInfo getOperatingSystem()
{
// QSysInfo works for all supported operating systems
OSInfo osInfo = {};
osInfo.name = QSysInfo::productType().toStdString();
osInfo.architecture = QSysInfo::buildCpuArchitecture().toStdString();
osInfo.version = QSysInfo::productVersion().toStdString();
// The Qt version used does not detect Windows 11, so we use Win32 API to detect it via the build version
#if defined(_WIN32)
HMODULE hModule = LoadLibrary(TEXT("ntdll.dll"));
if (hModule) {
typedef NTSTATUS(WINAPI* RtlGetVersionFN)(PRTL_OSVERSIONINFOW);
RtlGetVersionFN RtlGetVersion = reinterpret_cast<RtlGetVersionFN>(GetProcAddress(hModule, "RtlGetVersion"));
if (RtlGetVersion) {
RTL_OSVERSIONINFOW osVersionInfo = { 0 };
osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
if (RtlGetVersion(&osVersionInfo) == S_OK) {
if (osVersionInfo.dwBuildNumber >= 22000) {
osInfo.version = "11";
}
}
}
FreeLibrary(hModule);
}
#endif
// Also store os type lookup value used by the database (more precise than doing guesswork in a database trigger)
#if defined(VK_USE_PLATFORM_WIN32_KHR)
osInfo.type = 0;
#endif
#if defined(VK_USE_PLATFORM_WAYLAND_KHR) || defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_)
osInfo.type = 1;
#endif
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
osInfo.type = 2;
#endif
#if defined(VK_USE_PLATFORM_METAL_EXT)
osInfo.type = 3;
#endif
return osInfo;
}
// Convert a list variant into an imploded string
QString arrayToStr(QVariant value) {
QList<QVariant> list = value.toList();
QString imploded;
for (auto i = 0; i < list.size(); i++) {
imploded += list[i].toString();
if (i < list.size() - 1)
imploded += ", ";
}
return "[" + imploded + "]";
}
#if defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_ANDROID_KHR)
void setTouchProps(QWidget *widget) {
QScroller *scroller = QScroller::scroller(widget);
QScrollerProperties properties = scroller->scrollerProperties();
QVariant overshootPolicy = QVariant::fromValue<QScrollerProperties::OvershootPolicy>(QScrollerProperties::OvershootAlwaysOff);
properties.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy, overshootPolicy);
properties.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, overshootPolicy);
properties.setScrollMetric(QScrollerProperties::DragVelocitySmoothingFactor, 0.6);
properties.setScrollMetric(QScrollerProperties::MinimumVelocity, 0.0);
properties.setScrollMetric(QScrollerProperties::MaximumVelocity, 0.5);
properties.setScrollMetric(QScrollerProperties::AcceleratingFlickMaximumTime, 0.4);
properties.setScrollMetric(QScrollerProperties::AcceleratingFlickSpeedupFactor, 1.2);
properties.setScrollMetric(QScrollerProperties::SnapPositionRatio, 0.2);
properties.setScrollMetric(QScrollerProperties::MaximumClickThroughVelocity, 0);
properties.setScrollMetric(QScrollerProperties::DragStartDistance, 0.001);
properties.setScrollMetric(QScrollerProperties::MousePressEventDelay, 0.5);
scroller->grabGesture(widget, QScroller::LeftMouseButtonGesture);
scroller->setScrollerProperties(properties);
}
#endif
VulkanCapsViewer::VulkanCapsViewer(QWidget *parent)
: QMainWindow(parent)
{
// Set current working directory to writable document folder
#if defined(VK_USE_PLATFOROM_IOS_MVK)
setWorkingFolderForiOS();
#endif
ui.setupUi(this);
setWindowTitle("Vulkan Hardware Capability Viewer " + version);
// Connect slots
connect(ui.comboBoxGPU, SIGNAL(currentIndexChanged(int)), this, SLOT(slotComboBoxGPUIndexChanged(int)), Qt::QueuedConnection);
connect(ui.toolButtonUpload, SIGNAL(pressed()), this, SLOT(slotUploadReport()), Qt::QueuedConnection);
connect(ui.toolButtonSave, SIGNAL(pressed()), this, SLOT(slotSaveReport()), Qt::QueuedConnection);
connect(ui.toolButtonOnlineDevice, SIGNAL(pressed()), this, SLOT(slotDisplayOnlineReport()), Qt::QueuedConnection);
connect(ui.toolButtonOnlineDataBase, SIGNAL(pressed()), this, SLOT(slotBrowseDatabase()), Qt::QueuedConnection);
connect(ui.toolButtonAbout, SIGNAL(pressed()), this, SLOT(slotAbout()), Qt::QueuedConnection);
connect(ui.toolButtonExit, SIGNAL(pressed()), this, SLOT(slotClose()), Qt::QueuedConnection);
connect(ui.toolButtonSettings, SIGNAL(pressed()), this, SLOT(slotSettings()), Qt::QueuedConnection);
connect(ui.comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotComboTabChanged(int)), Qt::QueuedConnection);
qApp->setStyle(QStyleFactory::create("Fusion"));
boldFont.setBold(true);
ui.label_header_top->setText(ui.label_header_top->text() + " " + version);
#ifdef ANDROID
// Load Vulkan libraries on Android manually
if (!loadVulkanLibrary()) {
QMessageBox::warning(this, "Error", "Could not initialize Vulkan!\n\nPlease make sure that this device actually supports the Vulkan API.");
exit(EXIT_FAILURE);
}
#endif
#if defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_ANDROID_KHR)
// Adjust toolbar to better fit mobile devices
foreach (QToolButton *toolButton, findChildren<QToolButton *>()) {
toolButton->setToolButtonStyle(Qt::ToolButtonIconOnly);
}
ui.toolButtonSave->setVisible(false);
// Touch scrolling
foreach (QTreeView *widget, findChildren<QTreeWidget *>()) {
setTouchProps(widget);
widget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
widget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
widget->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
widget->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
widget->setSelectionMode(QAbstractItemView::NoSelection);
widget->setFrameStyle(QFrame::NoFrame);
}
foreach (QTreeView *widget, findChildren<QTreeView *>()) {
setTouchProps(widget);
widget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
widget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
widget->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
widget->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
widget->setSelectionMode(QAbstractItemView::NoSelection);
widget->setFrameStyle(QFrame::NoFrame);
}
// No identation
for (int i = 0; i < ui.tabWidgetDevice->count(); i++) {
ui.tabWidgetDevice->widget(i)->layout()->setMargin(0);
}
QTabBar *tabBar = ui.tabWidgetDevice->findChild<QTabBar *>();
tabBar->hide();
ui.comboBox->setVisible(true);
#else
ui.comboBox->setVisible(false);
#endif
if (!initVulkan())
{
QMessageBox::warning(this, "Error", "Could not initialize Vulkan!\n\nMake sure that at least one installed device supports Vulkan and supports at least Version 1.1.");
exit(EXIT_FAILURE);
}
if (QSysInfo::buildCpuArchitecture() == "i386")
{
QMessageBox::warning(this, "Warning", "You are running a 32-bit version of the application. Some Vulkan implementations may not support all GPU capabilities when running in 32-bit mode.");
}
// Models and filters
// Core 1.0 properties
ui.treeViewDeviceProperties->setModel(&filterProxies.propertiesCore10);
connectFilterAndModel(models.propertiesCore10, filterProxies.propertiesCore10);
connect(ui.filterLineEditProperties, SIGNAL(textChanged(QString)), this, SLOT(slotFilterPropertiesCore10(QString)));
// Core 1.1 properties
ui.treeViewDevicePropertiesCore11->setModel(&filterProxies.propertiesCore11);
connectFilterAndModel(models.propertiesCore11, filterProxies.propertiesCore11);
connect(ui.filterLineEditPropertiesCore11, SIGNAL(textChanged(QString)), this, SLOT(slotFilterPropertiesCore11(QString)));
// Core 1.2 properties
ui.treeViewDevicePropertiesCore12->setModel(&filterProxies.propertiesCore12);
connectFilterAndModel(models.propertiesCore12, filterProxies.propertiesCore12);
connect(ui.filterLineEditPropertiesCore12, SIGNAL(textChanged(QString)), this, SLOT(slotFilterPropertiesCore12(QString)));
// Core 1.3 properties
ui.treeViewDevicePropertiesCore13->setModel(&filterProxies.propertiesCore13);
connectFilterAndModel(models.propertiesCore13, filterProxies.propertiesCore13);
connect(ui.filterLineEditPropertiesCore13, SIGNAL(textChanged(QString)), this, SLOT(slotFilterPropertiesCore13(QString)));
// Extension properties
ui.treeViewDevicePropertiesExtensions->setModel(&filterProxies.propertiesExtensions);
connectFilterAndModel(models.propertiesExtensions, filterProxies.propertiesExtensions);
connect(ui.filterLineEditPropertiesExtensions, SIGNAL(textChanged(QString)), this, SLOT(slotFilterPropertiesExtensions(QString)));
// Core 1.0 features
ui.treeViewDeviceFeatures->setModel(&filterProxies.featuresCore10);
connectFilterAndModel(models.featuresCore10, filterProxies.featuresCore10);
connect(ui.filterLineEditFeatures, SIGNAL(textChanged(QString)), this, SLOT(slotFilterFeatures(QString)));
// Core 1.1 features
ui.treeViewDeviceFeaturesCore11->setModel(&filterProxies.featuresCore11);
connectFilterAndModel(models.featuresCore11, filterProxies.featuresCore11);
connect(ui.filterLineEditFeaturesCore11, SIGNAL(textChanged(QString)), this, SLOT(slotFilterFeaturesCore11(QString)));
// Core 1.2 features
ui.treeViewDeviceFeaturesCore12->setModel(&filterProxies.featuresCore12);
connectFilterAndModel(models.featuresCore12, filterProxies.featuresCore12);
connect(ui.filterLineEditFeaturesCore12, SIGNAL(textChanged(QString)), this, SLOT(slotFilterFeaturesCore12(QString)));
// Core 1.3 features
ui.treeViewDeviceFeaturesCore13->setModel(&filterProxies.featuresCore13);
connectFilterAndModel(models.featuresCore13, filterProxies.featuresCore13);
connect(ui.filterLineEditFeaturesCore13, SIGNAL(textChanged(QString)), this, SLOT(slotFilterFeaturesCore13(QString)));
// Extension features
ui.treeViewDeviceFeaturesExtensions->setModel(&filterProxies.featuresExtensions);
connectFilterAndModel(models.featuresExtensions, filterProxies.featuresExtensions);
connect(ui.filterLineEditFeaturesExtensions, SIGNAL(textChanged(QString)), this, SLOT(slotFilterFeaturesExtensions(QString)));
// Extensions
ui.treeViewDeviceExtensions->setModel(&filterProxies.extensions);
connectFilterAndModel(models.extensions, filterProxies.extensions);
connect(ui.filterLineEditExtensions, SIGNAL(textChanged(QString)), this, SLOT(slotFilterExtensions(QString)));
// Formats
ui.treeViewFormats->setModel(&filterProxies.formats);
connectFilterAndModel(models.formats, filterProxies.formats);
connect(ui.filterLineEditFormats, SIGNAL(textChanged(QString)), this, SLOT(slotFilterFormats(QString)));
// Profiles
ui.treeViewDeviceProfiles->setModel(&filterProxies.profiles);
connectFilterAndModel(models.profiles, filterProxies.profiles);
connect(ui.filterLineEditProfiles, SIGNAL(textChanged(QString)), this, SLOT(slotFilterProfiles(QString)));
getGPUs();
}
VulkanCapsViewer::~VulkanCapsViewer()
{
// Free up hidden window used on Apple platforms
#if defined(VK_USE_PLATFORM_METAL_EXT)
if(pMetalSurrogate != nullptr)
delete pMetalSurrogate;
#endif
for (VulkanDeviceInfo &gpu : vulkanGPUs) {
if (gpu.dev != VK_NULL_HANDLE) {
vkDestroyDevice(gpu.dev, nullptr);
}
}
if (vulkanContext.surface != VK_NULL_HANDLE) {
vkDestroySurfaceKHR(vulkanContext.instance, vulkanContext.surface, nullptr);
}
if (vulkanContext.instance != VK_NULL_HANDLE) {
vkDestroyInstance(vulkanContext.instance, nullptr);
}
}
void VulkanCapsViewer::slotClose()
{
close();
}
void VulkanCapsViewer::slotBrowseDatabase()
{
QString link = "https://vulkan.gpuinfo.org/";
QDesktopServices::openUrl(QUrl(link));
}
void VulkanCapsViewer::slotDisplayOnlineReport()
{
int reportId = database.getReportId(vulkanGPUs[selectedDeviceIndex]);
QUrl url(database.databaseUrl + "displayreport.php?id=" + QString::number(reportId));
QDesktopServices::openUrl(url);
}
std::string apiVersionText(uint32_t apiVersion)
{
return to_string(VK_VERSION_MAJOR(apiVersion)) + "." + to_string(VK_VERSION_MINOR(apiVersion)) + "." + to_string(VK_VERSION_PATCH(apiVersion));
}
void VulkanCapsViewer::slotAbout()
{
std::stringstream aboutText;
aboutText << "<p>Vulkan Hardware Capability Viewer " << version.toStdString() << "<br/><br/>"
"Copyright (c) 2016-2024 by <a href='https://www.saschawillems.de'>Sascha Willems</a><br/><br/>"
"This tool is <b>Free Open Source Software</b><br/><br/>"
"For usage and distribution details refer to the readme<br/><br/>"
"<a href='https://www.gpuinfo.org'>https://www.gpuinfo.org</a><br><br>"
"Vulkan instance API version: " + apiVersionText(instanceApiVersion) + "<br/>"
"Compiled against Vulkan header version: " + to_string(VK_HEADER_VERSION) + "<br/><br/>";
aboutText << "</p>";
QMessageBox::about(this, tr("About the Vulkan Hardware Capability Viewer"), QString::fromStdString(aboutText.str()));
}
void VulkanCapsViewer::slotComboBoxGPUIndexChanged(int index)
{
if (index != selectedDeviceIndex)
{
displayDevice(index);
}
}
void VulkanCapsViewer::slotSaveReport()
{
VulkanDeviceInfo device = vulkanGPUs[selectedDeviceIndex];
#ifndef VK_USE_PLATFORM_IOS_MVK
QString fileName = QFileDialog::getSaveFileName(this, tr("Save Report to disk"), device.properties["deviceName"].toString() + ".json", tr("json (*.json)"));
if (!fileName.isEmpty()) {
saveReport(fileName, "", "");
}
#else
// On iOS, you cannot choose where to save the file, but we need some sort of
// acknowledgement to the end user that the save has occured. It also seems
// rather disingenuous to say it's saved if we don't actually check for an error.
QString fileName = getWorkingFolderForiOS();
fileName += "/";
fileName += device.properties["deviceName"].toString();
fileName += ".json";
QMessageBox msgBox;
if (!saveReport(fileName, "", "")) {
msgBox.setText("Report saved to the iTunes file sharing folder.");
} else {
msgBox.setText("Error writing to iTunes file sharing folder.");
}
msgBox.exec();
#endif
}
void VulkanCapsViewer::slotUploadReport()
{
VulkanDeviceInfo device = vulkanGPUs[selectedDeviceIndex];
if (device.hasFeaturModifyingTool) {
QMessageBox::warning(this, "Upload disabled", "A feature modifying tool was detected (e.g. an active profiles layer)! Report uploads are disabled. Please disable any feature modifying tool and restart the application.");
return;
}
QString error;
if (!database.checkServerConnection(error))
{
QMessageBox::warning(this, "Error", "Could not connect to database:<br>" + error);
return;
}
// Upload new report
if (reportState == ReportState::not_present) {
SubmitDialog dialog(settings.submitterName, "Submit new report");
if (dialog.exec() == QDialog::Accepted) {
QString message;
QJsonObject reportJson;
reportToJson(dialog.getSubmitter(), dialog.getComment(), reportJson);
if (database.uploadReport(reportJson, message))
{
QMessageBox::information(this, "Report submitted", "Your report has been uploaded to the database!\n\nThank you for your contribution!");
checkReportDatabaseState();
}
else
{
QMessageBox::warning(this, "Error", "The report could not be uploaded : \n" + message);
}
}
return;
}
// Update existing report
if (reportState == ReportState::is_updatable) {
SubmitDialog dialog(settings.submitterName, "Update existing report");
if (dialog.exec() == QDialog::Accepted) {
int reportId = database.getReportId(device);
QApplication::setOverrideCursor(Qt::WaitCursor);
QString updateLog;
bool updateResult = database.postReportForUpdate(device, reportId, updateLog);
QApplication::restoreOverrideCursor();
if (updateResult)
{
QMessageBox::information(this, "Report updated", "The report has been updated with the following information:\n\n" + updateLog + "\nThank you for your contribution!");
}
else
{
QMessageBox::warning(this, "Error", "The report could not be updated");
}
checkReportDatabaseState();
}
return;
}
// Show link to database for existing reports
if (reportState == ReportState::is_present) {
int reportId = database.getReportId(device);
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, "Device already present", "A report for the selected device is already present in the database.\n\nDo you want to open the report in your browser?", QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::Yes)
{
QUrl url(database.databaseUrl + "displayreport.php?id=" + QString::number(reportId));
QDesktopServices::openUrl(url);
}
return;
}
}
void VulkanCapsViewer::slotSettings()
{
settingsDialog dialog(settings);
dialog.setModal(true);
dialog.exec();
settings.restore();
checkReportDatabaseState();
}
void VulkanCapsViewer::slotFilterPropertiesCore10(QString text)
{
QRegExp regExp(text, Qt::CaseInsensitive, QRegExp::RegExp);
filterProxies.propertiesCore10.setFilterRegExp(regExp);
}
void VulkanCapsViewer::slotFilterPropertiesCore11(QString text)
{
QRegExp regExp(text, Qt::CaseInsensitive, QRegExp::RegExp);
filterProxies.propertiesCore11.setFilterRegExp(regExp);
}
void VulkanCapsViewer::slotFilterPropertiesCore12(QString text)
{
QRegExp regExp(text, Qt::CaseInsensitive, QRegExp::RegExp);
filterProxies.propertiesCore12.setFilterRegExp(regExp);
}
void VulkanCapsViewer::slotFilterPropertiesCore13(QString text)
{
QRegExp regExp(text, Qt::CaseInsensitive, QRegExp::RegExp);
filterProxies.propertiesCore13.setFilterRegExp(regExp);
}
void VulkanCapsViewer::slotFilterPropertiesExtensions(QString text)
{
QRegExp regExp(text, Qt::CaseInsensitive, QRegExp::RegExp);
filterProxies.propertiesExtensions.setFilterRegExp(regExp);
}
void VulkanCapsViewer::slotFilterFeatures(QString text)
{
QRegExp regExp(text, Qt::CaseInsensitive, QRegExp::RegExp);
filterProxies.featuresCore10.setFilterRegExp(regExp);
}
void VulkanCapsViewer::slotFilterFeaturesCore11(QString text)
{
QRegExp regExp(text, Qt::CaseInsensitive, QRegExp::RegExp);
filterProxies.featuresCore11.setFilterRegExp(regExp);
}
void VulkanCapsViewer::slotFilterFeaturesCore12(QString text)
{
QRegExp regExp(text, Qt::CaseInsensitive, QRegExp::RegExp);
filterProxies.featuresCore12.setFilterRegExp(regExp);
}
void VulkanCapsViewer::slotFilterFeaturesCore13(QString text)
{
QRegExp regExp(text, Qt::CaseInsensitive, QRegExp::RegExp);
filterProxies.featuresCore13.setFilterRegExp(regExp);
}
void VulkanCapsViewer::slotFilterFeaturesExtensions(QString text)
{
QRegExp regExp(text, Qt::CaseInsensitive, QRegExp::RegExp);
filterProxies.featuresExtensions.setFilterRegExp(regExp);
}
void VulkanCapsViewer::slotFilterExtensions(QString text)
{
QRegExp regExp(text, Qt::CaseInsensitive, QRegExp::RegExp);
filterProxies.extensions.setFilterRegExp(regExp);
}
void VulkanCapsViewer::slotFilterFormats(QString text)
{
QRegExp regExp(text, Qt::CaseInsensitive, QRegExp::RegExp);
filterProxies.formats.setFilterRegExp(regExp);
}
void VulkanCapsViewer::slotFilterProfiles(QString text)
{
QRegExp regExp(text, Qt::CaseInsensitive, QRegExp::RegExp);
filterProxies.profiles.setFilterRegExp(regExp);
}
void VulkanCapsViewer::slotComboTabChanged(int index)
{
ui.tabWidgetDevice->setCurrentIndex(index);
}
bool VulkanCapsViewer::initVulkan()
{
VkResult vkRes;
// Get the max. supported Vulkan Version if vkEnumerateInstanceVersion is available (loader version 1.1 and up)
PFN_vkEnumerateInstanceVersion vkEnumerateInstanceVersion = reinterpret_cast<PFN_vkEnumerateInstanceVersion>(vkGetInstanceProcAddr(nullptr, "vkEnumerateInstanceVersion"));
if (vkEnumerateInstanceVersion) {
vkEnumerateInstanceVersion(&instanceApiVersion);
} else {
instanceApiVersion = VK_API_VERSION_1_0;
}
VkApplicationInfo appInfo = {};
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
appInfo.pApplicationName = "VulkanCapsViewer";
appInfo.applicationVersion = 1;
appInfo.pEngineName = "VulkanCapsViewer";
appInfo.engineVersion = 1;
appInfo.apiVersion = instanceApiVersion;
// Create Vulkan instance
VkInstanceCreateInfo instanceCreateInfo = {};
instanceCreateInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
instanceCreateInfo.pApplicationInfo = &appInfo;
// Get instance layers
uint32_t layerCount = 0;
std::vector<VkLayerProperties> instanceLayerProperties;
do
{
vkRes = vkEnumerateInstanceLayerProperties(&layerCount, NULL);
instanceLayerProperties.resize(layerCount);
if (layerCount > 0) {
vkRes = vkEnumerateInstanceLayerProperties(&layerCount, &instanceLayerProperties.front());
}
} while (vkRes == VK_INCOMPLETE);
assert(!vkRes);
for (auto& layerProperty : instanceLayerProperties) {
VulkanLayerInfo layer;
layer.properties = layerProperty;
instanceLayers.push_back(layer);
}
// Platform specific surface extensions
std::vector<std::string> possibleSurfaceExtensions = {
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
VK_KHR_ANDROID_SURFACE_EXTENSION_NAME,
#endif
#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME,
#endif
#if defined(VK_USE_PLATFORM_WIN32_KHR)
VK_KHR_WIN32_SURFACE_EXTENSION_NAME,
#endif
#if defined(VK_USE_PLATFORM_XCB_KHR)
VK_KHR_XCB_SURFACE_EXTENSION_NAME,
#endif
#if defined(VK_USE_PLATFORM_METAL_EXT)
VK_EXT_METAL_SURFACE_EXTENSION_NAME,
#endif
};
std::vector<const char*> enabledExtensions = {};
uint32_t availableExtensionCount = 0;
vkEnumerateInstanceExtensionProperties(nullptr, &availableExtensionCount, nullptr);
std::vector<VkExtensionProperties> availableExtensions(availableExtensionCount);
vkEnumerateInstanceExtensionProperties(nullptr, &availableExtensionCount, availableExtensions.data());
if (availableExtensionCount != 0) {
enabledExtensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
}
std::vector<std::string> surfaceExtensionsAvailable = {};
for (const std::string& possibleExtension : possibleSurfaceExtensions) {
for (const auto& availableExtension : availableExtensions) {
if (possibleExtension == availableExtension.extensionName) {
surfaceExtensionsAvailable.push_back(possibleExtension);
enabledExtensions.push_back(possibleExtension.c_str());
break;
}
}
}
// Get instance extensions
instanceExtensions.clear();
do {
uint32_t extCount;
vkRes = vkEnumerateInstanceExtensionProperties(NULL, &extCount, NULL);
if (vkRes != VK_SUCCESS) {
break;
}
std::vector<VkExtensionProperties> extensions(extCount);
vkRes = vkEnumerateInstanceExtensionProperties(NULL, &extCount, &extensions.front());
instanceExtensions.insert(instanceExtensions.end(), extensions.begin(), extensions.end());
} while (vkRes == VK_INCOMPLETE);
// Check support for new property and feature queries
deviceProperties2Available = false;
for (auto& ext : instanceExtensions) {
if (strcmp(ext.extensionName, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME) == 0) {
deviceProperties2Available = true;
enabledExtensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
}
// (On Android) enable color space extensions so we also get wide color gamut surface formats
if (strcmp(ext.extensionName, VK_EXT_SWAPCHAIN_COLOR_SPACE_EXTENSION_NAME) == 0) {
enabledExtensions.push_back(VK_EXT_SWAPCHAIN_COLOR_SPACE_EXTENSION_NAME);
}
#if defined(__APPLE__) && (VK_HEADER_VERSION >= 216)
if(strcmp(ext.extensionName, VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME) == 0) {
instanceCreateInfo.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
enabledExtensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
}
#endif
}
instanceCreateInfo.ppEnabledExtensionNames = enabledExtensions.data();
instanceCreateInfo.enabledExtensionCount = (uint32_t)enabledExtensions.size();
// Create vulkan Instance
vkRes = vkCreateInstance(&instanceCreateInfo, nullptr, &vulkanContext.instance);
if (vkRes != VK_SUCCESS)
{
QString error;
if (vkRes == VK_ERROR_INCOMPATIBLE_DRIVER)
{
error = "No compatible Vulkan driver found!\nThis version requires a Vulkan driver that is compatible with at least Vulkan 1.1";
}
else
{
error = "Could not create Vulkan instance!\nError: " + QString::fromStdString(vulkanResources::resultString(vkRes));
}
QMessageBox::warning(this, tr("Error"), error);
return false;
}
#ifdef ANDROID
loadVulkanFunctions();
#endif
// Function pointers for new features/properties
if (deviceProperties2Available) {
vulkanContext.vkGetPhysicalDeviceFeatures2KHR = reinterpret_cast<PFN_vkGetPhysicalDeviceFeatures2KHR>(vkGetInstanceProcAddr(vulkanContext.instance, "vkGetPhysicalDeviceFeatures2KHR"));
if (!vulkanContext.vkGetPhysicalDeviceFeatures2KHR) {
deviceProperties2Available = false;
QMessageBox::warning(this, tr("Error"), "Could not get function pointer for vkGetPhysicalDeviceFeatures2KHR (even though extension is enabled!)\nNew features and properties won't be displayed!");
}
vulkanContext.vkGetPhysicalDeviceProperties2KHR = reinterpret_cast<PFN_vkGetPhysicalDeviceProperties2KHR>(vkGetInstanceProcAddr(vulkanContext.instance, "vkGetPhysicalDeviceProperties2KHR"));
if (!vulkanContext.vkGetPhysicalDeviceProperties2KHR) {
deviceProperties2Available = false;
QMessageBox::warning(this, tr("Error"), "Could not get function pointer for vkGetPhysicalDeviceProperties2KHR (even though extension is enabled!)\nNew features and properties won't be displayed!");
}
}
vulkanContext.vkGetPhysicalDeviceSurfaceSupportKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceSurfaceSupportKHR>(vkGetInstanceProcAddr(vulkanContext.instance, "vkGetPhysicalDeviceSurfaceSupportKHR"));
// Create a surface
for (auto surface_extension : surfaceExtensionsAvailable) {
VkResult surfaceResult = VK_ERROR_INITIALIZATION_FAILED;
#if defined(VK_USE_PLATFORM_WIN32_KHR)
if (surface_extension == VK_KHR_WIN32_SURFACE_EXTENSION_NAME) {
VkWin32SurfaceCreateInfoKHR surfaceCreateInfo = {};
surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
surfaceCreateInfo.hinstance = GetModuleHandle(nullptr);
surfaceCreateInfo.hwnd = reinterpret_cast<HWND>(this->winId());
surfaceResult = vkCreateWin32SurfaceKHR(vulkanContext.instance, &surfaceCreateInfo, nullptr, &vulkanContext.surface);
}
#endif
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
if (surface_extension == VK_KHR_ANDROID_SURFACE_EXTENSION_NAME) {
// Get a native window via JNI
// Qt doesn't offer access to this, so we have to do this manually
// Note: Purely based on countless hours of trial-and-error, need to check on other devices
// todo: cleanup, error checking
// Get window
QAndroidJniObject activity = QtAndroid::androidActivity();
QAndroidJniObject window;
if (activity.isValid())
{
window = activity.callObjectMethod("getWindow", "()Landroid/view/Window;");
}
if (window.isValid())
{
// Get a surface texture
QAndroidJniObject surfaceTexture = QAndroidJniObject("android/graphics/SurfaceTexture", "(I)V", jint(0));
qDebug() << surfaceTexture.isValid();
// Get a surface based on the texture
QAndroidJniObject surface("android/view/Surface", "(Landroid/graphics/SurfaceTexture;)V", surfaceTexture.object());
qDebug() << surface.isValid();
if (surfaceTexture.isValid())
{
// Create a native window from our surface that can be used to create the Vulkan surface
QAndroidJniEnvironment qjniEnv;
nativeWindow = ANativeWindow_fromSurface(qjniEnv, surface.object());
}
}
if (nativeWindow)
{
VkAndroidSurfaceCreateInfoKHR surfaceCreateInfo = {};
surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
surfaceCreateInfo.window = nativeWindow;
surfaceResult = vkCreateAndroidSurfaceKHR(vulkanContext.instance, &surfaceCreateInfo, NULL, &vulkanContext.surface);
}
}
#endif
#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
if (surface_extension == VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) {
VkWaylandSurfaceCreateInfoKHR surfaceCreateInfo = {};
surfaceCreateInfo.pNext = nullptr;
surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR;
surfaceCreateInfo.display = wl_display_connect(NULL);
surfaceCreateInfo.surface = nullptr;
surfaceResult = vkCreateWaylandSurfaceKHR(vulkanContext.instance, &surfaceCreateInfo, nullptr, &vulkanContext.surface);
}
#endif
#if defined(VK_USE_PLATFORM_XCB_KHR)
if (surface_extension == VK_KHR_XCB_SURFACE_EXTENSION_NAME) {
VkXcbSurfaceCreateInfoKHR surfaceCreateInfo = {};
surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
surfaceCreateInfo.connection = QX11Info::connection();
surfaceCreateInfo.window = static_cast<xcb_window_t>(this->winId());
surfaceResult = vkCreateXcbSurfaceKHR(vulkanContext.instance, &surfaceCreateInfo, nullptr, &vulkanContext.surface);
}
#endif
// This works for deskop and iOS devices
#if defined(VK_USE_PLATFORM_METAL_EXT)
if(surface_extension == VK_EXT_METAL_SURFACE_EXTENSION_NAME) {
pMetalSurrogate = new QVukanSurrogate;
VkMetalSurfaceCreateInfoEXT info = {};
info.sType = VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT;
info.pNext = nullptr;
info.pLayer = (void*)makeViewMetalCompatible((void*)pMetalSurrogate->winId());
info.flags = 0;
surfaceResult = vkCreateMetalSurfaceEXT(vulkanContext.instance, &info, nullptr, &vulkanContext.surface);
}
#endif
if (surfaceResult == VK_SUCCESS) {
vulkanContext.surfaceExtension = surface_extension;
break;
} else {
vulkanContext.surface = VK_NULL_HANDLE;
}
}
displayInstanceLayers();
displayInstanceExtensions();
return true;
}
void VulkanCapsViewer::getGPUinfo(VulkanDeviceInfo *GPU, uint32_t id, VkPhysicalDevice device)
{
VkResult vkRes;
GPU->id = id;
GPU->device = device;
GPU->readExtensions();
GPU->readPhysicalProperties();
GPU->readLayers();
GPU->readQueueFamilies();
GPU->readPhysicalFeatures();
GPU->readPhysicalLimits();
GPU->readPhysicalMemoryProperties();
GPU->readSurfaceInfo();
GPU->readPlatformDetails();
GPU->readProfiles();
// Request all available queues
std::vector<VkDeviceQueueCreateInfo> queueCreateInfos;
for (uint32_t i = 0; i < GPU->queueFamilies.size(); ++i)
{
float queuePriorities[1] = { 0.0f };
VkDeviceQueueCreateInfo queueCreateInfo = {};
queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
queueCreateInfo.queueFamilyIndex = i;
queueCreateInfo.queueCount = 1;
queueCreateInfo.pQueuePriorities = queuePriorities;
queueCreateInfos.push_back(queueCreateInfo);
}
std::vector<const char*> enabledExtensions;
#if defined(__APPLE__) && (VK_HEADER_VERSION >= 216)
enabledExtensions.push_back(VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME);
#endif
// Init device
VkDeviceCreateInfo info = {};
info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
info.pQueueCreateInfos = queueCreateInfos.data();
info.queueCreateInfoCount = (uint32_t)queueCreateInfos.size();
info.enabledLayerCount = 0;
if (enabledExtensions.size() > 0) {
info.enabledExtensionCount = static_cast<uint32_t>(enabledExtensions.size());
info.ppEnabledExtensionNames = enabledExtensions.data();
};
vkRes = vkCreateDevice(GPU->device, &info, nullptr, &GPU->dev);
if (vkRes != VK_SUCCESS)
{
QString error = "Could not create a Vulkan device!\nError: " + QString::fromStdString(vulkanResources::resultString(vkRes));
QMessageBox::warning(this, tr("Error"), error);
exit(EXIT_FAILURE);
}
GPU->readSupportedFormats();
GPU->os = getOperatingSystem();
GPU->reportVersion = reportVersion;
GPU->appVersion = version;
// Check if any feature modifying tool is active for this device (e.g. profiles layer)
// This information is used to disable uploads to the database
GPU->hasFeaturModifyingTool = false;
PFN_vkGetPhysicalDeviceToolPropertiesEXT vkGetPhysicalDeviceToolPropertiesEXT{};
vkGetPhysicalDeviceToolPropertiesEXT = reinterpret_cast<PFN_vkGetPhysicalDeviceToolPropertiesEXT>(vkGetInstanceProcAddr(vulkanContext.instance, "vkGetPhysicalDeviceToolPropertiesEXT"));
if (vkGetPhysicalDeviceToolPropertiesEXT) {
uint32_t numTools;
vkGetPhysicalDeviceToolPropertiesEXT(vulkanGPUs[0].device, &numTools, nullptr);
std::vector<VkPhysicalDeviceToolPropertiesEXT> toolProperties{};
toolProperties.resize(numTools);
vkGetPhysicalDeviceToolPropertiesEXT(vulkanGPUs[0].device, &numTools, toolProperties.data());
for (auto& toolProps : toolProperties) {
if (toolProps.purposes & VK_TOOL_PURPOSE_MODIFYING_FEATURES_BIT_EXT) {
qWarning().nospace() << "Found feature modifying tool \"" << toolProps.description << "\" for \"" << GPU->props.deviceName << "\", uploads for this device will be disabled";
GPU->hasFeaturModifyingTool = true;
}
}
}
}
void VulkanCapsViewer::getGPUs()
{
VkResult vkRes;
uint32_t numGPUs;
// Enumerate devices
vkRes = vkEnumeratePhysicalDevices(vulkanContext.instance, &numGPUs, NULL);
if (vkRes != VK_SUCCESS)
{
QMessageBox::warning(this, tr("Error"), "Could not enumerate device count!");
return;
}
std::vector<VkPhysicalDevice> vulkanDevices;
vulkanDevices.resize(numGPUs);
vkRes = vkEnumeratePhysicalDevices(vulkanContext.instance, &numGPUs, &vulkanDevices.front());
if (vkRes != VK_SUCCESS)
{
QMessageBox::warning(this, tr("Error"), "Could not enumerate physical devices!");
return;
}
vulkanGPUs.resize(numGPUs);
for (uint32_t i = 0; i < numGPUs; i++)
{
getGPUinfo(&vulkanGPUs[i], i, vulkanDevices[i]);
}
ui.comboBoxGPU->clear();
for (auto& GPU : vulkanGPUs)
{
QString deviceName = QString::fromStdString("[GPU" + to_string(GPU.id) + "] " + GPU.props.deviceName);
ui.comboBoxGPU->addItem(deviceName);
}
if (vulkanGPUs.size() > 0)
{
displayDevice(0);
}
else
{
QMessageBox::warning(this, tr("Error"), "Could not find a GPU with Vulkan support!");
}
// Only display device selection of more than once device is present (Android only)
#ifdef __ANDROID__
ui.widgetDeviceSelection->setVisible(vulkanGPUs.size() > 1);
#endif
}
void VulkanCapsViewer::connectFilterAndModel(QStandardItemModel& model, CustomFilterProxyModel& filter)
{
filter.setSourceModel(&model);
filter.setFilterKeyColumn(-1);
filter.setRecursiveFilteringEnabled(true);
}
QTreeWidgetItem *addTreeItem(QTreeWidgetItem *parent, const std::string& key, const std::string& value)
{
QTreeWidgetItem *newItem = new QTreeWidgetItem(parent);
newItem->setText(0, QString::fromStdString(key));
newItem->setText(1, QString::fromStdString(value));
parent->addChild(newItem);
return newItem;
}
QTreeWidgetItem *addTreeItemVkBool32(QTreeWidgetItem *parent, const std::string& key, const VkBool32 value)
{
QTreeWidgetItem *newItem = new QTreeWidgetItem(parent);
newItem->setText(0, QString::fromStdString(key));
newItem->setText(1, (value) ? "true" : "false");
newItem->setForeground(1, (value) ? QColor::fromRgb(0, 128, 0) : QColor::fromRgb(255, 0, 0));
parent->addChild(newItem);
return newItem;
}
void addTreeItemFlag(QTreeWidgetItem *parent, const QString& flagName, const bool flag)
{
if (flag)
{
QTreeWidgetItem *newItem = new QTreeWidgetItem(parent);
newItem->setText(0, flagName);
parent->addChild(newItem);
}
}