Skip to content

Commit

Permalink
Fix visionOS build errors and warnings where possible.
Browse files Browse the repository at this point in the history
- Remove visionOS from multi-platform builds because it
  requires Xcode 15+ and will abort a multi-platform build.
- Define TARGET_OS_XR for older SDK's.
- A number of SDK deprecation warnings remain when building for visionOS.
  These cannot be removed without significant refactoring.
- Build visionOS dependencies for Release build by default.
- Fix local variable initialization warning (unrelated).
  • Loading branch information
billhollings committed Jul 11, 2023
1 parent 855c7a6 commit 6374d9d
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 39 deletions.
3 changes: 3 additions & 0 deletions Common/MVKCommonEnvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ extern "C" {
#endif

/** Building for visionOS. */
#ifndef TARGET_OS_XR
# define TARGET_OS_XR 0 // Older SDK's don't define TARGET_OS_XR
#endif
#ifndef MVK_VISIONOS
# define MVK_VISIONOS TARGET_OS_XR
#endif
Expand Down
1 change: 1 addition & 0 deletions Docs/Whats_New.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Released TBD
- `VK_EXT_shader_subgroup_ballot`
- `VK_EXT_shader_subgroup_vote`
- Add support for `VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN`.
- Support building MoltenVK for visionOS.
- Ensure non-dispatch compute commands don't interfere with compute encoding state used by dispatch commands.
- Support `VK_PRESENT_MODE_IMMEDIATE_KHR` if `VkPresentTimeGOOGLE::desiredPresentTime` is zero.
- Support maximizing the concurrent executing compilation tasks via `MVKConfiguration::shouldMaximizeConcurrentCompilation`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
buildConfiguration = "Release"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
Expand Down
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ MAKEARGS := $(strip \
$(v)=$(value $(v)) ,)))

# Specify individually (not as dependencies) so the sub-targets don't run in parallel
# visionos and visionossim are currently excluded from `all` because they require
# Xcode 15+ and will abort a multi-platform build on earlier Xcode versions.
.PHONY: all
all:
@$(MAKE) macos
Expand All @@ -29,8 +31,8 @@ all:
@$(MAKE) maccat
@$(MAKE) tvos
@$(MAKE) tvossim
@$(MAKE) visionos
@$(MAKE) visionossim
# @$(MAKE) visionos # Requires Xcode 15+
# @$(MAKE) visionossim # Requires Xcode 15+

.PHONY: all-debug
all-debug:
Expand All @@ -40,8 +42,8 @@ all-debug:
@$(MAKE) maccat-debug
@$(MAKE) tvos-debug
@$(MAKE) tvossim-debug
@$(MAKE) visionos-debug
@$(MAKE) visionossim-debug
# @$(MAKE) visionos-debug # Requires Xcode 15+
# @$(MAKE) visionossim-debug # Requires Xcode 15+

.PHONY: macos
macos:
Expand Down
2 changes: 1 addition & 1 deletion MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1993,7 +1993,7 @@ static MTLVertexFormat mvkAdjustFormatVectorToSize(MTLVertexFormat format, uint3
// We'll set the VALID bit on the stage feedback when we compile it.
VkPipelineCreationFeedback* pPipelineFB = nullptr;
VkPipelineCreationFeedback* pStageFB = nullptr;
uint64_t pipelineStart;
uint64_t pipelineStart = 0;
if (pFeedbackInfo) {
pPipelineFB = pFeedbackInfo->pPipelineCreationFeedback;
// n.b. Do *NOT* use mvkClear().
Expand Down
70 changes: 42 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Table of Contents
-----------------

- [Introduction to **MoltenVK**](#intro)
- [Developing Vulkan Applications on *macOS, iOS, and tvOS*](#developing_vulkan)
- [Developing Vulkan Applications on *macOS, iOS, tvOS, and visionOS*](#developing_vulkan)
- [Using the *Vulkan SDK*](#sdk)
- [Using MoltenVK Directly](#download)
- [Fetching **MoltenVK** Source Code](#install)
Expand All @@ -38,19 +38,20 @@ Introduction to MoltenVK

**MoltenVK** is a layered implementation of [*Vulkan 1.2*](https://www.khronos.org/vulkan)
graphics and compute functionality, that is built on Apple's [*Metal*](https://developer.apple.com/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*, *tvOS*,
*Simulators*, and *Mac Catalyst* on *macOS 11.0+*, and all *Apple* architectures, including *Apple Silicon*.
graphics and compute framework on *macOS*, *iOS*, *tvOS*, and *visionOS*. **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*, *tvOS*, *visionOS*, *Simulators*, and *Mac Catalyst* on *macOS 11.0+*,
and all *Apple* architectures, including *Apple Silicon*.

*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*.
To provide *Vulkan* capability to the *macOS*, *iOS*, *tvOS*, and *visionOS* 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:

Expand All @@ -67,8 +68,8 @@ The **MoltenVK** runtime package contains two products:


<a name="developing_vulkan"></a>
Developing *Vulkan* Applications for *macOS, iOS, and tvOS*
---------------------------------------------------------
Developing *Vulkan* Applications for *macOS, iOS, tvOS, and visionOS*
---------------------------------------------------------------------

<a name="sdk"></a>
### Using the *Vulkan SDK*
Expand Down Expand Up @@ -96,10 +97,10 @@ extension in the *Vulkan* specification for more information about the use of th
<a name="download"></a>
### Using MoltenVK Directly

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 or build of the
**MoltenVK** runtime library than provided in the *macOS Vulkan SDK*, you can access
a pre-built MoltenVK binary library from the **MoltenVK** repository, by
If you are developing a *Vulkan* application for *iOS*, *tvOS*, or *visionOS*, or are
developing a *Vulkan* application for *macOS* and want to use a different version or
build of the **MoltenVK** runtime library than provided in the *macOS Vulkan SDK*,
you can access a pre-built MoltenVK binary library from the **MoltenVK** repository, by
[selecting a repository commit from the list](https://github.com/KhronosGroup/MoltenVK/actions),
and downloading the associated **MoltenVK** runtime library artifact.

Expand Down Expand Up @@ -148,14 +149,21 @@ for which to build the external libraries. The platform choices include:
--maccat
--tvos
--tvossim
--visionos
--visionossim

The `visionos` and `visionossim` selections require Xcode 15+.

You can specify multiple of these selections. The result is a single `XCFramework`
for each external dependency library, with each `XCFramework` containing binaries for
each of the requested platforms.

The `--all` selection is the same as entering all of the other platform choices,
and will result in a single `XCFramework` for each external dependency library,
with each `XCFramework` containing binaries for all supported platforms and simulators.
The `--all` selection is the same as entering all of the other platform choices, except
`--visionos` and `--visionossim`, and will result in a single `XCFramework` for each
external dependency library, with each `XCFramework` containing binaries for all supported
platforms and simulators. The `--visionos` and `--visionossim` selections must be invoked
with a separate invocation of `fetchDependencies`, because those selections require
Xcode 15+, and will cause a multi-platform build on older versions of Xcode to abort.

Running `fetchDependencies` repeatedly with different platforms will accumulate
targets in the `XCFramework`.
Expand Down Expand Up @@ -196,11 +204,11 @@ _Xcode_ version. If you require support for earlier OS versions, modify the `MAC
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*.
Once built, the **MoltenVK** libraries can be run on *macOS*, *iOS*, *tvOS*, or *visionOS* devices
that support *Metal*,or on the *Xcode* *iOS Simulator*, *tvOS Simulator*, or *visionOS Simulator*.

- At runtime, **MoltenVK** requires at least *macOS 10.11*, *iOS 9*, or *tvOS 9*
(or *iOS 11* or *tvOS 11* if using `IOSurfaces`).
- At runtime, **MoltenVK** requires at least *macOS 10.11*, *iOS 9.0*, *tvOS 9.0*,
or *visionOS 1.0* (or *iOS 11* or *tvOS 11* if using `IOSurfaces`).
- Information on *macOS* devices that are compatible with *Metal* can be found in
[this article](http://www.idownloadblog.com/2015/06/22/how-to-find-mac-el-capitan-metal-compatible).
- Information on *iOS* devices that are compatible with *Metal* can be found in
Expand All @@ -220,6 +228,7 @@ platforms, or just one platform (in **_Release_** configuration):
- **MoltenVK Package (macOS only)**
- **MoltenVK Package (iOS only)**
- **MoltenVK Package (tvOS only)**
- **MoltenVK Package (visionOS only)** _(requires Xcode 15+)_

Each of these`MoltenVKPackaging.xcodeproj` *Xcode* project *Schemes* puts the resulting packages in the
`Package` directory, creating it if necessary. This directory contains separate `Release` and `Debug`
Expand Down Expand Up @@ -254,6 +263,8 @@ from the command line. The following `make` targets are provided:
make maccat
make tvos
make tvossim
make visionos
make visionossim

make all-debug
make macos-debug
Expand All @@ -262,12 +273,15 @@ from the command line. The following `make` targets are provided:
make maccat-debug
make tvos-debug
make tvossim-debug
make visionos-debug
make visionossim-debug

make clean
make install

- Running `make` repeatedly with different targets will accumulate binaries for these different targets.
- The `all` target executes all platform targets.
- The `all` target executes all platform targets, except `visionos` and `visionossim`, as these require
Xcode 15+, and will abort a multi-platform build on older versions of Xcode.
- The `all` target is the default target. Running `make` with no arguments is the same as running `make all`.
- The `*-debug` targets build the binaries using the **_Debug_** configuration.
- The `install` target will copy the most recently built `MoltenVK.xcframework` into the
Expand Down Expand Up @@ -346,14 +360,14 @@ the contents of that directory out of this **MoltenVK** repository into your own
------------------------------------

**MoltenVK** is designed to be an implementation of a *Vulkan 1.2* subset that runs on *macOS*, *iOS*,
and *tvOS* platforms by mapping *Vulkan* capability to native *Metal* capability.
*tvOS*, and *visionOS* 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.2* 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:
Such compliance and performance is inherently affected by the capability available through *Metal*,
as the native graphics driver on *macOS*, *iOS*, *tvOS*, and *visionOS* 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.
Expand All @@ -376,7 +390,7 @@ be implemented or worked around.
[*Khronos Vulkan Portability Initiative*](https://www.khronos.org/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.
*macOS*, *iOS*, *tvOS*, and *visionOS*, where a native *Vulkan* driver is not available.



Expand Down
13 changes: 8 additions & 5 deletions fetchDependencies
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#
# fetchDependencies - Retrieves the correct versions of all dependencies
#
# macOS usage: ./fetchDependencies [--macos] [--ios] [--iossim] [--tvos] [--tvossim] [--all] [--none]
# macOS usage: ./fetchDependencies [--macos] [--ios] [--iossim] [--tvos] [--tvossim]
# [--visionos] [--visionossim] [--all] [--none]
# [-v] [--debug] [--build-spirv-tools]
# [--v-headers-root path] [--spirv-cross-root path] [--glslang-root path]
#
Expand Down Expand Up @@ -33,9 +34,11 @@
# Build the external libraries for the visionOS Simulator platform.
#
# --all
# Equivalent to specifying [--macos --ios --iossim --maccat --tvos --tvossim --visionos --visionossim].
# Equivalent to specifying [--macos --ios --iossim --maccat --tvos --tvossim].
# Results in one XCFramework for each external library, each containing
# binaries for all supported platforms.
# Currently excludes --visionos and --visionossim targets because those
# require Xcode 15+ and will abort a multi-platform build.
#
# --none
# Don't build the external libraries for any platform (this is the default).
Expand Down Expand Up @@ -150,14 +153,14 @@ while (( "$#" )); do
shift 1
;;
--all)
BLD_MACOS="Y"
BLD_IOS="Y"
BLD_IOS_SIM="Y"
BLD_MAC_CAT="Y"
BLD_TVOS="Y"
BLD_TVOS_SIM="Y"
BLD_VISIONOS="Y"
BLD_VISIONOS_SIM="Y"
BLD_MACOS="Y"
# BLD_VISIONOS="Y" # Requires Xcode 15+
# BLD_VISIONOS_SIM="Y" # Requires Xcode 15+
shift 1
;;
--none)
Expand Down

0 comments on commit 6374d9d

Please sign in to comment.