Skip to content

Commit

Permalink
iOS: Support storage images in Metal argument buffers.
Browse files Browse the repository at this point in the history
On iOS GPUs with Tier1 argument buffer support, Metal does not
support writable textures in argument buffers. MoltenVK and
SPIRV-Cross were addressing this differently.

- Set CompilerMSL::Options::ArgumentBuffersTier to
  align behaviour between MoltenVK and SPIRV-Cross.
- On iOS Tier1 GPUs, if a descriptor set contains a storage image,
  don't use a Metal argument buffer for that descriptor set.
  • Loading branch information
billhollings committed Aug 1, 2024
1 parent 5b05413 commit bb476f5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions Docs/Whats_New.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Released TBD
- Fix rendering issue with render pass that immediately follows a kernel dispatch.
- Ensure all MoltenVK config info set by `VK_EXT_layer_settings` is used.
- Move primitive-restart-disabled warning from renderpass to pipeline creation, to reduce voluminous log noise.
- iOS: Support storage images in _Metal_ argument buffers.


MoltenVK 1.2.10
Expand Down
7 changes: 7 additions & 0 deletions MoltenVK/MoltenVK/GPUObjects/MVKDescriptor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,13 @@ void mvkPopulateShaderConversionConfig(mvk::SPIRVToMSLConversionConfiguration& s
setResourceIndexOffset(textureIndex, 1);
if (!getMetalFeatures().nativeTextureAtomics) { setResourceIndexOffset(bufferIndex, 1); }

#if MVK_IOS_OR_TVOS
// iOS Tier 1 argument buffers do not support writable images.
if (getMetalFeatures().argumentBuffersTier < MTLArgumentBuffersTier2) {
_layout->_canUseMetalArgumentBuffer = false;
}
#endif

if (pBinding->descriptorCount > 1 && !mtlFeats.arrayOfTextures) {
_layout->setConfigurationResult(reportError(VK_ERROR_FEATURE_NOT_PRESENT, "Device %s does not support arrays of textures.", _device->getName()));
}
Expand Down
1 change: 1 addition & 0 deletions MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class MVKDescriptorSetLayout : public MVKVulkanAPIDeviceObject {
MVKShaderResourceBinding _mtlResourceCounts;
int32_t _maxBufferIndex = -1;
bool _isPushDescriptorLayout = false;
bool _canUseMetalArgumentBuffer = true;
};


Expand Down
3 changes: 2 additions & 1 deletion MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.mm
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ static void populateAuxBuffer(mvk::SPIRVToMSLConversionConfiguration& shaderConf
}

bool MVKDescriptorSetLayout::isUsingMetalArgumentBuffers() {
return MVKDeviceTrackingMixin::isUsingMetalArgumentBuffers() && !_isPushDescriptorLayout;
return MVKDeviceTrackingMixin::isUsingMetalArgumentBuffers() && _canUseMetalArgumentBuffer;
};

// Returns an autoreleased MTLArgumentDescriptor suitable for adding an auxiliary buffer to the argument buffer.
Expand Down Expand Up @@ -354,6 +354,7 @@ static void populateAuxBuffer(mvk::SPIRVToMSLConversionConfiguration& shaderConf
const VkDescriptorSetLayoutCreateInfo* pCreateInfo) : MVKVulkanAPIDeviceObject(device) {

_isPushDescriptorLayout = mvkIsAnyFlagEnabled(pCreateInfo->flags, VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR);
_canUseMetalArgumentBuffer = !_isPushDescriptorLayout; // Push constants don't use argument buffers

const VkDescriptorBindingFlags* pBindingFlags = nullptr;
for (const auto* next = (VkBaseInStructure*)pCreateInfo->pNext; next; next = next->pNext) {
Expand Down
3 changes: 3 additions & 0 deletions MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1769,6 +1769,7 @@ static MTLVertexFormat mvkAdjustFormatVectorToSize(MTLVertexFormat format, uint3
shaderConfig.options.mslOptions.argument_buffers = useMetalArgBuff;
shaderConfig.options.mslOptions.force_active_argument_buffer_resources = false;
shaderConfig.options.mslOptions.pad_argument_buffer_resources = useMetalArgBuff;
shaderConfig.options.mslOptions.argument_buffers_tier = (SPIRV_CROSS_NAMESPACE::CompilerMSL::Options::ArgumentBuffersTier)getMetalFeatures().argumentBuffersTier;
shaderConfig.options.mslOptions.agx_manual_cube_grad_fixup = mtlFeats.needsCubeGradWorkaround;

MVKPipelineLayout* layout = (MVKPipelineLayout*)pCreateInfo->layout;
Expand Down Expand Up @@ -2213,6 +2214,7 @@ static MTLVertexFormat mvkAdjustFormatVectorToSize(MTLVertexFormat format, uint3
shaderConfig.options.mslOptions.argument_buffers = useMetalArgBuff;
shaderConfig.options.mslOptions.force_active_argument_buffer_resources = false;
shaderConfig.options.mslOptions.pad_argument_buffer_resources = useMetalArgBuff;
shaderConfig.options.mslOptions.argument_buffers_tier = (SPIRV_CROSS_NAMESPACE::CompilerMSL::Options::ArgumentBuffersTier)getMetalFeatures().argumentBuffersTier;

#if MVK_MACOS
shaderConfig.options.mslOptions.emulate_subgroups = !mtlFeats.simdPermute;
Expand Down Expand Up @@ -2600,6 +2602,7 @@ void serialize(Archive & archive, CompilerMSL::Options& opt) {
opt.texture_buffer_native,
opt.force_active_argument_buffer_resources,
opt.pad_argument_buffer_resources,
opt.argument_buffers_tier,
opt.force_native_arrays,
opt.enable_clip_distance_user_varying,
opt.multi_patch_workgroup,
Expand Down

0 comments on commit bb476f5

Please sign in to comment.