Skip to content

Commit 350566b

Browse files
committed
Add support for VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT
1 parent 712fbb8 commit 350566b

File tree

5 files changed

+172
-79
lines changed

5 files changed

+172
-79
lines changed

Docs/MoltenVK_Configuration_Parameters.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,9 @@ allocate textures and buffers from general device memory.
680680
Vulkan extension `VK_EXT_image_2d_view_of_3d` requires this parameter to be active,
681681
to allow aliasing of texture memory between the 3D image and the 2D view.
682682

683+
`VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT` also requires this parameter to be active,
684+
to allow aliasing of texture memory between the compressed image and the uncompressed view.
685+
683686
To force `MTLHeap` to be used on AMD GPUs, set this parameter to `2`.
684687
To disable the use of `MTLHeap` on any GPU, set this parameter to `0`.
685688

MoltenVK/MoltenVK/API/mvk_deprecated_api.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ typedef struct {
101101
VkDeviceSize mtlBufferAlignment; /**< The alignment used when allocating memory for MTLBuffers. Must be PoT. */
102102
VkDeviceSize maxQueryBufferSize; /**< The maximum size of an occlusion query buffer (in bytes). */
103103
VkDeviceSize mtlCopyBufferAlignment; /**< The alignment required during buffer copy operations (in bytes). */
104-
VkSampleCountFlags supportedSampleCounts; /**< A bitmask identifying the sample counts supported by the device. */
104+
VkSampleCountFlags supportedSampleCounts; /**< A bitmask identifying the sample counts supported by the device. */
105+
VkSampleCountFlags supportedSamplePosCounts; /**< A bitmask identifying the sample counts for which the device supports sample positions. */
105106
uint32_t minSwapchainImageCount; /**< The minimum number of swapchain images that can be supported by a surface. */
106107
uint32_t maxSwapchainImageCount; /**< The maximum number of swapchain images that can be supported by a surface. */
107108
VkBool32 combinedStoreResolveAction; /**< If true, the device supports VK_ATTACHMENT_STORE_OP_STORE with a simultaneous resolve attachment. */

MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,7 @@
12661266
}
12671267
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLE_LOCATIONS_PROPERTIES_EXT: {
12681268
auto* sampLocnProps = (VkPhysicalDeviceSampleLocationsPropertiesEXT*)next;
1269-
sampLocnProps->sampleLocationSampleCounts = _metalFeatures.supportedSampleCounts;
1269+
sampLocnProps->sampleLocationSampleCounts = _metalFeatures.supportedSamplePosCounts;
12701270
sampLocnProps->maxSampleLocationGridSize = kMVKSampleLocationPixelGridSize;
12711271
sampLocnProps->sampleLocationCoordinateRange[0] = kMVKMinSampleLocationCoordinate;
12721272
sampLocnProps->sampleLocationCoordinateRange[1] = kMVKMaxSampleLocationCoordinate;
@@ -1473,7 +1473,7 @@
14731473
void MVKPhysicalDevice::getMultisampleProperties(VkSampleCountFlagBits samples,
14741474
VkMultisamplePropertiesEXT* pMultisampleProperties) {
14751475
if (pMultisampleProperties) {
1476-
pMultisampleProperties->maxSampleLocationGridSize = (mvkIsOnlyAnyFlagEnabled(samples, _metalFeatures.supportedSampleCounts)
1476+
pMultisampleProperties->maxSampleLocationGridSize = (mvkIsOnlyAnyFlagEnabled(samples, _metalFeatures.supportedSamplePosCounts)
14771477
? kMVKSampleLocationPixelGridSize
14781478
: kMVKSampleLocationPixelGridSizeNotSupported);
14791479
}
@@ -1521,9 +1521,16 @@
15211521
}
15221522
}
15231523

1524-
// Metal does not support creating uncompressed views of compressed formats.
1524+
// These features require placement heaps to alias textures.
1525+
const auto placementHeapFlags = VK_IMAGE_CREATE_2D_VIEW_COMPATIBLE_BIT_EXT |
1526+
VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT |
1527+
VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT;
1528+
if (!getMVKConfig().useMTLHeap && mvkIsAnyFlagEnabled(flags, placementHeapFlags)) {
1529+
return VK_ERROR_FORMAT_NOT_SUPPORTED;
1530+
}
1531+
15251532
// Metal does not support split-instance images.
1526-
if (mvkIsAnyFlagEnabled(flags, VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT | VK_IMAGE_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT)) {
1533+
if (mvkIsAnyFlagEnabled(flags, VK_IMAGE_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT)) {
15271534
return VK_ERROR_FORMAT_NOT_SUPPORTED;
15281535
}
15291536

@@ -2834,6 +2841,11 @@
28342841
for (uint32_t sc = VK_SAMPLE_COUNT_1_BIT; sc <= VK_SAMPLE_COUNT_64_BIT; sc <<= 1) {
28352842
if ([_mtlDevice supportsTextureSampleCount: mvkSampleCountFromVkSampleCountFlagBits((VkSampleCountFlagBits)sc)]) {
28362843
_metalFeatures.supportedSampleCounts |= sc;
2844+
2845+
// Metal asserts: "count (1) is not a supported sample count for custom positions."
2846+
if (sc != VK_SAMPLE_COUNT_1_BIT) {
2847+
_metalFeatures.supportedSamplePosCounts |= sc;
2848+
}
28372849
}
28382850
}
28392851

MoltenVK/MoltenVK/GPUObjects/MVKImage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class MVKImagePlane : public MVKBaseObject {
6565
protected:
6666
friend class MVKImageMemoryBinding;
6767
friend MVKImage;
68+
friend class MVKImageViewPlane;
6869

6970
MTLTextureDescriptor* newMTLTextureDescriptor();
7071
void initSubresources(const VkImageCreateInfo* pCreateInfo);
@@ -402,6 +403,7 @@ class MVKImage : public MVKVulkanAPIDeviceObject {
402403
bool _shouldSupportAtomics;
403404
bool _isLinearForAtomics;
404405
bool _is2DViewOn3DImageCompatible = false;
406+
bool _isBlockTexelViewCompatible = false;
405407
};
406408

407409

0 commit comments

Comments
 (0)