building for 32/64-bit windows/linux works
authorJacob Lifshay <programmerjake@gmail.com>
Sat, 6 Oct 2018 00:34:13 +0000 (17:34 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Sat, 6 Oct 2018 00:34:13 +0000 (17:34 -0700)
vulkan-driver/Cargo.toml
vulkan-driver/build.rs
vulkan-driver/src/api_impl.rs
vulkan-driver/src/handle.rs
vulkan-driver/src/swapchain.rs
vulkan-driver/src/xcb_swapchain.rs

index 5bd3d44a1c1a829a0c19431fbe4f927b2e0a07e7..a2749b82f63fe02613c472568e160317d137cefa 100644 (file)
@@ -21,6 +21,6 @@ libc = "0.2"
 errno = "0.2"
 
 [build-dependencies]
-bindgen = "0.40"
+bindgen = "0.42"
 regex = "1"
 xmltree = "0.8"
index a35dbf4cb1966170b542763eca720db0412b6adc..d6ceb6edf12592bc6bb2639a74b38f2cd96f6327 100644 (file)
@@ -133,18 +133,22 @@ fn main() -> io::Result<()> {
         PathBuf::from(env::var("OUT_DIR").unwrap()).join("vulkan-types.rs"),
         code,
     )?;
-    let driver_name_prefix = if cfg!(unix) {
+    let target_family = env::var("CARGO_CFG_TARGET_FAMILY").unwrap();
+    let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
+    println!("target_family = {:?}", target_family);
+    println!("target_os = {:?}", target_os);
+    let driver_name_prefix = if target_family == "unix" {
         "lib"
-    } else if cfg!(target_os = "windows") {
+    } else if target_os == "windows" {
         ""
     } else {
         unimplemented!()
     };
-    let driver_name_suffix = if cfg!(any(target_os = "linux", target_os = "android")) {
+    let driver_name_suffix = if target_os == "linux" || target_os == "android" {
         ".so"
-    } else if cfg!(any(target_os = "macos", target_os = "ios")) {
+    } else if target_os == "macos" || target_os == "ios" {
         ".dylib"
-    } else if cfg!(target_os = "windows") {
+    } else if target_os == "windows" {
         ".dll"
     } else {
         unimplemented!()
index c7217dce1ff4dd59dc22069a192b82f4da8cb0b9..af883b5bf2d84c13ca842fc5f92ee6a522d30b4d 100644 (file)
@@ -21,6 +21,7 @@ use std::ops::*;
 use std::os::raw::{c_char, c_int, c_void};
 use std::ptr::null;
 use std::ptr::null_mut;
+#[cfg(unix)]
 use std::ptr::NonNull;
 use std::slice;
 use std::str::FromStr;
@@ -1812,7 +1813,8 @@ impl PhysicalDevice {
             standardSampleLocations: api::VK_TRUE,
             optimalBufferCopyOffsetAlignment: 16,
             optimalBufferCopyRowPitchAlignment: 16,
-            nonCoherentAtomSize: 1, //TODO: check if this is correct
+            nonCoherentAtomSize: 1,     //TODO: check if this is correct
+            ..unsafe { mem::zeroed() }  // for padding fields
         }
     }
     pub fn get_format_properties(format: api::VkFormat) -> api::VkFormatProperties {
@@ -3216,6 +3218,7 @@ impl Instance {
                         residencyAlignedMipSize: api::VK_FALSE,
                         residencyNonResidentStrict: api::VK_FALSE,
                     },
+                    ..mem::zeroed() // for padding fields
                 },
                 features: Features::new(),
                 system_memory_size,
@@ -3244,6 +3247,7 @@ impl Instance {
                     pNext: null_mut(),
                     maxPerSetDescriptors: !0,
                     maxMemoryAllocationSize: isize::max_value() as u64,
+                    ..mem::zeroed() // for padding fields
                 },
                 protected_memory_properties: api::VkPhysicalDeviceProtectedMemoryProperties {
                     sType: api::VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES,
@@ -3376,9 +3380,7 @@ pub unsafe extern "system" fn vkDestroyInstance(
     instance: api::VkInstance,
     _allocator: *const api::VkAllocationCallbacks,
 ) {
-    if !instance.is_null() {
-        OwnedHandle::from(instance);
-    }
+    OwnedHandle::from(instance);
 }
 
 #[allow(non_snake_case)]
@@ -3544,9 +3546,7 @@ pub unsafe extern "system" fn vkDestroyDevice(
     device: api::VkDevice,
     _allocator: *const api::VkAllocationCallbacks,
 ) {
-    if !device.is_null() {
-        OwnedHandle::from(device);
-    }
+    OwnedHandle::from(device);
 }
 
 unsafe fn enumerate_extension_properties(
@@ -4009,9 +4009,7 @@ pub unsafe extern "system" fn vkDestroyBuffer(
     buffer: api::VkBuffer,
     _allocator: *const api::VkAllocationCallbacks,
 ) {
-    if !buffer.is_null() {
-        OwnedHandle::from(buffer);
-    }
+    OwnedHandle::from(buffer);
 }
 
 #[allow(non_snake_case)]
@@ -4111,9 +4109,7 @@ pub unsafe extern "system" fn vkDestroyShaderModule(
     shader_module: api::VkShaderModule,
     _allocator: *const api::VkAllocationCallbacks,
 ) {
-    if !shader_module.is_null() {
-        OwnedHandle::from(shader_module);
-    }
+    OwnedHandle::from(shader_module);
 }
 
 #[allow(non_snake_case)]
@@ -4257,9 +4253,7 @@ pub unsafe extern "system" fn vkDestroySampler(
     sampler: api::VkSampler,
     _allocator: *const api::VkAllocationCallbacks,
 ) {
-    if !sampler.is_null() {
-        OwnedHandle::from(sampler);
-    }
+    OwnedHandle::from(sampler);
 }
 
 #[allow(non_snake_case)]
@@ -5038,6 +5032,7 @@ pub unsafe extern "system" fn vkGetBufferMemoryRequirements2(
         size: layout.size as u64,
         alignment: layout.alignment as u64,
         memoryTypeBits: DeviceMemoryType::Main.to_bits(),
+        ..mem::zeroed() // for padding fields
     };
     if !dedicated_requirements.is_null() {
         let ref mut dedicated_requirements = *dedicated_requirements;
@@ -5242,6 +5237,7 @@ pub unsafe extern "system" fn vkGetPhysicalDeviceMemoryProperties2(
                 DeviceMemoryHeap::Main => physical_device.system_memory_size * 7 / 8,
             },
             flags: memory_heap.flags(),
+            ..mem::zeroed() // for padding fields
         }
     }
     memory_properties.memoryProperties = properties;
@@ -5373,38 +5369,11 @@ pub unsafe extern "system" fn vkDestroySurfaceKHR(
     surface: api::VkSurfaceKHR,
     _allocator: *const api::VkAllocationCallbacks,
 ) {
-    if !surface.is_null() {
-        let surface = SharedHandle::from(surface).unwrap();
-        match surface.platform {
-            api::VK_ICD_WSI_PLATFORM_MIR => {
-                panic!("unimplemented platform: VK_ICD_WSI_PLATFORM_MIR")
-            }
-            api::VK_ICD_WSI_PLATFORM_WAYLAND => {
-                panic!("unimplemented platform: VK_ICD_WSI_PLATFORM_WAYLAND")
-            }
-            api::VK_ICD_WSI_PLATFORM_WIN32 => {
-                panic!("unimplemented platform: VK_ICD_WSI_PLATFORM_WIN32")
-            }
-            api::VK_ICD_WSI_PLATFORM_XCB => {
-                Box::from_raw(surface.take().get().unwrap().as_ptr() as *mut api::VkIcdSurfaceXcb);
-            }
-            api::VK_ICD_WSI_PLATFORM_XLIB => {
-                panic!("unimplemented platform: VK_ICD_WSI_PLATFORM_XLIB")
-            }
-            api::VK_ICD_WSI_PLATFORM_ANDROID => {
-                panic!("unimplemented platform: VK_ICD_WSI_PLATFORM_ANDROID")
-            }
-            api::VK_ICD_WSI_PLATFORM_MACOS => {
-                panic!("unimplemented platform: VK_ICD_WSI_PLATFORM_MACOS")
-            }
-            api::VK_ICD_WSI_PLATFORM_IOS => {
-                panic!("unimplemented platform: VK_ICD_WSI_PLATFORM_IOS")
-            }
-            api::VK_ICD_WSI_PLATFORM_DISPLAY => {
-                panic!("unimplemented platform: VK_ICD_WSI_PLATFORM_DISPLAY")
-            }
-            platform => panic!("unknown VkSurfaceKHR platform: {:?}", platform),
-        }
+    if let Some(surface) = SharedHandle::from(surface) {
+        let surface_implementation = SurfacePlatform::from(surface.platform)
+            .unwrap()
+            .get_surface_implementation();
+        surface_implementation.destroy_surface(surface.into_nonnull());
     }
 }
 
@@ -5531,9 +5500,7 @@ pub unsafe extern "system" fn vkDestroySwapchainKHR(
     swapchain: api::VkSwapchainKHR,
     _allocator: *const api::VkAllocationCallbacks,
 ) {
-    if !swapchain.is_null() {
-        OwnedHandle::from(swapchain);
-    }
+    OwnedHandle::from(swapchain);
 }
 
 #[allow(non_snake_case)]
index a2e1cd8f667a1fe5877116b66e57f06acca3694e..b4a976e57e5d3407f42ba5e420700a580b198b7b 100644 (file)
@@ -217,6 +217,9 @@ impl<T: Handle> SharedHandle<T> {
     pub unsafe fn get_handle(&self) -> T {
         T::new(Some(self.0))
     }
+    pub fn into_nonnull(self) -> NonNull<T::Value> {
+        self.0
+    }
 }
 
 impl<T: Handle> Deref for SharedHandle<T> {
index c86647bfeccba9da4f2c98f94fefe09937deb240..fc3aff9c532b48ee27d818a695693159efdb4765 100644 (file)
@@ -5,6 +5,7 @@ use std::any::Any;
 use std::borrow::Cow;
 use std::error::Error;
 use std::fmt::{self, Debug};
+use std::ptr::NonNull;
 #[cfg(unix)]
 use xcb_swapchain::XcbSurfaceImplementation;
 
@@ -96,6 +97,7 @@ pub trait SurfaceImplementation: Any + Sync + Send + Debug {
         create_info: &api::VkSwapchainCreateInfoKHR,
         device_group_create_info: Option<&api::VkDeviceGroupSwapchainCreateInfoKHR>,
     ) -> Result<Box<Swapchain>, api::VkResult>;
+    unsafe fn destroy_surface(&self, surface: NonNull<api::VkIcdSurfaceBase>);
     fn duplicate(&self) -> Box<dyn SurfaceImplementation>;
 }
 
@@ -147,6 +149,9 @@ impl SurfaceImplementation for FallbackSurfaceImplementation {
     ) -> Result<Box<Swapchain>, api::VkResult> {
         self.report_error()
     }
+    unsafe fn destroy_surface(&self, _surface: NonNull<api::VkIcdSurfaceBase>) {
+        self.report_error()
+    }
     fn duplicate(&self) -> Box<dyn SurfaceImplementation> {
         Box::new(FallbackSurfaceImplementation(self.0))
     }
index b687efda60202a744b369a5a85351a198e94ea92..982f3d91f287f26eca7f33bd2970a92807d1236c 100644 (file)
@@ -431,6 +431,9 @@ impl SurfaceImplementation for XcbSurfaceImplementation {
             device_group_create_info,
         )?))
     }
+    unsafe fn destroy_surface(&self, surface: NonNull<api::VkIcdSurfaceBase>) {
+        Box::from_raw(surface.as_ptr() as *mut api::VkIcdSurfaceXcb);
+    }
     fn duplicate(&self) -> Box<dyn SurfaceImplementation> {
         Box::new(Self {})
     }