1 Star 0 Fork 0

halx99 / MoltenVK

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0
MoltenVK

MoltenVK

Copyright (c) 2015-2020 The Brenwill Workshop Ltd.

This document is written in Markdown format. For best results, use a Markdown reader.

Build Status

Table of Contents

Developing Vulkan Applications for macOS, iOS, and tvOS

The recommended method for developing a Vulkan application for macOS is to use the Vulkan SDK.

The Vulkan SDK includes a MoltenVK runtime library for macOS. Vulkan is a layered architecture that allows applications to add additional functionality without modifying the application itself. The Validation Layers included in the Vulkan SDK are an essential debugging tool for application developers because they identify inappropriate use of the Vulkan API. If you are developing a Vulkan application for macOS, it is highly recommended that you use the Vulkan SDK and the MoltenVK library included in it.

If you are developing a Vulkan application for iOS or tvOS, or are developing a Vulkan application for macOS and want to use a different version of the MoltenVK runtime library provided in the macOS Vulkan SDK, you can use this document to learn how to build a MoltenVK runtime library from source code.

To learn how to integrate the MoltenVK runtime library into a game or application, see the MoltenVK_Runtime_UserGuide.md document in the Docs directory.

Introduction to MoltenVK

MoltenVK is a layered implementation of Vulkan 1.0 graphics and compute functionality, that is built on Apple's Metal graphics and compute framework on macOS, iOS, and tvOS. MoltenVK allows you to use Vulkan graphics and compute functionality to develop modern, cross-platform, high-performance graphical games and applications, and to run them across many platforms, including macOS, iOS, and tvOS.

Metal uses a different shading language, the Metal Shading Language (MSL), than Vulkan, which uses SPIR-V. MoltenVK automatically converts your SPIR-V shaders to their MSL equivalents.

To provide Vulkan capability to the macOS, iOS, and tvOS platforms, MoltenVK uses Apple's publicly available API's, including Metal. MoltenVK does not use any private or undocumented API calls or features, so your app will be compatible with all standard distribution channels, including Apple's App Store.

The MoltenVK runtime package contains two products:

  • MoltenVK is a implementation of an almost-complete subset of the Vulkan 1.0 graphics and compute API.

  • MoltenVKShaderConverter converts SPIR-V shader code to Metal Shading Language (MSL) shader code, and converts GLSL shader source code to SPIR-V shader code and/or Metal Shading Language (MSL) shader code. The SPIR-V portion of the converter is also embedded in the MoltenVK runtime to automatically convert SPIR-V shaders to their MSL equivalents. In addition, both the SPIR-V and GLSL converters are packaged into a stand-alone command-line MoltenVKShaderConverter macOS tool for converting shaders at development time from the command line.

Fetching MoltenVK Source Code

To fetch MoltenVK source code, clone this MoltenVK repository, and then run the fetchDependencies script to retrieve and build several external open-source libraries on which MoltenVK relies:

  1. Ensure you have cmake and python3 installed:

     brew install cmake
     brew install python3

    For faster dependency builds, you can also optionally install ninja:

     brew install ninja
  2. Clone the MoltenVK repository:

     git clone https://github.com/KhronosGroup/MoltenVK.git
  3. Retrieve and build the external libraries:

     cd MoltenVK
     ./fetchDependencies [platform...]

When running the fetchDependencies script, you must specify one or more platforms for which to build the external libraries. The platform choices include:

--all --macos --ios --iosfat --tvos --tvosfat

You can specify multiple of these selections. The --iosfat and --tvosfat selection builds one binary for each external library, with each binary including code for both iOS and iOS Simulator platforms, or tvOS and tvOS Simulator platforms, respectively. The --all selection is the same as selecting --macos --iosfat --tvosfat and results in three binaries for each external library: a macOS binary, a fat iOS binary, and a fat tvOS binary. The more selections you include, the longer the build time.

For more information about the external open-source libraries used by MoltenVK, see the ExternalRevisions/README.md document.

Building MoltenVK

During building, MoltenVK references the latest Apple SDK frameworks. To access these frameworks, and to avoid build errors, be sure to use the latest publicly available version of Xcode.

Note: To support IOSurfaces on iOS or tvOS, MoltenVK, and any app that uses MoltenVK, must be built with a minimum iOS Deployment Target (aka IPHONEOS_DEPLOYMENT_TARGET ) build setting of iOS 11.0 or greater, or a minimum tvOS Deployment Target (aka TVOS_DEPLOYMENT_TARGET ) build setting of tvOS 11.0 or greater.

Once built, the MoltenVK libraries can be run on macOS, iOS or tvOS devices that support Metal, or on the Xcode iOS Simulator or tvOS Simulator.

  • At runtime, MoltenVK requires at least macOS 10.11, iOS 9, or tvOS 9 (or iOS 11 or tvOS 11 if using IOSurfaces).
  • Information on macOS devices that are compatible with Metal can be found in this article.
  • Information on iOS devices that are compatible with Metal can be found in this article.

The MoltenVKPackaging.xcodeproj Xcode project contains targets and schemes to build and package the entire MoltenVK runtime distribution package, or to build individual MoltenVK or MoltenVKShaderConverter components.

To build a MoltenVK runtime distribution package, suitable for testing and integrating into an app, open MoltenVKPackaging.xcodeproj in Xcode, and use one of the following Xcode Schemes, depending on whether you want a Release or Debug configuration, and whether you want to build for all platforms, or just one platform (in Release configuration):

  • MoltenVK Package
  • MoltenVK Package (Debug)
  • MoltenVK Package (macOS only)
  • MoltenVK Package (iOS only)
  • MoltenVK Package (tvOS only)

Each of theseMoltenVKPackaging.xcodeproj Xcode project Schemes puts the resulting packages in the Package directory, creating it if necessary. This directory contains separate Release and Debug directories, holding the most recent Release and Debug builds, respectively.

A separate Latest directory links to the most recent build, regardless of whether it was a Release or Debug build. Effectively, the Package/Latest directory points to whichever of the Package/Release or Package/Debug directories was most recently updated.

With this packaging structure, you can follow the instructions below to link your application to the MoltenVK libraries and frameworks in the Package/Latest directory, to provide the flexibility to test your app with either a Debug build, or a higher-performance Release build.

Building from the Command Line

If you prefer to build MoltenVK from the command line, or to include the activity in a larger build script, you can do so by executing a command similar to the following command within the MoltenVK repository folder, and identifying one of the Xcode Schemes from the list above. For example, the following command will build MoltenVK in the Debug configuration for macOS only:

xcodebuild build -quiet -project MoltenVKPackaging.xcodeproj -scheme "MoltenVK Package (macOS only)" -configuration "Debug"

Alternately, you can use the basic Makefile in the MoltenVK repository folder to build MoltenVK from the command line. The following make targets are provided:

make
make all
make macos
make ios
make iosfat
make tvos
make tvosfat

make all-debug
make macos-debug
make ios-debug
make iosfat-debug
make tvos-debug
make tvosfat-debug

make clean
make install
  • The all target is the default target. Running make with no arguments is the same as running make all.
  • The *fat* targets build fat binaries containing both platform and simulator code.
  • The *-debug targets build the binaries using the Debug configuration.
  • The all target executes the macos, iosfat, and tvosfat targets.
  • The all-debug target executes the macos-debug, iosfat-debug, and tvosfat-debug targets.
  • The install target will copy the most recently built macOS MoltenVK.framework into the /Library/Frameworks folder of your computer. Since /Library/Frameworks is protected, you will generally need to run it as sudo make install and enter your password. The install target just installs the built framework, it does not first build the framework. You will first need to at least run make macos first.

The make targets all require that Xcode is installed on your system.

Building from the command line creates the same Package folder structure described above when building from within Xcode.

Running the MoltenVK Demo Applications

Once you have compiled and built the MoltenVK runtime distribution package from this MoltenVK repository, as described in the Building MoltenVK section, you can explore how MoltenVK provides Vulkan support on macOS, iOS, and tvOS by investigating and running the demo applications that are included in MoltenVK.

The MoltenVK demo apps are located in the Demos folder. Each demo app is available as an Xcode project. To review and run the included demo apps, open the Demos/Demos.xcworkspace workspace in Xcode.

Please read the Demos/README.md document for a description of each demo app, and instructions on running the demo apps. Several of the demo apps allow you to explore a variety of Vulkan features by modifying Xcode build settings. Additional demos can be downloaded and built from external repositories, as described in the Demos/README.md document

Using MoltenVK in Your Application

Once you have compiled and built the MoltenVK runtime distribution package from this MoltenVK repository, as described in the Building MoltenVK section, follow the instructions in the Installation section of the Docs/MoltenVK_Runtime_UserGuide.md document in the Docs directory, to link the MoltenVK libraries and frameworks to your application.

The runtime distribution package in the Package/Latest directory is a stand-alone package, and you can copy the contents of that directory out of this MoltenVK repository into your own application building environment.

MoltenVK and Vulkan Compliance

MoltenVK is designed to be an implementation of a Vulkan 1.0 subset that runs on macOS, iOS, and tvOS platforms by mapping Vulkan capability to native Metal capability.

The fundamental design and development goal of MoltenVK is to provide this capability in a way that is both maximally compliant with the Vulkan 1.0 specification, and maximally performant.

Such compliance and performance is inherently affected by the capability available through Metal, as the native graphics driver on macOS, iOS, and tvOS platforms. Vulkan compliance may fall into one of the following categories:

  • Direct mapping between Vulkan capabilities and Metal capabilities. Within MoltenVK, the vast majority of Vulkan capability is the result of this type of direct mapping.

  • Synthesized compliance through alternate implementation. A small amount of capability is provided using this mechanism, such as via an extra render or compute shader stage.

  • Non-compliance. This appears where the capabilities of Vulkan and Metal are sufficiently different, that there is no practical, or reasonably performant, mechanism to implement a Vulkan capability in Metal. Because of design differences between Vulkan and Metal, a very small amount of capability falls into this category, and at present MoltenVK is not fully compliant with the Vulkan specification. A list of known limitations is documented in the MoltenVK_Runtime_UserGuide.md document in the Docs directory.

The MoltenVK development team welcomes you to post Issues of non-compliance, and engage in discussions about how compliance can be improved, and non-compliant features can be implemented or worked around.

MoltenVK is a key component of the Khronos Vulkan Portability Initiative, whose intention is to provide specifications, resources, and tools to allow developers to understand and design their Vulkan apps for maximum cross-platform compatibility and portability, including on platforms, such as macOS, iOS, and tvOS, where a native Vulkan driver is not available.

Reporting Issues

  • If you encounter an issue with the behaviour of MoltenVK, you can report it in the MoltenVK Issues List.

  • If you encounter an issue with the Vulkan SDK, including the Validation Layers, you can report it in the Vulkan SDK Issues List.

  • If you explore MoltenVK and determine that it does not meet your requirements at this time, we would appreciate hearing why that is so, on the MoltenVK Issues List. The goal of MoltenVK is to increase the value of Vulkan as a true cross-platform ecosystem, by providing Vulkan on Apple platforms. Hearing why this is currently not working for you will help us in that goal.

Contributing to MoltenVK Development

As a public open-source project, MoltenVK benefits from code contributions from a wide range of developers, and we encourage you to get involved and contribute code to this MoltenVK repository.

To contribute your code, submit a Pull Request to this repository. The first time you do this, you will be asked to agree to the MoltenVK Contributor License Agreement.

Licensing

MoltenVK is licensed under the Apache 2.0 license. All new source code files should include a copyright header at the top, containing your authorship copyright and the Apache 2.0 licensing stub. You may copy the text from an existing source code file as a template.

The Apache 2.0 license guarantees that code in the MoltenVK repository is free of Intellectual Property encumbrances. In submitting code to this repository, you are agreeing that the code is free of any Intellectual Property claims.

Memory Management

Metal, and other Objective-C objects in Apple's SDK frameworks, use reference counting for memory management. When instantiating Objective-C objects, it is important that you do not rely on implied autorelease pools to do memory management for you. Because many Vulkan games and apps may be ported from other platforms, they will typically not include autorelease pools in their threading models.

Avoid the use of the autorelease method, or any object creation methods that imply use of autorelease, (eg- [NSString stringWithFormat: ], etc). Instead, favour object creation methods that return a retained object (eg- [[NSString alloc] initWithFormat: ], etc), and manually track and release those objects. If you need to use autoreleased objects, wrap code blocks in an @autoreleasepool {...} block.

Code Formatting

When contributing code, please honour the code formatting style found in existing MoltenVK source code. In future, this will formally be enforced using clang-format.

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

暂无描述 展开 收起
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/halx99/MoltenVK.git
git@gitee.com:halx99/MoltenVK.git
halx99
MoltenVK
MoltenVK
master

搜索帮助