From: Jacob Lifshay Date: Sat, 29 Sep 2018 01:18:04 +0000 (-0700) Subject: working on implementing vulkan functions X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=35b44629b7f9f5bce36965619ac4f20218e1af2a;p=kazan.git working on implementing vulkan functions --- diff --git a/vulkan-driver/Cargo.toml b/vulkan-driver/Cargo.toml index 5d9abff..ea35ba8 100644 --- a/vulkan-driver/Cargo.toml +++ b/vulkan-driver/Cargo.toml @@ -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" diff --git a/vulkan-driver/build.rs b/vulkan-driver/build.rs index 7c7fc09..1a76d12 100644 --- a/vulkan-driver/build.rs +++ b/vulkan-driver/build.rs @@ -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() diff --git a/vulkan-driver/src/api_impl.rs b/vulkan-driver/src/api_impl.rs index ec687d3..a675d4f 100644 --- a/vulkan-driver/src/api_impl.rs +++ b/vulkan-driver/src/api_impl.rs @@ -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::::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)] diff --git a/vulkan-driver/src/handle.rs b/vulkan-driver/src/handle.rs index 395edd1..127ff07 100644 --- a/vulkan-driver/src/handle.rs +++ b/vulkan-driver/src/handle.rs @@ -37,7 +37,7 @@ impl DerefMut for DispatchableType { } } -pub trait Handle: Clone { +pub trait Handle: Copy { type Value; fn get(&self) -> Option>; fn new(v: Option>) -> Self; @@ -71,6 +71,8 @@ impl Clone for DispatchableHandle { } } +impl Copy for DispatchableHandle {} + impl Handle for DispatchableHandle { type Value = DispatchableType; fn get(&self) -> Option>> { @@ -90,6 +92,8 @@ impl Clone for NondispatchableHandle { } } +impl Copy for NondispatchableHandle {} + impl Handle for NondispatchableHandle { type Value = T; fn get(&self) -> Option> { diff --git a/vulkan-driver/src/lib.rs b/vulkan-driver/src/lib.rs index 18fab2b..cef8753 100644 --- a/vulkan-driver/src/lib.rs +++ b/vulkan-driver/src/lib.rs @@ -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( diff --git a/vulkan-driver/vulkan-wrapper.h b/vulkan-driver/vulkan-wrapper.h index 7f728e1..9e95fbd 100644 --- a/vulkan-driver/vulkan-wrapper.h +++ b/vulkan-driver/vulkan-wrapper.h @@ -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 #include #ifdef __unix @@ -11,4 +11,4 @@ typedef uint32_t xcb_visualid_t; typedef uint32_t xcb_window_t; #include #endif -//#undef VK_NO_PROTOTYPES +#undef VK_NO_PROTOTYPES