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

Metal support #19

Open
BearishSun opened this issue Mar 16, 2018 · 11 comments
Open

Metal support #19

BearishSun opened this issue Mar 16, 2018 · 11 comments
Labels
OFFICIAL type: enhancement [MAJOR] Feature that takes a few weeks up to few months to implement
Milestone

Comments

@BearishSun
Copy link
Member

macOS currently uses an OpenGL render backend. This isn't an ideal solution as its OpenGL version is 4.1, meaning compute cannot be used. This requires a variety of rendering effects to be implemented in 4.5 and 4.1 variants, which isn't ideal (although this is something we likely also require for mobile, so maybe not that bad either). Ideally we should add a MetalRenderAPI plugin, and extend XShaderCompiler so it can output Metal shading language code.

@BearishSun BearishSun added type: enhancement [MAJOR] Feature that takes a few weeks up to few months to implement OFFICIAL labels Mar 16, 2018
@BearishSun BearishSun added this to the Longterm milestone Mar 16, 2018
@kattkieru
Copy link

Is there a specific use case for Metal that MoltenVK doesn't cover?

@BearishSun
Copy link
Member Author

The main concern is that MolenVK is a wrapper on top of Metal. I haven't used Metal myself yet but from what I've heard there are some considerable differences between it and Vulkan, which means the wrapper might need to do some extra busy-work, making it non-optimal.

Its probably not the worst thing ever, but since Metal is something users will use if they want maximum performance, having an unnecessary layer on top doesn't feel right. For that reason this is certainly not a huge priority, but will eventually be nice to have.

@kattkieru
Copy link

I haven't played with it too much yet (still learning Vulkan), but it would at least be a nice stop-gap since you already have a Vulkan backend and you'd get more features on Mac than their OpenGL support offers, plus it could be slipstreamed as a dependency.

Just a thought. :)

@BearishSun
Copy link
Member Author

BearishSun commented May 26, 2018

Definitely, I will be adding MoltenVK as soon as I get a chance. Metal support is a more of a long term goal.

I haven't tried it yet but it might literally be just the matter of installing the dependency, tweaking a few flags and such and getting it to work out of the box. Might be some kinks to work out afterwards.

@crookedbard
Copy link

There is this post about: Apple Rejects iOS App For Using MoltenVK Vulkan, Alleged Non-Public API
link
Might be interesting to read.

@christianclavet
Copy link

christianclavet commented Jul 12, 2018

Read it, MoltenVK was using a non-public interface that is not allowed by Apple. There is a pull request that has been submitted so it should work again.
link to article update

@remoe
Copy link
Contributor

remoe commented Oct 20, 2018

Hi folks. I've tried to build lastest master with MoltenVK 1.1.85. I've changed the file FindVulkan.cmake from:

set(Vulkan_LIBNAME vulkan)
to
set(Vulkan_LIBNAME MoltenVK)

Then it builds a lot of files, but then it throws this compile error:

Source/Plugins/bsfVulkanRenderAPI/BsVulkanDevice.cpp:10:
Source/Plugins/bsfVulkanRenderAPI/ThirdParty/vk_mem_alloc.h:1688:14: fatal error: 'malloc.h' file not found
    #include <malloc.h> // for aligned_alloc()

Source/Plugins/bsfVulkanRenderAPI/ThirdParty/vk_mem_alloc.h:2105:16: error: use of undeclared identifier 'aligned_alloc'
        return VMA_SYSTEM_ALIGNED_MALLOC(size, alignment);

Source/Plugins/bsfVulkanRenderAPI/ThirdParty/vk_mem_alloc.h:4887:10: error: call to member function 'WriteNumber' is ambiguous
    json.WriteNumber(m_Suballocations.size() - m_FreeCount);

It doesn't compile because this file is outdated. After update this from here:
https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator/blob/master/src/vk_mem_alloc.h

it compiles ;)

the next need more work:

bsf.git/Source/Plugins/bsfVulkanRenderAPI/BsVulkanCommandBuffer.cpp:26:1: error: static_assert failed "Other platforms go here"
static_assert(false, "Other platforms go here");

It needs a MacOS render window ...

btw: this project (bsf) has a really awesome CMake setup!

@BearishSun
Copy link
Member Author

Nice work. You can probably grab most of the render window code from the OpenGL version in Source\Plugins\bsfGLRenderAPI\MacOS, and replace any OpenGL calls with Vulkan ones.

@remoe
Copy link
Contributor

remoe commented Oct 20, 2018

I've done a first try. Not all code compiles. It's only a rough skeleton:

remoe@e9fae5a

@BearishSun can you please shortly look at it? I need to know if i go further.

I don't know much about Vulkan. For example i don't know for what the extension are:

"VK_MVK_MACOS_SURFACE_EXTENSION_NAME"

remoe@e9fae5a#diff-4fe8409ac8a139179166584cc5ff8657R152

is it similar to "VK_KHR_WIN32_SURFACE_EXTENSION_NAME" on windows?

@BearishSun
Copy link
Member Author

Yes that looks pretty close to what's its supposed to be.

Indeed VK_MVK_MACOS_SURFACE_EXTENSION_NAME is just a macOS version of that Win32 extension. Here's the window-system-specific part of the Vulkan spec that explains it: https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#wsi

@remoe
Copy link
Contributor

remoe commented Oct 21, 2018

Thanks for the info. I've pushed a WIP - integration of Vulkan in MacOSX:

#213

It compiles and links with MacOSX environment and with activated VulkanAPI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OFFICIAL type: enhancement [MAJOR] Feature that takes a few weeks up to few months to implement
Projects
None yet
Development

No branches or pull requests

5 participants