Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable unsupported Metal Pixel formats for iOS/tvOS Simulator #2361

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

SRSaunders
Copy link
Contributor

@SRSaunders SRSaunders commented Oct 2, 2024

Defines certain unsupported Metal Pixel formats as invalid for the iOS/tvOS Simulator. Fixes #2353 for MoltenVK 1.2.11.

I have tested this on an x86_64 host using Xcode 15.2 with the iOS Simulator (running iOS 17.2). I can't test on tvOS so I would appreciate others (@warmenhoven) checking out this scenario.

Also, I am not sure whether the #ifdef condition should also contain an Xcode version test. Perhaps @cdavis5e could weigh in on that aspect. Thanks.

@cdavis5e cdavis5e self-requested a review October 2, 2024 21:21
Copy link
Collaborator

@cdavis5e cdavis5e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A version check is only necessary for when earlier versions don't have the pixel format enumerator in the SDK but later versions do. That doesn't apply here, since all of those pixel formats have been supported since iOS 8. AFAIK, those formats have never been supported under the simulator, even on Apple Silicon for some reason.

Copy link
Contributor

@billhollings billhollings left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting this! And thanks everyone for all the discussion on #2353!

First of all, I'm sorry that my 5afeaa4 triggered the need for this!

Based upon the "I recall reading somewhere" comment by @cdavis5e in #2353, I went hunting, and sure enough, hidden away in the Apple docs, is the explanation.

Unfortunately, that doc also make this somewhat more complicated.

These 5 formats you identified MTLPixelFormats, plus all of the XR10 and YUV formats, are not supported on the simulator platforms.

So, @SRSaunders, can you add the following to this PR, please and thanks?

  1. Add all the XR10 and YUV formats to your conditional format remapping.
  2. Add && !MVK_OS_SIMULATOR to the #if MVK_APPLE_SILICON for the XR10 formats in MVKPhysicalDevice::getSurfaceFormats().
  3. According to the same doc, the format MTLPixelFormatRGB9E5Float cannot be used as a render target on the simulator. I think the best way to deal with this is in MVKPixelFormats::modifyMTLFormatCapabilities(). Perhaps add the following, right below the other two mods there for RGB9E5Float:
    disableMTLPixFmtCapsIf( MVK_OS_SIMULATOR, RGB9E5Float, ColorAtt );
  1. And finally, none of the _sRGB formats can be written to in the simulator. I think the best way to handle this might be in #define addMTLPixelFormatDescSRGB(), by adding something like:
    if(MVK_APPLE_SILICON) { mvkDisableFlags(appleGPUCaps, kMVKMTLFmtCapsWrite); }

Uggh! Needless to say, I'm not a fan of the simulator! 😉

@SRSaunders
Copy link
Contributor Author

SRSaunders commented Oct 3, 2024

Looking at the Apple docs, they do not mention MTLPixelFormatRG8Unorm_sRGB, but disabling this on the Simulator seems necessary. Did this format come later? Note I also added MTLPixelFormatBGR5A1Unorm (from the docs) for completeness, although this is already disabled elsewhere via addVkFormatDesc( B5G5R5A1_UNORM_PACK16, Invalid, ...).

These changes run correctly for my limited test cases (Vulkan-Samples project running on iOS Simulator on x86_64 host, macOS Ventura, Xcode 15.2). However, I cannot test all of the new changes here. This PR could benefit from additional code review at a minimum.

Question: Given release timing, does this mean the Simulator will be broken for MVK 1.2.11, Vulkan SDK 1.3.296? If so that's an unfortunate regression, and at minimum should be highlighted in the release notes.

Lastly, I have another Simulator issue outstanding - see #2285. When running the Vulkan-Samples on the Simulator, starting with MoltenVK 1.2.11, certain samples do not render (black screen) unless I disable Metal Argument Buffers. What is the status of Argument Buffers on the Simulator? Should they be disabled by default on the Simulator, or is there another defect lingering somewhere else that causes this behaviour?

Copy link
Contributor

@billhollings billhollings left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. LGTM now.

Bummer about all the changes required to the define macros, but that's the nature of macros.

I'll just wait for @cdavis5e to have a look before pulling this in.

@billhollings
Copy link
Contributor

billhollings commented Oct 3, 2024

Lastly, I have another Simulator issue outstanding - see #2285. When running the Vulkan-Samples on the Simulator, starting with MoltenVK 1.2.11, certain samples do not render (black screen) unless I disable Metal Argument Buffers. What is the status of Argument Buffers on the Simulator? Should they be disabled by default on the Simulator, or is there another defect lingering somewhere else that causes this behaviour?

Now that the SDK release is done, I'll have another closer look at #2285.

I really, REALLY don't want to have to disable arg buffers for any platform, so that will be an absolute last resort. Moving forward, arg buffers are important for a lot of Vulkan functionality, starting with the availability of larger numbers of bindless descriptors.

@SRSaunders
Copy link
Contributor Author

Bummer about all the changes required to the define macros, but that's the nature of macros.

Agreed the macro changes are kind of ugly. If you see a better solution please feel free to modify.

I really, REALLY don't want to have to disable arg buffers for any platform, so that will be an absolute last resort.

That's fine. The issue identified some Vulkan-Samples problems and a potential solution in the form of Arg Buffer disabling on the Simulator. But first I wanted to determine your overall intentions re Arg Buffers and the Simulator. I have my answer now, and will look at #2285 as a possible defect. Thanks.

@SRSaunders
Copy link
Contributor Author

A small change to move unsupported pixel formats to top level to ensure visionOS Simulator is covered too, not just iOS and tvOS Simulators. Docs indicate these pixel format restrictions apply to all Simulators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

iOS simulator initialization failure due to Invalid Pixel Format
3 participants