Example-specific fixes for: MoltenVK config, OpenMP build, UBO size alignment, descriptorindexing memory bounds error
This is a set of example-specific fixes:
- Set MoltenVK configuration for descriptorindexing (enable Metal argument buffers for descriptor indexing on macOS, not available on iOS), oit (use
VK_IMAGE_TILING_LINEARvs.VK_IMAGE_TILING_OPTIMALfor atomic image access on macOS/iOS), and computeraytracing / specializationcontants (disable Metal argument buffers for macOS) - Optimize CMakeLists for OpenMP build - only run
find_package(OpenMP)for texture3d example, minimizing per-example cmake build overhead which is significant when OpenMP is not installed, applies to all platforms - Fix vertex memory bounds error in descriptorindexing - this appeared as graphics corruption when testing on Apple M1, but is a generic problem. The indices list (index buffer) was constructed incorrectly and was referencing beyond the end of the cube vertices list (vertex buffer). The solution is a simple reordering of the fill loop, and results in the correct number of cubes being generated (loop count now set to 5 instead of 6, with 5 cubes + indices correctly generated)
- Fix UBO buffer size inconsistency between code and shaders for computeraytracing, ssao, and texturearray examples. I noticed this when testing on macOS where Xcode performs Metal API argument validation by default. The fixes are generic, and perhaps may be helpful for Vulkan API argument validators (??) on other platforms.
Tested on macOS, iOS, Windows, and Linux.
This is likely my last pull request for a while, as I have exhausted what I can do for the macOS/iOS platforms without further improvements in MoltenVK and/or Metal (e.g. 1.2 API, geometry shaders, ray tracing). At least for the moment I have 65 of the 79 examples running cleanly (no validation errors) on macOS with MoltenVK 1.1.10 (SDK 1.3.216) using my test rigs (Intel Mac/AMD GPU with Big Sur, MacBook Air M1 with Monterey).
This is a very useful project and thanks to @SaschaWillems for originating and maintaining it.
Just for reference, I thought I would list the missing extensions and device features that would be required for MoltenVK/Metal to support the remaining 14 examples:
VK_EXT_conditional_rendering (for conditionalrender example)
VK_EXT_conservative_rasterization (for conservativeraster example)
VK_KHR_pipeline_library (for graphicspipelinelibrary example)
VK_EXT_graphics_pipeline_library (for graphicspipelinelibrary example)
VK_KHR_acceleration_structure (for all ray* examples)
VK_KHR_buffer_device_address (for all ray* examples) - now supported by MoltenVK/Metal 3 on macOS 13/iOS 16
VK_KHR_spirv_1_4 (for all ray* examples)
VK_KHR_shader_float_controls (for all ray* examples)
VK_KHR_ray_tracing_pipeline (for all ray* examples except for rayquery)
VK_KHR_deferred_host_operations (for all ray* examples except for rayquery)
VK_KHR_ray_query (for rayquery example)
VK_NV_shading_rate_image (for variablerateshading example)
VkPhysicalDeviceFeatures::geometryShader (for deferredshadows, geometryshader, viewportarray examples)
VkPhysicalDeviceFeatures::pipelineStatisticsQuery (for pipelinestatistics example)
VkPhysicalDeviceFeatures::sparseBinding (for texturesparseresidency example)
VkPhysicalDeviceFeatures::sparseResidencyImage2D (for texturesparseresidency example)
Once again thank you very much for this PR. I really appreciate your fixes.
Will try to review this asap.