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

macOS: Initial support for vulkan on macOS ( MoltenVK ) #12583

Merged
merged 2 commits into from Jan 20, 2020

Conversation

CarterLi
Copy link
Contributor

@CarterLi CarterLi commented Jan 19, 2020

This PR tries to address #10654 - implement a highly experimental buggy vulkan MoltenVK support on modern macOS.

To test it:

  1. Build MoltenVK yourself. Please follow the official document. make macos is enough. Or use the official --outdated-- homebrew version brew install molten-vk
  2. Copy MoltenVK/macOS/dynamic/libMoltenVK.dylib ( or Package/Release/MoltenVK/dylib/macOS/libMoltenVK.dylib for higher version ) to /usr/local/lib or somewhere else that PPSSPP can find it. If use homebrew, skip this.
  3. Build PPSSPP with SDL mode. Qt mode is NOT supported

Tested on macOS 10.15.2 (19C57)

image
image

Copy link
Owner

@hrydgard hrydgard left a comment

Choose a reason for hiding this comment

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

Sweet!

I'm only a little concerned that it would now no longer build without the manually built dylib present.

Do you think we could either autodetect its presence and turn off VK_USE_PLATFORM_METAL_EXT for example, or maybe supply a precompiled dylib as a submodule or something? What might be best?

It's important for the build user experience that checking out and building is smooth.

Common/Vulkan/VulkanLoader.cpp Outdated Show resolved Hide resolved
SDL/SDLCocoaMetalLayer.h Outdated Show resolved Hide resolved
@CarterLi
Copy link
Contributor Author

CarterLi commented Jan 19, 2020

Sweet!

I'm only a little concerned that it would now no longer build without the manually built dylib present.

libMoltenVK.dylib is dynamic loaded using dlopen, like other platforms. If it's not found, PPSSPP will fall back to OGL mode.

Do you think we could either autodetect its presence and turn off VK_USE_PLATFORM_METAL_EXT for example, or maybe supply a precompiled dylib as a submodule or something? What might be best?

VK_USE_PLATFORM_METAL_EXT is in vulkan header, which is embeded into PPSSPP source tree. Thus it should not be a problem.

It's important for the build user experience that checking out and building is smooth.

One problem is that #define VK_USE_PLATFORM_METAL_EXT is guarded by #elif defined(__APPLE__), which may affect iOS build. VK_USE_PLATFORM_METAL_EXT itself is supported by both macOS and iOS. The only difference is that makeWindowMetalCompatible. NSWindow stuff are macOS specific, but should be easy to port them to iOS UIWindow

I have zero knowledge about iOS programming. Any contribution is welcome.

@CarterLi
Copy link
Contributor Author

One problem is that #define VK_USE_PLATFORM_METAL_EXT is guarded by #elif defined(APPLE), which may affect iOS build.

I can change this to PPSSPP_PLATFORM_MAC, if desired.

@hrydgard
Copy link
Owner

Oh right it's a dylib not a lib... then things should be fine even when not present indeed. Both builds seem to still pass, so I don't know if you need to change that preprocessor check, but it might still be a good idea.

@hrydgard
Copy link
Owner

hrydgard commented Jan 19, 2020

So this is a little odd. I built Moltenvk:

./fetchDependencies.sh
make macos
sudo make install

The last line of the output was /bin/cp -a Package/Latest/MoltenVK/macOS/framework/MoltenVK.framework /Library/Frameworks/

You'd think PPSSPP should be able to find it there, but it doesn't. It did however work copying it to /usr/local/lib indeed.

Anyway, happy to merge this, but seems I was wrong in the other issue that we don't need to care about swizzle anymore, this is from running Wipeout Pure:

[mvk-error] VK_ERROR_FORMAT_NOT_SUPPORTED: VkFormat VK_FORMAT_B4G4R4A4_UNORM_PACK16 is not supported on this device.
[mvk-error] VK_ERROR_FEATURE_NOT_PRESENT: The value of vkCreateImageView(VkImageViewCreateInfo::components) (VK_COMPONENT_SWIZZLE_A, VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B), when applied to a VkImageView, requires full component swizzling to be enabled both at the time when the VkImageView is created and at the time any pipeline that uses that VkImageView is compiled. Full component swizzling can be enabled via the MVKConfiguration::fullImageViewSwizzle config parameter or MVK_CONFIG_FULL_IMAGE_VIEW_SWIZZLE environment variable.
E: VulkanImage.cpp:156: vkCreateImageView failed: VK_ERROR_FEATURE_NOT_PRESENT```

So for this to be fully usable on old macs we need to do some work either enabling that feature or getting rid of our use of texture swizzle, and apparently of our use of that 16-bit texture format.

@CarterLi
Copy link
Contributor Author

CarterLi commented Jan 19, 2020

We use libMoltenVK.dylib, not the framework

VK_FORMAT_B4G4R4A4_UNORM_PACK16 is not supported on this device.

Yes I also encountered this error for some games, thus I marked this PR highly experimental ;)

Have no idea how to resolve it though...

@hrydgard
Copy link
Owner

We simply have to convert that texture to another supported format. Might be able to reuse the path we have to work around the lack of support for the 16-bit formats on Windows 7 / DX11.

@CarterLi
Copy link
Contributor Author

Add support for iOS ( completely untested )

And found more info about VK_FORMAT_B4G4R4A4_UNORM_PACK16:

KhronosGroup/MoltenVK#204
KhronosGroup/MoltenVK#203
gfx-rs/portability#125

@CarterLi
Copy link
Contributor Author

We simply have to convert that texture to another supported format. Might be able to reuse the path we have to work around the lack of support for the 16-bit formats on Windows 7 / DX11.

I have no idea how to do this. Would you mind merging my PR first and then work around this issue?

@hrydgard
Copy link
Owner

hrydgard commented Jan 20, 2020

Yeah, sure, I'm not expecting you to take care of that :) I will deal with it soon.

@hrydgard hrydgard merged commit 141ad16 into hrydgard:master Jan 20, 2020
@hrydgard
Copy link
Owner

Hm, by the way, do you know if we need to do anything to make it use Metal 3, as opposed to Metal 1 or 2? I have no idea how versioning works in Metal-land....

@CarterLi
Copy link
Contributor Author

Hm, by the way, do you know if we need to do anything to make it use Metal 3, as opposed to Metal 1 or 2? I have no idea how versioning works in Metal-land....

Sorry, but isn't it chosen by MoltenVK internally?

@hrydgard
Copy link
Owner

Hm, right, most probably. Was curious because Metal 3 is supposed to fix that swizzle issue and it does not seem to be enabled on my (old) macbook pro, maybe it doesn't support it (or it's just a secondary error of the texture format not being supported).

@Gcenx
Copy link

Gcenx commented Feb 4, 2020

Metal level is dependent on macOS version;

  • Metal (OS X El Capitan)
  • Metal 2 (macOS High Sierra)
  • Metal 3 (macOS Catalina)

To force software swizzle you use the following export

export MVK_CONFIG_FULL_IMAGE_VIEW_SWIZZLE=1

That or compile MoltenVK from source and force swizzle

@CarterLi
Copy link
Contributor Author

CarterLi commented Feb 5, 2020

Metal level is dependent on macOS version;

  • Metal (OS X El Capitan)
  • Metal 2 (macOS High Sierra)
  • Metal 3 (macOS Catalina)

To force software swizzle you use the following export

export MVK_CONFIG_FULL_IMAGE_VIEW_SWIZZLE=1

That or compile MoltenVK from source and force swizzle

Tested but it doesn't work for me.


Just found this

https://github.com/KhronosGroup/MoltenVK/blob/fd7b69b9e5ddd4bbbc7fda5f471dfe6c53858e80/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm#L866

And this

https://github.com/KhronosGroup/MoltenVK/blob/fd7b69b9e5ddd4bbbc7fda5f471dfe6c53858e80/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm#L1953

But the log for my device reads

[mvk-info] GPU device:
		model: AMD Radeon R9 M370X
		type: Discrete
		vendorID: 0x1002
		deviceID: 0x6821
		pipelineCacheUUID: 00002738-0300-07D2-F981-8F0804E6E73E
	supports the following Metal Versions, GPU's and Feature Sets:
		Metal Shading Language 2.2
		GPU Family Mac 2
		GPU Family Mac 1
		GPU Family Common 3
		GPU Family Common 2
		GPU Family Common 1
		macOS GPU Family 2 v1
		macOS GPU Family 1 v4
		macOS GPU Family 1 v3
		macOS GPU Family 1 v2
		macOS GPU Family 1 v1
		macOS Read-Write Texture Tier 2

Seems no luck for me :(

@hrydgard
Copy link
Owner

hrydgard commented Feb 5, 2020

I'll open a new issue for the swizzle thing.

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.

None yet

4 participants