Skip to content

Commit

Permalink
Use raw-window-metal to get a CAMetalLayer from raw-window-handle
Browse files Browse the repository at this point in the history
The way `raw-window-metal` works is by creating a layer, and inserting
that as a sublayer, just like we did on iOS before. The bounds are then
kept in-sync with an observer, ensuring smooth resizing.

This also fixes compilation errors on iOS, and adds preliminary support
for tvOS.

The implementation now solely uses `VK_EXT_metal_surface`, which was
added in 2018, and I've removed support for `VK_MVK_ios_surface` /
`VK_MVK_macos_surface`, which are deprecated, and only available a year
and a half earlier anyhow.

Note that apart from the above, there is a slight behavioral change on
macOS: we no longer set `edgeAntialiasingMask` on the layer, as it's not
really required, and allows us to avoid depending on `objc2` directly.
It was introduced without motivation in 40e0b24, so I doubt anyone uses
it, and if they do, they can change it on the layer themselves.
  • Loading branch information
madsmtm committed Sep 8, 2024
1 parent cd4603b commit 470d258
Show file tree
Hide file tree
Showing 15 changed files with 174 additions and 437 deletions.
18 changes: 12 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
not put changes into changelog files directly, they lead to frequent merging
conflicts. Instead put incoming changelog entries into the Pull Request
description. They will be transferred to this file right after the
Pull Request merge.
Pull Request merge.
-->

### Public dependency updates
Expand Down Expand Up @@ -56,6 +56,9 @@ Changes to descriptor set allocation:
Changes to `Surface`:
- `Surface::required_extensions` now returns a result.
- `Surface::from_window[_ref]` now take `HasWindowHandle + HasDisplayHandle` as the window and return a new error type.
- `Surface::from_ios` and the corresponding `SurfaceApi::Ios` was removed, use `Surface::from_metal` instead.
- `Surface::from_mac_os` and the corresponding `SurfaceApi::MacOs` was removed, use `Surface::from_metal` instead.
- `Surface::update_ios_sublayer_on_resize` was removed as it is no longer necessary.

Changes to surface creation and support functions:
- Where handles to foreign window system objects are passed, Vulkano no longer takes a generic pointer, but takes the same pointer type that Ash does.
Expand Down Expand Up @@ -144,6 +147,7 @@ Other:
- Vulkano-shaders: Support for Vulkan 1.3 target environment.
- Vulkano-shaders: Added `generate_structs: true` option that may be used to disable rust structs from generating. Useful in e.g. rust-gpu contexts where such functionality is not needed.
- Vulkano-util: `VulkanoWindowsRenderer::swapchain_image_views` allows access to the swapchain images.
- Add support for tvOS.

### Bugs fixed

Expand All @@ -164,6 +168,8 @@ Other:
- Fixed non-default image view usage being ignored.
- Fixed an off-by-one error in `SubpassDescription::validate`.
- Vulkano-shaders: Fixed shader struct names that are invalid rust idents from panicking the shader! macro. Rust-gpu emitted struct names such as `foo::bar::MyStruct` now work.
- Make resizing smooth, and let it interoperate better with windowing libraries.
- Fix compiling on iOS.

# Version 0.34.1 (2023-10-29)

Expand Down Expand Up @@ -507,7 +513,7 @@ Changes to vulkano-shaders:
### Breaking changes

Changes to queue operations:
- To do operations on a queue, you must now call `with` to gain access. This takes a closure that is passed a
- To do operations on a queue, you must now call `with` to gain access. This takes a closure that is passed a
- The `wait` method of devices and queues is renamed to `wait_idle` to match Vulkan.
- `Queue` now implements `VulkanObject` instead of `SynchronizedVulkanObject`, which is removed.
- `Queue` now takes ownership of resources belonging to operations that you execute on it, to keep them from being destroyed while in use.
Expand Down Expand Up @@ -855,7 +861,7 @@ Miscellaneous:
- Fixed bug in `begin_render_pass` causing a panic when clearing a depth-only attachment.
- Fixed bug in the `QueueFamily::supports_` methods causing a panic when querying support for a stage that needs no queue flags.
- Fixed buffer overflow bug in `AutoCommandBufferBuilder::push_constants`.
- Fixed `AutoCommandBufferBuilder::push_constants` to push multiple times in case of range overlap (to accommodate VUIDs 01795 and 01796)
- Fixed `AutoCommandBufferBuilder::push_constants` to push multiple times in case of range overlap (to accommodate VUIDs 01795 and 01796)
- Fixed `shader!` macro failing to compile with geometry shaders.
- Refactored `VertexBuffersCollection` to allow `Arc<dyn BufferAccess>`.
- Added a `Format::texels_per_block` method.\
Expand Down Expand Up @@ -1049,7 +1055,7 @@ Miscellaneous:
- The dynamic buffers parameter of `GraphicsPipelineBuilder::with_auto_layout` has been replaced with a closure that can be used to make tweaks to the descriptor set layouts as needed.
- `ComputePipeline::new` has an additional closure parameter identical to the one described above.
- **Breaking** `AttachmentImage::dimensions()` now returns `[u32; 3]` which includes the layer count.
- **Breaking** Buffers and Images that have `with_exportable_fd` use dedicated allocation, thus requiring khr_get_memory_requirements2 and khr_dedicated_allocation on top of
- **Breaking** Buffers and Images that have `with_exportable_fd` use dedicated allocation, thus requiring khr_get_memory_requirements2 and khr_dedicated_allocation on top of
already needed khr_external_memory and khr_external_memory_fd.
- **Breaking** `Compare` is renamed to `CompareOp` to match Vulkan.
- **Breaking** Vulkano-shaders no longer generates a `Shader` struct, but instead provides `load` as a standalone function that returns `Arc<ShaderModule>` directly.
Expand Down Expand Up @@ -1146,7 +1152,7 @@ already needed khr_external_memory and khr_external_memory_fd.
- Errors checking(by unwrapping) in `MappedDeviceMemory::read_write`.
- Add creation of Semaphores with exportable Linux file descriptor on.
- Add method to export file descriptor corresponding to Semaphore.
- `SemaphoreBuilder` introduced.
- `SemaphoreBuilder` introduced.
- Add DisplayNative enum variant to ColorSpaceEnum (AMD-specific feature).
- Vulkano-shaders now provides the image format for descriptors, if the shader requires a specific format.
- Vulkano-shaders now uses the `spirv_headers` crate for some of its types.
Expand Down Expand Up @@ -1209,7 +1215,7 @@ already needed khr_external_memory and khr_external_memory_fd.
- Updated winit to 0.25.
- Fixed the teapot example on ArchLinux (GTX 1650).
- Added support for the SPIR-V draw parameters capability.
- Added support for the VK_KHR_multiview extension.
- Added support for the VK_KHR_multiview extension.
- Vulkano-shaders: Added support for MultiView SPIR-V capability.
- Multiview example added showing how to utilize the VK_KHR_multiview extension to render to multiple layers of a framebuffer at once.
- All Vulkan extensions supported by Ash are now provided in `InstanceExtensions` and `DeviceExtensions`. This includes all but the very newest extensions; new extensions should be added whenever Ash is updated to a new version.
Expand Down
2 changes: 0 additions & 2 deletions COVERAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ Coverage of support for Vulkan core features and extensions in Vulkano, as of th
- [`VK_FUCHSIA_external_semaphore`](https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_FUCHSIA_external_semaphore.html)
- [`VK_FUCHSIA_imagepipe_surface`](https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_FUCHSIA_imagepipe_surface.html)
- [`VK_GGP_stream_descriptor_surface`](https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_GGP_stream_descriptor_surface.html)
- [`VK_MVK_ios_surface`](https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_FUCHSIA_imagepipe_surface.html) (deprecated)
- [`VK_MVK_macos_surface`](https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_MVK_macos_surface.html) (deprecated)
- [`VK_QNX_screen_surface`](https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_QNX_screen_surface.html)

### Partially supported
Expand Down
84 changes: 77 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,20 @@ ahash = "0.8"
ash = "0.38.0"
bytemuck = "1.9"
concurrent-slotmap = { git = "https://github.com/vulkano-rs/concurrent-slotmap", rev = "bf52f0a55713bb29dde3e38bc3497b03473d1628" }
core-graphics-types = "0.1"
crossbeam-queue = "0.3"
half = "2.0"
heck = "0.4"
indexmap = "2.0"
libloading = "0.8"
nom = "7.1"
objc = "0.2.5"
once_cell = "1.17"
parking_lot = "0.12"
proc-macro2 = "1.0"
proc-macro-crate = "2.0"
quote = "1.0"
rangemap = "1.5"
raw-window-handle = "0.6"
raw-window-metal = "1.0"
serde = "1.0"
serde_json = "1.0"
shaderc = "0.8.3"
Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Vulkano uses [shaderc-rs](https://github.com/google/shaderc-rs) for shader compi
Note that in general vulkano does **not** require you to install the official Vulkan SDK. This is
not something specific to vulkano (you don't need the SDK to write programs that use Vulkan, even
without vulkano), but many people are unaware of that and install the SDK thinking that it is
required. However, macOS and iOS platforms do require a little more Vulkan setup since it is not
required. However, macOS, iOS and tvOS platforms do require a little more Vulkan setup since it is not
natively supported. See below for more details.

Unless you provide libshaderc, in order to build libshaderc with the shaderc-sys crate, the following tools must be installed and available on `PATH`:
Expand Down Expand Up @@ -203,17 +203,16 @@ On arch based system
sudo pacman -Sy base-devel git python cmake vulkan-devel --noconfirm
```

### macOS and iOS Specific Setup
### macOS, iOS and tvOS Specific Setup

Vulkan is not natively supported by macOS and iOS. However, there exists [MoltenVK](https://github.com/KhronosGroup/MoltenVK)
an open-source Vulkan implementation on top of Apple's Metal API. This allows vulkano to build and run on macOS
and iOS platforms.
Vulkan is not natively supported by macOS, iOS and tvOS. However, there exists [MoltenVK](https://github.com/KhronosGroup/MoltenVK)
an open-source Vulkan implementation on top of Apple's Metal API. This allows vulkano to build and run on macOS, iOS and tvOS platforms.

The easiest way to get vulkano up and running with MoltenVK is to install the
[Vulkan SDK for macOS](https://vulkan.lunarg.com/sdk/home). There are [installation instructions](https://vulkan.lunarg.com/doc/sdk/latest/mac/getting_started.html) on the LunarG website.

On iOS, vulkano links directly to the MoltenVK framework. There is nothing else to do besides
installing it. Note that the Vulkan SDK for macOS also comes with the iOS framework.
On iOS and tvOS, vulkano links directly to the MoltenVK framework. There is nothing else to do besides
installing it. Note that the Vulkan SDK for macOS also comes with the framework for iOS and tvOS.

## License

Expand Down
5 changes: 2 additions & 3 deletions vulkano-util/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl VulkanoContext {
pub fn new(mut config: VulkanoConfig) -> Self {
let library = match VulkanLibrary::new() {
Ok(x) => x,
#[cfg(target_os = "macos")]
#[cfg(target_vendor = "apple")]
Err(vulkano::library::LoadingError::LibraryLoadFailure(err)) => panic!(
"failed to load Vulkan library: {err}; did you install VulkanSDK from \
https://vulkan.lunarg.com/sdk/home?",
Expand All @@ -140,8 +140,7 @@ impl VulkanoContext {
khr_wayland_surface: true,
khr_android_surface: true,
khr_win32_surface: true,
mvk_ios_surface: true,
mvk_macos_surface: true,
ext_metal_surface: true,
..InstanceExtensions::empty()
})
.union(&config.instance_create_info.enabled_extensions);
Expand Down
4 changes: 0 additions & 4 deletions vulkano-util/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,6 @@ impl VulkanoWindowRenderer {
self.remove_additional_image_view(i);
self.add_additional_image_view(i, format, usage);
}
#[cfg(target_os = "ios")]
unsafe {
self.surface.update_ios_sublayer_on_resize();
}
self.recreate_swapchain = false;
}
}
14 changes: 8 additions & 6 deletions vulkano-win/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
name = "vulkano-win"
version = "0.34.0"
edition = "2021"
authors = ["Pierre Krieger <[email protected]>", "The vulkano contributors"]
authors = [
"Pierre Krieger <[email protected]>",
"The vulkano contributors",
]
repository = "https://github.com/vulkano-rs/vulkano/tree/master/vulkano-win"
description = "Link between vulkano and winit"
license = "MIT OR Apache-2.0"
Expand All @@ -16,8 +19,8 @@ readme = "../README.md"
default = ["winit", "raw-window-handle"]
raw-window-handle = ["dep:raw-window-handle"]
raw-window-handle_ = ["dep:raw-window-handle"]
winit = ["dep:winit", "dep:objc", "dep:core-graphics-types"]
winit_ = ["dep:winit", "dep:objc", "dep:core-graphics-types"]
winit = ["dep:winit"]
winit_ = ["dep:winit"]

# NOTE(Marc): The dependencies here are not workspace dependencies because vulkano-win is
# deprecated and won't be receiving updates.
Expand All @@ -27,6 +30,5 @@ raw-window-handle = { version = "0.5", optional = true }
vulkano = { workspace = true }
winit = { version = "0.28", optional = true }

[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
objc = { version = "0.2.5", optional = true }
core-graphics-types = { version = "0.1", optional = true }
[target.'cfg(target_vendor = "apple")'.dependencies]
raw-window-metal.workspace = true
Loading

0 comments on commit 470d258

Please sign in to comment.