From 97df931b43afcfb02f87a0812dd663c273e88287 Mon Sep 17 00:00:00 2001 From: Bill Hollings Date: Wed, 15 Aug 2018 13:14:43 -0400 Subject: [PATCH] vkGetPhysicalDeviceFormatProperties() return VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT if supported, even if other format properties are not. --- MoltenVK/MoltenVK/API/mvk_datatypes.h | 19 ++++++++++--------- MoltenVK/MoltenVK/GPUObjects/MVKDevice.h | 2 +- MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm | 6 ++---- MoltenVK/MoltenVK/Vulkan/mvk_datatypes.mm | 4 ++-- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/MoltenVK/MoltenVK/API/mvk_datatypes.h b/MoltenVK/MoltenVK/API/mvk_datatypes.h index 0be95ce1..c02676bc 100644 --- a/MoltenVK/MoltenVK/API/mvk_datatypes.h +++ b/MoltenVK/MoltenVK/API/mvk_datatypes.h @@ -165,17 +165,18 @@ size_t mvkMTLPixelFormatBytesPerLayer(MTLPixelFormat mtlFormat, size_t bytesPerR /** * Returns the default properties for the specified Vulkan format. * - * Not all MTLPixelFormats returned by this function are supported by all GPU's, - * and, as a result, MoltenVK may return a different value from the - * vkGetPhysicalDeviceFormatProperties() function than is returned here. + * Not all MTLPixelFormats returned by this function are supported by all GPU's, and, as a + * result, MoltenVK may return a different value from the vkGetPhysicalDeviceFormatProperties() + * function than is returned here. Use the vkGetPhysicalDeviceFormatProperties() function to + * return the properties for a particular GPU. * - * Not all macOS GPU's support the MTLPixelFormatDepth24Unorm_Stencil8 - * (VK_FORMAT_D24_UNORM_S8_UINT) pixel format. On an macOS device that has more - * than one GPU, one of the GPU's may support that format, while another may not. - * Use the vkGetPhysicalDeviceFormatProperties() function to return the properties - * for a particular GPU. + * Setting assumeGPUSupportsDefault to true allows the default format properties to be returned. + * The assumeGPUSupportsDefault flag can be set to false if it is already known that the format + * is not supported by a particular GPU for images, in which case all of the returned properties + * will be disabled, except possibly VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT, which may be supported + * for the format even without image support. */ -VkFormatProperties mvkVkFormatProperties(VkFormat vkFormat); +VkFormatProperties mvkVkFormatProperties(VkFormat vkFormat, bool assumeGPUSupportsDefault = true); /** Returns the name of the specified Vulkan format. */ const char* mvkVkFormatName(VkFormat vkFormat); diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.h b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.h index b40fe42d..7f5a8931 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.h +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.h @@ -81,7 +81,7 @@ public: /** Populates the specified structure with the properties of this device. */ void getProperties(VkPhysicalDeviceProperties* properties); - /** Returns whether the specified format is supported. */ + /** 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. */ diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm index db8fad1e..66da7007 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm @@ -85,11 +85,9 @@ bool MVKPhysicalDevice::getFormatIsSupported(VkFormat format) { return true; } -void MVKPhysicalDevice::getFormatProperties(VkFormat format, - VkFormatProperties* pFormatProperties) { - static VkFormatProperties noFmtFeats = { 0, 0, 0 }; +void MVKPhysicalDevice::getFormatProperties(VkFormat format, VkFormatProperties* pFormatProperties) { if (pFormatProperties) { - *pFormatProperties = getFormatIsSupported(format) ? mvkVkFormatProperties(format) : noFmtFeats; + *pFormatProperties = mvkVkFormatProperties(format, getFormatIsSupported(format)); } } diff --git a/MoltenVK/MoltenVK/Vulkan/mvk_datatypes.mm b/MoltenVK/MoltenVK/Vulkan/mvk_datatypes.mm index 7e4e878e..3e67654a 100644 --- a/MoltenVK/MoltenVK/Vulkan/mvk_datatypes.mm +++ b/MoltenVK/MoltenVK/Vulkan/mvk_datatypes.mm @@ -594,9 +594,9 @@ MVK_PUBLIC_SYMBOL size_t mvkMTLPixelFormatBytesPerLayer(MTLPixelFormat mtlFormat return mvkCeilingDivide(texelRowsPerLayer, formatDescForMTLPixelFormat(mtlFormat).blockTexelSize.height) * bytesPerRow; } -MVK_PUBLIC_SYMBOL VkFormatProperties mvkVkFormatProperties(VkFormat vkFormat) { +MVK_PUBLIC_SYMBOL VkFormatProperties mvkVkFormatProperties(VkFormat vkFormat, bool assumeGPUSupportsDefault) { const MVKFormatDesc& fmtDesc = formatDescForVkFormat(vkFormat); - if (fmtDesc.isSupported()) { + if (assumeGPUSupportsDefault && fmtDesc.isSupported()) { return fmtDesc.properties; } else { // If texture format is unsupported, vertex buffer format may still be.