239: Remove lazy-static dependency r=kvark a=kvark



Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
This commit is contained in:
bors[bot] 2021-01-17 07:23:55 +00:00 committed by GitHub
commit e4e67c56a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 81 additions and 133 deletions

18
Cargo.lock generated
View file

@ -241,9 +241,9 @@ dependencies = [
[[package]]
name = "env_logger"
version = "0.7.1"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
checksum = "f26ecb66b4bdca6c1409b40fb255eefc2bd4f6d135dab3c3124f80ffa2a9661e"
dependencies = [
"atty",
"humantime",
@ -500,12 +500,9 @@ dependencies = [
[[package]]
name = "humantime"
version = "1.3.0"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f"
dependencies = [
"quick-error",
]
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]]
name = "inplace_it"
@ -760,7 +757,6 @@ dependencies = [
"gfx-backend-metal",
"gfx-backend-vulkan",
"gfx-hal",
"lazy_static 1.4.0",
"log",
"raw-window-handle",
"renderdoc",
@ -789,12 +785,6 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "quick-error"
version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
[[package]]
name = "quote"
version = "1.0.7"

View file

@ -20,8 +20,7 @@ metal-capture = ["gfx-backend-metal/auto-capture"]
[dependencies]
copyless = "0.1.1"
env_logger = { version = "0.7", optional = true }
lazy_static = "1"
env_logger = { version = "0.8", optional = true }
log = { version = "0.4", features = ["release_max_level_error"] }
renderdoc = { version = "0.3", optional = true }
typed-arena = "2"

View file

@ -136,7 +136,10 @@ pub unsafe extern "C" fn gfxCreateInstance(
create_info.enabledExtensionCount as _,
) {
let cstr = CStr::from_ptr(*raw);
if !INSTANCE_EXTENSION_NAMES.contains(&cstr.to_bytes_with_nul()) {
if !INSTANCE_EXTENSIONS
.iter()
.any(|&(ref name, _)| name == &cstr.to_bytes_with_nul())
{
return VkResult::VK_ERROR_EXTENSION_NOT_PRESENT;
}
let owned = cstr.to_str().expect("Invalid extension name").to_owned();
@ -934,7 +937,10 @@ pub unsafe extern "C" fn gfxCreateDevice(
dev_info.enabledExtensionCount as _,
) {
let cstr = CStr::from_ptr(*raw);
if !DEVICE_EXTENSION_NAMES.contains(&cstr.to_bytes_with_nul()) {
if !DEVICE_EXTENSIONS
.iter()
.any(|&(ref name, _)| name == &cstr.to_bytes_with_nul())
{
return VkResult::VK_ERROR_EXTENSION_NOT_PRESENT;
}
let owned = cstr.to_str().expect("Invalid extension name").to_owned();
@ -985,116 +991,61 @@ pub unsafe extern "C" fn gfxDestroyDevice(
}
}
lazy_static! {
// TODO: Request from backend
static ref INSTANCE_EXTENSION_NAMES: Vec<&'static [u8]> = {
vec![
VK_KHR_SURFACE_EXTENSION_NAME,
#[cfg(target_os="linux")]
VK_KHR_XLIB_SURFACE_EXTENSION_NAME,
#[cfg(target_os="linux")]
VK_KHR_XCB_SURFACE_EXTENSION_NAME,
#[cfg(target_os="windows")]
VK_KHR_WIN32_SURFACE_EXTENSION_NAME,
#[cfg(feature="gfx-backend-metal")]
VK_EXT_METAL_SURFACE_EXTENSION_NAME,
#[cfg(target_os="macos")]
VK_MVK_MACOS_SURFACE_EXTENSION_NAME,
VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME,
VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME,
]
};
const INSTANCE_EXTENSIONS: &[(&'static [u8], u32)] = &[
(VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_SURFACE_SPEC_VERSION),
#[cfg(target_os = "linux")]
(
VK_KHR_XLIB_SURFACE_EXTENSION_NAME,
VK_KHR_XLIB_SURFACE_SPEC_VERSION,
),
#[cfg(target_os = "linux")]
(
VK_KHR_XCB_SURFACE_EXTENSION_NAME,
VK_KHR_XCB_SURFACE_SPEC_VERSION,
),
#[cfg(target_os = "windows")]
(
VK_KHR_WIN32_SURFACE_EXTENSION_NAME,
VK_KHR_WIN32_SURFACE_SPEC_VERSION,
),
#[cfg(feature = "gfx-backend-metal")]
(
VK_EXT_METAL_SURFACE_EXTENSION_NAME,
VK_EXT_METAL_SURFACE_SPEC_VERSION,
),
#[cfg(target_os = "macos")]
(
VK_MVK_MACOS_SURFACE_EXTENSION_NAME,
VK_MVK_MACOS_SURFACE_SPEC_VERSION,
),
(
VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME,
VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_SPEC_VERSION,
),
(
VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME,
VK_KHR_GET_SURFACE_CAPABILITIES_2_SPEC_VERSION,
),
];
static ref INSTANCE_EXTENSIONS: Vec<VkExtensionProperties> = {
let mut extensions = vec![
VkExtensionProperties {
extensionName: [0; 256], // VK_KHR_SURFACE_EXTENSION_NAME
specVersion: VK_KHR_SURFACE_SPEC_VERSION,
},
#[cfg(target_os="linux")]
VkExtensionProperties {
extensionName: [0; 256], // VK_KHR_XLIB_SURFACE_EXTENSION_NAME
specVersion: VK_KHR_XLIB_SURFACE_SPEC_VERSION,
},
#[cfg(target_os="linux")]
VkExtensionProperties {
extensionName: [0; 256], // VK_KHR_XCB_SURFACE_EXTENSION_NAME
specVersion: VK_KHR_XCB_SURFACE_SPEC_VERSION,
},
#[cfg(target_os="windows")]
VkExtensionProperties {
extensionName: [0; 256], // VK_KHR_WIN32_SURFACE_EXTENSION_NAME
specVersion: VK_KHR_WIN32_SURFACE_SPEC_VERSION,
},
#[cfg(feature="gfx-backend-metal")]
VkExtensionProperties {
extensionName: [0; 256], // VK_EXT_METAL_SURFACE_EXTENSION_NAME
specVersion: VK_EXT_METAL_SURFACE_SPEC_VERSION,
},
#[cfg(target_os="macos")]
VkExtensionProperties {
extensionName: [0; 256], // VK_MVK_MACOS_SURFACE_EXTENSION_NAME
specVersion: VK_MVK_MACOS_SURFACE_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_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME
specVersion: VK_KHR_GET_SURFACE_CAPABILITIES_2_SPEC_VERSION,
},
];
for (&name, extension) in INSTANCE_EXTENSION_NAMES.iter().zip(&mut extensions) {
extension
.extensionName[.. name.len()]
.copy_from_slice(unsafe {
mem::transmute(name)
});
}
extensions
};
static ref DEVICE_EXTENSION_NAMES: Vec<&'static [u8]> = {
vec![
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
VK_KHR_MAINTENANCE1_EXTENSION_NAME,
VK_EXT_DEBUG_MARKER_EXTENSION_NAME,
VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME,
]
};
static ref DEVICE_EXTENSIONS: Vec<VkExtensionProperties> = {
let mut extensions = [
VkExtensionProperties {
extensionName: [0; 256], // VK_KHR_SWAPCHAIN_EXTENSION_NAME
specVersion: VK_KHR_SWAPCHAIN_SPEC_VERSION,
},
VkExtensionProperties {
extensionName: [0; 256], // VK_KHR_MAINTENANCE1_EXTENSION_NAME
specVersion: VK_KHR_MAINTENANCE1_SPEC_VERSION,
},
VkExtensionProperties {
extensionName: [0; 256], // VK_EXT_DEBUG_MARKER_EXTENSION_NAME
specVersion: VK_EXT_DEBUG_MARKER_SPEC_VERSION,
},
VkExtensionProperties {
extensionName: [0; 256], // VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME
specVersion: VK_KHR_PORTABILITY_SUBSET_SPEC_VERSION,
},
];
for (&name, extension) in DEVICE_EXTENSION_NAMES.iter().zip(&mut extensions) {
extension
.extensionName[.. name.len()]
.copy_from_slice(unsafe { mem::transmute(name) });
}
extensions.to_vec()
};
}
const DEVICE_EXTENSIONS: &[(&'static [u8], u32)] = &[
(
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
VK_KHR_SWAPCHAIN_SPEC_VERSION,
),
(
VK_KHR_MAINTENANCE1_EXTENSION_NAME,
VK_KHR_MAINTENANCE1_SPEC_VERSION,
),
(
VK_EXT_DEBUG_MARKER_EXTENSION_NAME,
VK_EXT_DEBUG_MARKER_SPEC_VERSION,
),
(
VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME,
VK_KHR_PORTABILITY_SUBSET_SPEC_VERSION,
),
];
#[inline]
pub unsafe extern "C" fn gfxEnumerateInstanceExtensionProperties(
@ -1112,10 +1063,14 @@ pub unsafe extern "C" fn gfxEnumerateInstanceExtensionProperties(
*property_count = num_extensions;
}
let properties = slice::from_raw_parts_mut(pProperties, *property_count as usize);
for i in 0..*property_count as usize {
properties[i] = INSTANCE_EXTENSIONS[i];
for (property, &(name, specVersion)) in properties.iter_mut().zip(INSTANCE_EXTENSIONS) {
let mut extensionName = [0i8; 256];
extensionName[..name.len()].copy_from_slice(mem::transmute(name));
*property = VkExtensionProperties {
extensionName,
specVersion,
};
}
if *property_count < num_extensions {
return VkResult::VK_INCOMPLETE;
}
@ -1141,8 +1096,13 @@ pub unsafe extern "C" fn gfxEnumerateDeviceExtensionProperties(
*property_count = num_extensions;
}
let properties = slice::from_raw_parts_mut(pProperties, *property_count as usize);
for i in 0..*property_count as usize {
properties[i] = DEVICE_EXTENSIONS[i];
for (property, &(name, specVersion)) in properties.iter_mut().zip(DEVICE_EXTENSIONS) {
let mut extensionName = [0i8; 256];
extensionName[..name.len()].copy_from_slice(mem::transmute(name));
*property = VkExtensionProperties {
extensionName,
specVersion,
};
}
if *property_count < num_extensions {

View file

@ -32,7 +32,6 @@ use gfx_backend_metal as back;
#[cfg(feature = "gfx-backend-vulkan")]
use gfx_backend_vulkan as back;
use lazy_static::lazy_static;
use log::{error, warn};
mod conv;