From 51afe4745e3f8fd9234be01d01cee4b8c6228248 Mon Sep 17 00:00:00 2001 From: Chip Davis Date: Wed, 28 Oct 2020 15:25:59 -0500 Subject: [PATCH 1/8] Enable VK_AMD_shader_image_load_store_lod for Apple Silicon on Mac. --- Docs/MoltenVK_Runtime_UserGuide.md | 2 +- Docs/Whats_New.md | 1 + MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm | 1 + MoltenVK/MoltenVK/Layers/MVKExtensions.mm | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Docs/MoltenVK_Runtime_UserGuide.md b/Docs/MoltenVK_Runtime_UserGuide.md index c4b6da05..92a18630 100644 --- a/Docs/MoltenVK_Runtime_UserGuide.md +++ b/Docs/MoltenVK_Runtime_UserGuide.md @@ -324,7 +324,7 @@ In addition to core *Vulkan* functionality, **MoltenVK** also supports the foll - `VK_MVK_moltenvk` - `VK_AMD_gpu_shader_half_float` - `VK_AMD_negative_viewport_height` -- `VK_AMD_shader_image_load_store_lod` *(iOS and tvOS)* +- `VK_AMD_shader_image_load_store_lod` *(requires Apple GPU)* - `VK_AMD_shader_trinary_minmax` *(requires Metal 2.1)* - `VK_IMG_format_pvrtc` *(requires Apple GPU)* - `VK_INTEL_shader_integer_functions2` diff --git a/Docs/Whats_New.md b/Docs/Whats_New.md index bb11f8ae..1426546e 100644 --- a/Docs/Whats_New.md +++ b/Docs/Whats_New.md @@ -21,6 +21,7 @@ Released TBD - Add support for extensions: - `VK_EXT_descriptor_indexing` (initial release limited to Metal Tier 1: 96/128 textures, 16 samplers) - `VK_EXT_private_data` + - `VK_AMD_shader_image_load_store` (macOS) - `VK_IMG_format_pvrtc` (macOS) - Use `VK_KHR_image_format_list` to disable `MTLTextureUsagePixelFormatView` if only swizzles or `sRGB` conversion will be used for image views, improving diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm index 22ce772e..c86739cd 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm @@ -2499,6 +2499,7 @@ void MVKPhysicalDevice::initExtensions() { } #if MVK_MACOS if (!supportsMTLGPUFamily(Apple5)) { + pWritableExtns->vk_AMD_shader_image_load_store_lod.enabled = false; pWritableExtns->vk_IMG_format_pvrtc.enabled = false; } #endif diff --git a/MoltenVK/MoltenVK/Layers/MVKExtensions.mm b/MoltenVK/MoltenVK/Layers/MVKExtensions.mm index 913ea99f..ac3768ea 100644 --- a/MoltenVK/MoltenVK/Layers/MVKExtensions.mm +++ b/MoltenVK/MoltenVK/Layers/MVKExtensions.mm @@ -49,7 +49,6 @@ static bool mvkIsSupportedOnPlatform(VkExtensionProperties* pProperties) { #if MVK_MACOS if (pProperties == &kVkExtProps_MVK_IOS_SURFACE) { return false; } if (pProperties == &kVkExtProps_EXT_POST_DEPTH_COVERAGE) { return false; } - if (pProperties == &kVkExtProps_AMD_SHADER_IMAGE_LOAD_STORE_LOD) { return false; } if (pProperties == &kVkExtProps_KHR_SHADER_SUBGROUP_EXTENDED_TYPES) { return mvkOSVersionIsAtLeast(10.14); } if (pProperties == &kVkExtProps_EXT_HDR_METADATA) { return mvkOSVersionIsAtLeast(10.15); } @@ -57,6 +56,7 @@ static bool mvkIsSupportedOnPlatform(VkExtensionProperties* pProperties) { if (pProperties == &kVkExtProps_EXT_MEMORY_BUDGET) { return mvkOSVersionIsAtLeast(10.13); } if (pProperties == &kVkExtProps_EXT_SHADER_STENCIL_EXPORT) { return mvkOSVersionIsAtLeast(10.14); } if (pProperties == &kVkExtProps_EXT_TEXEL_BUFFER_ALIGNMENT) { return mvkOSVersionIsAtLeast(10.13); } + if (pProperties == &kVkExtProps_AMD_SHADER_IMAGE_LOAD_STORE_LOD) { return mvkOSVersionIsAtLeast(10.16); } if (pProperties == &kVkExtProps_AMD_SHADER_TRINARY_MINMAX) { return mvkOSVersionIsAtLeast(10.14); } if (pProperties == &kVkExtProps_IMG_FORMAT_PVRTC) { return mvkOSVersionIsAtLeast(10.16); } #endif From 8bb9db2dce3419b995fe5c922464da2876dfb473 Mon Sep 17 00:00:00 2001 From: Chip Davis Date: Wed, 28 Oct 2020 15:44:59 -0500 Subject: [PATCH 2/8] Enable VK_EXT_post_depth_coverage for Apple Silicon on Mac. --- Docs/MoltenVK_Runtime_UserGuide.md | 2 +- Docs/Whats_New.md | 1 + MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm | 1 + MoltenVK/MoltenVK/Layers/MVKExtensions.mm | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Docs/MoltenVK_Runtime_UserGuide.md b/Docs/MoltenVK_Runtime_UserGuide.md index 92a18630..e7f2d092 100644 --- a/Docs/MoltenVK_Runtime_UserGuide.md +++ b/Docs/MoltenVK_Runtime_UserGuide.md @@ -310,7 +310,7 @@ In addition to core *Vulkan* functionality, **MoltenVK** also supports the foll - `VK_EXT_inline_uniform_block` - `VK_EXT_memory_budget` *(requires Metal 2.0)* - `VK_EXT_metal_surface` -- `VK_EXT_post_depth_coverage` *(iOS, requires GPU family 4)* +- `VK_EXT_post_depth_coverage` *(iOS and macOS, requires family 4 (A11) or better Apple GPU)* - `VK_EXT_private_data ` - `VK_EXT_robustness2` - `VK_EXT_scalar_block_layout` diff --git a/Docs/Whats_New.md b/Docs/Whats_New.md index 1426546e..34819ae1 100644 --- a/Docs/Whats_New.md +++ b/Docs/Whats_New.md @@ -20,6 +20,7 @@ Released TBD - Add support for extensions: - `VK_EXT_descriptor_indexing` (initial release limited to Metal Tier 1: 96/128 textures, 16 samplers) + - `VK_EXT_post_depth_coverage` (macOS) - `VK_EXT_private_data` - `VK_AMD_shader_image_load_store` (macOS) - `VK_IMG_format_pvrtc` (macOS) diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm index c86739cd..dd4f1fc1 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm @@ -1347,6 +1347,7 @@ void MVKPhysicalDevice::initMetalFeatures() { _metalFeatures.mtlCopyBufferAlignment = 1; _metalFeatures.mtlBufferAlignment = 16; _metalFeatures.maxPerStageDynamicMTLBufferCount = _metalFeatures.maxPerStageBufferCount; + _metalFeatures.postDepthCoverage = true; } } #endif diff --git a/MoltenVK/MoltenVK/Layers/MVKExtensions.mm b/MoltenVK/MoltenVK/Layers/MVKExtensions.mm index ac3768ea..39a4bb5d 100644 --- a/MoltenVK/MoltenVK/Layers/MVKExtensions.mm +++ b/MoltenVK/MoltenVK/Layers/MVKExtensions.mm @@ -48,12 +48,12 @@ static VkExtensionProperties kVkExtProps_ ##EXT = mvkMakeExtProps(VK_ ##EXT ##_E static bool mvkIsSupportedOnPlatform(VkExtensionProperties* pProperties) { #if MVK_MACOS if (pProperties == &kVkExtProps_MVK_IOS_SURFACE) { return false; } - if (pProperties == &kVkExtProps_EXT_POST_DEPTH_COVERAGE) { return false; } if (pProperties == &kVkExtProps_KHR_SHADER_SUBGROUP_EXTENDED_TYPES) { return mvkOSVersionIsAtLeast(10.14); } if (pProperties == &kVkExtProps_EXT_HDR_METADATA) { return mvkOSVersionIsAtLeast(10.15); } if (pProperties == &kVkExtProps_EXT_FRAGMENT_SHADER_INTERLOCK) { return mvkOSVersionIsAtLeast(10.13); } if (pProperties == &kVkExtProps_EXT_MEMORY_BUDGET) { return mvkOSVersionIsAtLeast(10.13); } + if (pProperties == &kVkExtProps_EXT_POST_DEPTH_COVERAGE) { return mvkOSVersionIsAtLeast(10.16); } if (pProperties == &kVkExtProps_EXT_SHADER_STENCIL_EXPORT) { return mvkOSVersionIsAtLeast(10.14); } if (pProperties == &kVkExtProps_EXT_TEXEL_BUFFER_ALIGNMENT) { return mvkOSVersionIsAtLeast(10.13); } if (pProperties == &kVkExtProps_AMD_SHADER_IMAGE_LOAD_STORE_LOD) { return mvkOSVersionIsAtLeast(10.16); } From 23f113f1cd94e1ae7f1b4276eaae752e9e382c42 Mon Sep 17 00:00:00 2001 From: Chip Davis Date: Thu, 29 Oct 2020 23:51:29 -0500 Subject: [PATCH 3/8] MVKPipelineLayout: Only set configuration result if validating. Fixes a race condition picked up by `tsan`. --- MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.mm | 6 +++--- MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm | 14 ++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.mm index b8a4b940..e5a00ba4 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.mm @@ -32,7 +32,7 @@ uint32_t MVKDescriptorSetLayout::bindDescriptorSet(MVKCommandEncoder* cmdEncoder MVKShaderResourceBinding& dslMTLRezIdxOffsets, MVKArrayRef dynamicOffsets, uint32_t dynamicOffsetIndex) { - clearConfigurationResult(); + if (!cmdEncoder) { clearConfigurationResult(); } uint32_t dynOffsetsConsumed = 0; if ( !_isPushDescriptorLayout ) { for (auto& dslBind : _bindings) { @@ -91,7 +91,7 @@ void MVKDescriptorSetLayout::pushDescriptorSet(MVKCommandEncoder* cmdEncoder, if (!_isPushDescriptorLayout) return; - clearConfigurationResult(); + if (!cmdEncoder) { clearConfigurationResult(); } for (const VkWriteDescriptorSet& descWrite : descriptorWrites) { uint32_t dstBinding = descWrite.dstBinding; uint32_t dstArrayElement = descWrite.dstArrayElement; @@ -142,7 +142,7 @@ void MVKDescriptorSetLayout::pushDescriptorSet(MVKCommandEncoder* cmdEncoder, descUpdateTemplate->getType() != VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR) return; - clearConfigurationResult(); + if (!cmdEncoder) { clearConfigurationResult(); } for (uint32_t i = 0; i < descUpdateTemplate->getNumberOfEntries(); i++) { const VkDescriptorUpdateTemplateEntryKHR* pEntry = descUpdateTemplate->getEntry(i); uint32_t dstBinding = pEntry->dstBinding; diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm b/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm index a0c6e9b0..34b9cae2 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm @@ -41,7 +41,7 @@ void MVKPipelineLayout::bindDescriptorSets(MVKCommandEncoder* cmdEncoder, MVKArrayRef descriptorSets, uint32_t firstSet, MVKArrayRef dynamicOffsets) { - clearConfigurationResult(); + if (!cmdEncoder) { clearConfigurationResult(); } uint32_t dynamicOffsetIndex = 0; size_t dsCnt = descriptorSets.size; for (uint32_t dsIdx = 0; dsIdx < dsCnt; dsIdx++) { @@ -51,7 +51,9 @@ void MVKPipelineLayout::bindDescriptorSets(MVKCommandEncoder* cmdEncoder, dynamicOffsetIndex += dsl->bindDescriptorSet(cmdEncoder, descSet, _dslMTLResourceIndexOffsets[dslIdx], dynamicOffsets, dynamicOffsetIndex); - setConfigurationResult(dsl->getConfigurationResult()); + if (!cmdEncoder && dsl->getConfigurationResult() != VK_SUCCESS) { + setConfigurationResult(dsl->getConfigurationResult()); + } } } @@ -59,10 +61,10 @@ void MVKPipelineLayout::bindDescriptorSets(MVKCommandEncoder* cmdEncoder, void MVKPipelineLayout::pushDescriptorSet(MVKCommandEncoder* cmdEncoder, MVKArrayRef descriptorWrites, uint32_t set) { - clearConfigurationResult(); + if (!cmdEncoder) { clearConfigurationResult(); } MVKDescriptorSetLayout* dsl = _descriptorSetLayouts[set]; dsl->pushDescriptorSet(cmdEncoder, descriptorWrites, _dslMTLResourceIndexOffsets[set]); - setConfigurationResult(dsl->getConfigurationResult()); + if (!cmdEncoder) { setConfigurationResult(dsl->getConfigurationResult()); } } // A null cmdEncoder can be passed to perform a validation pass @@ -70,10 +72,10 @@ void MVKPipelineLayout::pushDescriptorSet(MVKCommandEncoder* cmdEncoder, MVKDescriptorUpdateTemplate* descUpdateTemplate, uint32_t set, const void* pData) { - clearConfigurationResult(); + if (!cmdEncoder) { clearConfigurationResult(); } MVKDescriptorSetLayout* dsl = _descriptorSetLayouts[set]; dsl->pushDescriptorSet(cmdEncoder, descUpdateTemplate, pData, _dslMTLResourceIndexOffsets[set]); - setConfigurationResult(dsl->getConfigurationResult()); + if (!cmdEncoder) { setConfigurationResult(dsl->getConfigurationResult()); } } void MVKPipelineLayout::populateShaderConverterContext(SPIRVToMSLConversionConfiguration& context) { From 75129b849b346888b594b782b0610d60adb57496 Mon Sep 17 00:00:00 2001 From: Chip Davis Date: Wed, 28 Oct 2020 20:45:04 -0500 Subject: [PATCH 4/8] Support the VK_EXT_texture_compression_astc_hdr extension. Requires Apple family 6. This adds one too many `MTLPixelFormats`, so I bumped the `_mtlPixelFormatCount`. Fixes #738. --- Docs/MoltenVK_Runtime_UserGuide.md | 1 + Docs/Whats_New.md | 1 + MoltenVK/MoltenVK/API/vk_mvk_moltenvk.h | 1 + MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm | 14 ++++ .../MoltenVK/GPUObjects/MVKPixelFormats.h | 2 +- .../MoltenVK/GPUObjects/MVKPixelFormats.mm | 71 +++++++++++++++++++ MoltenVK/MoltenVK/Layers/MVKExtensions.def | 1 + MoltenVK/MoltenVK/Layers/MVKExtensions.mm | 2 + 8 files changed, 92 insertions(+), 1 deletion(-) diff --git a/Docs/MoltenVK_Runtime_UserGuide.md b/Docs/MoltenVK_Runtime_UserGuide.md index e7f2d092..a63ab3e0 100644 --- a/Docs/MoltenVK_Runtime_UserGuide.md +++ b/Docs/MoltenVK_Runtime_UserGuide.md @@ -319,6 +319,7 @@ In addition to core *Vulkan* functionality, **MoltenVK** also supports the foll - `VK_EXT_swapchain_colorspace` - `VK_EXT_vertex_attribute_divisor` - `VK_EXT_texel_buffer_alignment` *(requires Metal 2.0)* +- `VK_EXT_texture_compression_astc_hdr` *(iOS and macOS, requires family 6 (A13) or better Apple GPU)* - `VK_MVK_ios_surface` *(iOS) (Obsolete. Use `VK_EXT_metal_surface` instead.)* - `VK_MVK_macos_surface` *(macOS) (Obsolete. Use `VK_EXT_metal_surface` instead.)* - `VK_MVK_moltenvk` diff --git a/Docs/Whats_New.md b/Docs/Whats_New.md index 34819ae1..09b26658 100644 --- a/Docs/Whats_New.md +++ b/Docs/Whats_New.md @@ -22,6 +22,7 @@ Released TBD - `VK_EXT_descriptor_indexing` (initial release limited to Metal Tier 1: 96/128 textures, 16 samplers) - `VK_EXT_post_depth_coverage` (macOS) - `VK_EXT_private_data` + - `VK_EXT_texture_compression_astc_hdr` - `VK_AMD_shader_image_load_store` (macOS) - `VK_IMG_format_pvrtc` (macOS) - Use `VK_KHR_image_format_list` to disable `MTLTextureUsagePixelFormatView` diff --git a/MoltenVK/MoltenVK/API/vk_mvk_moltenvk.h b/MoltenVK/MoltenVK/API/vk_mvk_moltenvk.h index fbe42f9a..220006ac 100644 --- a/MoltenVK/MoltenVK/API/vk_mvk_moltenvk.h +++ b/MoltenVK/MoltenVK/API/vk_mvk_moltenvk.h @@ -627,6 +627,7 @@ typedef struct { VkBool32 stencilResolve; /**< If true, resolving stencil textures with filters other than Sample0 is supported. */ uint32_t maxPerStageDynamicMTLBufferCount; /**< The maximum number of inline buffers that can be set on a command buffer. */ uint32_t maxPerStageStorageTextureCount; /**< The total number of per-stage Metal textures with read-write access available for writing to from a shader. */ + VkBool32 astcHDRTextures; /**< If true, ASTC HDR pixel formats are supported. */ } MVKPhysicalDeviceMetalFeatures; /** MoltenVK performance of a particular type of activity. */ diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm index dd4f1fc1..bb756bc5 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm @@ -197,6 +197,11 @@ void MVKPhysicalDevice::getFeatures(VkPhysicalDeviceFeatures2* features) { texelBuffAlignFeatures->texelBufferAlignment = _metalFeatures.texelBuffers && [_mtlDevice respondsToSelector: @selector(minimumLinearTextureAlignmentForPixelFormat:)]; break; } + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXTURE_COMPRESSION_ASTC_HDR_FEATURES_EXT: { + auto* astcHDRFeatures = (VkPhysicalDeviceTextureCompressionASTCHDRFeaturesEXT*)next; + astcHDRFeatures->textureCompressionASTC_HDR = _metalFeatures.astcHDRTextures; + break; + } case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT: { auto* divisorFeatures = (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT*)next; divisorFeatures->vertexAttributeInstanceRateDivisor = true; @@ -1261,6 +1266,9 @@ void MVKPhysicalDevice::initMetalFeatures() { if (supportsMTLGPUFamily(Apple4)) { _metalFeatures.nativeTextureSwizzle = true; } + if (supportsMTLGPUFamily(Apple6) ) { + _metalFeatures.astcHDRTextures = true; + } } if (supportsMTLGPUFamily(Apple4)) { @@ -1349,6 +1357,9 @@ void MVKPhysicalDevice::initMetalFeatures() { _metalFeatures.maxPerStageDynamicMTLBufferCount = _metalFeatures.maxPerStageBufferCount; _metalFeatures.postDepthCoverage = true; } + if (supportsMTLGPUFamily(Apple6)) { + _metalFeatures.astcHDRTextures = true; + } } #endif @@ -2498,6 +2509,9 @@ void MVKPhysicalDevice::initExtensions() { if (!_metalFeatures.stencilFeedback) { pWritableExtns->vk_EXT_shader_stencil_export.enabled = false; } + if (!_metalFeatures.astcHDRTextures) { + pWritableExtns->vk_EXT_texture_compression_astc_hdr.enabled = false; + } #if MVK_MACOS if (!supportsMTLGPUFamily(Apple5)) { pWritableExtns->vk_AMD_shader_image_load_store_lod.enabled = false; diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.h b/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.h index 0c9de9d4..3d011002 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.h +++ b/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.h @@ -33,7 +33,7 @@ class MVKPhysicalDevice; // Validate these values periodically as new formats are added over time. static const uint32_t _vkFormatCount = 256; static const uint32_t _vkFormatCoreCount = VK_FORMAT_ASTC_12x12_SRGB_BLOCK + 1; -static const uint32_t _mtlPixelFormatCount = 128; +static const uint32_t _mtlPixelFormatCount = 256; static const uint32_t _mtlPixelFormatCoreCount = MTLPixelFormatX32_Stencil8 + 2; // The actual last enum value is not available on iOS static const uint32_t _mtlVertexFormatCount = MTLVertexFormatHalf + 1; diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm b/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm index 5c2fa3bb..2d8dd086 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm @@ -46,32 +46,46 @@ using namespace std; # define MTLPixelFormatEAC_RG11Unorm MTLPixelFormatInvalid # define MTLPixelFormatEAC_RG11Snorm MTLPixelFormatInvalid +# define MTLPixelFormatASTC_4x4_HDR MTLPixelFormatInvalid # define MTLPixelFormatASTC_4x4_LDR MTLPixelFormatInvalid # define MTLPixelFormatASTC_4x4_sRGB MTLPixelFormatInvalid +# define MTLPixelFormatASTC_5x4_HDR MTLPixelFormatInvalid # define MTLPixelFormatASTC_5x4_LDR MTLPixelFormatInvalid # define MTLPixelFormatASTC_5x4_sRGB MTLPixelFormatInvalid +# define MTLPixelFormatASTC_5x5_HDR MTLPixelFormatInvalid # define MTLPixelFormatASTC_5x5_LDR MTLPixelFormatInvalid # define MTLPixelFormatASTC_5x5_sRGB MTLPixelFormatInvalid +# define MTLPixelFormatASTC_6x5_HDR MTLPixelFormatInvalid # define MTLPixelFormatASTC_6x5_LDR MTLPixelFormatInvalid # define MTLPixelFormatASTC_6x5_sRGB MTLPixelFormatInvalid +# define MTLPixelFormatASTC_6x6_HDR MTLPixelFormatInvalid # define MTLPixelFormatASTC_6x6_LDR MTLPixelFormatInvalid # define MTLPixelFormatASTC_6x6_sRGB MTLPixelFormatInvalid +# define MTLPixelFormatASTC_8x5_HDR MTLPixelFormatInvalid # define MTLPixelFormatASTC_8x5_LDR MTLPixelFormatInvalid # define MTLPixelFormatASTC_8x5_sRGB MTLPixelFormatInvalid +# define MTLPixelFormatASTC_8x6_HDR MTLPixelFormatInvalid # define MTLPixelFormatASTC_8x6_LDR MTLPixelFormatInvalid # define MTLPixelFormatASTC_8x6_sRGB MTLPixelFormatInvalid +# define MTLPixelFormatASTC_8x8_HDR MTLPixelFormatInvalid # define MTLPixelFormatASTC_8x8_LDR MTLPixelFormatInvalid # define MTLPixelFormatASTC_8x8_sRGB MTLPixelFormatInvalid +# define MTLPixelFormatASTC_10x5_HDR MTLPixelFormatInvalid # define MTLPixelFormatASTC_10x5_LDR MTLPixelFormatInvalid # define MTLPixelFormatASTC_10x5_sRGB MTLPixelFormatInvalid +# define MTLPixelFormatASTC_10x6_HDR MTLPixelFormatInvalid # define MTLPixelFormatASTC_10x6_LDR MTLPixelFormatInvalid # define MTLPixelFormatASTC_10x6_sRGB MTLPixelFormatInvalid +# define MTLPixelFormatASTC_10x8_HDR MTLPixelFormatInvalid # define MTLPixelFormatASTC_10x8_LDR MTLPixelFormatInvalid # define MTLPixelFormatASTC_10x8_sRGB MTLPixelFormatInvalid +# define MTLPixelFormatASTC_10x10_HDR MTLPixelFormatInvalid # define MTLPixelFormatASTC_10x10_LDR MTLPixelFormatInvalid # define MTLPixelFormatASTC_10x10_sRGB MTLPixelFormatInvalid +# define MTLPixelFormatASTC_12x10_HDR MTLPixelFormatInvalid # define MTLPixelFormatASTC_12x10_LDR MTLPixelFormatInvalid # define MTLPixelFormatASTC_12x10_sRGB MTLPixelFormatInvalid +# define MTLPixelFormatASTC_12x12_HDR MTLPixelFormatInvalid # define MTLPixelFormatASTC_12x12_LDR MTLPixelFormatInvalid # define MTLPixelFormatASTC_12x12_sRGB MTLPixelFormatInvalid @@ -928,32 +942,46 @@ void MVKPixelFormats::initVkFormatCapabilities() { addVkFormatDesc( EAC_R11G11_SNORM_BLOCK, EAC_RG11Snorm, Invalid, Invalid, Invalid, 4, 4, 16, Compressed ); addVkFormatDesc( ASTC_4x4_UNORM_BLOCK, ASTC_4x4_LDR, Invalid, Invalid, Invalid, 4, 4, 16, Compressed ); + addVkFormatDesc( ASTC_4x4_SFLOAT_BLOCK_EXT, ASTC_4x4_HDR, Invalid, Invalid, Invalid, 4, 4, 16, Compressed ); addVkFormatDesc( ASTC_4x4_SRGB_BLOCK, ASTC_4x4_sRGB, Invalid, Invalid, Invalid, 4, 4, 16, Compressed ); addVkFormatDesc( ASTC_5x4_UNORM_BLOCK, ASTC_5x4_LDR, Invalid, Invalid, Invalid, 5, 4, 16, Compressed ); + addVkFormatDesc( ASTC_5x4_SFLOAT_BLOCK_EXT, ASTC_5x4_HDR, Invalid, Invalid, Invalid, 5, 4, 16, Compressed ); addVkFormatDesc( ASTC_5x4_SRGB_BLOCK, ASTC_5x4_sRGB, Invalid, Invalid, Invalid, 5, 4, 16, Compressed ); addVkFormatDesc( ASTC_5x5_UNORM_BLOCK, ASTC_5x5_LDR, Invalid, Invalid, Invalid, 5, 5, 16, Compressed ); + addVkFormatDesc( ASTC_5x5_SFLOAT_BLOCK_EXT, ASTC_5x5_HDR, Invalid, Invalid, Invalid, 5, 5, 16, Compressed ); addVkFormatDesc( ASTC_5x5_SRGB_BLOCK, ASTC_5x5_sRGB, Invalid, Invalid, Invalid, 5, 5, 16, Compressed ); addVkFormatDesc( ASTC_6x5_UNORM_BLOCK, ASTC_6x5_LDR, Invalid, Invalid, Invalid, 6, 5, 16, Compressed ); + addVkFormatDesc( ASTC_6x5_SFLOAT_BLOCK_EXT, ASTC_6x5_HDR, Invalid, Invalid, Invalid, 6, 5, 16, Compressed ); addVkFormatDesc( ASTC_6x5_SRGB_BLOCK, ASTC_6x5_sRGB, Invalid, Invalid, Invalid, 6, 5, 16, Compressed ); addVkFormatDesc( ASTC_6x6_UNORM_BLOCK, ASTC_6x6_LDR, Invalid, Invalid, Invalid, 6, 6, 16, Compressed ); + addVkFormatDesc( ASTC_6x6_SFLOAT_BLOCK_EXT, ASTC_6x6_HDR, Invalid, Invalid, Invalid, 6, 6, 16, Compressed ); addVkFormatDesc( ASTC_6x6_SRGB_BLOCK, ASTC_6x6_sRGB, Invalid, Invalid, Invalid, 6, 6, 16, Compressed ); addVkFormatDesc( ASTC_8x5_UNORM_BLOCK, ASTC_8x5_LDR, Invalid, Invalid, Invalid, 8, 5, 16, Compressed ); + addVkFormatDesc( ASTC_8x5_SFLOAT_BLOCK_EXT, ASTC_8x5_HDR, Invalid, Invalid, Invalid, 8, 5, 16, Compressed ); addVkFormatDesc( ASTC_8x5_SRGB_BLOCK, ASTC_8x5_sRGB, Invalid, Invalid, Invalid, 8, 5, 16, Compressed ); addVkFormatDesc( ASTC_8x6_UNORM_BLOCK, ASTC_8x6_LDR, Invalid, Invalid, Invalid, 8, 6, 16, Compressed ); + addVkFormatDesc( ASTC_8x6_SFLOAT_BLOCK_EXT, ASTC_8x6_HDR, Invalid, Invalid, Invalid, 8, 6, 16, Compressed ); addVkFormatDesc( ASTC_8x6_SRGB_BLOCK, ASTC_8x6_sRGB, Invalid, Invalid, Invalid, 8, 6, 16, Compressed ); addVkFormatDesc( ASTC_8x8_UNORM_BLOCK, ASTC_8x8_LDR, Invalid, Invalid, Invalid, 8, 8, 16, Compressed ); + addVkFormatDesc( ASTC_8x8_SFLOAT_BLOCK_EXT, ASTC_8x8_HDR, Invalid, Invalid, Invalid, 8, 8, 16, Compressed ); addVkFormatDesc( ASTC_8x8_SRGB_BLOCK, ASTC_8x8_sRGB, Invalid, Invalid, Invalid, 8, 8, 16, Compressed ); addVkFormatDesc( ASTC_10x5_UNORM_BLOCK, ASTC_10x5_LDR, Invalid, Invalid, Invalid, 10, 5, 16, Compressed ); + addVkFormatDesc( ASTC_10x5_SFLOAT_BLOCK_EXT, ASTC_10x5_HDR, Invalid, Invalid, Invalid, 10, 5, 16, Compressed ); addVkFormatDesc( ASTC_10x5_SRGB_BLOCK, ASTC_10x5_sRGB, Invalid, Invalid, Invalid, 10, 5, 16, Compressed ); addVkFormatDesc( ASTC_10x6_UNORM_BLOCK, ASTC_10x6_LDR, Invalid, Invalid, Invalid, 10, 6, 16, Compressed ); + addVkFormatDesc( ASTC_10x6_SFLOAT_BLOCK_EXT, ASTC_10x6_HDR, Invalid, Invalid, Invalid, 10, 6, 16, Compressed ); addVkFormatDesc( ASTC_10x6_SRGB_BLOCK, ASTC_10x6_sRGB, Invalid, Invalid, Invalid, 10, 6, 16, Compressed ); addVkFormatDesc( ASTC_10x8_UNORM_BLOCK, ASTC_10x8_LDR, Invalid, Invalid, Invalid, 10, 8, 16, Compressed ); + addVkFormatDesc( ASTC_10x8_SFLOAT_BLOCK_EXT, ASTC_10x8_HDR, Invalid, Invalid, Invalid, 10, 8, 16, Compressed ); addVkFormatDesc( ASTC_10x8_SRGB_BLOCK, ASTC_10x8_sRGB, Invalid, Invalid, Invalid, 10, 8, 16, Compressed ); addVkFormatDesc( ASTC_10x10_UNORM_BLOCK, ASTC_10x10_LDR, Invalid, Invalid, Invalid, 10, 10, 16, Compressed ); + addVkFormatDesc( ASTC_10x10_SFLOAT_BLOCK_EXT, ASTC_10x10_HDR, Invalid, Invalid, Invalid, 10, 10, 16, Compressed ); addVkFormatDesc( ASTC_10x10_SRGB_BLOCK, ASTC_10x10_sRGB, Invalid, Invalid, Invalid, 10, 10, 16, Compressed ); addVkFormatDesc( ASTC_12x10_UNORM_BLOCK, ASTC_12x10_LDR, Invalid, Invalid, Invalid, 12, 10, 16, Compressed ); + addVkFormatDesc( ASTC_12x10_SFLOAT_BLOCK_EXT, ASTC_12x10_HDR, Invalid, Invalid, Invalid, 12, 10, 16, Compressed ); addVkFormatDesc( ASTC_12x10_SRGB_BLOCK, ASTC_12x10_sRGB, Invalid, Invalid, Invalid, 12, 10, 16, Compressed ); addVkFormatDesc( ASTC_12x12_UNORM_BLOCK, ASTC_12x12_LDR, Invalid, Invalid, Invalid, 12, 12, 16, Compressed ); + addVkFormatDesc( ASTC_12x12_SFLOAT_BLOCK_EXT, ASTC_12x12_HDR, Invalid, Invalid, Invalid, 12, 12, 16, Compressed ); addVkFormatDesc( ASTC_12x12_SRGB_BLOCK, ASTC_12x12_sRGB, Invalid, Invalid, Invalid, 12, 12, 16, Compressed ); // Extension VK_IMG_format_pvrtc @@ -1118,32 +1146,46 @@ void MVKPixelFormats::initMTLPixelFormatCapabilities() { addMTLPixelFormatDesc ( ASTC_4x4_LDR, ASTC_4x4, None, None ); addMTLPixelFormatDescSRGB( ASTC_4x4_sRGB, ASTC_4x4, None, None, ASTC_4x4_LDR ); + addMTLPixelFormatDesc ( ASTC_4x4_HDR, ASTC_4x4, None, None ); addMTLPixelFormatDesc ( ASTC_5x4_LDR, ASTC_5x4, None, None ); addMTLPixelFormatDescSRGB( ASTC_5x4_sRGB, ASTC_5x4, None, None, ASTC_5x4_LDR ); + addMTLPixelFormatDesc ( ASTC_5x4_HDR, ASTC_5x4, None, None ); addMTLPixelFormatDesc ( ASTC_5x5_LDR, ASTC_5x5, None, None ); addMTLPixelFormatDescSRGB( ASTC_5x5_sRGB, ASTC_5x5, None, None, ASTC_5x5_LDR ); + addMTLPixelFormatDesc ( ASTC_5x5_HDR, ASTC_5x5, None, None ); addMTLPixelFormatDesc ( ASTC_6x5_LDR, ASTC_6x5, None, None ); addMTLPixelFormatDescSRGB( ASTC_6x5_sRGB, ASTC_6x5, None, None, ASTC_6x5_LDR ); + addMTLPixelFormatDesc ( ASTC_6x5_HDR, ASTC_6x5, None, None ); addMTLPixelFormatDesc ( ASTC_6x6_LDR, ASTC_6x6, None, None ); addMTLPixelFormatDescSRGB( ASTC_6x6_sRGB, ASTC_6x6, None, None, ASTC_6x6_LDR ); + addMTLPixelFormatDesc ( ASTC_6x6_HDR, ASTC_6x6, None, None ); addMTLPixelFormatDesc ( ASTC_8x5_LDR, ASTC_8x5, None, None ); addMTLPixelFormatDescSRGB( ASTC_8x5_sRGB, ASTC_8x5, None, None, ASTC_8x5_LDR ); + addMTLPixelFormatDesc ( ASTC_8x5_HDR, ASTC_8x5, None, None ); addMTLPixelFormatDesc ( ASTC_8x6_LDR, ASTC_8x6, None, None ); addMTLPixelFormatDescSRGB( ASTC_8x6_sRGB, ASTC_8x6, None, None, ASTC_8x6_LDR ); + addMTLPixelFormatDesc ( ASTC_8x6_HDR, ASTC_8x6, None, None ); addMTLPixelFormatDesc ( ASTC_8x8_LDR, ASTC_8x8, None, None ); addMTLPixelFormatDescSRGB( ASTC_8x8_sRGB, ASTC_8x8, None, None, ASTC_8x8_LDR ); + addMTLPixelFormatDesc ( ASTC_8x8_HDR, ASTC_8x8, None, None ); addMTLPixelFormatDesc ( ASTC_10x5_LDR, ASTC_10x5, None, None ); addMTLPixelFormatDescSRGB( ASTC_10x5_sRGB, ASTC_10x5, None, None, ASTC_10x5_LDR ); + addMTLPixelFormatDesc ( ASTC_10x5_HDR, ASTC_10x5, None, None ); addMTLPixelFormatDesc ( ASTC_10x6_LDR, ASTC_10x6, None, None ); addMTLPixelFormatDescSRGB( ASTC_10x6_sRGB, ASTC_10x6, None, None, ASTC_10x6_LDR ); + addMTLPixelFormatDesc ( ASTC_10x6_HDR, ASTC_10x6, None, None ); addMTLPixelFormatDesc ( ASTC_10x8_LDR, ASTC_10x8, None, None ); addMTLPixelFormatDescSRGB( ASTC_10x8_sRGB, ASTC_10x8, None, None, ASTC_10x8_LDR ); + addMTLPixelFormatDesc ( ASTC_10x8_HDR, ASTC_10x8, None, None ); addMTLPixelFormatDesc ( ASTC_10x10_LDR, ASTC_10x10, None, None ); addMTLPixelFormatDescSRGB( ASTC_10x10_sRGB, ASTC_10x10, None, None, ASTC_10x10_LDR ); + addMTLPixelFormatDesc ( ASTC_10x10_HDR, ASTC_10x10, None, None ); addMTLPixelFormatDesc ( ASTC_12x10_LDR, ASTC_12x10, None, None ); addMTLPixelFormatDescSRGB( ASTC_12x10_sRGB, ASTC_12x10, None, None, ASTC_12x10_LDR ); + addMTLPixelFormatDesc ( ASTC_12x10_HDR, ASTC_12x10, None, None ); addMTLPixelFormatDesc ( ASTC_12x12_LDR, ASTC_12x12, None, None ); addMTLPixelFormatDescSRGB( ASTC_12x12_sRGB, ASTC_12x12, None, None, ASTC_12x12_LDR ); + addMTLPixelFormatDesc ( ASTC_12x12_HDR, ASTC_12x12, None, None ); addMTLPixelFormatDesc ( BC1_RGBA, BC1_RGBA, None, RF ); addMTLPixelFormatDescSRGB( BC1_RGBA_sRGB, BC1_RGBA, None, RF, BC1_RGBA ); @@ -1491,32 +1533,46 @@ void MVKPixelFormats::modifyMTLFormatCapabilities(id mtlDevice) { addGPUOSMTLPixFmtCaps( Apple5, 10.16, ASTC_4x4_LDR, RF ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, ASTC_4x4_sRGB, RF ); + addGPUOSMTLPixFmtCaps( Apple6, 10.16, ASTC_4x4_HDR, RF ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, ASTC_5x4_LDR, RF ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, ASTC_5x4_sRGB, RF ); + addGPUOSMTLPixFmtCaps( Apple6, 10.16, ASTC_5x4_HDR, RF ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, ASTC_5x5_LDR, RF ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, ASTC_5x5_sRGB, RF ); + addGPUOSMTLPixFmtCaps( Apple6, 10.16, ASTC_5x5_HDR, RF ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, ASTC_6x5_LDR, RF ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, ASTC_6x5_sRGB, RF ); + addGPUOSMTLPixFmtCaps( Apple6, 10.16, ASTC_6x5_HDR, RF ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, ASTC_6x6_LDR, RF ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, ASTC_6x6_sRGB, RF ); + addGPUOSMTLPixFmtCaps( Apple6, 10.16, ASTC_6x6_HDR, RF ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, ASTC_8x5_LDR, RF ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, ASTC_8x5_sRGB, RF ); + addGPUOSMTLPixFmtCaps( Apple6, 10.16, ASTC_8x5_HDR, RF ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, ASTC_8x6_LDR, RF ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, ASTC_8x6_sRGB, RF ); + addGPUOSMTLPixFmtCaps( Apple6, 10.16, ASTC_8x6_HDR, RF ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, ASTC_8x8_LDR, RF ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, ASTC_8x8_sRGB, RF ); + addGPUOSMTLPixFmtCaps( Apple6, 10.16, ASTC_8x8_HDR, RF ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, ASTC_10x5_LDR, RF ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, ASTC_10x5_sRGB, RF ); + addGPUOSMTLPixFmtCaps( Apple6, 10.16, ASTC_10x5_HDR, RF ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, ASTC_10x6_LDR, RF ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, ASTC_10x6_sRGB, RF ); + addGPUOSMTLPixFmtCaps( Apple6, 10.16, ASTC_10x6_HDR, RF ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, ASTC_10x8_LDR, RF ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, ASTC_10x8_sRGB, RF ); + addGPUOSMTLPixFmtCaps( Apple6, 10.16, ASTC_10x8_HDR, RF ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, ASTC_10x10_LDR, RF ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, ASTC_10x10_sRGB, RF ); + addGPUOSMTLPixFmtCaps( Apple6, 10.16, ASTC_10x10_HDR, RF ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, ASTC_12x10_LDR, RF ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, ASTC_12x10_sRGB, RF ); + addGPUOSMTLPixFmtCaps( Apple6, 10.16, ASTC_12x10_HDR, RF ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, ASTC_12x12_LDR, RF ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, ASTC_12x12_sRGB, RF ); + addGPUOSMTLPixFmtCaps( Apple6, 10.16, ASTC_12x12_HDR, RF ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, BGRA10_XR, All ); addGPUOSMTLPixFmtCaps( Apple5, 10.16, BGRA10_XR_sRGB, All ); @@ -1759,6 +1815,21 @@ void MVKPixelFormats::modifyMTLFormatCapabilities(id mtlDevice) { addFeatSetMTLPixFmtCaps( iOS_GPUFamily1_v4, BGR10A2Unorm, All ); + addGPUOSMTLPixFmtCaps( Apple6, 13.0, ASTC_4x4_HDR, RF ); + addGPUOSMTLPixFmtCaps( Apple6, 13.0, ASTC_5x4_HDR, RF ); + addGPUOSMTLPixFmtCaps( Apple6, 13.0, ASTC_5x5_HDR, RF ); + addGPUOSMTLPixFmtCaps( Apple6, 13.0, ASTC_6x5_HDR, RF ); + addGPUOSMTLPixFmtCaps( Apple6, 13.0, ASTC_6x6_HDR, RF ); + addGPUOSMTLPixFmtCaps( Apple6, 13.0, ASTC_8x5_HDR, RF ); + addGPUOSMTLPixFmtCaps( Apple6, 13.0, ASTC_8x6_HDR, RF ); + addGPUOSMTLPixFmtCaps( Apple6, 13.0, ASTC_8x8_HDR, RF ); + addGPUOSMTLPixFmtCaps( Apple6, 13.0, ASTC_10x5_HDR, RF ); + addGPUOSMTLPixFmtCaps( Apple6, 13.0, ASTC_10x6_HDR, RF ); + addGPUOSMTLPixFmtCaps( Apple6, 13.0, ASTC_10x8_HDR, RF ); + addGPUOSMTLPixFmtCaps( Apple6, 13.0, ASTC_10x10_HDR, RF ); + addGPUOSMTLPixFmtCaps( Apple6, 13.0, ASTC_12x10_HDR, RF ); + addGPUOSMTLPixFmtCaps( Apple6, 13.0, ASTC_12x12_HDR, RF ); + addGPUOSMTLPixFmtCaps( Apple1, 13.0, Depth16Unorm, DRFM ); addGPUOSMTLPixFmtCaps( Apple3, 13.0, Depth16Unorm, DRFMR ); diff --git a/MoltenVK/MoltenVK/Layers/MVKExtensions.def b/MoltenVK/MoltenVK/Layers/MVKExtensions.def index c9bd20fe..267e4f24 100644 --- a/MoltenVK/MoltenVK/Layers/MVKExtensions.def +++ b/MoltenVK/MoltenVK/Layers/MVKExtensions.def @@ -97,6 +97,7 @@ MVK_EXTENSION(EXT_shader_stencil_export, EXT_SHADER_STENCIL_EXPORT, DEVICE) MVK_EXTENSION(EXT_shader_viewport_index_layer, EXT_SHADER_VIEWPORT_INDEX_LAYER, DEVICE) MVK_EXTENSION(EXT_swapchain_colorspace, EXT_SWAPCHAIN_COLOR_SPACE, INSTANCE) MVK_EXTENSION(EXT_texel_buffer_alignment, EXT_TEXEL_BUFFER_ALIGNMENT, DEVICE) +MVK_EXTENSION(EXT_texture_compression_astc_hdr, EXT_TEXTURE_COMPRESSION_ASTC_HDR, DEVICE) MVK_EXTENSION(EXT_vertex_attribute_divisor, EXT_VERTEX_ATTRIBUTE_DIVISOR, DEVICE) MVK_EXTENSION(AMD_gpu_shader_half_float, AMD_GPU_SHADER_HALF_FLOAT, DEVICE) MVK_EXTENSION(AMD_negative_viewport_height, AMD_NEGATIVE_VIEWPORT_HEIGHT, DEVICE) diff --git a/MoltenVK/MoltenVK/Layers/MVKExtensions.mm b/MoltenVK/MoltenVK/Layers/MVKExtensions.mm index 39a4bb5d..76f4159c 100644 --- a/MoltenVK/MoltenVK/Layers/MVKExtensions.mm +++ b/MoltenVK/MoltenVK/Layers/MVKExtensions.mm @@ -56,6 +56,7 @@ static bool mvkIsSupportedOnPlatform(VkExtensionProperties* pProperties) { if (pProperties == &kVkExtProps_EXT_POST_DEPTH_COVERAGE) { return mvkOSVersionIsAtLeast(10.16); } if (pProperties == &kVkExtProps_EXT_SHADER_STENCIL_EXPORT) { return mvkOSVersionIsAtLeast(10.14); } if (pProperties == &kVkExtProps_EXT_TEXEL_BUFFER_ALIGNMENT) { return mvkOSVersionIsAtLeast(10.13); } + if (pProperties == &kVkExtProps_EXT_TEXTURE_COMPRESSION_ASTC_HDR) { return mvkOSVersionIsAtLeast(10.16); } if (pProperties == &kVkExtProps_AMD_SHADER_IMAGE_LOAD_STORE_LOD) { return mvkOSVersionIsAtLeast(10.16); } if (pProperties == &kVkExtProps_AMD_SHADER_TRINARY_MINMAX) { return mvkOSVersionIsAtLeast(10.14); } if (pProperties == &kVkExtProps_IMG_FORMAT_PVRTC) { return mvkOSVersionIsAtLeast(10.16); } @@ -72,6 +73,7 @@ static bool mvkIsSupportedOnPlatform(VkExtensionProperties* pProperties) { if (pProperties == &kVkExtProps_EXT_SHADER_STENCIL_EXPORT) { return mvkOSVersionIsAtLeast(12.0); } if (pProperties == &kVkExtProps_EXT_SWAPCHAIN_COLOR_SPACE) { return mvkOSVersionIsAtLeast(9.0); } if (pProperties == &kVkExtProps_EXT_TEXEL_BUFFER_ALIGNMENT) { return mvkOSVersionIsAtLeast(11.0); } + if (pProperties == &kVkExtProps_EXT_TEXTURE_COMPRESSION_ASTC_HDR) { return mvkOSVersionIsAtLeast(13.0); } if (pProperties == &kVkExtProps_AMD_SHADER_TRINARY_MINMAX) { return mvkOSVersionIsAtLeast(12.0); } #endif From b1e304bf918b19f6e4fcfff39f83d1e6b9c35fc9 Mon Sep 17 00:00:00 2001 From: Chip Davis Date: Wed, 4 Nov 2020 16:08:33 -0600 Subject: [PATCH 5/8] MVKCmdBlitImage: Use layered draws when possible. I wanted to do this in the last release, but I ran out of time. It doesn't seem to provide much speed up. --- MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm | 38 ++++++++++++++++--- ...KCommandPipelineStateFactoryShaderSource.h | 16 ++++++++ .../Commands/MVKCommandResourceFactory.mm | 16 ++++++-- 3 files changed, 60 insertions(+), 10 deletions(-) diff --git a/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm b/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm index 2de9d4fc..582b827c 100644 --- a/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm +++ b/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm @@ -485,18 +485,34 @@ void MVKCmdBlitImage::encode(MVKCommandEncoder* cmdEncoder, MVKCommandUse com mtlColorAttDesc.level = mvkIBR.region.dstSubresource.mipLevel; mtlDepthAttDesc.level = mvkIBR.region.dstSubresource.mipLevel; mtlStencilAttDesc.level = mvkIBR.region.dstSubresource.mipLevel; + + bool isLayeredBlit = blitKey.dstSampleCount > 1 ? cmdEncoder->getDevice()->_pMetalFeatures->multisampleLayeredRendering : cmdEncoder->getDevice()->_pMetalFeatures->layeredRendering; uint32_t layCnt = mvkIBR.region.srcSubresource.layerCount; if (_dstImage->getMTLTextureType() == MTLTextureType3D) { layCnt = mvkAbsDiff(mvkIBR.region.dstOffsets[1].z, mvkIBR.region.dstOffsets[0].z); } + if (isLayeredBlit) { + // In this case, I can blit all layers at once with a layered draw. + mtlRPD.renderTargetArrayLengthMVK = layCnt; + layCnt = 1; // Only need to run the loop once. + } for (uint32_t layIdx = 0; layIdx < layCnt; layIdx++) { // Update the render pass descriptor for the texture level and slice, and create a render encoder. if (_dstImage->getMTLTextureType() == MTLTextureType3D) { - uint32_t depthPlane = mvkIBR.region.dstOffsets[0].z + (mvkIBR.region.dstOffsets[1].z > mvkIBR.region.dstOffsets[0].z ? layIdx : -(layIdx + 1)); - mtlColorAttDesc.depthPlane = depthPlane; - mtlDepthAttDesc.depthPlane = depthPlane; - mtlStencilAttDesc.depthPlane = depthPlane; + if (isLayeredBlit) { + // For layered blits, the layers are always in ascending order. I'll reverse the order + // of the 'r' coordinates if the destination is mirrored. + uint32_t depthPlane = std::min(mvkIBR.region.dstOffsets[0].z, mvkIBR.region.dstOffsets[1].z); + mtlColorAttDesc.depthPlane = depthPlane; + mtlDepthAttDesc.depthPlane = depthPlane; + mtlStencilAttDesc.depthPlane = depthPlane; + } else { + uint32_t depthPlane = mvkIBR.region.dstOffsets[0].z + (mvkIBR.region.dstOffsets[1].z > mvkIBR.region.dstOffsets[0].z ? layIdx : -(layIdx + 1)); + mtlColorAttDesc.depthPlane = depthPlane; + mtlDepthAttDesc.depthPlane = depthPlane; + mtlStencilAttDesc.depthPlane = depthPlane; + } } else { mtlColorAttDesc.slice = mvkIBR.region.dstSubresource.baseArrayLayer + layIdx; mtlDepthAttDesc.slice = mvkIBR.region.dstSubresource.baseArrayLayer + layIdx; @@ -505,6 +521,7 @@ void MVKCmdBlitImage::encode(MVKCommandEncoder* cmdEncoder, MVKCommandUse com id mtlRendEnc = [cmdEncoder->_mtlCmdBuffer renderCommandEncoderWithDescriptor: mtlRPD]; setLabelIfNotNil(mtlRendEnc, mvkMTLRenderCommandEncoderLabel(commandUse)); + float zIncr; if (blitKey.srcMTLTextureType == MTLTextureType3D) { // In this case, I need to interpolate along the third dimension manually. VkExtent3D srcExtent = _srcImage->getExtent3D(srcPlaneIndex, mvkIBR.region.dstSubresource.mipLevel); @@ -512,7 +529,12 @@ void MVKCmdBlitImage::encode(MVKCommandEncoder* cmdEncoder, MVKCommandUse com VkOffset3D do0 = mvkIBR.region.dstOffsets[0], do1 = mvkIBR.region.dstOffsets[1]; float startZ = (float)so0.z / (float)srcExtent.depth; float endZ = (float)so1.z / (float)srcExtent.depth; - float z = startZ + (endZ - startZ) * (layIdx + 0.5) / mvkAbsDiff(do1.z, do0.z); + if (isLayeredBlit && do0.z > do1.z) { + // Swap start and end points so interpolation moves in the right direction. + std::swap(startZ, endZ); + } + zIncr = (endZ - startZ) / mvkAbsDiff(do1.z, do0.z); + float z = startZ + (isLayeredBlit ? 0.0 : (layIdx + 0.5)) * zIncr; for (uint32_t i = 0; i < kMVKBlitVertexCount; ++i) { mvkIBR.vertices[i].texCoord.z = z; } @@ -521,6 +543,9 @@ void MVKCmdBlitImage::encode(MVKCommandEncoder* cmdEncoder, MVKCommandUse com [mtlRendEnc setRenderPipelineState: mtlRPS]; [mtlRendEnc setDepthStencilState: mtlDSS]; cmdEncoder->setVertexBytes(mtlRendEnc, mvkIBR.vertices, sizeof(mvkIBR.vertices), vtxBuffIdx); + if (isLayeredBlit) { + cmdEncoder->setVertexBytes(mtlRendEnc, &zIncr, sizeof(zIncr), 0); + } if (!mvkIsOnlyAnyFlagEnabled(blitKey.srcAspect, (VK_IMAGE_ASPECT_STENCIL_BIT))) { [mtlRendEnc setFragmentTexture: srcMTLTex atIndex: 0]; } @@ -556,7 +581,8 @@ void MVKCmdBlitImage::encode(MVKCommandEncoder* cmdEncoder, MVKCommandUse com texSubRez.lod = mvkIBR.region.srcSubresource.mipLevel; cmdEncoder->setFragmentBytes(mtlRendEnc, &texSubRez, sizeof(texSubRez), 0); - [mtlRendEnc drawPrimitives: MTLPrimitiveTypeTriangleStrip vertexStart: 0 vertexCount: kMVKBlitVertexCount]; + NSUInteger instanceCount = isLayeredBlit ? mtlRPD.renderTargetArrayLengthMVK : 1; + [mtlRendEnc drawPrimitives: MTLPrimitiveTypeTriangleStrip vertexStart: 0 vertexCount: kMVKBlitVertexCount instanceCount: instanceCount]; [mtlRendEnc popDebugGroup]; [mtlRendEnc endEncoding]; } diff --git a/MoltenVK/MoltenVK/Commands/MVKCommandPipelineStateFactoryShaderSource.h b/MoltenVK/MoltenVK/Commands/MVKCommandPipelineStateFactoryShaderSource.h index d5621835..e9e65f82 100644 --- a/MoltenVK/MoltenVK/Commands/MVKCommandPipelineStateFactoryShaderSource.h +++ b/MoltenVK/MoltenVK/Commands/MVKCommandPipelineStateFactoryShaderSource.h @@ -37,6 +37,12 @@ typedef struct { float3 v_texCoord; \n\ } VaryingsPosTex; \n\ \n\ +typedef struct { \n\ + float4 v_position [[position]]; \n\ + float3 v_texCoord; \n\ + uint v_layer [[render_target_array_index]]; \n\ +} VaryingsPosTexLayer; \n\ + \n\ typedef size_t VkDeviceSize; \n\ \n\ typedef enum : uint32_t { \n\ @@ -79,6 +85,16 @@ vertex VaryingsPosTex vtxCmdBlitImage(AttributesPosTex attributes [[stage_in]]) return varyings; \n\ } \n\ \n\ +vertex VaryingsPosTexLayer vtxCmdBlitImageLayered(AttributesPosTex attributes [[stage_in]], \n\ + uint instanceID [[instance_id]], \n\ + constant float &zIncr [[buffer(0)]]) { \n\ + VaryingsPosTexLayer varyings; \n\ + varyings.v_position = float4(attributes.a_position, 0.0, 1.0); \n\ + varyings.v_texCoord = float3(attributes.a_texCoord.xy, attributes.a_texCoord.z + (instanceID + 0.5) * zIncr);\n\ + varyings.v_layer = instanceID; \n\ + return varyings; \n\ +} \n\ + \n\ typedef struct { \n\ uint32_t srcOffset; \n\ uint32_t dstOffset; \n\ diff --git a/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.mm b/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.mm index 0a42be02..c5af54f0 100644 --- a/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.mm +++ b/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.mm @@ -33,14 +33,18 @@ using namespace std; id MVKCommandResourceFactory::newCmdBlitImageMTLRenderPipelineState(MVKRPSKeyBlitImg& blitKey, MVKVulkanAPIDeviceObject* owner) { - id vtxFunc = newFunctionNamed("vtxCmdBlitImage"); // temp retain - id fragFunc = newBlitFragFunction(blitKey); // temp retain - MTLRenderPipelineDescriptor* plDesc = [MTLRenderPipelineDescriptor new]; // temp retain + bool isLayeredBlit = blitKey.dstSampleCount > 1 ? _device->_pMetalFeatures->multisampleLayeredRendering : _device->_pMetalFeatures->layeredRendering; + id vtxFunc = newFunctionNamed(isLayeredBlit ? "vtxCmdBlitImageLayered" : "vtxCmdBlitImage"); // temp retain + id fragFunc = newBlitFragFunction(blitKey); // temp retain + MTLRenderPipelineDescriptor* plDesc = [MTLRenderPipelineDescriptor new]; // temp retain plDesc.label = @"CmdBlitImage"; plDesc.vertexFunction = vtxFunc; plDesc.fragmentFunction = fragFunc; plDesc.sampleCount = blitKey.dstSampleCount; + if (isLayeredBlit) { + plDesc.inputPrimitiveTopology = MTLPrimitiveTopologyClassTriangle; + } if (mvkIsAnyFlagEnabled(blitKey.srcAspect, (VK_IMAGE_ASPECT_DEPTH_BIT))) { plDesc.depthAttachmentPixelFormat = blitKey.getDstMTLPixelFormat(); @@ -162,6 +166,7 @@ id MVKCommandResourceFactory::newCmdClearMTLRenderPipeli id MVKCommandResourceFactory::newBlitFragFunction(MVKRPSKeyBlitImg& blitKey) { @autoreleasepool { + bool isLayeredBlit = blitKey.dstSampleCount > 1 ? _device->_pMetalFeatures->multisampleLayeredRendering : _device->_pMetalFeatures->layeredRendering; NSString* typeStr = getMTLFormatTypeString(blitKey.getSrcMTLPixelFormat()); bool isArrayType = blitKey.isSrcArrayType(); @@ -198,7 +203,7 @@ id MVKCommandResourceFactory::newBlitFragFunction(MVKRPSKeyBlitImg& coordArg = @""; break; } - NSString* sliceArg = isArrayType ? @", subRez.slice" : @""; + NSString* sliceArg = isArrayType ? (isLayeredBlit ? @", subRez.slice + varyings.v_layer" : @", subRez.slice") : @""; NSString* srcFilter = isLinearFilter ? @"linear" : @"nearest"; NSMutableString* msl = [NSMutableString stringWithCapacity: (2 * KIBI) ]; @@ -208,6 +213,9 @@ id MVKCommandResourceFactory::newBlitFragFunction(MVKRPSKeyBlitImg& [msl appendLineMVK: @"typedef struct {"]; [msl appendLineMVK: @" float4 v_position [[position]];"]; [msl appendLineMVK: @" float3 v_texCoord;"]; + if (isLayeredBlit && isArrayType) { + [msl appendLineMVK: @" uint v_layer [[render_target_array_index]];"]; + } [msl appendLineMVK: @"} VaryingsPosTex;"]; [msl appendLineMVK]; [msl appendLineMVK: @"typedef struct {"]; From 8cb48464b4e16c3f79259cf00f14fa93aec5a892 Mon Sep 17 00:00:00 2001 From: Chip Davis Date: Fri, 30 Oct 2020 22:49:24 -0500 Subject: [PATCH 6/8] MVKPhysicalDevice: Set max visibility buffer size to 256 kiB where supported. Starting in macOS 10.15, all desktop GPUs support 256 kiB offsets. Apple GPUs, however, do not support this until family 7. It isn't clear which one is the supported limit on Apple Silicon Macs with family 5 or 6 GPUs, so I have left the Apple Silicon limit at 64 kiB for now. --- MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm index bb756bc5..87604dac 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm @@ -1280,6 +1280,9 @@ void MVKPhysicalDevice::initMetalFeatures() { #if MVK_XCODE_12 if ( mvkOSVersionIsAtLeast(14.0) ) { _metalFeatures.mslVersionEnum = MTLLanguageVersion2_3; + if ( supportsMTLGPUFamily(Apple7) ) { + _metalFeatures.maxQueryBufferSize = (256 * KIBI); + } } #endif @@ -1336,6 +1339,7 @@ void MVKPhysicalDevice::initMetalFeatures() { if ( mvkOSVersionIsAtLeast(10.15) ) { _metalFeatures.mslVersionEnum = MTLLanguageVersion2_2; + _metalFeatures.maxQueryBufferSize = (256 * KIBI); _metalFeatures.native3DCompressedTextures = true; _metalFeatures.renderWithoutAttachments = true; if ( mvkOSVersionIsAtLeast(mvkMakeOSVersion(10, 15, 6)) ) { @@ -1354,12 +1358,14 @@ void MVKPhysicalDevice::initMetalFeatures() { // This is an Apple GPU--treat it accordingly. _metalFeatures.mtlCopyBufferAlignment = 1; _metalFeatures.mtlBufferAlignment = 16; + _metalFeatures.maxQueryBufferSize = (64 * KIBI); _metalFeatures.maxPerStageDynamicMTLBufferCount = _metalFeatures.maxPerStageBufferCount; _metalFeatures.postDepthCoverage = true; } if (supportsMTLGPUFamily(Apple6)) { _metalFeatures.astcHDRTextures = true; } + // TODO: When Apple7 is added, set max query buffer size back to 256 kiB. } #endif From 779ae2aa45820e8a6e0cd4aacdfbab39c385a12f Mon Sep 17 00:00:00 2001 From: Bill Hollings Date: Thu, 5 Nov 2020 13:41:55 -0500 Subject: [PATCH 7/8] Fix tvOS builds. Add macros to set MTLPixelFormatASTC_*_HDR to MTLPixelFormatInvalid on tvOS. Use MTLRenderPipelineDescriptor::inputPrimitiveTopologyMVK instead of native method. --- .../Commands/MVKCommandResourceFactory.mm | 2 +- MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.mm b/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.mm index c5af54f0..bc943eb7 100644 --- a/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.mm +++ b/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.mm @@ -43,7 +43,7 @@ id MVKCommandResourceFactory::newCmdBlitImageMTLRenderPi plDesc.fragmentFunction = fragFunc; plDesc.sampleCount = blitKey.dstSampleCount; if (isLayeredBlit) { - plDesc.inputPrimitiveTopology = MTLPrimitiveTopologyClassTriangle; + plDesc.inputPrimitiveTopologyMVK = MTLPrimitiveTopologyClassTriangle; } if (mvkIsAnyFlagEnabled(blitKey.srcAspect, (VK_IMAGE_ASPECT_DEPTH_BIT))) { diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm b/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm index 2d8dd086..7832a9ab 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm @@ -128,6 +128,23 @@ using namespace std; # define MTLPixelFormatDepth16Unorm_Stencil8 MTLPixelFormatDepth32Float_Stencil8 #endif +#if MVK_TVOS +# define MTLPixelFormatASTC_4x4_HDR MTLPixelFormatInvalid +# define MTLPixelFormatASTC_5x4_HDR MTLPixelFormatInvalid +# define MTLPixelFormatASTC_5x5_HDR MTLPixelFormatInvalid +# define MTLPixelFormatASTC_6x5_HDR MTLPixelFormatInvalid +# define MTLPixelFormatASTC_6x6_HDR MTLPixelFormatInvalid +# define MTLPixelFormatASTC_8x5_HDR MTLPixelFormatInvalid +# define MTLPixelFormatASTC_8x6_HDR MTLPixelFormatInvalid +# define MTLPixelFormatASTC_8x8_HDR MTLPixelFormatInvalid +# define MTLPixelFormatASTC_10x5_HDR MTLPixelFormatInvalid +# define MTLPixelFormatASTC_10x6_HDR MTLPixelFormatInvalid +# define MTLPixelFormatASTC_10x8_HDR MTLPixelFormatInvalid +# define MTLPixelFormatASTC_10x10_HDR MTLPixelFormatInvalid +# define MTLPixelFormatASTC_12x10_HDR MTLPixelFormatInvalid +# define MTLPixelFormatASTC_12x12_HDR MTLPixelFormatInvalid +#endif + #pragma mark - #pragma mark MVKPixelFormats From 223a1f4d304ccbbf87913cbb608b8db583fb9704 Mon Sep 17 00:00:00 2001 From: Bill Hollings Date: Thu, 5 Nov 2020 13:58:30 -0500 Subject: [PATCH 8/8] Fix build warnings. Replace use of MTLDevice::supportsGPUFamily: with supportsFamily:. Wrap unused variable of tvOS with conditional compile macro. --- MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm b/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm index 7832a9ab..94f4fead 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm @@ -2032,7 +2032,9 @@ void MVKPixelFormats::setFormatProperties(MVKVkFormatDesc& vkDesc) { enableFormatFeatures(DSAtt, Tex, mtlPixFmtCaps, vkProps.optimalTilingFeatures); enableFormatFeatures(Blend, Tex, mtlPixFmtCaps, vkProps.optimalTilingFeatures); +#if MVK_MACOS_OR_IOS id mtlDev = _physicalDevice ? _physicalDevice->getMTLDevice() : nil; +#endif if ( chromaSubsamplingComponentBits > 0 || // XXX We really want to use the device's Metal features instead of duplicating the // logic from MVKPhysicalDevice, but those may not have been initialized yet. @@ -2063,7 +2065,7 @@ void MVKPixelFormats::setFormatProperties(MVKVkFormatDesc& vkDesc) { #if MVK_MACOS // On IMR GPUs, linear textures cannot be used as attachments, so disable those features. - if (![mtlDev respondsToSelector: @selector(supportsGPUFamily:)] || ![mtlDev supportsGPUFamily: MTLGPUFamilyApple5]) { + if (![mtlDev respondsToSelector: @selector(supportsFamily:)] || ![mtlDev supportsFamily: MTLGPUFamilyApple5]) { mvkDisableFlags(vkProps.linearTilingFeatures, (kMVKVkFormatFeatureFlagsTexColorAtt | kMVKVkFormatFeatureFlagsTexDSAtt | kMVKVkFormatFeatureFlagsTexBlend));