Standardize design pattern for enumerations of Vulkan struct pNext chains.
Consistently use for-loops, VkBaseInStructure and VkBaseOutStructure.
Remove redundant MVKVkAPIStructHeader structure.
Remove unnecessary null tests on incoming Vulkan struct pointers.
diff --git a/MoltenVK/MoltenVK/Commands/MVKCmdPipeline.mm b/MoltenVK/MoltenVK/Commands/MVKCmdPipeline.mm
index 01b8daf..af83890 100644
--- a/MoltenVK/MoltenVK/Commands/MVKCmdPipeline.mm
+++ b/MoltenVK/MoltenVK/Commands/MVKCmdPipeline.mm
@@ -261,18 +261,17 @@
}
if (mvkDvc->_enabledExtensions.vk_EXT_inline_uniform_block.enabled) {
const VkWriteDescriptorSetInlineUniformBlockEXT* pInlineUniformBlock = nullptr;
- for (auto* next = (VkWriteDescriptorSetInlineUniformBlockEXT*)descWrite.pNext; next; next = (VkWriteDescriptorSetInlineUniformBlockEXT*)next->pNext)
- {
+ for (const auto* next = (VkBaseInStructure*)descWrite.pNext; next; next = next->pNext) {
switch (next->sType) {
case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_INLINE_UNIFORM_BLOCK_EXT: {
- pInlineUniformBlock = next;
+ pInlineUniformBlock = (VkWriteDescriptorSetInlineUniformBlockEXT*)next;
break;
}
default:
break;
}
}
- if (pInlineUniformBlock != nullptr) {
+ if (pInlineUniformBlock) {
auto *pNewInlineUniformBlock = new VkWriteDescriptorSetInlineUniformBlockEXT(*pInlineUniformBlock);
pNewInlineUniformBlock->pNext = nullptr; // clear pNext just in case, no other extensions are supported at this time
descWrite.pNext = pNewInlineUniformBlock;
@@ -300,11 +299,10 @@
if (descWrite.pTexelBufferView) { delete[] descWrite.pTexelBufferView; }
const VkWriteDescriptorSetInlineUniformBlockEXT* pInlineUniformBlock = nullptr;
- for (auto* next = (VkWriteDescriptorSetInlineUniformBlockEXT*)descWrite.pNext; next; next = (VkWriteDescriptorSetInlineUniformBlockEXT*)next->pNext)
- {
+ for (const auto* next = (VkBaseInStructure*)descWrite.pNext; next; next = next->pNext) {
switch (next->sType) {
case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_INLINE_UNIFORM_BLOCK_EXT: {
- pInlineUniformBlock = next;
+ pInlineUniformBlock = (VkWriteDescriptorSetInlineUniformBlockEXT*)next;
break;
}
default:
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.mm
index a433703..45d5ba5 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.mm
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.mm
@@ -109,11 +109,10 @@
const VkBufferView* pTexelBufferView = descWrite.pTexelBufferView;
const VkWriteDescriptorSetInlineUniformBlockEXT* pInlineUniformBlock = nullptr;
if (_device->_enabledExtensions.vk_EXT_inline_uniform_block.enabled) {
- for (auto* next = (VkWriteDescriptorSetInlineUniformBlockEXT*)descWrite.pNext; next; next = (VkWriteDescriptorSetInlineUniformBlockEXT*)next->pNext)
- {
+ for (const auto* next = (VkBaseInStructure*)descWrite.pNext; next; next = next->pNext) {
switch (next->sType) {
case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_INLINE_UNIFORM_BLOCK_EXT: {
- pInlineUniformBlock = next;
+ pInlineUniformBlock = (VkWriteDescriptorSetInlineUniformBlockEXT*)next;
break;
}
default:
@@ -689,11 +688,10 @@
const VkWriteDescriptorSetInlineUniformBlockEXT* pInlineUniformBlock = nullptr;
if (dstSet->getDevice()->_enabledExtensions.vk_EXT_inline_uniform_block.enabled) {
- for (auto* next = (VkWriteDescriptorSetInlineUniformBlockEXT*)pDescWrite->pNext; next; next = (VkWriteDescriptorSetInlineUniformBlockEXT*)next->pNext)
- {
+ for (const auto* next = (VkBaseInStructure*)pDescWrite->pNext; next; next = next->pNext) {
switch (next->sType) {
case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_INLINE_UNIFORM_BLOCK_EXT: {
- pInlineUniformBlock = next;
+ pInlineUniformBlock = (VkWriteDescriptorSetInlineUniformBlockEXT*)next;
break;
}
default:
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
index 96f7f29..79a3db4 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
@@ -62,156 +62,152 @@
}
void MVKPhysicalDevice::getFeatures(VkPhysicalDeviceFeatures* features) {
- if (features) { *features = _features; }
+ *features = _features;
}
void MVKPhysicalDevice::getFeatures(VkPhysicalDeviceFeatures2* features) {
- if (features) {
- features->sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
- features->features = _features;
- for (auto* next = (VkBaseOutStructure*)features->pNext; next; next = next->pNext) {
- switch ((uint32_t)next->sType) {
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES: {
- auto* storageFeatures = (VkPhysicalDevice16BitStorageFeatures*)next;
- storageFeatures->storageBuffer16BitAccess = true;
- storageFeatures->uniformAndStorageBuffer16BitAccess = true;
- storageFeatures->storagePushConstant16 = true;
- storageFeatures->storageInputOutput16 = true;
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR: {
- auto* storageFeatures = (VkPhysicalDevice8BitStorageFeaturesKHR*)next;
- storageFeatures->storageBuffer8BitAccess = true;
- storageFeatures->uniformAndStorageBuffer8BitAccess = true;
- storageFeatures->storagePushConstant8 = true;
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR: {
- auto* f16Features = (VkPhysicalDeviceFloat16Int8FeaturesKHR*)next;
- f16Features->shaderFloat16 = true;
- f16Features->shaderInt8 = true;
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES_KHR: {
- auto* uboLayoutFeatures = (VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR*)next;
- uboLayoutFeatures->uniformBufferStandardLayout = true;
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES: {
- auto* varPtrFeatures = (VkPhysicalDeviceVariablePointerFeatures*)next;
- varPtrFeatures->variablePointersStorageBuffer = true;
- varPtrFeatures->variablePointers = true;
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADER_INTERLOCK_FEATURES_EXT: {
- auto* interlockFeatures = (VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT*)next;
- interlockFeatures->fragmentShaderSampleInterlock = _metalFeatures.rasterOrderGroups;
- interlockFeatures->fragmentShaderPixelInterlock = _metalFeatures.rasterOrderGroups;
- interlockFeatures->fragmentShaderShadingRateInterlock = false; // Requires variable rate shading; not supported yet in Metal
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT: {
- auto* hostQueryResetFeatures = (VkPhysicalDeviceHostQueryResetFeaturesEXT*)next;
- hostQueryResetFeatures->hostQueryReset = true;
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES_EXT: {
- auto* scalarLayoutFeatures = (VkPhysicalDeviceScalarBlockLayoutFeaturesEXT*)next;
- scalarLayoutFeatures->scalarBlockLayout = true;
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_FEATURES_EXT: {
- auto* texelBuffAlignFeatures = (VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT*)next;
- texelBuffAlignFeatures->texelBufferAlignment = _metalFeatures.texelBuffers && [_mtlDevice respondsToSelector: @selector(minimumLinearTextureAlignmentForPixelFormat:)];
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT: {
- auto* divisorFeatures = (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT*)next;
- divisorFeatures->vertexAttributeInstanceRateDivisor = true;
- divisorFeatures->vertexAttributeInstanceRateZeroDivisor = true;
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PORTABILITY_SUBSET_FEATURES_EXTX: {
- auto* portabilityFeatures = (VkPhysicalDevicePortabilitySubsetFeaturesEXTX*)next;
- portabilityFeatures->triangleFans = false;
- portabilityFeatures->separateStencilMaskRef = true;
- portabilityFeatures->events = true;
- portabilityFeatures->standardImageViews = _mvkInstance->getMoltenVKConfiguration()->fullImageViewSwizzle || _metalFeatures.nativeTextureSwizzle;
- portabilityFeatures->samplerMipLodBias = false;
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_INTEGER_FUNCTIONS_2_FEATURES_INTEL: {
- auto* shaderIntFuncsFeatures = (VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL*)next;
- shaderIntFuncsFeatures->shaderIntegerFunctions2 = true;
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT: {
- auto* inlineUniformBlockFeatures = (VkPhysicalDeviceInlineUniformBlockFeaturesEXT*)next;
- inlineUniformBlockFeatures->inlineUniformBlock = true;
- inlineUniformBlockFeatures->descriptorBindingInlineUniformBlockUpdateAfterBind = true;
- break;
- }
- default:
- break;
- }
- }
- }
+ features->sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
+ features->features = _features;
+ for (auto* next = (VkBaseOutStructure*)features->pNext; next; next = next->pNext) {
+ switch ((uint32_t)next->sType) {
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES: {
+ auto* storageFeatures = (VkPhysicalDevice16BitStorageFeatures*)next;
+ storageFeatures->storageBuffer16BitAccess = true;
+ storageFeatures->uniformAndStorageBuffer16BitAccess = true;
+ storageFeatures->storagePushConstant16 = true;
+ storageFeatures->storageInputOutput16 = true;
+ break;
+ }
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR: {
+ auto* storageFeatures = (VkPhysicalDevice8BitStorageFeaturesKHR*)next;
+ storageFeatures->storageBuffer8BitAccess = true;
+ storageFeatures->uniformAndStorageBuffer8BitAccess = true;
+ storageFeatures->storagePushConstant8 = true;
+ break;
+ }
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR: {
+ auto* f16Features = (VkPhysicalDeviceFloat16Int8FeaturesKHR*)next;
+ f16Features->shaderFloat16 = true;
+ f16Features->shaderInt8 = true;
+ break;
+ }
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES_KHR: {
+ auto* uboLayoutFeatures = (VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR*)next;
+ uboLayoutFeatures->uniformBufferStandardLayout = true;
+ break;
+ }
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES: {
+ auto* varPtrFeatures = (VkPhysicalDeviceVariablePointerFeatures*)next;
+ varPtrFeatures->variablePointersStorageBuffer = true;
+ varPtrFeatures->variablePointers = true;
+ break;
+ }
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADER_INTERLOCK_FEATURES_EXT: {
+ auto* interlockFeatures = (VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT*)next;
+ interlockFeatures->fragmentShaderSampleInterlock = _metalFeatures.rasterOrderGroups;
+ interlockFeatures->fragmentShaderPixelInterlock = _metalFeatures.rasterOrderGroups;
+ interlockFeatures->fragmentShaderShadingRateInterlock = false; // Requires variable rate shading; not supported yet in Metal
+ break;
+ }
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT: {
+ auto* hostQueryResetFeatures = (VkPhysicalDeviceHostQueryResetFeaturesEXT*)next;
+ hostQueryResetFeatures->hostQueryReset = true;
+ break;
+ }
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES_EXT: {
+ auto* scalarLayoutFeatures = (VkPhysicalDeviceScalarBlockLayoutFeaturesEXT*)next;
+ scalarLayoutFeatures->scalarBlockLayout = true;
+ break;
+ }
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_FEATURES_EXT: {
+ auto* texelBuffAlignFeatures = (VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT*)next;
+ texelBuffAlignFeatures->texelBufferAlignment = _metalFeatures.texelBuffers && [_mtlDevice respondsToSelector: @selector(minimumLinearTextureAlignmentForPixelFormat:)];
+ break;
+ }
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT: {
+ auto* divisorFeatures = (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT*)next;
+ divisorFeatures->vertexAttributeInstanceRateDivisor = true;
+ divisorFeatures->vertexAttributeInstanceRateZeroDivisor = true;
+ break;
+ }
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PORTABILITY_SUBSET_FEATURES_EXTX: {
+ auto* portabilityFeatures = (VkPhysicalDevicePortabilitySubsetFeaturesEXTX*)next;
+ portabilityFeatures->triangleFans = false;
+ portabilityFeatures->separateStencilMaskRef = true;
+ portabilityFeatures->events = true;
+ portabilityFeatures->standardImageViews = _mvkInstance->getMoltenVKConfiguration()->fullImageViewSwizzle || _metalFeatures.nativeTextureSwizzle;
+ portabilityFeatures->samplerMipLodBias = false;
+ break;
+ }
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_INTEGER_FUNCTIONS_2_FEATURES_INTEL: {
+ auto* shaderIntFuncsFeatures = (VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL*)next;
+ shaderIntFuncsFeatures->shaderIntegerFunctions2 = true;
+ break;
+ }
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT: {
+ auto* inlineUniformBlockFeatures = (VkPhysicalDeviceInlineUniformBlockFeaturesEXT*)next;
+ inlineUniformBlockFeatures->inlineUniformBlock = true;
+ inlineUniformBlockFeatures->descriptorBindingInlineUniformBlockUpdateAfterBind = true;
+ break;
+ }
+ default:
+ break;
+ }
+ }
}
void MVKPhysicalDevice::getProperties(VkPhysicalDeviceProperties* properties) {
- if (properties) { *properties = _properties; }
+ *properties = _properties;
}
void MVKPhysicalDevice::getProperties(VkPhysicalDeviceProperties2* properties) {
- if (properties) {
- properties->sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
- properties->properties = _properties;
- for (auto* next = (VkBaseOutStructure*)properties; next; next = next->pNext) {
- switch ((uint32_t)next->sType) {
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES: {
- auto* pointClipProps = (VkPhysicalDevicePointClippingProperties*)next;
- pointClipProps->pointClippingBehavior = VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES;
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES: {
- auto* maint3Props = (VkPhysicalDeviceMaintenance3Properties*)next;
- maint3Props->maxPerSetDescriptors = (_metalFeatures.maxPerStageBufferCount + _metalFeatures.maxPerStageTextureCount + _metalFeatures.maxPerStageSamplerCount) * 4;
- maint3Props->maxMemoryAllocationSize = _metalFeatures.maxMTLBufferSize;
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR: {
- auto* pushDescProps = (VkPhysicalDevicePushDescriptorPropertiesKHR*)next;
- pushDescProps->maxPushDescriptors = _properties.limits.maxPerStageResources;
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_PROPERTIES_EXT: {
- auto* texelBuffAlignProps = (VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT*)next;
- // Save the 'next' pointer; we'll unintentionally overwrite it
- // on the next line. Put it back when we're done.
- void* savedNext = texelBuffAlignProps->pNext;
- *texelBuffAlignProps = _texelBuffAlignProperties;
- texelBuffAlignProps->pNext = savedNext;
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT: {
- auto* divisorProps = (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT*)next;
- divisorProps->maxVertexAttribDivisor = kMVKUndefinedLargeUInt32;
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES: {
- populate((VkPhysicalDeviceIDProperties*)next);
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PORTABILITY_SUBSET_PROPERTIES_EXTX: {
- auto* portabilityProps = (VkPhysicalDevicePortabilitySubsetPropertiesEXTX*)next;
- portabilityProps->minVertexInputBindingStrideAlignment = 4;
- break;
- }
- default:
- break;
+ properties->sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
+ properties->properties = _properties;
+ for (auto* next = (VkBaseOutStructure*)properties->pNext; next; next = next->pNext) {
+ switch ((uint32_t)next->sType) {
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES: {
+ auto* pointClipProps = (VkPhysicalDevicePointClippingProperties*)next;
+ pointClipProps->pointClippingBehavior = VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES;
+ break;
}
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES: {
+ auto* maint3Props = (VkPhysicalDeviceMaintenance3Properties*)next;
+ maint3Props->maxPerSetDescriptors = (_metalFeatures.maxPerStageBufferCount + _metalFeatures.maxPerStageTextureCount + _metalFeatures.maxPerStageSamplerCount) * 4;
+ maint3Props->maxMemoryAllocationSize = _metalFeatures.maxMTLBufferSize;
+ break;
+ }
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR: {
+ auto* pushDescProps = (VkPhysicalDevicePushDescriptorPropertiesKHR*)next;
+ pushDescProps->maxPushDescriptors = _properties.limits.maxPerStageResources;
+ break;
+ }
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_PROPERTIES_EXT: {
+ auto* texelBuffAlignProps = (VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT*)next;
+ // Save the 'next' pointer; we'll unintentionally overwrite it
+ // on the next line. Put it back when we're done.
+ void* savedNext = texelBuffAlignProps->pNext;
+ *texelBuffAlignProps = _texelBuffAlignProperties;
+ texelBuffAlignProps->pNext = savedNext;
+ break;
+ }
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT: {
+ auto* divisorProps = (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT*)next;
+ divisorProps->maxVertexAttribDivisor = kMVKUndefinedLargeUInt32;
+ break;
+ }
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES: {
+ populate((VkPhysicalDeviceIDProperties*)next);
+ break;
+ }
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PORTABILITY_SUBSET_PROPERTIES_EXTX: {
+ auto* portabilityProps = (VkPhysicalDevicePortabilitySubsetPropertiesEXTX*)next;
+ portabilityProps->minVertexInputBindingStrideAlignment = 4;
+ break;
+ }
+ default:
+ break;
}
- }
+ }
}
// Populates the device ID properties structure
@@ -270,17 +266,12 @@
}
void MVKPhysicalDevice::getFormatProperties(VkFormat format, VkFormatProperties* pFormatProperties) {
- if (pFormatProperties) {
- *pFormatProperties = _pixelFormats.getVkFormatProperties(format);
- }
+ *pFormatProperties = _pixelFormats.getVkFormatProperties(format);
}
-void MVKPhysicalDevice::getFormatProperties(VkFormat format,
- VkFormatProperties2KHR* pFormatProperties) {
- if (pFormatProperties) {
- pFormatProperties->sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2_KHR;
- pFormatProperties->formatProperties = _pixelFormats.getVkFormatProperties(format);
- }
+void MVKPhysicalDevice::getFormatProperties(VkFormat format, VkFormatProperties2KHR* pFormatProperties) {
+ pFormatProperties->sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2_KHR;
+ pFormatProperties->formatProperties = _pixelFormats.getVkFormatProperties(format);
}
VkResult MVKPhysicalDevice::getImageFormatProperties(VkFormat format,
@@ -419,13 +410,13 @@
VkResult MVKPhysicalDevice::getImageFormatProperties(const VkPhysicalDeviceImageFormatInfo2 *pImageFormatInfo,
VkImageFormatProperties2* pImageFormatProperties) {
- for (const auto* nextInfo = (VkBaseInStructure*)pImageFormatInfo; nextInfo; nextInfo = nextInfo->pNext) {
- switch ((uint32_t)nextInfo->sType) {
+ for (const auto* nextInfo = (VkBaseInStructure*)pImageFormatInfo->pNext; nextInfo; nextInfo = nextInfo->pNext) {
+ switch (nextInfo->sType) {
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO: {
// Return information about external memory support for MTLTexture.
// Search VkImageFormatProperties2 for the corresponding VkExternalImageFormatProperties and populate it.
auto* pExtImgFmtInfo = (VkPhysicalDeviceExternalImageFormatInfo*)nextInfo;
- for (auto* nextProps = (VkBaseOutStructure*)pImageFormatProperties; nextProps; nextProps = nextProps->pNext) {
+ for (auto* nextProps = (VkBaseOutStructure*)pImageFormatProperties->pNext; nextProps; nextProps = nextProps->pNext) {
if (nextProps->sType == VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES) {
auto* pExtImgFmtProps = (VkExternalImageFormatProperties*)nextProps;
@@ -453,8 +444,7 @@
// If the image format info links portability image view info, test if an image view of that configuration is supported
bool MVKPhysicalDevice::getImageViewIsSupported(const VkPhysicalDeviceImageFormatInfo2 *pImageFormatInfo) {
- auto* next = (MVKVkAPIStructHeader*)pImageFormatInfo->pNext;
- while (next) {
+ for (const auto* next = (VkBaseInStructure*)pImageFormatInfo->pNext; next; next = next->pNext) {
switch ((uint32_t)next->sType) {
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_VIEW_SUPPORT_EXTX: {
auto* portImgViewInfo = (VkPhysicalDeviceImageViewSupportEXTX*)next;
@@ -462,7 +452,7 @@
// Create an image view and test whether it could be configured
VkImageViewCreateInfo viewInfo = {
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
- .pNext = (VkStructureType*)portImgViewInfo->pNext,
+ .pNext = portImgViewInfo->pNext,
.flags = portImgViewInfo->flags,
.image = nullptr,
.viewType = portImgViewInfo->viewType,
@@ -483,7 +473,6 @@
mtlPixFmt, useSwizzle) == VK_SUCCESS);
}
default:
- next = (MVKVkAPIStructHeader*)next->pNext;
break;
}
}
@@ -823,11 +812,10 @@
}
VkResult MVKPhysicalDevice::getMemoryProperties(VkPhysicalDeviceMemoryProperties2* pMemoryProperties) {
- if (pMemoryProperties) {
- pMemoryProperties->sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2;
- pMemoryProperties->memoryProperties = _memoryProperties;
- for (auto* next = (VkBaseOutStructure*)pMemoryProperties->pNext; next; next = next->pNext) {
- switch (next->sType) {
+ pMemoryProperties->sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2;
+ pMemoryProperties->memoryProperties = _memoryProperties;
+ for (auto* next = (VkBaseOutStructure*)pMemoryProperties->pNext; next; next = next->pNext) {
+ switch (next->sType) {
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT: {
auto* budgetProps = (VkPhysicalDeviceMemoryBudgetPropertiesEXT*)next;
mvkClear(budgetProps->heapBudget, VK_MAX_MEMORY_HEAPS);
@@ -842,7 +830,6 @@
}
default:
break;
- }
}
}
return VK_SUCCESS;
@@ -2909,8 +2896,7 @@
&pdFeats2.features.robustBufferAccess, 55);
}
- auto* next = (MVKVkAPIStructHeader*)pCreateInfo->pNext;
- while (next) {
+ for (const auto* next = (VkBaseInStructure*)pCreateInfo->pNext; next; next = next->pNext) {
switch ((uint32_t)next->sType) {
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2: {
auto* requestedFeatures = (VkPhysicalDeviceFeatures2*)next;
@@ -2999,7 +2985,6 @@
default:
break;
}
- next = (MVKVkAPIStructHeader*)next->pNext;
}
}
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm b/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm
index 89fb6dd..0fdd941 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm
@@ -1002,11 +1002,9 @@
default:
break;
}
- if (swapchainInfo) { break; }
}
- if (!swapchainInfo) {
- return VK_ERROR_OUT_OF_DEVICE_MEMORY;
- }
+ if (!swapchainInfo) { return VK_ERROR_OUT_OF_DEVICE_MEMORY; }
+
_swapchainIndex = swapchainInfo->imageIndex;
return VK_SUCCESS;
}
@@ -1114,17 +1112,14 @@
_image = (MVKImage*)pCreateInfo->image;
_usage = _image->_usage;
- auto* next = (MVKVkAPIStructHeader*)pCreateInfo->pNext;
- while (next) {
- switch ((uint32_t)next->sType) {
+ for (const auto* next = (VkBaseInStructure*)pCreateInfo->pNext; next; next = next->pNext) {
+ switch (next->sType) {
case VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO: {
auto* pViewUsageInfo = (VkImageViewUsageCreateInfo*)next;
if (!(pViewUsageInfo->usage & ~_usage)) { _usage = pViewUsageInfo->usage; }
- next = (MVKVkAPIStructHeader*)next->pNext;
break;
}
default:
- next = (MVKVkAPIStructHeader*)next->pNext;
break;
}
}
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKInstance.mm b/MoltenVK/MoltenVK/GPUObjects/MVKInstance.mm
index aa08efa..66d7a6b 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKInstance.mm
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKInstance.mm
@@ -383,8 +383,7 @@
_hasDebugUtilsMessengers = false;
_debugReportCallbackLayerPrefix = getDriverLayer()->getName();
- MVKVkAPIStructHeader* next = (MVKVkAPIStructHeader*)pCreateInfo->pNext;
- while (next) {
+ for (const auto* next = (VkBaseInStructure*)pCreateInfo->pNext; next; next = next->pNext) {
switch (next->sType) {
case VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT:
createDebugReportCallback((VkDebugReportCallbackCreateInfoEXT*)next, nullptr);
@@ -395,7 +394,6 @@
default:
break;
}
- next = (MVKVkAPIStructHeader*)next->pNext;
}
}
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm b/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm
index 727f02b..c67ab8c 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm
@@ -944,15 +944,12 @@
const SPIRVToMSLConversionConfiguration& shaderContext) {
// Collect extension structures
VkPipelineVertexInputDivisorStateCreateInfoEXT* pVertexInputDivisorState = nullptr;
- auto* next = (MVKVkAPIStructHeader*)pVI->pNext;
- while (next) {
+ for (const auto* next = (VkBaseInStructure*)pVI->pNext; next; next = next->pNext) {
switch (next->sType) {
case VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_DIVISOR_STATE_CREATE_INFO_EXT:
pVertexInputDivisorState = (VkPipelineVertexInputDivisorStateCreateInfoEXT*)next;
- next = (MVKVkAPIStructHeader*)pVertexInputDivisorState->pNext;
break;
default:
- next = (MVKVkAPIStructHeader*)next->pNext;
break;
}
}
@@ -1032,15 +1029,12 @@
VkPipelineTessellationDomainOriginStateCreateInfo* pTessDomainOriginState = nullptr;
if (reflectData.patchKind == spv::ExecutionModeTriangles) {
- auto* next = (MVKVkAPIStructHeader*)pTS->pNext;
- while (next) {
+ for (const auto* next = (VkBaseInStructure*)pTS->pNext; next; next = next->pNext) {
switch (next->sType) {
case VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_DOMAIN_ORIGIN_STATE_CREATE_INFO:
pTessDomainOriginState = (VkPipelineTessellationDomainOriginStateCreateInfo*)next;
- next = (MVKVkAPIStructHeader*)pTessDomainOriginState->pNext;
break;
default:
- next = (MVKVkAPIStructHeader*)next->pNext;
break;
}
}
@@ -1131,15 +1125,12 @@
VkPipelineTessellationDomainOriginStateCreateInfo* pTessDomainOriginState = nullptr;
if (pCreateInfo->pTessellationState) {
- auto* next = (MVKVkAPIStructHeader*)pCreateInfo->pTessellationState->pNext;
- while (next) {
+ for (const auto* next = (VkBaseInStructure*)pCreateInfo->pTessellationState->pNext; next; next = next->pNext) {
switch (next->sType) {
case VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_DOMAIN_ORIGIN_STATE_CREATE_INFO:
pTessDomainOriginState = (VkPipelineTessellationDomainOriginStateCreateInfo*)next;
- next = (MVKVkAPIStructHeader*)pTessDomainOriginState->pNext;
break;
default:
- next = (MVKVkAPIStructHeader*)next->pNext;
break;
}
}
diff --git a/MoltenVK/MoltenVK/Utility/MVKFoundation.h b/MoltenVK/MoltenVK/Utility/MVKFoundation.h
index c256bf0..c2c17f3 100644
--- a/MoltenVK/MoltenVK/Utility/MVKFoundation.h
+++ b/MoltenVK/MoltenVK/Utility/MVKFoundation.h
@@ -55,12 +55,6 @@
/** A representation of the value of 1.0 as a 16-bit half-float. */
#define kHalfFloat1 0x3C00
-/** Common header for many standard Vulkan API structures. */
-typedef struct {
- VkStructureType sType;
- const void* pNext;
-} MVKVkAPIStructHeader;
-
#pragma mark -
#pragma mark Vertex content structures