From c425d5c3704e60f4fc454191aadd0824004d08b7 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Fri, 8 Feb 2019 14:53:06 -0500 Subject: [PATCH] Portability extensions fixes, README update --- Cargo.lock | 18 +++++----- README.md | 17 ++++++++- libportability-gfx/src/impls.rs | 61 ++++++++++++--------------------- libportability-gfx/src/lib.rs | 6 ++-- 4 files changed, 50 insertions(+), 52 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0298cdd..fad1216 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,7 +13,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "line_drawing 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rusttype 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rusttype 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "xdg 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -305,7 +305,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "gfx-backend-dx11" version = "0.1.0" -source = "git+https://github.com/gfx-rs/gfx#85015738a3b5597e0ee9877f43bd04cb2682463d" +source = "git+https://github.com/gfx-rs/gfx#f1ad3182a05c01ea38182337a97b7d0676fc527f" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "derivative 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -323,7 +323,7 @@ dependencies = [ [[package]] name = "gfx-backend-dx12" version = "0.1.0" -source = "git+https://github.com/gfx-rs/gfx#85015738a3b5597e0ee9877f43bd04cb2682463d" +source = "git+https://github.com/gfx-rs/gfx#f1ad3182a05c01ea38182337a97b7d0676fc527f" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "d3d12 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -340,7 +340,7 @@ dependencies = [ [[package]] name = "gfx-backend-metal" version = "0.1.0" -source = "git+https://github.com/gfx-rs/gfx#85015738a3b5597e0ee9877f43bd04cb2682463d" +source = "git+https://github.com/gfx-rs/gfx#f1ad3182a05c01ea38182337a97b7d0676fc527f" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -362,7 +362,7 @@ dependencies = [ [[package]] name = "gfx-backend-vulkan" version = "0.1.0" -source = "git+https://github.com/gfx-rs/gfx#85015738a3b5597e0ee9877f43bd04cb2682463d" +source = "git+https://github.com/gfx-rs/gfx#f1ad3182a05c01ea38182337a97b7d0676fc527f" dependencies = [ "ash 0.27.1 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -379,7 +379,7 @@ dependencies = [ [[package]] name = "gfx-hal" version = "0.1.0" -source = "git+https://github.com/gfx-rs/gfx#85015738a3b5597e0ee9877f43bd04cb2682463d" +source = "git+https://github.com/gfx-rs/gfx#f1ad3182a05c01ea38182337a97b7d0676fc527f" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -849,7 +849,7 @@ dependencies = [ [[package]] name = "range-alloc" version = "0.1.0" -source = "git+https://github.com/gfx-rs/gfx#85015738a3b5597e0ee9877f43bd04cb2682463d" +source = "git+https://github.com/gfx-rs/gfx#f1ad3182a05c01ea38182337a97b7d0676fc527f" [[package]] name = "rdrand" @@ -928,7 +928,7 @@ dependencies = [ [[package]] name = "rusttype" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "approx 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1481,7 +1481,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum renderdoc 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3aee9badfb4078c375d2d0479ed29c9c057b51ade78f94792ba2dcb11f343e7e" "checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -"checksum rusttype 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ae90f66c7ca5fb2c566d373c9ccb3ce1ae1aeebf236b74ad0d413196facb31b3" +"checksum rusttype 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ce3926a2057b315b3e8bca6d1cec1e97f19436a8f9127621cd538cda9c96a38b" "checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" diff --git a/README.md b/README.md index b42fe32..bdd1917 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,11 @@ This is a prototype library implementing [Vulkan Portability Initiative](https:/ ## Instructions -Despite the fact it's written in Rust, the produced binary is a standard dynamic library that can be linked to from any program (written in the language of your choice). Typically, you'd need to create a symbolic link with a name that a target application expects, e.g. `libvulkan.dylib -> libportability.dylib`. +Despite the fact it's written in Rust, the produced binaries have standard lining interface compatible with any program (written in the language of your choice). There are multiple ways to link to gfx-portability. + +### Dynamic linking + +Typically, you'd need to create a symbolic link with a name that a target application expects, e.g. `libvulkan.dylib -> libportability.dylib`. Check out and build: ``` @@ -32,6 +36,17 @@ git clone --recursive https://github.com/gfx-rs/portability && cd portability cargo build --manifest-path libportability/Cargo.toml --features ``` +### ICD provider + +gfx-portability can be used with Vulkan loader like any other Vulkan driver. In order to use it this way, you need to build `libportability-icd` and point to it from an ICD json file: +``` +VK_ICD_FILENAMES=portability/libportability-icd/portability-macos-debug.json +``` + +### Static linking + +For C, you'd need to add `crate-type = ["cdylib"]` to `libportability-gfx/Cargo.toml` and build it with the backend of your choice. Note: features of this library are fully-qualified crate names, e.g. `features gfx-backend-metal`. For rust, just point the cargo dependency to `libportability-gfx`. + ## Running Samples ### LunarG (API-Samples) diff --git a/libportability-gfx/src/impls.rs b/libportability-gfx/src/impls.rs index 2b89ede..42769dc 100644 --- a/libportability-gfx/src/impls.rs +++ b/libportability-gfx/src/impls.rs @@ -214,12 +214,13 @@ pub extern "C" fn gfxGetPhysicalDeviceFeatures2KHR( let features = adapter.physical_device.features(); let mut ptr = pFeatures as *const VkStructureType; while !ptr.is_null() { - match unsafe { *ptr } { + ptr = match unsafe { *ptr } { VkStructureType::VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR => { let data = unsafe { (ptr as *mut VkPhysicalDeviceFeatures2KHR).as_mut().unwrap() }; data.features = conv::features_from_hal(features); + data.pNext } VkStructureType::VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PORTABILITY_SUBSET_FEATURES_EXTX =>{ let data = unsafe { @@ -238,6 +239,7 @@ pub extern "C" fn gfxGetPhysicalDeviceFeatures2KHR( if !cfg!(feature = "gfx-backend-metal") { data.standardImageViews = VK_TRUE; } + data.pNext } VkStructureType::VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PORTABILITY_SUBSET_PROPERTIES_EXTX => { let data = unsafe { @@ -245,14 +247,15 @@ pub extern "C" fn gfxGetPhysicalDeviceFeatures2KHR( }; let limits = adapter.physical_device.limits(); data.minVertexInputBindingStrideAlignment = limits.min_vertex_input_binding_stride_alignment as u32; + data.pNext } other => { warn!("Unrecognized {:?}, skipping", other); + unsafe { + (ptr as *const VkPhysicalDeviceFeatures2KHR).as_ref().unwrap() + }.pNext } - }; - ptr = unsafe { - *(ptr.offset(1) as *const *const VkStructureType) - }; + } as *const VkStructureType; } } #[inline] @@ -284,7 +287,7 @@ fn get_physical_device_image_format_properties( conv::map_image_usage(info.usage), conv::map_image_create_flags(info.flags), ) - .map(conv::image_format_properties_from_hal) + .map(conv::image_format_properties_from_hal) } #[inline] pub extern "C" fn gfxGetPhysicalDeviceImageFormatProperties( @@ -323,56 +326,36 @@ pub extern "C" fn gfxGetPhysicalDeviceImageFormatProperties2KHR( let mut ptr = pImageFormatInfo as *const VkStructureType; while !ptr.is_null() { - match unsafe { *ptr } { + ptr = match unsafe { *ptr } { VkStructureType::VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2_KHR => { let data = unsafe { (ptr as *const VkPhysicalDeviceImageFormatInfo2KHR).as_ref().unwrap() }; properties = get_physical_device_image_format_properties(adapter, data); + data.pNext } VkStructureType::VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_VIEW_SUPPORT_EXTX => { let data = unsafe { (ptr as *const VkPhysicalDeviceImageViewSupportEXTX).as_ref().unwrap() }; - //TODO: provide the data from gfx-rs itself - // copied from `map_format_with_swizzle` - let identity = VkComponentMapping { - r: VkComponentSwizzle::VK_COMPONENT_SWIZZLE_R, - g: VkComponentSwizzle::VK_COMPONENT_SWIZZLE_G, - b: VkComponentSwizzle::VK_COMPONENT_SWIZZLE_B, - a: VkComponentSwizzle::VK_COMPONENT_SWIZZLE_A, - }; - let bgra = VkComponentMapping { - r: identity.b, - b: identity.r, - .. identity - }; - if data.components != identity && cfg!(feature = "gfx-backend-metal") { - let supported = match data.format { - VkFormat::VK_FORMAT_R8_UNORM => data.components == VkComponentMapping { - r: VkComponentSwizzle::VK_COMPONENT_SWIZZLE_ZERO, - g: VkComponentSwizzle::VK_COMPONENT_SWIZZLE_ZERO, - b: VkComponentSwizzle::VK_COMPONENT_SWIZZLE_ZERO, - a: VkComponentSwizzle::VK_COMPONENT_SWIZZLE_R, - }, - VkFormat::VK_FORMAT_R8G8B8A8_UNORM => data.components == bgra, - VkFormat::VK_FORMAT_B8G8R8A8_UNORM => data.components == bgra, - VkFormat::VK_FORMAT_B8G8R8A8_SRGB => data.components == bgra, - VkFormat::VK_FORMAT_B5G6R5_UNORM_PACK16 => data.components == bgra, - _ => false, - }; - if !supported { + #[cfg(feature = "gfx-backend-metal")] + { + if !adapter.physical_device.supports_swizzle( + conv::map_format(data.format).unwrap(), + conv::map_swizzle(data.components), + ) { return VkResult::VK_ERROR_FORMAT_NOT_SUPPORTED; } } + data.pNext } other => { warn!("Unrecognized {:?}, skipping", other); + unsafe { + (ptr as *const VkPhysicalDeviceImageFormatInfo2KHR).as_ref().unwrap() + }.pNext } - }; - ptr = unsafe { - *(ptr.offset(1) as *const *const VkStructureType) - }; + } as *const VkStructureType; } match properties { diff --git a/libportability-gfx/src/lib.rs b/libportability-gfx/src/lib.rs index 6bc6c88..86ce996 100644 --- a/libportability-gfx/src/lib.rs +++ b/libportability-gfx/src/lib.rs @@ -518,7 +518,7 @@ pub const VK_EXT_DISCARD_RECTANGLES_EXTENSION_NAME: &'static [u8; 26usize] = pub const VK_EXTX_portability_subset: ::std::os::raw::c_uint = 1; pub const VK_EXTX_PORTABILITY_SUBSET_SPEC_VERSION: ::std::os::raw::c_uint = - 2; + 1; pub const VK_EXTX_PORTABILITY_SUBSET_EXTENSION_NAME: &'static [u8; 27usize] = b"VK_EXTX_portability_subset\x00"; @@ -843,8 +843,8 @@ pub enum VkStructureType { VK_STRUCTURE_TYPE_IOS_SURFACE_CREATE_INFO_MVK = 1000122000, VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK = 1000123000, VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT = 1000248000, - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PORTABILITY_SUBSET_FEATURES_EXTX = 100163000, - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PORTABILITY_SUBSET_PROPERTIES_EXTX = 100163001, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PORTABILITY_SUBSET_FEATURES_EXTX = 1000163000, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PORTABILITY_SUBSET_PROPERTIES_EXTX = 1000163001, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_VIEW_SUPPORT_EXTX = 100163002, VK_STRUCTURE_TYPE_MAX_ENUM = 2147483647, }