KhronosGroup / Vulkan-Samples

One stop solution for all Vulkan samples
Apache License 2.0
4.33k stars 647 forks source link

iOS runtime fixes #1173

Open SRSaunders opened 1 month ago

SRSaunders commented 1 month ago

Description

This PR fixes multiple runtime issues for iOS physical device and iOS Simulator targets:

  1. General: Fixes error handling for main_loop_frame() and eliminates redundancy with main_loop(). Moved window close logic from main_loop() to main_loop_frame() so iOS can handle this condition properly. This does not change behaviour for other platforms since main_loop() calls main_loop_frame().
  2. General: Asserts for valid render context before calling render() within [HPP]ApiVulkanSample::update(). This is primarily defensive code but the issue was visible before improving error detection in main_loop_frame().
  3. iOS only: Adds main_loop_frame() return code handling within iOS renderLoop() - this was previously missing. Also adds exit handling when an error is encountered or batch mode is complete. The latter is unconventional for iOS, but is justified here since this is an Xcode-controlled developer application.
  4. iOS only: Adds support for setting and getting iOS window content scale factor, which is important for the rendering of certain samples on retina displays.
  5. General: Fixes [HPP]Gui::draw() to work with iOS Simulator with its vkCmdDrawIndexed() vertex offset limitations. The iOS Simulator does not support vertex offets > 0, so I made a modification that rebinds the vertex buffer with an offset when running on the iOS Simulator. Functionality is unchanged when running on real iOS targets or other platforms.
  6. General: Initializes pipeline variables to null handles for better startup error recovery in oit* samples. This issue shows up when a platform does not support the required sample features, and teardown crashes with uninitialized pipelines.
  7. General: Use Vulkan API 1.0 support funcs for Vulkan API 1.0 sample _host_imagecopy. The sample originally used vkGetPhysicalDeviceFormatProperties2() (API 1.1) but should use vkGetPhysicalDeviceFormatProperties2KHR(). This issue shows up when using MoltenVK which is more sensitive to the Vulkan API version than the Vulkan loader. Moved to a separate PR.
  8. iOS Simulator only: Disable MoltenVK's Metal Argument Buffers on the iOS Simulator for samples: _layout_transitions, pipelinebarriers, subpasses. Otherwise the samples can display blank screens on the iOS Simulator. Reverted for now until issue resolved in MoltenVK project.

Tested on iOS 17 with an iPhone 15, on the iOS Simulator, and macOS Ventura.

General Checklist:

Please ensure the following points are checked:

Sample Checklist

If your PR contains a new or modified sample, these further checks must be carried out in addition to the General Checklist: