Support the VK_KHR_get_physical_device_properties2 extension.

This extension is a prerequisite for multiple other extensions, the
`VK_KHR_push_descriptor` extension in particular.
This commit is contained in:
Chip Davis 2018-08-27 12:36:57 -05:00
parent 0f55290829
commit 80bde624cf
5 changed files with 184 additions and 0 deletions

View File

@ -75,18 +75,27 @@ public:
/** Populates the specified structure with the features of this device. */
void getFeatures(VkPhysicalDeviceFeatures* features);
/** Populates the specified structure with the features of this device. */
void getFeatures(VkPhysicalDeviceFeatures2KHR* features);
/** Populates the specified structure with the Metal-specific features of this device. */
void getMetalFeatures(MVKPhysicalDeviceMetalFeatures* mtlFeatures);
/** Populates the specified structure with the properties of this device. */
void getProperties(VkPhysicalDeviceProperties* properties);
/** Populates the specified structure with the properties of this device. */
void getProperties(VkPhysicalDeviceProperties2KHR* properties);
/** Returns whether the specified format is supported on this device. */
bool getFormatIsSupported(VkFormat format);
/** Populates the specified structure with the format properties of this device. */
void getFormatProperties(VkFormat format, VkFormatProperties* pFormatProperties);
/** Populates the specified structure with the format properties of this device. */
void getFormatProperties(VkFormat format, VkFormatProperties2KHR* pFormatProperties);
/**
* Populates the specified structure with the image format properties
* supported for the specified image characteristics on this device.
@ -98,6 +107,13 @@ public:
VkImageCreateFlags flags,
VkImageFormatProperties* pImageFormatProperties);
/**
* Populates the specified structure with the image format properties
* supported for the specified image characteristics on this device.
*/
VkResult getImageFormatProperties(const VkPhysicalDeviceImageFormatInfo2KHR* pImageFormatInfo,
VkImageFormatProperties2KHR* pImageFormatProperties);
#pragma mark Surfaces
/**
@ -158,6 +174,20 @@ public:
*/
VkResult getQueueFamilyProperties(uint32_t* pCount, VkQueueFamilyProperties* properties);
/**
* If properties is null, the value of pCount is updated with the number of
* queue families supported by this instance.
*
* If properties is not null, then pCount queue family properties are copied into the
* array. If the number of available queue families is less than pCount, the value of
* pCount is updated to indicate the number of queue families actually returned in the array.
*
* Returns VK_SUCCESS if successful. Returns VK_INCOMPLETE if the number of queue families
* available in this instance is larger than the specified pCount. Returns other values if
* an error occurs.
*/
VkResult getQueueFamilyProperties(uint32_t* pCount, VkQueueFamilyProperties2KHR* properties);
/** Returns a pointer to the Vulkan instance. */
inline MVKInstance* getInstance() { return _mvkInstance; }
@ -173,6 +203,9 @@ public:
/** Populates the specified memory properties with the memory characteristics of this device. */
VkResult getPhysicalDeviceMemoryProperties(VkPhysicalDeviceMemoryProperties* pMemoryProperties);
/** Populates the specified memory properties with the memory characteristics of this device. */
VkResult getPhysicalDeviceMemoryProperties(VkPhysicalDeviceMemoryProperties2KHR* pMemoryProperties);
/**
* Returns a bit mask of all memory type indices.
* Each bit [0..31] in the returned bit mask indicates a distinct memory type.

View File

@ -58,6 +58,13 @@ void MVKPhysicalDevice::getFeatures(VkPhysicalDeviceFeatures* features) {
if (features) { *features = _features; }
}
void MVKPhysicalDevice::getFeatures(VkPhysicalDeviceFeatures2KHR* features) {
if (features) {
features->sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR;
features->features = _features;
}
}
void MVKPhysicalDevice::getMetalFeatures(MVKPhysicalDeviceMetalFeatures* mtlFeatures) {
if (mtlFeatures) { *mtlFeatures = _metalFeatures; }
}
@ -66,6 +73,13 @@ void MVKPhysicalDevice::getProperties(VkPhysicalDeviceProperties* properties) {
if (properties) { *properties = _properties; }
}
void MVKPhysicalDevice::getProperties(VkPhysicalDeviceProperties2KHR* properties) {
if (properties) {
properties->sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR;
properties->properties = _properties;
}
}
bool MVKPhysicalDevice::getFormatIsSupported(VkFormat format) {
if ( !mvkVkFormatIsSupported(format) ) { return false; }
@ -91,6 +105,15 @@ void MVKPhysicalDevice::getFormatProperties(VkFormat format, VkFormatProperties*
}
}
void MVKPhysicalDevice::getFormatProperties(VkFormat format,
VkFormatProperties2KHR* pFormatProperties) {
static VkFormatProperties noFmtFeats = { 0, 0, 0 };
if (pFormatProperties) {
pFormatProperties->sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2_KHR;
pFormatProperties->formatProperties = getFormatIsSupported(format) ? mvkVkFormatProperties(format) : noFmtFeats;
}
}
VkResult MVKPhysicalDevice::getImageFormatProperties(VkFormat format,
VkImageType type,
VkImageTiling tiling,
@ -148,6 +171,25 @@ VkResult MVKPhysicalDevice::getImageFormatProperties(VkFormat format,
return VK_SUCCESS;
}
VkResult MVKPhysicalDevice::getImageFormatProperties(const VkPhysicalDeviceImageFormatInfo2KHR *pImageFormatInfo,
VkImageFormatProperties2KHR* pImageFormatProperties) {
if ( !pImageFormatInfo || pImageFormatInfo->sType != VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2_KHR ) {
return VK_ERROR_FORMAT_NOT_SUPPORTED;
}
if ( !getFormatIsSupported(pImageFormatInfo->format) ) { return VK_ERROR_FORMAT_NOT_SUPPORTED; }
if ( !pImageFormatProperties ) {
return VK_SUCCESS;
}
pImageFormatProperties->sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2_KHR;
return getImageFormatProperties(pImageFormatInfo->format, pImageFormatInfo->type,
pImageFormatInfo->tiling, pImageFormatInfo->usage,
pImageFormatInfo->flags,
&pImageFormatProperties->imageFormatProperties);
}
#pragma mark Surfaces
@ -293,6 +335,31 @@ VkResult MVKPhysicalDevice::getQueueFamilyProperties(uint32_t* pCount,
return (*pCount <= qfCnt) ? VK_SUCCESS : VK_INCOMPLETE;
}
VkResult MVKPhysicalDevice::getQueueFamilyProperties(uint32_t* pCount,
VkQueueFamilyProperties2KHR* queueProperties) {
uint32_t qfCnt = uint32_t(_queueFamilies.size());
// If properties aren't actually being requested yet, simply update the returned count
if ( !queueProperties ) {
*pCount = qfCnt;
return VK_SUCCESS;
}
// Determine how many families we'll return, and return that number
*pCount = min(*pCount, qfCnt);
// Now populate the queue families
if (queueProperties) {
for (uint32_t qfIdx = 0; qfIdx < *pCount; qfIdx++) {
queueProperties[qfIdx].sType = VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2_KHR;
_queueFamilies[qfIdx]->getProperties(&queueProperties[qfIdx].queueFamilyProperties);
}
}
return (*pCount <= qfCnt) ? VK_SUCCESS : VK_INCOMPLETE;
}
#pragma mark Memory models
@ -302,6 +369,14 @@ VkResult MVKPhysicalDevice::getPhysicalDeviceMemoryProperties(VkPhysicalDeviceMe
return VK_SUCCESS;
}
VkResult MVKPhysicalDevice::getPhysicalDeviceMemoryProperties(VkPhysicalDeviceMemoryProperties2KHR* pMemoryProperties) {
if (pMemoryProperties) {
pMemoryProperties->sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2_KHR;
pMemoryProperties->memoryProperties = _memoryProperties;
}
return VK_SUCCESS;
}
#pragma mark Construction

View File

@ -242,6 +242,13 @@ void MVKInstance::initProcAddrs() {
ADD_PROC_ADDR(vkAcquireNextImageKHR);
ADD_PROC_ADDR(vkQueuePresentKHR);
ADD_PROC_ADDR(vkTrimCommandPoolKHR);
ADD_PROC_ADDR(vkGetPhysicalDeviceFeatures2KHR);
ADD_PROC_ADDR(vkGetPhysicalDeviceProperties2KHR);
ADD_PROC_ADDR(vkGetPhysicalDeviceFormatProperties2KHR);
ADD_PROC_ADDR(vkGetPhysicalDeviceImageFormatProperties2KHR);
ADD_PROC_ADDR(vkGetPhysicalDeviceQueueFamilyProperties2KHR);
ADD_PROC_ADDR(vkGetPhysicalDeviceMemoryProperties2KHR);
ADD_PROC_ADDR(vkGetPhysicalDeviceSparseImageFormatProperties2KHR);
ADD_PROC_ADDR(vkGetMoltenVKConfigurationMVK);
ADD_PROC_ADDR(vkSetMoltenVKConfigurationMVK);
ADD_PROC_ADDR(vkGetPhysicalDeviceMetalFeaturesMVK);

View File

@ -102,6 +102,11 @@ MVKLayer::MVKLayer() {
extTmplt.specVersion = VK_KHR_SHADER_DRAW_PARAMETERS_SPEC_VERSION;
_extensions.push_back(extTmplt);
memset(extTmplt.extensionName, 0, sizeof(extTmplt.extensionName));
strcpy(extTmplt.extensionName, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
extTmplt.specVersion = VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_SPEC_VERSION;
_extensions.push_back(extTmplt);
#if MVK_IOS
memset(extTmplt.extensionName, 0, sizeof(extTmplt.extensionName));
strcpy(extTmplt.extensionName, VK_MVK_IOS_SURFACE_EXTENSION_NAME);

View File

@ -1613,6 +1613,70 @@ MVK_PUBLIC_SYMBOL void vkTrimCommandPoolKHR(
}
#pragma mark -
#pragma mark VK_KHR_get_physical_device_properties2 extension
MVK_PUBLIC_SYMBOL void vkGetPhysicalDeviceFeatures2KHR(
VkPhysicalDevice physicalDevice,
VkPhysicalDeviceFeatures2KHR* pFeatures) {
MVKPhysicalDevice* mvkPD = MVKPhysicalDevice::getMVKPhysicalDevice(physicalDevice);
mvkPD->getFeatures(pFeatures);
}
MVK_PUBLIC_SYMBOL void vkGetPhysicalDeviceProperties2KHR(
VkPhysicalDevice physicalDevice,
VkPhysicalDeviceProperties2KHR* pProperties) {
MVKPhysicalDevice* mvkPD = MVKPhysicalDevice::getMVKPhysicalDevice(physicalDevice);
mvkPD->getProperties(pProperties);
}
MVK_PUBLIC_SYMBOL void vkGetPhysicalDeviceFormatProperties2KHR(
VkPhysicalDevice physicalDevice,
VkFormat format,
VkFormatProperties2KHR* pFormatProperties) {
MVKPhysicalDevice* mvkPD = MVKPhysicalDevice::getMVKPhysicalDevice(physicalDevice);
mvkPD->getFormatProperties(format, pFormatProperties);
}
MVK_PUBLIC_SYMBOL VkResult vkGetPhysicalDeviceImageFormatProperties2KHR(
VkPhysicalDevice physicalDevice,
const VkPhysicalDeviceImageFormatInfo2KHR* pImageFormatInfo,
VkImageFormatProperties2KHR* pImageFormatProperties) {
MVKPhysicalDevice* mvkPD = MVKPhysicalDevice::getMVKPhysicalDevice(physicalDevice);
return mvkPD->getImageFormatProperties(pImageFormatInfo, pImageFormatProperties);
}
MVK_PUBLIC_SYMBOL void vkGetPhysicalDeviceQueueFamilyProperties2KHR(
VkPhysicalDevice physicalDevice,
uint32_t* pQueueFamilyPropertyCount,
VkQueueFamilyProperties2KHR* pQueueFamilyProperties) {
MVKPhysicalDevice* mvkPD = MVKPhysicalDevice::getMVKPhysicalDevice(physicalDevice);
mvkPD->getQueueFamilyProperties(pQueueFamilyPropertyCount, pQueueFamilyProperties);
}
MVK_PUBLIC_SYMBOL void vkGetPhysicalDeviceMemoryProperties2KHR(
VkPhysicalDevice physicalDevice,
VkPhysicalDeviceMemoryProperties2KHR* pMemoryProperties) {
MVKPhysicalDevice* mvkPD = MVKPhysicalDevice::getMVKPhysicalDevice(physicalDevice);
mvkPD->getPhysicalDeviceMemoryProperties(pMemoryProperties);
}
MVK_PUBLIC_SYMBOL void vkGetPhysicalDeviceSparseImageFormatProperties2KHR(
VkPhysicalDevice physicalDevice,
const VkPhysicalDeviceSparseImageFormatInfo2KHR* pFormatInfo,
uint32_t* pPropertyCount,
VkSparseImageFormatProperties2KHR* pProperties) {
MVKLogUnimplemented("vkGetPhysicalDeviceSparseImageFormatProperties");
}
#pragma mark -
#pragma mark Loader and Layer ICD interface extension