Skip to content

Commit ce1cded

Browse files
committed
Add support for VK_KHR_maintenance8
1 parent 2c6767a commit ce1cded

File tree

9 files changed

+52
-10
lines changed

9 files changed

+52
-10
lines changed

Docs/MoltenVK_Runtime_UserGuide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ In addition to core *Vulkan* functionality, **MoltenVK** also supports the foll
266266
- `VK_KHR_maintenance5`
267267
- `VK_KHR_maintenance6`
268268
- `VK_KHR_maintenance7`
269+
- `VK_KHR_maintenance8`
269270
- `VK_KHR_map_memory2`
270271
- `VK_KHR_multiview`
271272
- `VK_KHR_portability_subset`

Docs/Whats_New.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Released TBD
2121
- Add support for extensions:
2222
- `VK_KHR_global_priority`
2323
- `VK_KHR_maintenance5`
24+
- `VK_KHR_maintenance8`
2425
- `VK_KHR_present_id`
2526
- `VK_KHR_present_wait`
2627
- `VK_KHR_shader_relaxed_extended_instruction`
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e07cec7482ed583f58625d3f3c34874e53a003be
1+
f1cb5b6634c58be69c327450d0023fb061f0f650

MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,26 @@ static inline MTLSize mvkClampMTLSize(MTLSize size, MTLOrigin origin, MTLSize ma
102102
return VK_SUCCESS;
103103
}
104104

105+
static inline MTLPixelFormat getDepthStencilAspectFormat(const MTLPixelFormat format, const VkImageAspectFlags aspectMask) {
106+
if (format == MTLPixelFormatDepth32Float_Stencil8) {
107+
if (aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) return MTLPixelFormatDepth32Float;
108+
if (aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) return MTLPixelFormatStencil8;
109+
}
110+
return format;
111+
}
112+
105113
template <size_t N>
106114
inline VkResult MVKCmdCopyImage<N>::validate(MVKCommandBuffer* cmdBuff, const VkImageCopy2* region) {
107115
uint8_t srcPlaneIndex = MVKImage::getPlaneFromVkImageAspectFlags(region->srcSubresource.aspectMask);
108116
uint8_t dstPlaneIndex = MVKImage::getPlaneFromVkImageAspectFlags(region->dstSubresource.aspectMask);
109117

118+
auto srcFormat = getDepthStencilAspectFormat(_srcImage->getMTLPixelFormat(srcPlaneIndex), region->srcSubresource.aspectMask);
119+
auto dstFormat = getDepthStencilAspectFormat(_dstImage->getMTLPixelFormat(dstPlaneIndex), region->dstSubresource.aspectMask);
120+
110121
// Validate
111122
MVKPixelFormats* pixFmts = cmdBuff->getPixelFormats();
112123
if ((_dstImage->getSampleCount() != _srcImage->getSampleCount()) ||
113-
(pixFmts->getBytesPerBlock(_dstImage->getMTLPixelFormat(dstPlaneIndex)) != pixFmts->getBytesPerBlock(_srcImage->getMTLPixelFormat(srcPlaneIndex)))) {
124+
(pixFmts->getBytesPerBlock(srcFormat) != pixFmts->getBytesPerBlock(dstFormat))) {
114125
return cmdBuff->reportError(VK_ERROR_FEATURE_NOT_PRESENT, "vkCmdCopyImage(): Cannot copy between incompatible formats, such as formats of different pixel sizes, or between images with different sample counts.");
115126
}
116127
return VK_SUCCESS;
@@ -133,17 +144,20 @@ static inline MTLSize mvkClampMTLSize(MTLSize size, MTLOrigin origin, MTLSize ma
133144

134145
MTLPixelFormat srcMTLPixFmt = _srcImage->getMTLPixelFormat(srcPlaneIndex);
135146
bool isSrcCompressed = _srcImage->getIsCompressed();
147+
bool isSrcCombinedDepthStencil = srcMTLPixFmt == MTLPixelFormatDepth32Float_Stencil8;
136148
bool canReinterpretSrc = _srcImage->hasPixelFormatView(srcPlaneIndex);
137149

138150
MTLPixelFormat dstMTLPixFmt = _dstImage->getMTLPixelFormat(dstPlaneIndex);
139151
bool isDstCompressed = _dstImage->getIsCompressed();
152+
bool isDstCombinedDepthStencil = dstMTLPixFmt == MTLPixelFormatDepth32Float_Stencil8;
140153
bool canReinterpretDst = _dstImage->hasPixelFormatView(dstPlaneIndex);
141154

142155
bool isEitherCompressed = isSrcCompressed || isDstCompressed;
156+
bool isOneCombinedDepthStencil = isSrcCombinedDepthStencil != isDstCombinedDepthStencil;
143157
bool canReinterpret = canReinterpretSrc || canReinterpretDst;
144158

145159
// If source and destination can't be reinterpreted to matching formats use a temporary intermediary buffer
146-
bool useTempBuffer = (srcMTLPixFmt != dstMTLPixFmt) && (isEitherCompressed || !canReinterpret);
160+
bool useTempBuffer = (srcMTLPixFmt != dstMTLPixFmt) && (isEitherCompressed || isOneCombinedDepthStencil || !canReinterpret);
147161

148162
if (useTempBuffer) {
149163
// Add copy from source image to temp buffer.
@@ -459,7 +473,6 @@ static inline MTLSize mvkClampMTLSize(MTLSize size, MTLOrigin origin, MTLSize ma
459473

460474
template <size_t N>
461475
void MVKCmdBlitImage<N>::encode(MVKCommandEncoder* cmdEncoder, MVKCommandUse commandUse) {
462-
463476
auto& mtlFeats = cmdEncoder->getMetalFeatures();
464477
size_t vkIBCnt = _vkImageBlits.size();
465478
VkImageCopy vkImageCopies[vkIBCnt];
@@ -587,11 +600,23 @@ static inline MTLSize mvkClampMTLSize(MTLSize size, MTLOrigin origin, MTLSize ma
587600

588601
bool isLayeredBlit = blitKey.dstSampleCount > 1 ? mtlFeats.multisampleLayeredRendering : mtlFeats.layeredRendering;
589602

590-
uint32_t layCnt = mvkIBR.region.srcSubresource.layerCount == VK_REMAINING_ARRAY_LAYERS ?
603+
uint32_t srcLayCnt = mvkIBR.region.srcSubresource.layerCount == VK_REMAINING_ARRAY_LAYERS ?
591604
_srcImage->getLayerCount() - mvkIBR.region.srcSubresource.baseArrayLayer :
592605
mvkIBR.region.srcSubresource.layerCount;
606+
uint32_t dstLayCnt = mvkIBR.region.dstSubresource.layerCount == VK_REMAINING_ARRAY_LAYERS ?
607+
_dstImage->getLayerCount() - mvkIBR.region.dstSubresource.baseArrayLayer :
608+
mvkIBR.region.dstSubresource.layerCount;
609+
uint32_t layCnt;
610+
// If either image is 3D, the difference in z offset must:
611+
// - Equal the difference in z offset of the other subresource, if it is also 3D.
612+
// - Equal the number of layers in the other subresource, if it is not 3D.
613+
// Otherwise, the number of layers should be the same.
593614
if (_dstImage->getMTLTextureType() == MTLTextureType3D) {
594615
layCnt = mvkAbsDiff(mvkIBR.region.dstOffsets[1].z, mvkIBR.region.dstOffsets[0].z);
616+
} else if (blitKey.srcMTLTextureType == MTLTextureType3D) {
617+
layCnt = mvkAbsDiff(mvkIBR.region.srcOffsets[1].z, mvkIBR.region.srcOffsets[0].z);
618+
} else {
619+
layCnt = srcLayCnt;
595620
}
596621
if (isLayeredBlit) {
597622
// In this case, I can blit all layers at once with a layered draw.
@@ -629,14 +654,19 @@ static inline MTLSize mvkClampMTLSize(MTLSize size, MTLOrigin origin, MTLSize ma
629654
// In this case, I need to interpolate along the third dimension manually.
630655
VkExtent3D srcExtent = _srcImage->getExtent3D(srcPlaneIndex, mvkIBR.region.dstSubresource.mipLevel);
631656
VkOffset3D so0 = mvkIBR.region.srcOffsets[0], so1 = mvkIBR.region.srcOffsets[1];
632-
VkOffset3D do0 = mvkIBR.region.dstOffsets[0], do1 = mvkIBR.region.dstOffsets[1];
657+
// If the dst is also 3D use the z offsets, otherwise use the layers.
658+
float do0z = mvkIBR.region.dstOffsets[0].z, do1z = mvkIBR.region.dstOffsets[1].z;
659+
if (_dstImage->getMTLTextureType() != MTLTextureType3D) {
660+
do0z = mvkIBR.region.dstSubresource.baseArrayLayer;
661+
do1z = do0z + dstLayCnt;
662+
}
633663
float startZ = (float)so0.z / (float)srcExtent.depth;
634664
float endZ = (float)so1.z / (float)srcExtent.depth;
635-
if (isLayeredBlit && do0.z > do1.z) {
665+
if (isLayeredBlit && do0z > do1z) {
636666
// Swap start and end points so interpolation moves in the right direction.
637667
std::swap(startZ, endZ);
638668
}
639-
zIncr = (endZ - startZ) / mvkAbsDiff(do1.z, do0.z);
669+
zIncr = (endZ - startZ) / mvkAbsDiff(do1z, do0z);
640670
float z = startZ + (isLayeredBlit ? 0.0 : (layIdx + 0.5)) * zIncr;
641671
for (uint32_t i = 0; i < kMVKBlitVertexCount; ++i) {
642672
mvkIBR.vertices[i].texCoord.z = z;

MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,11 @@
515515
maintenance7Features->maintenance7 = true;
516516
break;
517517
}
518+
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_8_FEATURES_KHR: {
519+
auto* maintenance8Features = (VkPhysicalDeviceMaintenance8FeaturesKHR*)next;
520+
maintenance8Features->maintenance8 = true;
521+
break;
522+
}
518523
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PORTABILITY_SUBSET_FEATURES_KHR: {
519524
auto* portabilityFeatures = (VkPhysicalDevicePortabilitySubsetFeaturesKHR*)next;
520525
portabilityFeatures->constantAlphaColorBlendFactors = true;

MoltenVK/MoltenVK/GPUObjects/MVKDeviceFeatureStructs.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ MVK_DEVICE_FEATURE_EXTN(FragmentShaderBarycentric, FRAGMENT_SHADER_BARYCE
7373
MVK_DEVICE_FEATURE_EXTN(Maintenance5, MAINTENANCE_5, KHR, 1)
7474
MVK_DEVICE_FEATURE_EXTN(Maintenance6, MAINTENANCE_6, KHR, 1)
7575
MVK_DEVICE_FEATURE_EXTN(Maintenance7, MAINTENANCE_7, KHR, 1)
76+
MVK_DEVICE_FEATURE_EXTN(Maintenance8, MAINTENANCE_8, KHR, 1)
7677
MVK_DEVICE_FEATURE_EXTN(PortabilitySubset, PORTABILITY_SUBSET, KHR, 15)
7778
MVK_DEVICE_FEATURE_EXTN(PresentId, PRESENT_ID, KHR, 1)
7879
MVK_DEVICE_FEATURE_EXTN(PresentWait, PRESENT_WAIT, KHR, 1)

MoltenVK/MoltenVK/GPUObjects/MVKPipeline.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ class MVKPipelineCache : public MVKVulkanAPIDeviceObject {
576576
size_t _dataSize = 0;
577577
std::mutex _shaderCacheLock;
578578
bool _isExternallySynchronized = false;
579+
bool _isMergeInternallySynchronized = false;
579580
};
580581

581582

MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2645,7 +2645,7 @@ static MTLVertexFormat mvkAdjustFormatVectorToSize(MTLVertexFormat format, uint3
26452645
}
26462646

26472647
VkResult MVKPipelineCache::mergePipelineCaches(uint32_t srcCacheCount, const VkPipelineCache* pSrcCaches) {
2648-
if (_isExternallySynchronized) {
2648+
if (!_isMergeInternallySynchronized) {
26492649
return mergePipelineCachesImpl(srcCacheCount, pSrcCaches);
26502650
} else {
26512651
lock_guard<mutex> lock(_shaderCacheLock);
@@ -2894,7 +2894,9 @@ void serialize(Archive & archive, MVKCompressor<C>& comp) {
28942894
MVKPipelineCache::MVKPipelineCache(MVKDevice* device, const VkPipelineCacheCreateInfo* pCreateInfo) :
28952895
MVKVulkanAPIDeviceObject(device),
28962896
_isExternallySynchronized(getEnabledPipelineCreationCacheControlFeatures().pipelineCreationCacheControl &&
2897-
mvkIsAnyFlagEnabled(pCreateInfo->flags, VK_PIPELINE_CACHE_CREATE_EXTERNALLY_SYNCHRONIZED_BIT)) {
2897+
mvkIsAnyFlagEnabled(pCreateInfo->flags, VK_PIPELINE_CACHE_CREATE_EXTERNALLY_SYNCHRONIZED_BIT)),
2898+
_isMergeInternallySynchronized(getEnabledPipelineCreationCacheControlFeatures().pipelineCreationCacheControl &&
2899+
mvkIsAnyFlagEnabled(pCreateInfo->flags, VK_PIPELINE_CACHE_CREATE_INTERNALLY_SYNCHRONIZED_MERGE_BIT_KHR)) {
28982900

28992901
readData(pCreateInfo);
29002902
}

MoltenVK/MoltenVK/Layers/MVKExtensions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ MVK_EXTENSION(KHR_maintenance4, KHR_MAINTENANCE_4,
8181
MVK_EXTENSION(KHR_maintenance5, KHR_MAINTENANCE_5, DEVICE, 10.11, 8.0, 1.0)
8282
MVK_EXTENSION(KHR_maintenance6, KHR_MAINTENANCE_6, DEVICE, 10.11, 8.0, 1.0)
8383
MVK_EXTENSION(KHR_maintenance7, KHR_MAINTENANCE_7, DEVICE, 10.11, 8.0, 1.0)
84+
MVK_EXTENSION(KHR_maintenance8, KHR_MAINTENANCE_8, DEVICE, 10.11, 8.0, 1.0)
8485
MVK_EXTENSION(KHR_map_memory2, KHR_MAP_MEMORY_2, DEVICE, 10.11, 8.0, 1.0)
8586
MVK_EXTENSION(KHR_multiview, KHR_MULTIVIEW, DEVICE, 10.11, 8.0, 1.0)
8687
MVK_EXTENSION(KHR_portability_subset, KHR_PORTABILITY_SUBSET, DEVICE, 10.11, 8.0, 1.0)

0 commit comments

Comments
 (0)