From b817d0c6665b0bda394a5f5ad1f6a0f70af41135 Mon Sep 17 00:00:00 2001 From: sean Date: Fri, 29 Dec 2023 01:49:51 +0100 Subject: [PATCH] Add: KHR_format_feature_flags2 --- MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm | 18 ++++++++++++++- .../MoltenVK/GPUObjects/MVKPixelFormats.h | 9 ++++---- .../MoltenVK/GPUObjects/MVKPixelFormats.mm | 22 +++++++++++++++---- MoltenVK/MoltenVK/Layers/MVKExtensions.def | 1 + 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm index a47b4e626..587bc0325 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm @@ -888,6 +888,22 @@ void MVKPhysicalDevice::getFormatProperties(VkFormat format, VkFormatProperties2KHR* pFormatProperties) { pFormatProperties->sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2_KHR; + + for (auto* next = (VkBaseOutStructure*)pFormatProperties->pNext; next; next = next->pNext) { + switch (next->sType) { + case VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_3_KHR: { + auto* properties3 = (VkFormatProperties3*)next; + auto& properties = _pixelFormats.getVkFormatProperties3(format); + properties3->linearTilingFeatures = properties.linearTilingFeatures; + properties3->optimalTilingFeatures = properties.optimalTilingFeatures; + properties3->bufferFeatures = properties.bufferFeatures; + break; + } + default: + break; + } + } + getFormatProperties(format, &pFormatProperties->formatProperties); } @@ -2530,7 +2546,7 @@ } else { alignment = [_mtlDevice minimumLinearTextureAlignmentForPixelFormat: mtlFmt]; } - VkFormatProperties& props = _pixelFormats.getVkFormatProperties(vk); + VkFormatProperties props = _pixelFormats.getVkFormatProperties(vk); // For uncompressed formats, this is the size of a single texel. // Note that no implementations of Metal support compressed formats // in a linear texture (including texture buffers). It's likely that even diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.h b/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.h index 0e1ecd74d..bbc71fa5a 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.h +++ b/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.h @@ -147,7 +147,7 @@ typedef struct MVKVkFormatDesc { VkExtent2D blockTexelSize; uint32_t bytesPerBlock; MVKFormatType formatType; - VkFormatProperties properties; + VkFormatProperties3 properties; VkComponentMapping componentMapping; const char* name; bool hasReportedSubstitution; @@ -344,7 +344,8 @@ class MVKPixelFormats : public MVKBaseObject { MTLTextureSwizzleChannels getMTLTextureSwizzleChannels(VkFormat vkFormat); /** Returns the default properties for the specified Vulkan format. */ - VkFormatProperties& getVkFormatProperties(VkFormat vkFormat); + VkFormatProperties getVkFormatProperties(VkFormat format); + VkFormatProperties3& getVkFormatProperties3(VkFormat vkFormat); /** Returns the Metal format capabilities supported by the specified Vulkan format, without substitution. */ MVKMTLFmtCaps getCapabilities(VkFormat vkFormat, bool isExtended = false); @@ -404,8 +405,8 @@ class MVKPixelFormats : public MVKBaseObject { * Vulkan VkFormat as used as a vertex attribute format. */ MTLVertexFormat getMTLVertexFormat(VkFormat vkFormat); - - + + static VkFormatFeatureFlags convertFormatPropertiesFlagBits(VkFormatFeatureFlags2 flags); #pragma mark Construction MVKPixelFormats(MVKPhysicalDevice* physicalDevice = nullptr); diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm b/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm index ce60ba3e7..e6004b517 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm @@ -420,10 +420,19 @@ return mvkMTLTextureSwizzleChannelsFromVkComponentMapping(getVkComponentMapping(vkFormat)); } -VkFormatProperties& MVKPixelFormats::getVkFormatProperties(VkFormat vkFormat) { +VkFormatProperties3& MVKPixelFormats::getVkFormatProperties3(VkFormat vkFormat) { return getVkFormatDesc(vkFormat).properties; } +VkFormatProperties MVKPixelFormats::getVkFormatProperties(VkFormat vkFormat) { + auto& properties = getVkFormatProperties3(vkFormat); + VkFormatProperties ret; + ret.linearTilingFeatures = MVKPixelFormats::convertFormatPropertiesFlagBits(properties.linearTilingFeatures); + ret.optimalTilingFeatures = MVKPixelFormats::convertFormatPropertiesFlagBits(properties.optimalTilingFeatures); + ret.bufferFeatures = MVKPixelFormats::convertFormatPropertiesFlagBits(properties.bufferFeatures); + return ret; +} + MVKMTLFmtCaps MVKPixelFormats::getCapabilities(VkFormat vkFormat, bool isExtended) { return getCapabilities(getVkFormatDesc(vkFormat).mtlPixelFormat, isExtended); } @@ -460,7 +469,7 @@ } void MVKPixelFormats::enumerateSupportedFormats(VkFormatProperties properties, bool any, std::function func) { - static const auto areFeaturesSupported = [any](uint32_t a, uint32_t b) { + static const auto areFeaturesSupported = [any](VkFlags64 a, VkFlags64 b) { if (b == 0) return true; if (any) return mvkIsAnyFlagEnabled(a, b); @@ -792,6 +801,11 @@ return _mtlVertexFormatDescriptions[fmtIdx]; } +VkFormatFeatureFlags MVKPixelFormats::convertFormatPropertiesFlagBits(VkFormatFeatureFlags2 flags) { + // Truncate to 32-bits and just return. All current values are identical. + return static_cast(flags); +} + #pragma mark Construction @@ -811,7 +825,7 @@ #define addVkFormatDescFull(VK_FMT, MTL_FMT, MTL_FMT_ALT, MTL_VTX_FMT, MTL_VTX_FMT_ALT, CSPC, CSCB, BLK_W, BLK_H, BLK_BYTE_CNT, MVK_FMT_TYPE, SWIZ_R, SWIZ_G, SWIZ_B, SWIZ_A) \ MVKAssert(fmtIdx < _vkFormatCount, "Attempting to describe %d VkFormats, but only have space for %d. Increase the value of _vkFormatCount", fmtIdx + 1, _vkFormatCount); \ _vkFormatDescriptions[fmtIdx++] = { VK_FORMAT_ ##VK_FMT, MTLPixelFormat ##MTL_FMT, MTLPixelFormat ##MTL_FMT_ALT, MTLVertexFormat ##MTL_VTX_FMT, MTLVertexFormat ##MTL_VTX_FMT_ALT, \ - CSPC, CSCB, { BLK_W, BLK_H }, BLK_BYTE_CNT, kMVKFormat ##MVK_FMT_TYPE, { 0, 0, 0 }, \ + CSPC, CSCB, { BLK_W, BLK_H }, BLK_BYTE_CNT, kMVKFormat ##MVK_FMT_TYPE, { VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_3, nullptr, 0, 0, 0 }, \ { VK_COMPONENT_SWIZZLE_ ##SWIZ_R, VK_COMPONENT_SWIZZLE_ ##SWIZ_G, VK_COMPONENT_SWIZZLE_ ##SWIZ_B, VK_COMPONENT_SWIZZLE_ ##SWIZ_A }, \ "VK_FORMAT_" #VK_FMT, false } @@ -2119,7 +2133,7 @@ mvkEnableFlags(VK_FEATS, kMVKVkFormatFeatureFlags ##TYPE ##CAP); \ } - VkFormatProperties& vkProps = vkDesc.properties; + VkFormatProperties3& vkProps = vkDesc.properties; MVKMTLFmtCaps mtlPixFmtCaps = getMTLPixelFormatDesc(vkDesc.mtlPixelFormat).mtlFmtCaps; vkProps.optimalTilingFeatures = kMVKVkFormatFeatureFlagsTexNone; vkProps.linearTilingFeatures = kMVKVkFormatFeatureFlagsTexNone; diff --git a/MoltenVK/MoltenVK/Layers/MVKExtensions.def b/MoltenVK/MoltenVK/Layers/MVKExtensions.def index c9917b79a..bbda1dcfa 100644 --- a/MoltenVK/MoltenVK/Layers/MVKExtensions.def +++ b/MoltenVK/MoltenVK/Layers/MVKExtensions.def @@ -63,6 +63,7 @@ MVK_EXTENSION(KHR_external_memory_capabilities, KHR_EXTERNAL_MEMORY_CAPABI MVK_EXTENSION(KHR_external_semaphore, KHR_EXTERNAL_SEMAPHORE, DEVICE, 10.11, 8.0, 1.0) MVK_EXTENSION(KHR_external_semaphore_capabilities, KHR_EXTERNAL_SEMAPHORE_CAPABILITIES, INSTANCE, 10.11, 8.0, 1.0) MVK_EXTENSION(KHR_fragment_shader_barycentric, KHR_FRAGMENT_SHADER_BARYCENTRIC, DEVICE, 10.15, 14.0, 1.0) +MVK_EXTENSION(KHR_format_feature_flags2, KHR_FORMAT_FEATURE_FLAGS_2, DEVICE, 10.11, 8.0, 1.0) MVK_EXTENSION(KHR_get_memory_requirements2, KHR_GET_MEMORY_REQUIREMENTS_2, DEVICE, 10.11, 8.0, 1.0) MVK_EXTENSION(KHR_get_physical_device_properties2, KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2, INSTANCE, 10.11, 8.0, 1.0) MVK_EXTENSION(KHR_get_surface_capabilities2, KHR_GET_SURFACE_CAPABILITIES_2, INSTANCE, 10.11, 8.0, 1.0)