Skip to content

Commit 2176d2c

Browse files
committed
Add support for displaying and storing cooperative matrix properties
KHR extension only Refs #190
1 parent 7799598 commit 2176d2c

File tree

4 files changed

+91
-2
lines changed

4 files changed

+91
-2
lines changed

VulkanContext.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* Vulkan hardware capability viewer
44
*
5-
* Copyright (C) 2016-2022 by Sascha Willems (www.saschawillems.de)
5+
* Copyright (C) 2016-2025 by Sascha Willems (www.saschawillems.de)
66
*
77
* This code is free software, you can redistribute it and/or
88
* modify it under the terms of the GNU Lesser General Public
@@ -31,6 +31,7 @@ struct VulkanContext
3131
PFN_vkGetPhysicalDeviceFeatures2KHR vkGetPhysicalDeviceFeatures2KHR = nullptr;
3232
PFN_vkGetPhysicalDeviceProperties2KHR vkGetPhysicalDeviceProperties2KHR = nullptr;
3333
PFN_vkGetPhysicalDeviceSurfaceSupportKHR vkGetPhysicalDeviceSurfaceSupportKHR = nullptr;
34+
PFN_vkGetPhysicalDeviceCooperativeMatrixPropertiesKHR vkGetPhysicalDeviceCooperativeMatrixPropertiesKHR = nullptr;
3435
};
3536

3637
extern VulkanContext vulkanContext;

VulkanDeviceInfoExtensions.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,21 @@ void VulkanDeviceInfoExtensions::readPhysicalProperties_KHR() {
962962
deviceProps2 = initDeviceProperties2(extProps);
963963
vulkanContext.vkGetPhysicalDeviceProperties2KHR(device, &deviceProps2);
964964
pushProperty2(extension, "cooperativeMatrixSupportedStages", QVariant(extProps->cooperativeMatrixSupportedStages));
965+
// This extension needs some special handling, this code has to be adjusted manually after header generation
966+
// If changed after header-update, DO NOT COMMIT the changes, but revert them
967+
if (vulkanContext.vkGetPhysicalDeviceCooperativeMatrixPropertiesKHR != nullptr) {
968+
uint32_t propCount = 0;
969+
vulkanContext.vkGetPhysicalDeviceCooperativeMatrixPropertiesKHR(device, &propCount, nullptr);
970+
std::vector<VkCooperativeMatrixPropertiesKHR> props(propCount);
971+
vulkanContext.vkGetPhysicalDeviceCooperativeMatrixPropertiesKHR(device, &propCount, props.data());
972+
// The structure is flattened to an array without property names due to database column size limits
973+
QVariantList qvl{};
974+
for (auto& prop : props) {
975+
auto value = QVariantList({ prop.MSize, prop.NSize, prop.KSize, prop.AType, prop.BType, prop.CType, prop.ResultType, prop.saturatingAccumulation, prop.scope});
976+
qvl.push_back(value);
977+
}
978+
pushProperty2(extension, "cooperativeMatrixProperties", qvl);
979+
};
965980
delete extProps;
966981
}
967982
if (extensionSupported("VK_KHR_compute_shader_derivatives")) {

vulkancapsviewer.cpp

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,8 @@ bool VulkanCapsViewer::initVulkan()
736736
deviceProperties2Available = false;
737737
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!");
738738
}
739+
// These are optional and only required for certain extensions
740+
vulkanContext.vkGetPhysicalDeviceCooperativeMatrixPropertiesKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceCooperativeMatrixPropertiesKHR>(vkGetInstanceProcAddr(vulkanContext.instance, "vkGetPhysicalDeviceCooperativeMatrixPropertiesKHR"));
739741
}
740742

741743
vulkanContext.vkGetPhysicalDeviceSurfaceSupportKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceSurfaceSupportKHR>(vkGetInstanceProcAddr(vulkanContext.instance, "vkGetPhysicalDeviceSurfaceSupportKHR"));
@@ -1101,6 +1103,15 @@ void addVkBool32Item(QStandardItem* parent, const QVariantMap::const_iterator& i
11011103
parent->appendRow(item);
11021104
}
11031105

1106+
void addVkBool32Item(QStandardItem* parent, const QString& name, const bool value)
1107+
{
1108+
QList<QStandardItem*> item;
1109+
item << new QStandardItem(name);
1110+
item << new QStandardItem(value ? "true" : "false");
1111+
item[1]->setForeground(value ? QColor::fromRgb(0, 128, 0) : QColor::fromRgb(255, 0, 0));
1112+
parent->appendRow(item);
1113+
}
1114+
11041115
void addVkSampleCountFlagsItem(QStandardItem* parent, const QVariantMap::const_iterator& iterator)
11051116
{
11061117
const auto samples = static_cast<VkSampleCountFlags>(iterator.value().toUInt());
@@ -1162,6 +1173,13 @@ void addHexItem(QStandardItem* parent, const QVariantMap::const_iterator& iterat
11621173
parent->appendRow(item);
11631174
}
11641175

1176+
void addCaptionedRow(QStandardItem* parent, QString caption, QString value) {
1177+
QList<QStandardItem*> item;
1178+
item << new QStandardItem(caption);
1179+
item << new QStandardItem(value);
1180+
parent->appendRow(item);
1181+
}
1182+
11651183
void addVariantListItem(QStandardItem* parent, const QVariantMap::const_iterator& iterator)
11661184
{
11671185
QList<QStandardItem*> item;
@@ -1304,6 +1322,7 @@ void addExtensionPropertiesRow(QList<QStandardItem*> item, Property2 property)
13041322
}
13051323

13061324
if (property.value.canConvert(QVariant::List)) {
1325+
bool displayRawValue{ true };
13071326
if ((strcmp(property.extension, VK_EXT_HOST_IMAGE_COPY_EXTENSION_NAME) == 0) && ((property.name == "pCopySrcLayouts") || (property.name == "pCopyDstLayouts"))) {
13081327
QList<QVariant> list = property.value.toList();
13091328
for (auto i = 0; i < list.size(); i++) {
@@ -1312,7 +1331,28 @@ void addExtensionPropertiesRow(QList<QStandardItem*> item, Property2 property)
13121331
propertyItem.first()->appendRow(formatItem);
13131332
}
13141333
}
1315-
propertyItem << new QStandardItem(arrayToStr(property.value));
1334+
if ((strcmp(property.extension, VK_KHR_COOPERATIVE_MATRIX_EXTENSION_NAME) == 0) && (property.name == "cooperativeMatrixProperties")) {
1335+
QList<QVariant> list = property.value.toList();
1336+
for (auto i = 0; i < list.size(); i++) {
1337+
QStandardItem* entryItem = new QStandardItem();
1338+
QVariantList value = list[i].toList();
1339+
entryItem->setText("[" + QString::number(i) + "]");
1340+
addCaptionedRow(entryItem, "MSize", value[0].toString());
1341+
addCaptionedRow(entryItem, "NSize", value[1].toString());
1342+
addCaptionedRow(entryItem, "KSize", value[2].toString());
1343+
addCaptionedRow(entryItem, "AType", vulkanResources::VkComponentTypeKHRString((VkComponentTypeKHR)value[3].toInt()));
1344+
addCaptionedRow(entryItem, "BType", vulkanResources::VkComponentTypeKHRString((VkComponentTypeKHR)value[4].toInt()));
1345+
addCaptionedRow(entryItem, "CType", vulkanResources::VkComponentTypeKHRString((VkComponentTypeKHR)value[5].toInt()));
1346+
addCaptionedRow(entryItem, "ResultType", vulkanResources::VkComponentTypeKHRString((VkComponentTypeKHR)value[6].toInt()));
1347+
addVkBool32Item(entryItem,"saturatingAccumulation", value[7].toBool());
1348+
addCaptionedRow(entryItem, "scope", vulkanResources::VkScopeKHRString((VkScopeKHR)value[8].toInt()));
1349+
propertyItem.first()->appendRow(entryItem);
1350+
}
1351+
displayRawValue = false;
1352+
}
1353+
if (displayRawValue) {
1354+
propertyItem << new QStandardItem(arrayToStr(property.value));
1355+
}
13161356
}
13171357
else {
13181358
switch (property.value.type()) {

vulkanresources.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,39 @@ namespace vulkanResources {
679679
};
680680
}
681681

682+
inline QString VkComponentTypeKHRString(const VkComponentTypeKHR value)
683+
{
684+
switch (value) {
685+
#define STR(r) case VK_COMPONENT_TYPE_##r: return #r
686+
STR(FLOAT16_KHR);
687+
STR(FLOAT32_KHR);
688+
STR(FLOAT64_KHR);
689+
STR(SINT8_KHR);
690+
STR(SINT16_KHR);
691+
STR(SINT32_KHR);
692+
STR(SINT64_KHR);
693+
STR(UINT8_KHR);
694+
STR(UINT16_KHR);
695+
STR(UINT32_KHR);
696+
STR(UINT64_KHR);
697+
#undef STR
698+
default: QString::fromStdString("UNKNOWN_ENUM (" + toHexString(value) + ")");
699+
};
700+
}
701+
702+
inline QString VkScopeKHRString(const VkScopeKHR value)
703+
{
704+
switch (value) {
705+
#define STR(r) case VK_SCOPE_##r: return #r
706+
STR(DEVICE_KHR);
707+
STR(WORKGROUP_KHR);
708+
STR(SUBGROUP_KHR);
709+
STR(QUEUE_FAMILY_KHR);
710+
#undef STR
711+
default: QString::fromStdString("UNKNOWN_ENUM (" + toHexString(value) + ")");
712+
};
713+
}
714+
682715
inline std::string joinString(const char separator, const std::vector<std::string>& stringList)
683716
{
684717
std::stringstream ss;

0 commit comments

Comments
 (0)