Implement VK_EXTX_portability_subset v2

This commit is contained in:
Dzmitry Malyshau 2019-02-06 15:06:48 -05:00
parent 4f83168891
commit d5fb1b6f6c
3 changed files with 297 additions and 100 deletions

View file

@ -1,5 +1,5 @@
use hal::{buffer, command, error, format, image, memory, pass, pso, query, window}; use hal::{buffer, command, error, format, image, memory, pass, pso, query, window};
use hal::{IndexType, Limits, PatchSize, Primitive}; use hal::{IndexType, Features, Limits, PatchSize, Primitive};
use std::mem; use std::mem;
@ -41,6 +41,66 @@ pub fn limits_from_hal(limits: Limits) -> VkPhysicalDeviceLimits {
} }
} }
pub fn features_from_hal(features: Features) -> VkPhysicalDeviceFeatures {
VkPhysicalDeviceFeatures {
robustBufferAccess: features.contains(Features::ROBUST_BUFFER_ACCESS) as _,
fullDrawIndexUint32: features.contains(Features::FULL_DRAW_INDEX_U32) as _,
imageCubeArray: features.contains(Features::IMAGE_CUBE_ARRAY) as _,
independentBlend: features.contains(Features::INDEPENDENT_BLENDING) as _,
geometryShader: features.contains(Features::GEOMETRY_SHADER) as _,
tessellationShader: features.contains(Features::TESSELLATION_SHADER) as _,
sampleRateShading: features.contains(Features::SAMPLE_RATE_SHADING) as _,
dualSrcBlend: features.contains(Features::DUAL_SRC_BLENDING) as _,
logicOp: features.contains(Features::LOGIC_OP) as _,
multiDrawIndirect: features.contains(Features::MULTI_DRAW_INDIRECT) as _,
drawIndirectFirstInstance: features.contains(Features::DRAW_INDIRECT_FIRST_INSTANCE) as _,
depthClamp: features.contains(Features::DEPTH_CLAMP) as _,
depthBiasClamp: features.contains(Features::DEPTH_BIAS_CLAMP) as _,
fillModeNonSolid: features.contains(Features::NON_FILL_POLYGON_MODE) as _,
depthBounds: features.contains(Features::DEPTH_BOUNDS) as _,
wideLines: features.contains(Features::LINE_WIDTH) as _,
largePoints: features.contains(Features::POINT_SIZE) as _,
alphaToOne: features.contains(Features::ALPHA_TO_ONE) as _,
multiViewport: features.contains(Features::MULTI_VIEWPORTS) as _,
samplerAnisotropy: features.contains(Features::SAMPLER_ANISOTROPY) as _,
textureCompressionETC2: features.contains(Features::FORMAT_ETC2) as _,
textureCompressionASTC_LDR: features.contains(Features::FORMAT_ASTC_LDR) as _,
textureCompressionBC: features.contains(Features::FORMAT_BC) as _,
occlusionQueryPrecise: features.contains(Features::PRECISE_OCCLUSION_QUERY) as _,
pipelineStatisticsQuery: features.contains(Features::PIPELINE_STATISTICS_QUERY) as _,
vertexPipelineStoresAndAtomics: features.contains(Features::VERTEX_STORES_AND_ATOMICS) as _,
fragmentStoresAndAtomics: features.contains(Features::FRAGMENT_STORES_AND_ATOMICS) as _,
shaderTessellationAndGeometryPointSize: features.contains(Features::SHADER_TESSELLATION_AND_GEOMETRY_POINT_SIZE) as _,
shaderImageGatherExtended: features.contains(Features::SHADER_IMAGE_GATHER_EXTENDED) as _,
shaderStorageImageExtendedFormats: features.contains(Features::SHADER_STORAGE_IMAGE_EXTENDED_FORMATS) as _,
shaderStorageImageMultisample: features.contains(Features::SHADER_STORAGE_IMAGE_MULTISAMPLE) as _,
shaderStorageImageReadWithoutFormat: features.contains(Features::SHADER_STORAGE_IMAGE_READ_WITHOUT_FORMAT) as _,
shaderStorageImageWriteWithoutFormat: features.contains(Features::SHADER_STORAGE_IMAGE_WRITE_WITHOUT_FORMAT) as _,
shaderUniformBufferArrayDynamicIndexing: features.contains(Features::SHADER_UNIFORM_BUFFER_ARRAY_DYNAMIC_INDEXING) as _,
shaderSampledImageArrayDynamicIndexing: features.contains(Features::SHADER_SAMPLED_IMAGE_ARRAY_DYNAMIC_INDEXING) as _,
shaderStorageBufferArrayDynamicIndexing: features.contains(Features::SHADER_STORAGE_BUFFER_ARRAY_DYNAMIC_INDEXING) as _,
shaderStorageImageArrayDynamicIndexing: features.contains(Features::SHADER_STORAGE_IMAGE_ARRAY_DYNAMIC_INDEXING) as _,
shaderClipDistance: features.contains(Features::SHADER_CLIP_DISTANCE) as _,
shaderCullDistance: features.contains(Features::SHADER_CULL_DISTANCE) as _,
shaderFloat64: features.contains(Features::SHADER_FLOAT64) as _,
shaderInt64: features.contains(Features::SHADER_INT64) as _,
shaderInt16: features.contains(Features::SHADER_INT16) as _,
shaderResourceResidency: features.contains(Features::SHADER_RESOURCE_RESIDENCY) as _,
shaderResourceMinLod: features.contains(Features::SHADER_RESOURCE_MIN_LOD) as _,
sparseBinding: features.contains(Features::SPARSE_BINDING) as _,
sparseResidencyBuffer: features.contains(Features::SPARSE_RESIDENCY_BUFFER) as _,
sparseResidencyImage2D: features.contains(Features::SPARSE_RESIDENCY_IMAGE_2D) as _,
sparseResidencyImage3D: features.contains(Features::SPARSE_RESIDENCY_IMAGE_3D) as _,
sparseResidency2Samples: features.contains(Features::SPARSE_RESIDENCY_2_SAMPLES) as _,
sparseResidency4Samples: features.contains(Features::SPARSE_RESIDENCY_4_SAMPLES) as _,
sparseResidency8Samples: features.contains(Features::SPARSE_RESIDENCY_8_SAMPLES) as _,
sparseResidency16Samples: features.contains(Features::SPARSE_RESIDENCY_16_SAMPLES) as _,
sparseResidencyAliased: features.contains(Features::SPARSE_RESIDENCY_ALIASED) as _,
variableMultisampleRate: features.contains(Features::VARIABLE_MULTISAMPLE_RATE) as _,
inheritedQueries: features.contains(Features::INHERITED_QUERIES) as _,
}
}
#[inline] #[inline]
pub fn format_from_hal(format: format::Format) -> VkFormat { pub fn format_from_hal(format: format::Format) -> VkFormat {
// HAL formats have the same numeric representation as Vulkan formats // HAL formats have the same numeric representation as Vulkan formats

View file

@ -13,7 +13,7 @@ use std::ffi::{CStr, CString};
use std::os::raw::c_int; use std::os::raw::c_int;
#[cfg(feature = "renderdoc")] #[cfg(feature = "renderdoc")]
use std::os::raw::c_void; use std::os::raw::c_void;
use std::{mem, ptr}; use std::{mem, ptr, str};
use super::*; use super::*;
@ -208,64 +208,56 @@ pub extern "C" fn gfxGetPhysicalDeviceFeatures(
pFeatures: *mut VkPhysicalDeviceFeatures, pFeatures: *mut VkPhysicalDeviceFeatures,
) { ) {
let features = adapter.physical_device.features(); let features = adapter.physical_device.features();
unsafe { unsafe {
*pFeatures = VkPhysicalDeviceFeatures { *pFeatures = conv::features_from_hal(features);
robustBufferAccess: features.contains(Features::ROBUST_BUFFER_ACCESS) as _, }
fullDrawIndexUint32: features.contains(Features::FULL_DRAW_INDEX_U32) as _, }
imageCubeArray: features.contains(Features::IMAGE_CUBE_ARRAY) as _, #[inline]
independentBlend: features.contains(Features::INDEPENDENT_BLENDING) as _, pub extern "C" fn gfxGetPhysicalDeviceFeatures2KHR(
geometryShader: features.contains(Features::GEOMETRY_SHADER) as _, adapter: VkPhysicalDevice,
tessellationShader: features.contains(Features::TESSELLATION_SHADER) as _, pFeatures: *mut VkPhysicalDeviceFeatures2KHR,
sampleRateShading: features.contains(Features::SAMPLE_RATE_SHADING) as _, ) {
dualSrcBlend: features.contains(Features::DUAL_SRC_BLENDING) as _, let features = adapter.physical_device.features();
logicOp: features.contains(Features::LOGIC_OP) as _, let mut ptr = pFeatures as *const VkStructureType;
multiDrawIndirect: features.contains(Features::MULTI_DRAW_INDIRECT) as _, while !ptr.is_null() {
drawIndirectFirstInstance: features.contains(Features::DRAW_INDIRECT_FIRST_INSTANCE) as _, match unsafe { *ptr } {
depthClamp: features.contains(Features::DEPTH_CLAMP) as _, VkStructureType::VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR => {
depthBiasClamp: features.contains(Features::DEPTH_BIAS_CLAMP) as _, let data = unsafe {
fillModeNonSolid: features.contains(Features::NON_FILL_POLYGON_MODE) as _, (ptr as *mut VkPhysicalDeviceFeatures2KHR).as_mut().unwrap()
depthBounds: features.contains(Features::DEPTH_BOUNDS) as _, };
wideLines: features.contains(Features::LINE_WIDTH) as _, data.features = conv::features_from_hal(features);
largePoints: features.contains(Features::POINT_SIZE) as _, }
alphaToOne: features.contains(Features::ALPHA_TO_ONE) as _, VkStructureType::VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PORTABILITY_SUBSET_FEATURES_EXTX =>{
multiViewport: features.contains(Features::MULTI_VIEWPORTS) as _, let data = unsafe {
samplerAnisotropy: features.contains(Features::SAMPLER_ANISOTROPY) as _, (ptr as *mut VkPhysicalDevicePortabilitySubsetFeaturesEXTX).as_mut().unwrap()
textureCompressionETC2: features.contains(Features::FORMAT_ETC2) as _, };
textureCompressionASTC_LDR: features.contains(Features::FORMAT_ASTC_LDR) as _, if features.contains(hal::Features::TRIANGLE_FAN) {
textureCompressionBC: features.contains(Features::FORMAT_BC) as _, data.triangleFans = VK_TRUE;
occlusionQueryPrecise: features.contains(Features::PRECISE_OCCLUSION_QUERY) as _, }
pipelineStatisticsQuery: features.contains(Features::PIPELINE_STATISTICS_QUERY) as _, if features.contains(hal::Features::SEPARATE_STENCIL_REF_VALUES) {
vertexPipelineStoresAndAtomics: features.contains(Features::VERTEX_STORES_AND_ATOMICS) as _, data.separateStencilMaskRef = VK_TRUE;
fragmentStoresAndAtomics: features.contains(Features::FRAGMENT_STORES_AND_ATOMICS) as _, }
shaderTessellationAndGeometryPointSize: features.contains(Features::SHADER_TESSELLATION_AND_GEOMETRY_POINT_SIZE) as _, //TODO: turn those into feature flags
shaderImageGatherExtended: features.contains(Features::SHADER_IMAGE_GATHER_EXTENDED) as _, if !cfg!(feature = "gfx-backend-metal") {
shaderStorageImageExtendedFormats: features.contains(Features::SHADER_STORAGE_IMAGE_EXTENDED_FORMATS) as _, data.standardImageViews = VK_TRUE;
shaderStorageImageMultisample: features.contains(Features::SHADER_STORAGE_IMAGE_MULTISAMPLE) as _, data.samplerMipLodBias = VK_TRUE;
shaderStorageImageReadWithoutFormat: features.contains(Features::SHADER_STORAGE_IMAGE_READ_WITHOUT_FORMAT) as _, }
shaderStorageImageWriteWithoutFormat: features.contains(Features::SHADER_STORAGE_IMAGE_WRITE_WITHOUT_FORMAT) as _, }
shaderUniformBufferArrayDynamicIndexing: features.contains(Features::SHADER_UNIFORM_BUFFER_ARRAY_DYNAMIC_INDEXING) as _, VkStructureType::VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PORTABILITY_SUBSET_PROPERTIES_EXTX => {
shaderSampledImageArrayDynamicIndexing: features.contains(Features::SHADER_SAMPLED_IMAGE_ARRAY_DYNAMIC_INDEXING) as _, let data = unsafe {
shaderStorageBufferArrayDynamicIndexing: features.contains(Features::SHADER_STORAGE_BUFFER_ARRAY_DYNAMIC_INDEXING) as _, (ptr as *mut VkPhysicalDevicePortabilitySubsetPropertiesEXTX).as_mut().unwrap()
shaderStorageImageArrayDynamicIndexing: features.contains(Features::SHADER_STORAGE_IMAGE_ARRAY_DYNAMIC_INDEXING) as _, };
shaderClipDistance: features.contains(Features::SHADER_CLIP_DISTANCE) as _, //TODO: turn this into a limit value
shaderCullDistance: features.contains(Features::SHADER_CULL_DISTANCE) as _, if cfg!(feature = "gfx-backend-metal") {
shaderFloat64: features.contains(Features::SHADER_FLOAT64) as _, data.minVertexInputBindingStrideAlignment = 4;
shaderInt64: features.contains(Features::SHADER_INT64) as _, }
shaderInt16: features.contains(Features::SHADER_INT16) as _, }
shaderResourceResidency: features.contains(Features::SHADER_RESOURCE_RESIDENCY) as _, other => {
shaderResourceMinLod: features.contains(Features::SHADER_RESOURCE_MIN_LOD) as _, warn!("Unrecognized {:?}, skipping", other);
sparseBinding: features.contains(Features::SPARSE_BINDING) as _, }
sparseResidencyBuffer: features.contains(Features::SPARSE_RESIDENCY_BUFFER) as _, };
sparseResidencyImage2D: features.contains(Features::SPARSE_RESIDENCY_IMAGE_2D) as _, ptr = unsafe {
sparseResidencyImage3D: features.contains(Features::SPARSE_RESIDENCY_IMAGE_3D) as _, *(ptr.offset(1) as *const *const VkStructureType)
sparseResidency2Samples: features.contains(Features::SPARSE_RESIDENCY_2_SAMPLES) as _,
sparseResidency4Samples: features.contains(Features::SPARSE_RESIDENCY_4_SAMPLES) as _,
sparseResidency8Samples: features.contains(Features::SPARSE_RESIDENCY_8_SAMPLES) as _,
sparseResidency16Samples: features.contains(Features::SPARSE_RESIDENCY_16_SAMPLES) as _,
sparseResidencyAliased: features.contains(Features::SPARSE_RESIDENCY_ALIASED) as _,
variableMultisampleRate: features.contains(Features::VARIABLE_MULTISAMPLE_RATE) as _,
inheritedQueries: features.contains(Features::INHERITED_QUERIES) as _,
}; };
} }
} }
@ -280,31 +272,118 @@ pub extern "C" fn gfxGetPhysicalDeviceFormatProperties(
*pFormatProperties = conv::format_properties_from_hal(properties); *pFormatProperties = conv::format_properties_from_hal(properties);
} }
} }
fn get_physical_device_image_format_properties(
adapter: VkPhysicalDevice,
info: &VkPhysicalDeviceImageFormatInfo2KHR,
) -> Option<VkImageFormatProperties> {
adapter.physical_device
.image_format_properties(
conv::map_format(info.format).unwrap(),
match info.type_ {
VkImageType::VK_IMAGE_TYPE_1D => 1,
VkImageType::VK_IMAGE_TYPE_2D => 2,
VkImageType::VK_IMAGE_TYPE_3D => 3,
other => panic!("Unexpected image type: {:?}", other),
},
conv::map_tiling(info.tiling),
conv::map_image_usage(info.usage),
conv::map_image_create_flags(info.flags),
)
.map(conv::image_format_properties_from_hal)
}
#[inline] #[inline]
pub extern "C" fn gfxGetPhysicalDeviceImageFormatProperties( pub extern "C" fn gfxGetPhysicalDeviceImageFormatProperties(
adapter: VkPhysicalDevice, adapter: VkPhysicalDevice,
format: VkFormat, format: VkFormat,
typ: VkImageType, type_: VkImageType,
tiling: VkImageTiling, tiling: VkImageTiling,
usage: VkImageUsageFlags, usage: VkImageUsageFlags,
create_flags: VkImageCreateFlags, flags: VkImageCreateFlags,
pImageFormatProperties: *mut VkImageFormatProperties, pImageFormatProperties: *mut VkImageFormatProperties,
) -> VkResult { ) -> VkResult {
let properties = adapter.physical_device.image_format_properties( let info = VkPhysicalDeviceImageFormatInfo2KHR {
conv::map_format(format).unwrap(), sType: VkStructureType::VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2_KHR,
match typ { pNext: ptr::null(),
VkImageType::VK_IMAGE_TYPE_1D => 1, format,
VkImageType::VK_IMAGE_TYPE_2D => 2, type_,
VkImageType::VK_IMAGE_TYPE_3D => 3, tiling,
_ => panic!("Unexpected image type: {:?}", typ), usage,
flags
};
match get_physical_device_image_format_properties(adapter, &info) {
Some(props) => unsafe {
*pImageFormatProperties = props;
VkResult::VK_SUCCESS
}, },
conv::map_tiling(tiling), None => VkResult::VK_ERROR_FORMAT_NOT_SUPPORTED,
conv::map_image_usage(usage), }
conv::map_image_create_flags(create_flags), }
); #[inline]
pub extern "C" fn gfxGetPhysicalDeviceImageFormatProperties2KHR(
adapter: VkPhysicalDevice,
pImageFormatInfo: *const VkPhysicalDeviceImageFormatInfo2KHR,
pImageFormatProperties: *mut VkImageFormatProperties2KHR,
) -> VkResult {
let mut properties = None;
let mut ptr = pImageFormatInfo as *const VkStructureType;
while !ptr.is_null() {
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);
}
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 {
return VkResult::VK_ERROR_FORMAT_NOT_SUPPORTED;
}
}
}
other => {
warn!("Unrecognized {:?}, skipping", other);
}
};
ptr = unsafe {
*(ptr.offset(1) as *const *const VkStructureType)
};
}
match properties { match properties {
Some(props) => unsafe { Some(props) => unsafe {
*pImageFormatProperties = conv::image_format_properties_from_hal(props); (*pImageFormatProperties).imageFormatProperties = props;
VkResult::VK_SUCCESS VkResult::VK_SUCCESS
}, },
None => VkResult::VK_ERROR_FORMAT_NOT_SUPPORTED, None => VkResult::VK_ERROR_FORMAT_NOT_SUPPORTED,
@ -399,9 +478,11 @@ pub extern "C" fn gfxGetInstanceProcAddr(
vkEnumerateDeviceLayerProperties, PFN_vkEnumerateDeviceLayerProperties => gfxEnumerateDeviceLayerProperties, vkEnumerateDeviceLayerProperties, PFN_vkEnumerateDeviceLayerProperties => gfxEnumerateDeviceLayerProperties,
vkGetPhysicalDeviceFeatures, PFN_vkGetPhysicalDeviceFeatures => gfxGetPhysicalDeviceFeatures, vkGetPhysicalDeviceFeatures, PFN_vkGetPhysicalDeviceFeatures => gfxGetPhysicalDeviceFeatures,
vkGetPhysicalDeviceFeatures2KHR, PFN_vkGetPhysicalDeviceFeatures2KHR => gfxGetPhysicalDeviceFeatures2KHR,
vkGetPhysicalDeviceProperties, PFN_vkGetPhysicalDeviceProperties => gfxGetPhysicalDeviceProperties, vkGetPhysicalDeviceProperties, PFN_vkGetPhysicalDeviceProperties => gfxGetPhysicalDeviceProperties,
vkGetPhysicalDeviceFormatProperties, PFN_vkGetPhysicalDeviceFormatProperties => gfxGetPhysicalDeviceFormatProperties, vkGetPhysicalDeviceFormatProperties, PFN_vkGetPhysicalDeviceFormatProperties => gfxGetPhysicalDeviceFormatProperties,
vkGetPhysicalDeviceImageFormatProperties, PFN_vkGetPhysicalDeviceImageFormatProperties => gfxGetPhysicalDeviceImageFormatProperties, vkGetPhysicalDeviceImageFormatProperties, PFN_vkGetPhysicalDeviceImageFormatProperties => gfxGetPhysicalDeviceImageFormatProperties,
vkGetPhysicalDeviceImageFormatProperties2KHR, PFN_vkGetPhysicalDeviceImageFormatProperties2KHR => gfxGetPhysicalDeviceImageFormatProperties2KHR,
vkGetPhysicalDeviceMemoryProperties, PFN_vkGetPhysicalDeviceMemoryProperties => gfxGetPhysicalDeviceMemoryProperties, vkGetPhysicalDeviceMemoryProperties, PFN_vkGetPhysicalDeviceMemoryProperties => gfxGetPhysicalDeviceMemoryProperties,
vkGetPhysicalDeviceQueueFamilyProperties, PFN_vkGetPhysicalDeviceQueueFamilyProperties => gfxGetPhysicalDeviceQueueFamilyProperties, vkGetPhysicalDeviceQueueFamilyProperties, PFN_vkGetPhysicalDeviceQueueFamilyProperties => gfxGetPhysicalDeviceQueueFamilyProperties,
vkGetPhysicalDeviceSparseImageFormatProperties, PFN_vkGetPhysicalDeviceSparseImageFormatProperties => gfxGetPhysicalDeviceSparseImageFormatProperties, vkGetPhysicalDeviceSparseImageFormatProperties, PFN_vkGetPhysicalDeviceSparseImageFormatProperties => gfxGetPhysicalDeviceSparseImageFormatProperties,
@ -438,11 +519,10 @@ pub extern "C" fn gfxGetDeviceProcAddr(
| "vkGetSwapchainImagesKHR" | "vkGetSwapchainImagesKHR"
| "vkAcquireNextImageKHR" | "vkAcquireNextImageKHR"
| "vkQueuePresentKHR" => { | "vkQueuePresentKHR" => {
let swapchain_extension_enabled = device let search_name = str::from_utf8(
.enabled_extensions &VK_KHR_SWAPCHAIN_EXTENSION_NAME[.. VK_KHR_SWAPCHAIN_EXTENSION_NAME.len()-1]
.iter() ).unwrap();
.any(|e| e == DEVICE_EXTENSION_NAME_VK_KHR_SWAPCHAIN); if !device.enabled_extensions.iter().any(|ext| ext == search_name) {
if !swapchain_extension_enabled {
return None; return None;
} }
} }
@ -740,20 +820,19 @@ pub extern "C" fn gfxCreateDevice(
let enabled_extensions = if dev_info.enabledExtensionCount == 0 { let enabled_extensions = if dev_info.enabledExtensionCount == 0 {
Vec::new() Vec::new()
} else { } else {
let extensions = unsafe { let mut extensions = Vec::new();
slice::from_raw_parts(dev_info.ppEnabledExtensionNames, dev_info.enabledExtensionCount as _) for raw in unsafe {
.iter() slice::from_raw_parts(dev_info.ppEnabledExtensionNames, dev_info.enabledExtensionCount as _)
.map(|raw| CStr::from_ptr(*raw) } {
.to_str() let cstr = unsafe { CStr::from_ptr(*raw) };
.expect("Invalid extension name") if !DEVICE_EXTENSION_NAMES.contains(&cstr.to_bytes_with_nul()) {
.to_owned()
)
.collect::<Vec<_>>()
};
for extension in &extensions {
if !DEVICE_EXTENSION_NAMES.contains(&extension.as_ref()) {
return VkResult::VK_ERROR_EXTENSION_NOT_PRESENT; return VkResult::VK_ERROR_EXTENSION_NOT_PRESENT;
} }
let owned = cstr
.to_str()
.expect("Invalid extension name")
.to_owned();
extensions.push(owned);
} }
extensions extensions
}; };
@ -806,8 +885,6 @@ static INSTANCE_EXTENSION_NAME_VK_KHR_SURFACE: &str = "VK_KHR_surface";
static INSTANCE_EXTENSION_NAME_VK_KHR_WIN32_SURFACE: &str = "VK_KHR_win32_surface"; static INSTANCE_EXTENSION_NAME_VK_KHR_WIN32_SURFACE: &str = "VK_KHR_win32_surface";
#[cfg(target_os="macos")] #[cfg(target_os="macos")]
static INSTANCE_EXTENSION_NAME_VK_MACOS_SURFACE: &str = "VK_MVK_macos_surface"; static INSTANCE_EXTENSION_NAME_VK_MACOS_SURFACE: &str = "VK_MVK_macos_surface";
static DEVICE_EXTENSION_NAME_VK_KHR_SWAPCHAIN: &str = "VK_KHR_swapchain";
static DEVICE_EXTENSION_NAME_VK_KHR_MAINTENANCE1: &str = "VK_KHR_maintenance1";
lazy_static! { lazy_static! {
// TODO: Request from backend // TODO: Request from backend
@ -850,10 +927,12 @@ lazy_static! {
extensions.to_vec() extensions.to_vec()
}; };
static ref DEVICE_EXTENSION_NAMES: Vec<&'static str> = { static ref DEVICE_EXTENSION_NAMES: Vec<&'static [u8]> = {
vec![ vec![
DEVICE_EXTENSION_NAME_VK_KHR_SWAPCHAIN, &VK_KHR_SWAPCHAIN_EXTENSION_NAME[..],
DEVICE_EXTENSION_NAME_VK_KHR_MAINTENANCE1, &VK_KHR_MAINTENANCE1_EXTENSION_NAME[..],
&VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME[..],
&VK_EXTX_PORTABILITY_SUBSET_EXTENSION_NAME[..],
] ]
}; };
@ -867,14 +946,20 @@ lazy_static! {
extensionName: [0; 256], // VK_KHR_MAINTENANCE1_EXTENSION_NAME extensionName: [0; 256], // VK_KHR_MAINTENANCE1_EXTENSION_NAME
specVersion: VK_KHR_MAINTENANCE1_SPEC_VERSION, specVersion: VK_KHR_MAINTENANCE1_SPEC_VERSION,
}, },
VkExtensionProperties {
extensionName: [0; 256], // VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME
specVersion: VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_SPEC_VERSION,
},
VkExtensionProperties {
extensionName: [0; 256], // VK_EXTX_PORTABILITY_SUBSET_EXTENSION_NAME
specVersion: VK_EXTX_PORTABILITY_SUBSET_SPEC_VERSION,
},
]; ];
for (&name, extension) in DEVICE_EXTENSION_NAMES.iter().zip(&mut extensions) { for (&name, extension) in DEVICE_EXTENSION_NAMES.iter().zip(&mut extensions) {
extension extension
.extensionName[.. name.len()] .extensionName[.. name.len()]
.copy_from_slice(unsafe { .copy_from_slice(unsafe { mem::transmute(name) });
mem::transmute(name.as_bytes())
});
} }
extensions.to_vec() extensions.to_vec()

View file

@ -512,6 +512,15 @@ pub const VK_EXT_discard_rectangles: ::std::os::raw::c_uint = 1;
pub const VK_EXT_DISCARD_RECTANGLES_SPEC_VERSION: ::std::os::raw::c_uint = 1; pub const VK_EXT_DISCARD_RECTANGLES_SPEC_VERSION: ::std::os::raw::c_uint = 1;
pub const VK_EXT_DISCARD_RECTANGLES_EXTENSION_NAME: &'static [u8; 26usize] = pub const VK_EXT_DISCARD_RECTANGLES_EXTENSION_NAME: &'static [u8; 26usize] =
b"VK_EXT_discard_rectangles\x00"; b"VK_EXT_discard_rectangles\x00";
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;
pub const VK_EXTX_PORTABILITY_SUBSET_EXTENSION_NAME:
&'static [u8; 27usize] =
b"VK_EXTX_portability_subset\x00";
pub type wchar_t = ::std::os::raw::c_int; pub type wchar_t = ::std::os::raw::c_int;
#[repr(C)] #[repr(C)]
#[derive(Debug, Copy)] #[derive(Debug, Copy)]
@ -721,6 +730,7 @@ pub enum VkStructureType {
VK_STRUCTURE_TYPE_MEMORY_BARRIER = 46, VK_STRUCTURE_TYPE_MEMORY_BARRIER = 46,
VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO = 47, VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO = 47,
VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO = 48, VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO = 48,
VK_STRUCTURE_TYPE_RANGE_SIZE = 49,
VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR = 1000001000, VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR = 1000001000,
VK_STRUCTURE_TYPE_PRESENT_INFO_KHR = 1000001001, VK_STRUCTURE_TYPE_PRESENT_INFO_KHR = 1000001001,
VK_STRUCTURE_TYPE_DISPLAY_MODE_CREATE_INFO_KHR = 1000002000, VK_STRUCTURE_TYPE_DISPLAY_MODE_CREATE_INFO_KHR = 1000002000,
@ -829,7 +839,9 @@ pub enum VkStructureType {
1000099001, 1000099001,
VK_STRUCTURE_TYPE_IOS_SURFACE_CREATE_INFO_MVK = 1000122000, VK_STRUCTURE_TYPE_IOS_SURFACE_CREATE_INFO_MVK = 1000122000,
VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK = 1000123000, VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK = 1000123000,
VK_STRUCTURE_TYPE_RANGE_SIZE = 49, 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_IMAGE_VIEW_SUPPORT_EXTX = 100163002,
VK_STRUCTURE_TYPE_MAX_ENUM = 2147483647, VK_STRUCTURE_TYPE_MAX_ENUM = 2147483647,
} }
pub const VkSystemAllocationScope_VK_SYSTEM_ALLOCATION_SCOPE_BEGIN_RANGE: pub const VkSystemAllocationScope_VK_SYSTEM_ALLOCATION_SCOPE_BEGIN_RANGE:
@ -2601,7 +2613,7 @@ impl Clone for VkSubresourceLayout {
fn clone(&self) -> Self { *self } fn clone(&self) -> Self { *self }
} }
#[repr(C)] #[repr(C)]
#[derive(Debug, Copy)] #[derive(Debug, Copy, PartialEq)]
pub struct VkComponentMapping { pub struct VkComponentMapping {
pub r: VkComponentSwizzle, pub r: VkComponentSwizzle,
pub g: VkComponentSwizzle, pub g: VkComponentSwizzle,
@ -6907,3 +6919,43 @@ pub type PFN_vkCreateMacOSSurfaceMVK = ::std::option::Option<unsafe extern "C" f
pAllocator: *const VkAllocationCallbacks, pAllocator: *const VkAllocationCallbacks,
pSurface: *mut VkSurfaceKHR, pSurface: *mut VkSurfaceKHR,
) -> VkResult>; ) -> VkResult>;
#[repr(C)]
#[derive(Debug, Copy)]
pub struct VkPhysicalDevicePortabilitySubsetFeaturesEXTX {
pub sType: VkStructureType,
pub pNext: *const ::std::os::raw::c_void,
pub triangleFans: VkBool32,
pub separateStencilMaskRef: VkBool32,
pub events: VkBool32,
pub standardImageViews: VkBool32,
pub samplerMipLodBias: VkBool32,
}
impl Clone for VkPhysicalDevicePortabilitySubsetFeaturesEXTX {
fn clone(&self) -> Self { *self }
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct VkPhysicalDevicePortabilitySubsetPropertiesEXTX {
pub sType: VkStructureType,
pub pNext: *const ::std::os::raw::c_void,
pub minVertexInputBindingStrideAlignment: u32,
}
impl Clone for VkPhysicalDevicePortabilitySubsetPropertiesEXTX {
fn clone(&self) -> Self { *self }
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct VkPhysicalDeviceImageViewSupportEXTX {
pub sType: VkStructureType,
pub pNext: *const ::std::os::raw::c_void,
pub flags: VkImageViewCreateFlags,
pub viewType: VkImageViewType,
pub format: VkFormat,
pub components: VkComponentMapping,
pub aspectMask: VkImageAspectFlags,
}
impl Clone for VkPhysicalDeviceImageViewSupportEXTX {
fn clone(&self) -> Self { *self }
}