Skip to content

Commit

Permalink
Merge #175
Browse files Browse the repository at this point in the history
175: Portability extensions fixes, README update r=grovesNL a=kvark

This version is confirmed to work with VkPI CTS 🎉 

Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
  • Loading branch information
bors[bot] and kvark committed Feb 9, 2019
2 parents 2d2e3fd + c425d5c commit a0f7261
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 52 deletions.
18 changes: 9 additions & 9 deletions Cargo.lock

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

17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,29 @@ 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:
```
git clone --recursive https://github.com/gfx-rs/portability && cd portability
cargo build --manifest-path libportability/Cargo.toml --features <vulkan|dx12|metal>
```

### 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 <some_vulkan_app>
```

### 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)
Expand Down
61 changes: 22 additions & 39 deletions libportability-gfx/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -238,21 +239,23 @@ 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 {
(ptr as *mut VkPhysicalDevicePortabilitySubsetPropertiesEXTX).as_mut().unwrap()
};
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]
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions libportability-gfx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
}
Expand Down

0 comments on commit a0f7261

Please sign in to comment.