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