b920b61c9fbad5db55364e1e928bc882f575bb59
[kazan.git] / vulkan-driver / src / lib.rs
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 // Copyright 2018 Jacob Lifshay
3 #![cfg_attr(feature = "cargo-clippy", allow(clippy::new_ret_no_self))]
4 #[macro_use]
5 extern crate enum_map;
6 #[cfg(target_os = "linux")]
7 extern crate errno;
8 #[cfg(target_os = "linux")]
9 extern crate libc;
10 extern crate shader_compiler_backend;
11 extern crate sys_info;
12 extern crate uuid;
13 #[cfg(target_os = "linux")]
14 extern crate xcb;
15 mod api;
16 mod api_impl;
17 mod buffer;
18 mod descriptor_set;
19 mod device_memory;
20 mod handle;
21 mod image;
22 mod render_pass;
23 mod sampler;
24 mod shader_module;
25 #[cfg(target_os = "linux")]
26 mod shm;
27 mod swapchain;
28 #[cfg(target_os = "linux")]
29 mod xcb_swapchain;
30 use std::ffi::CStr;
31 use std::os::raw::c_char;
32
33 mod constants {
34 pub const KAZAN_DEVICE_NAME: &str = "Kazan Software Renderer";
35 pub const MIN_MEMORY_MAP_ALIGNMENT: usize = 128; // must be at least 64 and a power of 2 according to Vulkan spec
36 pub const QUEUE_FAMILY_COUNT: u32 = 1;
37 pub const QUEUE_COUNTS: [u32; QUEUE_FAMILY_COUNT as usize] = [1];
38 pub const TOTAL_QUEUE_COUNT: usize = 1;
39 pub const BUFFER_ALIGNMENT: usize = 64; // FIXME: determine correct value
40 pub const IMAGE_ALIGNMENT: usize = 64; // FIXME: determine correct value
41 }
42
43 #[no_mangle]
44 pub unsafe extern "system" fn vk_icdGetInstanceProcAddr(
45 instance: api::VkInstance,
46 name: *const c_char,
47 ) -> api::PFN_vkVoidFunction {
48 api_impl::vkGetInstanceProcAddr(instance, name)
49 }
50
51 // note that if the following fails, then you may be encountering bindgen issue #1402
52 // https://github.com/rust-lang-nursery/rust-bindgen/issues/1402
53 #[allow(dead_code)]
54 const ASSERT_TYPE_VK_ICD_GET_INSTANCE_PROC_ADDR: api::PFN_vkGetInstanceProcAddr =
55 Some(vk_icdGetInstanceProcAddr);
56
57 const ICD_VERSION: u32 = 5;
58
59 #[no_mangle]
60 pub unsafe extern "system" fn vk_icdNegotiateLoaderICDInterfaceVersion(
61 supported_version: *mut u32,
62 ) -> api::VkResult {
63 if *supported_version > ICD_VERSION {
64 *supported_version = ICD_VERSION;
65 }
66 api::VK_SUCCESS
67 }
68
69 #[allow(dead_code)]
70 const ASSERT_TYPE_VK_ICD_NEGOTIATE_LOADER_ICD_INTERFACE_VERSION:
71 api::PFN_vkNegotiateLoaderICDInterfaceVersion = Some(vk_icdNegotiateLoaderICDInterfaceVersion);
72
73 #[no_mangle]
74 pub unsafe extern "system" fn vk_icdGetPhysicalDeviceProcAddr(
75 instance: api::VkInstance,
76 name: *const c_char,
77 ) -> api::PFN_vkVoidFunction {
78 match CStr::from_ptr(name).to_str().ok()? {
79 "vkCreateDevice"
80 | "vkCreateDisplayModeKHR"
81 | "vkEnumerateDeviceExtensionProperties"
82 | "vkEnumerateDeviceLayerProperties"
83 | "vkGetDisplayModeProperties2KHR"
84 | "vkGetDisplayModePropertiesKHR"
85 | "vkGetDisplayPlaneCapabilities2KHR"
86 | "vkGetDisplayPlaneCapabilitiesKHR"
87 | "vkGetDisplayPlaneSupportedDisplaysKHR"
88 | "vkGetPhysicalDeviceDisplayPlaneProperties2KHR"
89 | "vkGetPhysicalDeviceDisplayPlanePropertiesKHR"
90 | "vkGetPhysicalDeviceDisplayProperties2KHR"
91 | "vkGetPhysicalDeviceDisplayPropertiesKHR"
92 | "vkGetPhysicalDeviceExternalBufferProperties"
93 | "vkGetPhysicalDeviceExternalBufferPropertiesKHR"
94 | "vkGetPhysicalDeviceExternalFenceProperties"
95 | "vkGetPhysicalDeviceExternalFencePropertiesKHR"
96 | "vkGetPhysicalDeviceExternalImageFormatPropertiesNV"
97 | "vkGetPhysicalDeviceExternalSemaphoreProperties"
98 | "vkGetPhysicalDeviceExternalSemaphorePropertiesKHR"
99 | "vkGetPhysicalDeviceFeatures"
100 | "vkGetPhysicalDeviceFeatures2"
101 | "vkGetPhysicalDeviceFeatures2KHR"
102 | "vkGetPhysicalDeviceFormatProperties"
103 | "vkGetPhysicalDeviceFormatProperties2"
104 | "vkGetPhysicalDeviceFormatProperties2KHR"
105 | "vkGetPhysicalDeviceGeneratedCommandsPropertiesNVX"
106 | "vkGetPhysicalDeviceImageFormatProperties"
107 | "vkGetPhysicalDeviceImageFormatProperties2"
108 | "vkGetPhysicalDeviceImageFormatProperties2KHR"
109 | "vkGetPhysicalDeviceMemoryProperties"
110 | "vkGetPhysicalDeviceMemoryProperties2"
111 | "vkGetPhysicalDeviceMemoryProperties2KHR"
112 | "vkGetPhysicalDeviceMultisamplePropertiesEXT"
113 | "vkGetPhysicalDevicePresentRectanglesKHR"
114 | "vkGetPhysicalDeviceProperties"
115 | "vkGetPhysicalDeviceProperties2"
116 | "vkGetPhysicalDeviceProperties2KHR"
117 | "vkGetPhysicalDeviceQueueFamilyProperties"
118 | "vkGetPhysicalDeviceQueueFamilyProperties2"
119 | "vkGetPhysicalDeviceQueueFamilyProperties2KHR"
120 | "vkGetPhysicalDeviceSparseImageFormatProperties"
121 | "vkGetPhysicalDeviceSparseImageFormatProperties2"
122 | "vkGetPhysicalDeviceSparseImageFormatProperties2KHR"
123 | "vkGetPhysicalDeviceSurfaceCapabilities2EXT"
124 | "vkGetPhysicalDeviceSurfaceCapabilities2KHR"
125 | "vkGetPhysicalDeviceSurfaceCapabilitiesKHR"
126 | "vkGetPhysicalDeviceSurfaceFormats2KHR"
127 | "vkGetPhysicalDeviceSurfaceFormatsKHR"
128 | "vkGetPhysicalDeviceSurfacePresentModesKHR"
129 | "vkGetPhysicalDeviceSurfaceSupportKHR"
130 | "vkGetPhysicalDeviceXcbPresentationSupportKHR"
131 | "vkReleaseDisplayEXT" => vk_icdGetInstanceProcAddr(instance, name),
132 _ => None,
133 }
134 }
135
136 #[allow(dead_code)]
137 const ASSERT_TYPE_VK_ICD_GET_PHYSICAL_DEVICE_PROC_ADDR: api::PFN_GetPhysicalDeviceProcAddr =
138 Some(vk_icdGetInstanceProcAddr);
139
140 #[cfg(test)]
141 mod tests {}