working on implementing vulkan functions
authorJacob Lifshay <programmerjake@gmail.com>
Sat, 29 Sep 2018 01:18:04 +0000 (18:18 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Sat, 29 Sep 2018 01:18:04 +0000 (18:18 -0700)
vulkan-driver/Cargo.toml
vulkan-driver/build.rs
vulkan-driver/src/api_impl.rs
vulkan-driver/src/handle.rs
vulkan-driver/src/lib.rs
vulkan-driver/vulkan-wrapper.h

index 5d9abfff5c726f1703c2a4f49eec464958a3b201..ea35ba8d08a64257901f3a1a5be6a6d6a1c13361 100644 (file)
@@ -10,6 +10,7 @@ crate-type = ["cdylib"]
 [dependencies]
 enum-map = "0.4"
 uuid = {version = "0.7", features = ["v5"]}
+sys-info = "0.5"
 
 [target.'cfg(unix)'.dependencies]
 xcb = "0.8"
index 7c7fc09b36f8759a8c9d3dbd3ed06f6b108c7d64..1a76d12f21f0df0f3d87095085b9ab102151526f 100644 (file)
@@ -97,14 +97,15 @@ fn main() -> io::Result<()> {
             continue;
         }
         builder = builder
-            .blacklist_type(name)
-            .blacklist_type(format!("{}_T", name));
+            .blacklist_type(format!("^{}$", name))
+            .blacklist_type(format!("^{}_T$", name));
     }
     builder = builder
         .whitelist_type("PFN_.*")
+        .whitelist_type("^Vk.*")
         .blacklist_type("^xcb_.*")
         .derive_debug(false)
-        .blacklist_function(".*")
+        .ignore_functions()
         .constified_enum(".*");
     let mut code = builder
         .generate()
index ec687d3b31a248a4197129947c1281588f97a29f..a675d4fd461bbee84d58c50c1e5cc34d9b431e2d 100644 (file)
@@ -1,5 +1,6 @@
 #![allow(dead_code)]
 use api;
+use constants::*;
 use enum_map::EnumMap;
 use handle::{Handle, OwnedHandle, SharedHandle};
 use std::borrow::Borrow;
@@ -10,11 +11,9 @@ use std::ops::*;
 use std::os::raw::c_char;
 use std::slice;
 use std::str::FromStr;
+use sys_info;
 use uuid;
 use xcb;
-use KAZAN_DEVICE_NAME;
-use KAZAN_VENDOR_ID;
-use MIN_MEMORY_MAP_ALIGNMENT;
 
 fn copy_str_to_char_array(dest: &mut [c_char], src: &str) {
     assert!(dest.len() >= src.len() + 1);
@@ -533,6 +532,7 @@ pub struct PhysicalDevice {
     enabled_extensions: Extensions,
     allowed_extensions: Extensions,
     properties: api::VkPhysicalDeviceProperties,
+    system_memory_size: u64,
 }
 
 impl PhysicalDevice {
@@ -585,6 +585,14 @@ impl Instance {
                 );
             }
         }
+        let system_memory_size;
+        match sys_info::mem_info() {
+            Err(error) => {
+                eprintln!("mem_info error: {}", error);
+                return Err(api::VK_ERROR_INITIALIZATION_FAILED);
+            }
+            Ok(info) => system_memory_size = info.total * 1024,
+        }
         let mut device_name = [0; api::VK_MAX_PHYSICAL_DEVICE_NAME_SIZE as usize];
         copy_str_to_char_array(&mut device_name, KAZAN_DEVICE_NAME);
         let retval = OwnedHandle::<api::VkInstance>::new(Instance {
@@ -598,7 +606,7 @@ impl Instance {
                         env!("CARGO_PKG_VERSION_MINOR").parse().unwrap(),
                         env!("CARGO_PKG_VERSION_PATCH").parse().unwrap(),
                     ),
-                    vendorID: KAZAN_VENDOR_ID,
+                    vendorID: api::VK_VENDOR_ID_KAZAN,
                     deviceID: 1,
                     deviceType: api::VK_PHYSICAL_DEVICE_TYPE_CPU,
                     deviceName: device_name,
@@ -727,6 +735,7 @@ impl Instance {
                         residencyNonResidentStrict: api::VK_FALSE,
                     },
                 },
+                system_memory_size,
             }),
         });
         Ok(retval.take())
@@ -901,19 +910,51 @@ pub unsafe extern "system" fn vkGetPhysicalDeviceProperties(
 
 #[allow(non_snake_case)]
 pub unsafe extern "system" fn vkGetPhysicalDeviceQueueFamilyProperties(
-    _physicalDevice: api::VkPhysicalDevice,
-    _pQueueFamilyPropertyCount: *mut u32,
-    _pQueueFamilyProperties: *mut api::VkQueueFamilyProperties,
+    _physical_device: api::VkPhysicalDevice,
+    queue_family_property_count: *mut u32,
+    queue_family_properties: *mut api::VkQueueFamilyProperties,
 ) {
-    unimplemented!()
+    enumerate_helper(
+        queue_family_property_count,
+        queue_family_properties,
+        QUEUE_COUNTS
+            .iter()
+            .map(|&count| api::VkQueueFamilyProperties {
+                queueFlags: api::VK_QUEUE_GRAPHICS_BIT
+                    | api::VK_QUEUE_COMPUTE_BIT
+                    | api::VK_QUEUE_TRANSFER_BIT,
+                queueCount: count,
+                timestampValidBits: 0,
+                minImageTransferGranularity: api::VkExtent3D {
+                    width: 1,
+                    height: 1,
+                    depth: 1,
+                },
+            }),
+    );
 }
 
 #[allow(non_snake_case)]
 pub unsafe extern "system" fn vkGetPhysicalDeviceMemoryProperties(
-    _physicalDevice: api::VkPhysicalDevice,
-    _pMemoryProperties: *mut api::VkPhysicalDeviceMemoryProperties,
+    physical_device: api::VkPhysicalDevice,
+    memory_properties: *mut api::VkPhysicalDeviceMemoryProperties,
 ) {
-    unimplemented!()
+    let physical_device = SharedHandle::from(physical_device);
+    let mut properties: api::VkPhysicalDeviceMemoryProperties = mem::zeroed();
+    properties.memoryTypeCount = 1;
+    properties.memoryTypes[0] = api::VkMemoryType {
+        propertyFlags: api::VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
+            | api::VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
+            | api::VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
+            | api::VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
+        heapIndex: 0,
+    };
+    properties.memoryHeapCount = 1;
+    properties.memoryHeaps[0] = api::VkMemoryHeap {
+        size: physical_device.system_memory_size * 7 / 8,
+        flags: api::VK_MEMORY_HEAP_DEVICE_LOCAL_BIT,
+    };
+    *memory_properties = properties;
 }
 
 #[allow(non_snake_case)]
index 395edd1680194aee871a9955759a0e5a6ddedce3..127ff078e447fc700bc88d6fb2e0af2dc181419a 100644 (file)
@@ -37,7 +37,7 @@ impl<T> DerefMut for DispatchableType<T> {
     }
 }
 
-pub trait Handle: Clone {
+pub trait Handle: Copy {
     type Value;
     fn get(&self) -> Option<NonNull<Self::Value>>;
     fn new(v: Option<NonNull<Self::Value>>) -> Self;
@@ -71,6 +71,8 @@ impl<T> Clone for DispatchableHandle<T> {
     }
 }
 
+impl<T> Copy for DispatchableHandle<T> {}
+
 impl<T> Handle for DispatchableHandle<T> {
     type Value = DispatchableType<T>;
     fn get(&self) -> Option<NonNull<DispatchableType<T>>> {
@@ -90,6 +92,8 @@ impl<T> Clone for NondispatchableHandle<T> {
     }
 }
 
+impl<T> Copy for NondispatchableHandle<T> {}
+
 impl<T> Handle for NondispatchableHandle<T> {
     type Value = T;
     fn get(&self) -> Option<NonNull<T>> {
index 18fab2b0cfc36a47f45aed406d81c935e96b3380..cef875372a4d94ffb1f3f7f1a2b0a2c596223454 100644 (file)
@@ -1,5 +1,6 @@
 #[macro_use]
 extern crate enum_map;
+extern crate sys_info;
 extern crate uuid;
 #[cfg(unix)]
 extern crate xcb;
@@ -9,9 +10,12 @@ mod handle;
 use std::ffi::CStr;
 use std::os::raw::c_char;
 
-pub const KAZAN_VENDOR_ID: u32 = 0x10003;
-pub const KAZAN_DEVICE_NAME: &'static str = "Kazan Software Renderer";
-pub const MIN_MEMORY_MAP_ALIGNMENT: usize = 128; // must be at least 64 and a power of 2 according to Vulkan spec
+mod constants {
+    pub const KAZAN_DEVICE_NAME: &'static str = "Kazan Software Renderer";
+    pub const MIN_MEMORY_MAP_ALIGNMENT: usize = 128; // must be at least 64 and a power of 2 according to Vulkan spec
+    pub const QUEUE_FAMILY_COUNT: u32 = 1;
+    pub const QUEUE_COUNTS: [u32; QUEUE_FAMILY_COUNT as usize] = [1];
+}
 
 #[no_mangle]
 pub unsafe extern "system" fn vk_icdGetInstanceProcAddr(
index 7f728e11da2f69bf835f41733c86f68f2fec9b23..9e95fbd04654f9d12ccb5ce26ac7f5d188884be7 100644 (file)
@@ -2,7 +2,7 @@
 #ifdef __ANDROID__
 #error not supported on Android; need to fix ABI
 #endif
-//#define VK_NO_PROTOTYPES
+#define VK_NO_PROTOTYPES
 #include <vulkan/vulkan.h>
 #include <vulkan/vk_icd.h>
 #ifdef __unix
@@ -11,4 +11,4 @@ typedef uint32_t xcb_visualid_t;
 typedef uint32_t xcb_window_t;
 #include <vulkan/vulkan_xcb.h>
 #endif
-//#undef VK_NO_PROTOTYPES
+#undef VK_NO_PROTOTYPES