Almost names are the same as the Vulkan C API. But for some simplification reasons, a little change must be taken. The enum
variant name is changed to without VK_
prefix and enum name. For example the VkFormat.VK_FORMAT_UNDEFINED
is changed to VkFormat::UNDEFINED
. Because of language limitations, some exceptions exist. They are the following:
| C version | Corresponding vulkan_raw version|
| ------ | ------ |
| VkImageCreateFlagBits.VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT
| VkImageCreateFlagBits::IC_2D_ARRAY_COMPATIBLE_BIT
|
| VkQueryResultFlagBits.VK_QUERY_RESULT_64_BIT
| VkQueryResultFlagBits::U64_BIT
|
| VkSampleCountFlagBits.VK_SAMPLE_COUNT_1_BIT
| VkSampleCountFlagBits::SC_1_BIT
|
| VkSampleCountFlagBits.VK_SAMPLE_COUNT_2_BIT
| VkSampleCountFlagBits::SC_2_BIT
|
| VkSampleCountFlagBits.VK_SAMPLE_COUNT_4_BIT
| VkSampleCountFlagBits::SC_4_BIT
|
| VkSampleCountFlagBits.VK_SAMPLE_COUNT_8_BIT
| VkSampleCountFlagBits::SC_8_BIT
|
| VkSampleCountFlagBits.VK_SAMPLE_COUNT_16_BIT
| VkSampleCountFlagBits::SC_16_BIT
|
| VkSampleCountFlagBits.VK_SAMPLE_COUNT_32_BIT
| VkSampleCountFlagBits::SC_32_BIT
|
| VkSampleCountFlagBits.VK_SAMPLE_COUNT_64_BIT
| VkSampleCountFlagBits::SC_64_BIT
|
| VkImageType.VK_IMAGE_TYPE_1D
| VkImageType::IT_1D
|
| VkImageType.VK_IMAGE_TYPE_2D
| VkImageType::IT_2D
|
| VkImageType.VK_IMAGE_TYPE_3D
| VkImageType::IT_3D
|
| VkImageViewType.VK_IMAGE_VIEW_TYPE_1D
| VkImageViewType::IVT_1D
|
| VkImageViewType.VK_IMAGE_VIEW_TYPE_2D
| VkImageViewType::IVT_2D
|
| VkImageViewType.VK_IMAGE_VIEW_TYPE_3D
| VkImageViewType::IVT_3D
|
| VkImageViewType.VK_IMAGE_VIEW_TYPE_1D_ARRAY
| VkImageViewType::IVT_1D_ARRAY
|
| VkImageViewType.VK_IMAGE_VIEW_TYPE_2D_ARRAY
| VkImageViewType::IVT_2D_ARRAY
|
| VkShaderFloatControlsIndependence.VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY
| VkShaderFloatControlsIndependence::F32_BIT_ONLY
|
Most functions must need to obtain a corresponding function pointer before use. We provide a Functions
object to do this on every module, echo one corresponding to the module's functions set.
```rust use vulkan_raw::*; use std::ptr; use std::ffi::CStr;
fn main(){ let mut instanceversion: u32 = 0; unsafe {vkEnumerateInstanceVersion(&mut instanceversion)}; println!("instance version: {}", ApiVersion::from(instance_version));
// Create Vulkan instance
let app_info = VkApplicationInfo{
sType: VkStructureType::APPLICATION_INFO,
pNext: ptr::null(),
pApplicationName: ptr::null(),
applicationVersion: 1,
pEngineName: ptr::null(),
engineVersion: 1,
apiVersion: ApiVersion::new(1, 2, 0).into(),
};
let create_info = VkInstanceCreateInfo{
sType: VkStructureType::INSTANCE_CREATE_INFO,
pNext: ptr::null(),
flags: Default::default(),
pApplicationInfo: &app_info,
enabledLayerCount: 0,
ppEnabledLayerNames: ptr::null(),
enabledExtensionCount: 0,
ppEnabledExtensionNames: ptr::null(),
};
let mut instance: VkInstance = VkInstance::none();
let result = unsafe {vkCreateInstance(&create_info, ptr::null(), &mut instance)};
if result != VkResult::SUCCESS { panic!("error!") }
let core_functions = Functions::load_from_instance(instance).unwrap();
// Enumerate all devices
let mut count: u32 = 0;
let result = unsafe { core_functions.vkEnumeratePhysicalDevices(instance, &mut count, ptr::null_mut())};
if result != VkResult::SUCCESS { panic!("error!") }
let mut physical_devices: Vec<VkPhysicalDevice> = Vec::with_capacity(count as usize);
let result = unsafe {core_functions.vkEnumeratePhysicalDevices(instance, &mut count, physical_devices.as_mut_ptr())};
if result != VkResult::SUCCESS { panic!("error!") }
unsafe {physical_devices.set_len(count as usize); }
for physical_device in physical_devices{
let mut physical_device_properties = VkPhysicalDeviceProperties2{
sType: VkStructureType::PHYSICAL_DEVICE_PROPERTIES_2,
pNext: ptr::null(),
properties: Default::default(),
};
unsafe { core_functions.vkGetPhysicalDeviceProperties2(physical_device, &mut physical_device_properties); }
println!(
"device: {}, supported vulkan version: {}",
unsafe {CStr::from_ptr(physical_device_properties.properties.deviceName.as_ptr())}.to_str().unwrap(),
ApiVersion::from(physical_device_properties.properties.apiVersion)
);
}
unsafe { core_functions.vkDestroyInstance(instance, ptr::null())};
} ```