### Run a Vulkano Example Source: https://github.com/vulkano-rs/vulkano/blob/master/examples/README.md Use this command to run any of the provided Vulkano examples. Replace `` with the name of the example you wish to run. ```sh cargo run --bin ``` -------------------------------- ### InstanceCreateInfo Example Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-instance.md Example demonstrating how to initialize InstanceCreateInfo with application name, version, and enabled extensions. ```rust let create_info = InstanceCreateInfo { application_name: Some("My App"), application_version: Version { major: 1, minor: 0, patch: 0 }, enabled_extensions: &InstanceExtensions { khr_surface: true, ..InstanceExtensions::empty() }, ..Default::default() }; ``` -------------------------------- ### DeviceCreateInfo Example Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-device.md Example of how to instantiate DeviceCreateInfo for device creation. Ensure all required fields are populated. ```rust let create_info = DeviceCreateInfo { queue_create_infos: &[QueueCreateInfo { queue_family_index: 0, ..Default::default() }], enabled_extensions: &DeviceExtensions::empty(), enabled_features: &DeviceFeatures::empty(), ..Default::default() }; ``` -------------------------------- ### QueueCreateInfo Example Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-device.md Example of how to instantiate QueueCreateInfo. Set the queue family index and desired queue priorities. ```rust QueueCreateInfo { queue_family_index: 0, queues: smallvec![1.0], } ``` -------------------------------- ### BufferCreateInfo Example Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-buffer.md Example of initializing BufferCreateInfo with a specific size and usage, relying on default values for other fields. ```rust let create_info = BufferCreateInfo { size: 1024, usage: BufferUsage::TRANSFER_DST | BufferUsage::STORAGE_BUFFER, ..Default::default() }; ``` -------------------------------- ### Run the Triangle Example Source: https://github.com/vulkano-rs/vulkano/blob/master/examples/README.md This is a specific example of how to run the 'triangle' demo. For performance-critical comparisons, consider using the `--release` flag. ```sh cargo run --bin triangle ``` -------------------------------- ### Version Example Usage Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-instance.md Example of creating a Version instance to represent a specific Vulkan API version. ```rust let version = Version { major: 1, minor: 2, patch: 0 }; ``` -------------------------------- ### PipelineShaderStageCreateInfo Example Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-pipeline.md An example of how to instantiate PipelineShaderStageCreateInfo for a vertex shader. Uses default values for unspecified fields. ```rust PipelineShaderStageCreateInfo { stage: ShaderStage::Vertex, module: vertex_shader_module, entry_point: "main".into(), ..Default::default() } ``` -------------------------------- ### InstanceExtensions Example Usage Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-instance.md Example of initializing InstanceExtensions to enable specific Vulkan instance extensions. Common extensions include khr_surface for window rendering and ext_debug_utils for debugging. ```rust let extensions = InstanceExtensions { khr_surface: true, khr_get_physical_device_properties2: true, ..InstanceExtensions::empty() }; ``` -------------------------------- ### Example AttachmentDescription Initialization Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-render-pass.md Provides a concrete example of how to initialize an AttachmentDescription. This is useful for setting up image formats, sample counts, and layout transitions for render pass attachments. ```rust AttachmentDescription { format: Format::R8G8B8A8_UNORM, samples: SampleCount::Sample1, load_op: LoadOp::Clear, store_op: StoreOp::Store, stencil_load_op: LoadOp::DontCare, stencil_store_op: StoreOp::DontCare, initial_layout: ImageLayout::Undefined, final_layout: ImageLayout::PresentSrc, } ``` -------------------------------- ### Install Linux Development Tools Source: https://github.com/vulkano-rs/vulkano/blob/master/README.md Installs essential build tools, Git, Python, CMake, and Vulkan development libraries on Ubuntu. ```bash sudo apt-get install build-essential git python cmake libvulkan-dev vulkan-tools ``` -------------------------------- ### ImageUsage Example Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-image.md Example of creating an ImageUsage with transfer destination and sampled flags. ```rust let usage = ImageUsage::TRANSFER_DST | ImageUsage::SAMPLED; ``` -------------------------------- ### Install Arch Linux Development Tools Source: https://github.com/vulkano-rs/vulkano/blob/master/README.md Installs necessary development packages and Vulkan libraries on Arch-based Linux distributions. ```bash sudo pacman -Sy base-devel git python cmake vulkan-devel --noconfirm ``` -------------------------------- ### PushConstantRange Example Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-pipeline.md An example demonstrating how to create a PushConstantRange for vertex and fragment shaders, with an offset of 0 and a size of 64 bytes. ```rust PushConstantRange { stages: ShaderStages::VERTEX | ShaderStages::FRAGMENT, offset: 0, size: 64, } ``` -------------------------------- ### BufferUsage Example Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-buffer.md Example of defining buffer usage flags, combining transfer destination and vertex buffer capabilities. ```rust let usage = BufferUsage::TRANSFER_DST | BufferUsage::VERTEX_BUFFER; ``` -------------------------------- ### Example DescriptorSetLayoutBinding Initialization Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-descriptor-set.md Demonstrates how to initialize a DescriptorSetLayoutBinding for a uniform buffer in the vertex shader stage. ```rust DescriptorSetLayoutBinding { descriptor_type: DescriptorType::UniformBuffer, descriptor_count: 1, stages: ShaderStages::VERTEX, ..Default::default() } ``` -------------------------------- ### ImageCreateInfo Example Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-image.md Demonstrates how to instantiate ImageCreateInfo for a 2D image with a specific format, extent, and usage flags. Uses Default::default() for unspecified fields. ```rust let create_info = ImageCreateInfo { image_type: ImageType::Dim2d, format: Format::R8G8B8A8_UNORM, extent: [1920, 1080, 1], usage: ImageUsage::TRANSFER_DST | ImageUsage::SAMPLED, ..Default::default() }; ``` -------------------------------- ### SwapchainCreateInfo Example Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-swapchain.md Demonstrates how to initialize a SwapchainCreateInfo struct with common settings. Ensure all required fields are provided, and use `Default::default()` for optional fields not explicitly set. ```rust let create_info = SwapchainCreateInfo { min_image_count: 2, image_format: Format::B8G8R8A8_UNORM, image_extent: [1920, 1080], image_usage: ImageUsage::COLOR_ATTACHMENT, composite_alpha: CompositeAlpha::Opaque, present_mode: PresentMode::Fifo, ..Default::default() }; ``` -------------------------------- ### ImageSubresourceRange Example Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-image.md An example demonstrating how to instantiate an ImageSubresourceRange for the color aspect, covering the first mip level and the first array layer. ```rust ImageSubresourceRange { aspects: ImageAspect::COLOR, mip_levels: 0..1, array_layers: 0..1, } ``` -------------------------------- ### Compute Dispatch Example Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/README.md Example of performing a compute dispatch. This involves binding a compute pipeline, descriptor sets, and then issuing the dispatch command with specified workgroup counts. ```rust builder .bind_pipeline_compute(compute_pipeline.clone())? .bind_descriptor_sets( PipelineBindPoint::Compute, pipeline_layout.clone(), 0, iter::once(descriptor_set), )? .dispatch([8, 8, 1])?; ``` -------------------------------- ### Example Usage of RenderPassBeginInfo Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-render-pass.md Demonstrates how to instantiate and populate a RenderPassBeginInfo struct for a given render pass and framebuffer. ```rust use vulkano::render_pass::RenderPassBeginInfo; let render_pass_begin_info = RenderPassBeginInfo { render_pass: render_pass.clone(), framebuffer: framebuffer.clone(), render_area: Rect2D { offset: [0, 0], extent: [1920, 1080], }, clear_values: vec![ Some([0.0, 0.0, 0.0, 1.0].into()), Some(1.0f32.into()), ], }; ``` -------------------------------- ### SubpassDescription Example Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-render-pass.md Example of creating a `SubpassDescription` with a color attachment and a depth stencil attachment. Uses `Default::default()` to initialize other fields. ```rust SubpassDescription { color_attachments: vec![AttachmentReference { attachment: 0, layout: ImageLayout::ColorAttachmentOptimal, }], depth_stencil_attachment: Some(AttachmentReference { attachment: 1, layout: ImageLayout::DepthStencilAttachmentOptimal, }), ..Default::default() } ``` -------------------------------- ### Vulkano Memory Allocation with StandardMemoryAllocator Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/README.md This example demonstrates how to allocate memory and create a buffer using Vulkano's StandardMemoryAllocator. It shows creating a vertex buffer and filling it with data. ```rust use vulkano::{ buffer::{Buffer, BufferCreateInfo, BufferUsage}, memory::allocator::{AllocationCreateInfo, MemoryTypeFilter, StandardMemoryAllocator}, }; let allocator = StandardMemoryAllocator::new(device.clone()); // Create and fill a buffer let vertex_data = vec![0.0f32, 1.0f32, 2.0f32]; let buffer = Buffer::from_data( &allocator, &BufferCreateInfo { usage: BufferUsage::VERTEX_BUFFER, ..Default::default() }, &AllocationCreateInfo { memory_type_filter: MemoryTypeFilter::PREFER_HOST, ..Default::default() }, vertex_data, )?; ``` -------------------------------- ### Install MSYS2 Packages for Windows Source: https://github.com/vulkano-rs/vulkano/blob/master/README.md Installs CMake, Python 2, and Ninja using pacman within an MSYS2 terminal on Windows. ```bash pacman --noconfirm -Syu mingw-w64-x86_64-cmake mingw-w64-x86_64-python2 mingw-w64-x86_64-ninja ``` -------------------------------- ### Start Building a Primary Command Buffer Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-command-buffer.md Initiates the process of building a primary command buffer. Requires an allocator, queue family index, and usage information. ```rust let builder = AutoCommandBufferBuilder::primary( &allocator, queue.queue_family_index(), CommandBufferUsage::OneTimeSubmit, )?; ``` -------------------------------- ### Create a new Vulkano Swapchain Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-swapchain.md Creates a new swapchain for presenting images to a surface. Ensure the device, surface, and create info are correctly configured. This example demonstrates setting image count, format, extent, usage, composite alpha, and present mode. ```rust use vulkano::swapchain::{Swapchain, SwapchainCreateInfo, PresentMode}; let (swapchain, images) = Swapchain::new( &device, surface, &SwapchainCreateInfo { min_image_count: capabilities.min_image_count, image_format: Format::B8G8R8A8_UNORM, image_extent: [1920, 1080], image_usage: ImageUsage::COLOR_ATTACHMENT, composite_alpha: CompositeAlpha::Opaque, present_mode: PresentMode::Fifo, ..Default::default() }, )?; ``` -------------------------------- ### Install MSYS2 Packages for Windows GNU Toolchain Source: https://github.com/vulkano-rs/vulkano/blob/master/README.md Installs pkg-config, GCC, CMake, Make, Python 2, and Ninja using pacman for the Windows GNU toolchain. ```bash pacman --noconfirm -Syu mingw64/mingw-w64-x86_64-pkg-config mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake mingw-w64-x86_64-make mingw-w64-x86_64-python2 mingw-w64-x86_64-ninja ``` -------------------------------- ### Check Enabled Instance Extensions Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-instance.md Checks if specific instance extensions are enabled. This example specifically checks for the `khr_surface` extension, which is required for window surface creation. ```rust if instance.enabled_extensions().khr_surface { println!("Surface extension is enabled"); } ``` -------------------------------- ### Compile GLSL/HLSL to SPIR-V with vulkano-shaders Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-shader.md Example demonstrating how to use the `vulkano_shaders` crate to compile GLSL source code into SPIR-V and load it as a shader module. Ensure the `vulkano_shaders` crate is added as a dependency. ```rust mod shader { vulkano_shaders::shader! { ty: "vertex", src: r#"#, #version 450 layout(location = 0) out vec4 color; void main() { color = vec4(1.0); } "#, } } let module = shader::load(device.clone())?; ``` -------------------------------- ### Get Supported Device Extensions Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-device.md Retrieve all Vulkan extensions supported by a physical device. Requires a `PhysicalDevice` instance. ```rust pub fn supported_extensions(&self) -> &DeviceExtensions ``` -------------------------------- ### Cross-compile for Windows GNU Source: https://github.com/vulkano-rs/vulkano/blob/master/README.md Example cargo command to build a project targeting the x86_64-pc-windows-gnu toolchain. ```bash cargo run --target x86_64-pc-windows-gnu ``` -------------------------------- ### Get Shader Entry Point Information Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-shader.md Retrieves information about a specific shader entry point by its name. Returns `None` if the entry point does not exist. ```rust if let Some(entry_point) = shader_module.entry_point("main") { println!("Entry point info: {:?}", entry_point); } ``` -------------------------------- ### Get Supported Device Features Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-device.md Retrieve all Vulkan features supported by a physical device. Requires a `PhysicalDevice` instance. ```rust pub fn supported_features(&self) -> &DeviceFeatures ``` -------------------------------- ### Recording Draw Commands Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/README.md Example of recording draw commands for a graphics pipeline. This includes setting up a render pass, binding graphics pipeline, vertex and index buffers, and issuing a draw call. ```rust use vulkano::command_buffer::{AutoCommandBufferBuilder, CommandBufferUsage, SubpassContents}; let mut builder = AutoCommandBufferBuilder::primary( &allocator, queue.queue_family_index(), CommandBufferUsage::OneTimeSubmit, )?; builder .begin_render_pass( RenderPassBeginInfo { render_pass: render_pass.clone(), framebuffer: framebuffer.clone(), render_area: Rect2D { offset: [0, 0], extent: [800, 600], }, clear_values: vec![Some([0.0, 0.0, 0.0, 1.0].into())], }, SubpassContents::Inline, )? .bind_pipeline_graphics(pipeline.clone())? .bind_vertex_buffers(0, iter::once(vertex_buffer))? .bind_index_buffer(index_buffer.clone())? .draw_indexed(6, 1, 0, 0, 0)? .end_render_pass()?; let command_buffer = builder.build()?; queue.submit(iter::once(command_buffer))?; ``` -------------------------------- ### Handle Graphics Pipeline Creation Errors Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/errors.md This example demonstrates how to catch and report errors that occur when creating a Vulkano graphics pipeline, including shader validation and memory issues. ```rust match GraphicsPipeline::new(&device, None, &create_info) { Ok(pipeline) => { /* use pipeline */ }, Err(Validated::Err(e)) => { eprintln!("Invalid graphics pipeline: {}", e.message); }, Err(Validated::Ok(VulkanError::OutOfDeviceMemory)) => { eprintln!("Not enough GPU memory to compile pipeline"); }, } ``` -------------------------------- ### Enable Validation Layers in Vulkano Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/README.md This snippet demonstrates how to enable the core validation layer during Vulkano instance creation. Ensure the validation layer is installed on your system. ```rust let instance = Instance::new( &library, &InstanceCreateInfo { enabled_layers: &["VK_LAYER_KHRONOS_validation"], ..Default::default() } )?; ``` -------------------------------- ### Instance::new Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-instance.md Creates a new Vulkan instance, representing an initialized Vulkan context. This is the first step in using the Vulkan API. ```APIDOC ## Instance::new ### Description Creates a new Vulkan instance. This object represents an initialized Vulkan context and must be created before any other Vulkan objects. ### Method Rust function call ### Signature ```rust pub fn new( library: &VulkanLibrary, create_info: &InstanceCreateInfo<'_> ) -> Result, VulkanError> ``` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - `library` (`&VulkanLibrary`) - Required - The loaded Vulkan library - `create_info` (`&InstanceCreateInfo<'_>`) - Required - Configuration for instance creation ### Request Example ```rust use vulkano::{ instance::{Instance, InstanceCreateInfo}, VulkanLibrary, }; let library = unsafe { VulkanLibrary::new() }?; let instance = Instance::new(&library, &Default::default())?; ``` ### Response #### Success Response - `Ok(Arc)` on success #### Error Response - `Err(VulkanError)` on failure - `VulkanError::IncompatibleDriver`: Vulkan driver is incompatible or not available - `VulkanError::ExtensionNotPresent`: Requested extension is not supported - `VulkanError::LayerNotPresent`: Requested validation layer is not available ``` -------------------------------- ### Minimal Vulkano Device Creation Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/README.md This snippet shows the basic steps to create a Vulkan instance and a logical device. It loads the Vulkan library, selects a physical device, and sets up queues for the logical device. ```rust use vulkano::{ VulkanLibrary, Version, instance::{Instance, InstanceCreateInfo}, device::{Device, DeviceCreateInfo, QueueCreateInfo}, }; // 1. Load Vulkan library let library = unsafe { VulkanLibrary::new() }?; // 2. Create instance let instance = Instance::new( &library, &InstanceCreateInfo { api_version: Version { major: 1, minor: 2, patch: 0 }, ..Default::default() } )?; // 3. Select physical device let physical_device = instance .enumerate_physical_devices()? .next() .expect("no devices"); // 4. Create logical device with queues let (device, mut queues) = Device::new( &physical_device, &DeviceCreateInfo { queue_create_infos: &[QueueCreateInfo { queue_family_index: 0, ..Default::default() }], ..Default::default() } )?; let queue = queues.next().unwrap(); println!("Created device: {:?}", physical_device.properties().device_name); ``` -------------------------------- ### Create a new Vulkano Sampler Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-sampler.md Demonstrates how to create a new sampler with specified magnification, minification, mipmap modes, and address modes. Requires the Vulkano library and a logical device. ```rust use vulkano::image::sampler::{Sampler, SamplerCreateInfo, Filter, SamplerAddressMode}; let sampler = Sampler::new( &device, &SamplerCreateInfo { mag_filter: Filter::Linear, min_filter: Filter::Linear, mipmap_mode: SamplerMipmapMode::Linear, address_mode: [SamplerAddressMode::Repeat; 3], ..Default::default() }, )?; ``` -------------------------------- ### InstanceCreateInfo Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-instance.md Configuration structure for instance creation. This struct defines all the parameters needed to initialize a Vulkan instance. ```APIDOC ## InstanceCreateInfo ### Description Configuration structure for instance creation. This struct defines all the parameters needed to initialize a Vulkan instance. ### Fields - **application_name** (`Option<&'a str>`) - Optional - Name of the application. - **application_version** (`Version`) - Optional - Version of the application. Defaults to `0.0.0`. - **engine_name** (`Option<&'a str>`) - Optional - Name of the engine used. - **engine_version** (`Version`) - Optional - Version of the engine. Defaults to `0.0.0`. - **api_version** (`Version`) - Required - Maximum Vulkan API version to use. Defaults to `1.0`. - **enabled_extensions** (`&'a InstanceExtensions`) - Required - Vulkan extensions to enable. - **enabled_layers** (`&'a [&'a str]`) - Optional - Validation layers to enable. Defaults to `&[]`. - **flags** (`InstanceCreateFlags`) - Optional - Instance creation flags. Defaults to empty. - **enumerate_portability** (`bool`) - Optional - Allow portability subset devices. Defaults to `false`. ### Example ```rust let create_info = InstanceCreateInfo { application_name: Some("My App"), application_version: Version { major: 1, minor: 0, patch: 0 }, enabled_extensions: &InstanceExtensions { khr_surface: true, ..InstanceExtensions::empty() }, ..Default::default() }; ``` ``` -------------------------------- ### Create Vulkan Instance Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-instance.md Creates a new Vulkan instance, which is the main API entry point. Requires a loaded Vulkan library and instance creation information. Use `Default::default()` for basic configuration. ```rust use vulkano { instance::{Instance, InstanceCreateInfo}, VulkanLibrary, }; let library = unsafe { VulkanLibrary::new() }?; let instance = Instance::new(&library, &Default::default())?; ``` -------------------------------- ### Get Physical Device Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-device.md Returns the underlying `PhysicalDevice` object from which this logical device was created. ```rust pub fn physical_device(&self) -> &Arc ``` -------------------------------- ### Instance::enumerate_physical_devices Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-instance.md Enumerates all physical Vulkan devices available on the system that are compatible with the created instance. ```APIDOC ## enumerate_physical_devices ### Description Enumerates all physical devices available on the system that are compatible with this Vulkan instance. ### Method Rust method call ### Signature ```rust pub fn enumerate_physical_devices( &self ) -> Result>, VulkanError> ``` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example ```rust for physical_device in instance.enumerate_physical_devices()? { println!("Device: {}", physical_device.properties().device_name); } ``` ### Response #### Success Response - `Ok(impl ExactSizeIterator>)`: An iterator over available physical devices. #### Error Response - `Err(VulkanError)`: If enumeration fails. ``` -------------------------------- ### Get Swapchain Images Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-swapchain.md Retrieves a slice of images associated with the swapchain. These are the images that can be rendered to and presented. ```rust pub fn images(&self) -> &[Arc] ``` -------------------------------- ### Get Device API Version Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-device.md Returns the Vulkan API version that this logical device supports. ```rust pub fn api_version(&self) -> Version ``` -------------------------------- ### Get Enabled Device Features Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-device.md Retrieves the set of Vulkan features that have been enabled for this logical device. ```rust pub fn enabled_features(&self) -> &DeviceFeatures ``` -------------------------------- ### Get Enabled Device Extensions Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-device.md Retrieves the set of Vulkan extensions that have been enabled for this logical device. ```rust pub fn enabled_extensions(&self) -> &DeviceExtensions ``` -------------------------------- ### Create Vulkano Event Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-sampler.md Demonstrates how to create a new Vulkan event. Ensure you have a `Device` and `EventCreateInfo` available. ```rust use vulkano::sync::{Event, EventCreateInfo}; let event = Event::new(&device, &EventCreateInfo::default())?; ``` -------------------------------- ### Get Queue Family Properties Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-device.md Iterate over the properties of all queue families on a physical device. Requires a `PhysicalDevice` instance. ```rust for (index, queue_family) in physical_device.queue_family_properties().iter().enumerate() { println!("Queue family {}: {:?}", index, queue_family.queue_flags); } ``` -------------------------------- ### Create Pipeline Layout Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-pipeline.md Initializes a new pipeline layout with specified descriptor set layouts and push constant ranges. Ensure the device and create_info are correctly configured. ```rust use vulkano::pipeline::layout::{PipelineLayout, PipelineLayoutCreateInfo}; use vulkano::descriptor_set::layout::DescriptorSetLayout; let layout = PipelineLayout::new( &device, &PipelineLayoutCreateInfo { set_layouts: vec![descriptor_set_layout], push_constant_ranges: vec![], ..Default::default() }, )?; ``` -------------------------------- ### InstanceCreateInfo Structure Definition Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-instance.md Defines the configuration options for creating a Vulkan instance, including application details, API version, extensions, and layers. ```rust pub struct InstanceCreateInfo<'a> { pub application_name: Option<&'a str>, pub application_version: Version, pub engine_name: Option<&'a str>, pub engine_version: Version, pub api_version: Version, pub enabled_extensions: &'a InstanceExtensions, pub enabled_layers: &'a [&'a str], pub flags: InstanceCreateFlags, pub enumerate_portability: bool, pub _ne: NonExhaustive, } ``` -------------------------------- ### Access Parent Device Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-device.md Gets a reference to the `Device` that owns this queue. Useful for accessing device-level properties or operations. ```rust pub fn device(&self) -> &Arc; ``` -------------------------------- ### Get Physical Device Properties Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-device.md Retrieve properties of a physical Vulkan device, such as its name and type. Requires a `PhysicalDevice` instance. ```rust let props = physical_device.properties(); println!("Device name: {}", props.device_name); println!("Device type: {:?}", props.device_type); ``` -------------------------------- ### Draw Command Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-command-buffer.md Records a non-indexed draw command. Specify the number of vertices and instances to draw, along with their starting indices. ```rust pub fn draw( &mut self, vertex_count: u32, instance_count: u32, first_vertex: u32, first_instance: u32, ) -> Result<&mut Self, Box> ``` -------------------------------- ### DeviceCreateInfo Structure Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-device.md Defines the configuration for creating a Vulkan device. Specify queue families, enabled extensions, and features. ```rust pub struct DeviceCreateInfo<'a> { pub queue_create_infos: &'a [QueueCreateInfo], pub enabled_extensions: &'a DeviceExtensions, pub enabled_features: &'a DeviceFeatures, pub flags: DeviceCreateFlags, pub _ne: NonExhaustive, } ``` -------------------------------- ### Get Index Buffer Length Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-buffer.md Retrieve the number of indices in an IndexBuffer. This is useful for understanding the size of index data for draw commands. ```rust let indices: IndexBuffer = IndexBuffer::U32(index_buffer); println!("Index count: {}", indices.len()); ``` -------------------------------- ### Save and Load Pipeline Cache Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/configuration.md Demonstrates how to save pipeline cache data to a file and load it back for faster subsequent initialization. Ensure the file path is correct. ```rust // Save cache to file let cache_data = cache.get_data()?; std::fs::write("pipeline.cache", cache_data)?; // Load cache from file let cached = std::fs::read("pipeline.cache").ok(); let cache = PipelineCache::new( &device, &PipelineCacheCreateInfo { initial_data: cached.as_deref().unwrap_or_default(), _ne: Default::default(), }, )?; ``` -------------------------------- ### Bind Vertex Buffers Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-command-buffer.md Binds vertex buffers to the command buffer. Specify the starting binding index and an iterator of vertex buffers. ```rust pub fn bind_vertex_buffers( &mut self, first_binding: u32, vertex_buffers: impl Iterator>, ) -> Result<&mut Self, Box> ``` -------------------------------- ### AutoCommandBufferBuilder::primary Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-command-buffer.md Starts building a primary command buffer. This method initializes the builder for recording commands into a primary command buffer. ```APIDOC ## AutoCommandBufferBuilder::primary ### Description Starts building a primary command buffer. This method initializes the builder for recording commands into a primary command buffer. ### Signature ```rust pub fn primary( allocator: &Arc, queue_family_index: u32, usage: CommandBufferUsage, ) -> Result> ``` ### Parameters #### Path Parameters - **allocator** (Arc) - Required - Command buffer allocator - **queue_family_index** (u32) - Required - Queue family index for recording - **usage** (CommandBufferUsage) - Required - Expected usage pattern ### Return Type `Result>` ### Example ```rust let builder = AutoCommandBufferBuilder::primary( &allocator, queue.queue_family_index(), CommandBufferUsage::OneTimeSubmit, )?; ``` ``` -------------------------------- ### DeviceCreateInfo Structure Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/configuration.md Defines the configuration for creating a Vulkan logical device. Specify queue families, extensions, features, and creation flags. ```rust pub struct DeviceCreateInfo<'a> { pub queue_create_infos: &'a [QueueCreateInfo], pub enabled_extensions: &'a DeviceExtensions, pub enabled_features: &'a DeviceFeatures, pub flags: DeviceCreateFlags, } ``` -------------------------------- ### Device::new Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-device.md Creates a new logical Vulkan device from a physical device. This is a fundamental step before most Vulkan operations can be performed. ```APIDOC ## Device::new ### Description Creates a new logical Vulkan device from a physical device. ### Signature ```rust pub fn new( physical_device: &Arc, create_info: &DeviceCreateInfo<'_> ) -> Result<(Arc, impl ExactSizeIterator> + use<>), VulkanError> ``` ### Parameters #### Path Parameters - `physical_device` (*&Arc*) - Required - Selected physical device - `create_info` (*&DeviceCreateInfo<'_>*) - Required - Device creation configuration ### Return Type `Result<(Arc, impl ExactSizeIterator>), VulkanError>` - `Ok((device, queues))` - Device and associated queues - `Err(VulkanError)` - Creation failed ### Throws/Rejects - `VulkanError::OutOfHostMemory` - Insufficient host memory - `VulkanError::OutOfDeviceMemory` - Insufficient device memory - `VulkanError::InitializationFailed` - Device initialization failed - `VulkanError::ExtensionNotPresent` - Requested extension not supported - `VulkanError::FeatureNotPresent` - Requested feature not supported ### Example ```rust use vulkano::device::{Device, DeviceCreateInfo, QueueCreateInfo}; let (device, mut queues) = Device::new( &physical_device, &DeviceCreateInfo { queue_create_infos: &[QueueCreateInfo { queue_family_index: 0, ..Default::default() }], ..Default::default() } )?; let queue = queues.next().unwrap(); ``` ``` -------------------------------- ### Fence::new Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-sampler.md Creates a new CPU-GPU synchronization primitive. ```APIDOC ## Fence::new ### Description Creates a new fence. ### Signature ```rust pub fn new( device: &Arc, create_info: &FenceCreateInfo, ) -> Result, Validated> ``` ### Parameters #### Path Parameters - **device** (`&Arc`) - Required - Logical device - **create_info** (`&FenceCreateInfo`) - Required - Fence configuration ### Request Example ```rust use vulkano::sync::{Fence, FenceCreateInfo}; let fence = Fence::new(&device, &FenceCreateInfo::default())?; ``` ``` -------------------------------- ### Get Swapchain Image Format Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-swapchain.md Returns the pixel format of the images within this swapchain. This is crucial for selecting the correct image processing and rendering operations. ```rust pub fn format(&self) -> Format ``` -------------------------------- ### Get Maximum API Version Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-instance.md Retrieves the highest Vulkan API version supported by the created instance. Useful for checking compatibility or feature availability. ```rust let version = instance.max_api_version(); println!("Instance API version: {}.{}", version.major, version.minor); ``` -------------------------------- ### Handle Swapchain Creation Errors Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/errors.md Demonstrates how to match on `Swapchain::new` results to handle specific errors like `SurfaceLost` or general validation errors. ```rust match Swapchain::new(&device, surface, &create_info) { Ok((swapchain, images)) => { /* use swapchain */ }, Err(Validated::Ok(VulkanError::SurfaceLost)) => { eprintln!("Window surface was lost"); // Recreate swapchain or exit }, Err(Validated::Err(e)) => { eprintln!("Invalid swapchain configuration: {}", e.message); }, } ``` -------------------------------- ### Draw Indexed Command Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-command-buffer.md Records an indexed draw command. Specify index and instance counts, starting indices, vertex offset, and first instance. ```rust pub fn draw_indexed( &mut self, index_count: u32, instance_count: u32, first_index: u32, vertex_offset: i32, first_instance: u32, ) -> Result<&mut Self, Box> ``` -------------------------------- ### QueueCreateInfo Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-device.md Configuration for queue creation, including queue family index and priorities. ```APIDOC ## QueueCreateInfo ### Description Configuration for queue creation, including queue family index and priorities. ### Struct Fields - **`queue_family_index`** (`u32`) - Required - Index of queue family to create queues from. - **`queues`** (`SmallVec<[f32; 1]>`) - Optional - Priority values for each queue (0.0-1.0). ### Example ```rust QueueCreateInfo { queue_family_index: 0, queues: smallvec![1.0], } ``` ``` -------------------------------- ### AutoCommandBufferBuilder::secondary Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-command-buffer.md Starts building a secondary command buffer. This method initializes the builder for recording commands into a secondary command buffer, requiring inheritance information. ```APIDOC ## AutoCommandBufferBuilder::secondary ### Description Starts building a secondary command buffer. This method initializes the builder for recording commands into a secondary command buffer, requiring inheritance information. ### Signature ```rust pub fn secondary( allocator: &Arc, queue_family_index: u32, usage: CommandBufferUsage, inheritance: CommandBufferInheritanceInfo, ) -> Result> ``` ### Parameters #### Path Parameters - **allocator** (Arc) - Required - Command buffer allocator - **queue_family_index** (u32) - Required - Queue family index for recording - **usage** (CommandBufferUsage) - Required - Expected usage pattern - **inheritance** (CommandBufferInheritanceInfo) - Required - Inheritance information for secondary buffers ### Return Type `Result>` ``` -------------------------------- ### Enable Serde Feature in Cargo.toml Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/configuration.md Shows how to enable the 'serde' feature for Vulkano in your Cargo.toml file to include (de)serialization support. ```toml [dependencies] vulkano = { version = "0.35", features = ["serde"] } ``` -------------------------------- ### Combine ShaderStages for Vertex and Fragment Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-descriptor-set.md Example of combining shader stage flags to indicate access for both vertex and fragment shaders. This is useful when defining descriptor set layouts. ```rust let stages = ShaderStages::VERTEX | ShaderStages::FRAGMENT; ``` -------------------------------- ### Create StandardCommandBufferAllocator Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-command-buffer.md Creates a new instance of the StandardCommandBufferAllocator. Requires an associated Vulkan device. ```rust let allocator = StandardCommandBufferAllocator::new(device); ``` -------------------------------- ### SwapchainCreateInfo Structure Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-swapchain.md The `SwapchainCreateInfo` struct holds all the necessary information to create a new swapchain. It includes details about image count, format, extent, usage, sharing, transform, alpha blending, present mode, clipping, and optionally, a previous swapchain for recreation. ```APIDOC ## Struct: SwapchainCreateInfo ### Description Configuration for swapchain creation. ### Fields - `min_image_count` (u32) - Required - Minimum number of images. - `image_format` (Format) - Required - Image format. - `image_color_space` (ColorSpace) - Optional - Default: `SRgbNonlinear` - Color space. - `image_extent` ([u32; 2]) - Required - Image size [width, height]. - `image_array_layers` (u32) - Optional - Default: 1 - Array layers per image. - `image_usage` (ImageUsage) - Required - How images will be used. - `image_sharing` (Sharing<'_>) - Optional - Default: Exclusive - Queue family sharing. - `pre_transform` (SurfaceTransform) - Optional - Default: Identity - Pre-presentation transform. - `composite_alpha` (CompositeAlpha) - Required - Alpha blending mode. - `present_mode` (PresentMode) - Required - How to present images. - `clipped` (bool) - Optional - Default: `true` - Rendering outside window clipped. - `old_swapchain` (Option>) - Optional - Default: None - Previous swapchain for recreation. - `full_screen_exclusive` (FullScreenExclusive) - Optional - Default: Default - Full-screen exclusivity mode. ### Example ```rust let create_info = SwapchainCreateInfo { min_image_count: 2, image_format: Format::B8G8R8A8_UNORM, image_extent: [1920, 1080], image_usage: ImageUsage::COLOR_ATTACHMENT, composite_alpha: CompositeAlpha::Opaque, present_mode: PresentMode::Fifo, ..Default::default() }; ``` ``` -------------------------------- ### Get Swapchain Present Mode Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-swapchain.md Returns the present mode configured for this swapchain. The present mode dictates how queued images are presented to the screen, affecting latency and tearing. ```rust pub fn present_mode(&self) -> PresentMode ``` -------------------------------- ### Get Pipeline Cache Data Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-pipeline.md Retrieves the binary data of a pipeline cache. This data can be saved and later used to re-create the cache, potentially speeding up pipeline compilation. ```rust let cache_data = cache.get_data()?; // Save to disk for later use ``` -------------------------------- ### ShaderModule::entry_point Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-shader.md Retrieves information about a specific shader entry point by its name. ```APIDOC ## ShaderModule::entry_point ### Description Gets information about a shader entry point. ### Signature ```rust pub fn entry_point(&self, name: &str) -> Option<&ShaderEntryPoint> ``` ### Parameters #### Path Parameters - `name` (str) - Required - Entry point function name (e.g., "main") ### Response #### Success Response - `Option<&ShaderEntryPoint>` - An optional reference to the shader entry point information if found. ### Request Example ```rust if let Some(entry_point) = shader_module.entry_point("main") { println!("Entry point info: {:?}", entry_point); } ``` ``` -------------------------------- ### Bind Descriptor Sets Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-command-buffer.md Binds descriptor sets to the command buffer for use with a pipeline. Requires specifying the pipeline bind point, layout, and the starting set index. ```rust pub fn bind_descriptor_sets( &mut self, pipeline_bind_point: PipelineBindPoint, layout: Arc, first_set: u32, descriptor_sets: impl Iterator>, ) -> Result<&mut Self, Box> ``` -------------------------------- ### PhysicalDevice.supported_extensions Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-device.md Retrieves a list of all Vulkan extensions supported by the physical device. ```APIDOC ## PhysicalDevice.supported_extensions ### Description Returns all extensions supported by this physical device. ### Method GET ### Endpoint `/devices/{device_id}/extensions` ### Parameters #### Path Parameters - **device_id** (string) - Required - The unique identifier of the physical device. ### Response #### Success Response (200) - **extensions** (array) - A list of supported extension names. ### Response Example ```json { "example": { "extensions": [ "VK_KHR_swapchain", "VK_KHR_maintenance1" ] } } ``` ``` -------------------------------- ### Swapchain::new Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-swapchain.md Creates a new swapchain for a given device and surface with specified creation information. It returns the created swapchain and a vector of associated images. ```APIDOC ## Swapchain::new ### Description Creates a new swapchain. ### Method Rust function call ### Parameters #### Path Parameters - `device` (&Arc) - Yes - Logical device - `surface` (Arc) - Yes - Surface to present to - `create_info` (&SwapchainCreateInfo) - Yes - Swapchain configuration ### Request Example ```rust use vulkano::swapchain::{Swapchain, SwapchainCreateInfo, PresentMode}; let (swapchain, images) = Swapchain::new( &device, surface, &SwapchainCreateInfo { min_image_count: capabilities.min_image_count, image_format: Format::B8G8R8A8_UNORM, image_extent: [1920, 1080], image_usage: ImageUsage::COLOR_ATTACHMENT, composite_alpha: CompositeAlpha::Opaque, present_mode: PresentMode::Fifo, ..Default::default() }, )?; ``` ### Response #### Success Response - `(Arc, Vec>)` - The created swapchain and its associated images. #### Throws/Rejects - `SwapchainCreationError::IncompatibleDevice` - Device cannot present to surface - `SwapchainCreationError::SurfaceLost` - Surface was lost - `SwapchainCreationError::InvalidCompositeAlpha` - Composite alpha not supported ``` -------------------------------- ### Sampler::new Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-sampler.md Creates a new sampler with the specified device and creation information. This sampler defines how images are sampled in shaders. ```APIDOC ## Sampler::new ### Description Creates a new sampler with the specified device and creation information. This sampler defines how images are sampled in shaders. ### Signature ```rust pub fn new( device: &Arc, create_info: &SamplerCreateInfo, ) -> Result, Validated> ``` ### Parameters #### Path Parameters - `device` (Arc) - Required - Logical device - `create_info` (SamplerCreateInfo) - Required - Sampler configuration ### Request Example ```rust use vulkano::image::sampler::{Sampler, SamplerCreateInfo, Filter, SamplerAddressMode}; let sampler = Sampler::new( &device, &SamplerCreateInfo { mag_filter: Filter::Linear, min_filter: Filter::Linear, mipmap_mode: SamplerMipmapMode::Linear, address_mode: [SamplerAddressMode::Repeat; 3], ..Default::default() }, )?; ``` ### Response #### Success Response - `Arc` - A new sampler instance. #### Error Response - `Validated` - An error encountered during sampler creation. ``` -------------------------------- ### Begin Render Pass Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-command-buffer.md Begins a render pass within a command buffer. Specify render pass, framebuffer, render area, and clear values. ```rust builder.begin_render_pass( RenderPassBeginInfo { render_pass: render_pass.clone(), framebuffer: framebuffer.clone(), render_area: Rect2D { offset: [0, 0], extent: [800, 600], }, clear_values: vec![Some([0.0, 0.0, 0.0, 1.0].into())], }, SubpassContents::Inline, )?; ``` -------------------------------- ### Create Vulkan Logical Device Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-device.md Use this constructor to create a new logical Vulkan device from a physical device. Ensure you provide valid `DeviceCreateInfo` including queue family information. ```rust pub fn new( physical_device: &Arc, create_info: &DeviceCreateInfo<'_> ) -> Result< ( Arc, impl ExactSizeIterator> + use<> ), VulkanError > ``` ```rust use vulkano::device::{Device, DeviceCreateInfo, QueueCreateInfo}; let (device, mut queues) = Device::new( &physical_device, &DeviceCreateInfo { queue_create_infos: &[QueueCreateInfo { queue_family_index: 0, ..Default::default() }], ..Default::default() } )?; let queue = queues.next().unwrap(); ``` -------------------------------- ### AutoCommandBufferBuilder::begin_render_pass Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-command-buffer.md Begins a render pass within the command buffer. This method records the necessary commands to start a render pass, specifying render area, clear values, and subpass contents. ```APIDOC ## AutoCommandBufferBuilder::begin_render_pass ### Description Begins a render pass within the command buffer. This method records the necessary commands to start a render pass, specifying render area, clear values, and subpass contents. ### Signature ```rust pub fn begin_render_pass( &mut self, render_pass_begin_info: RenderPassBeginInfo, contents: SubpassContents, ) -> Result<&mut Self, Box> ``` ### Parameters #### Path Parameters - **render_pass_begin_info** (RenderPassBeginInfo) - Required - Render pass and framebuffer info - **contents** (SubpassContents) - Required - Inline or secondary command buffers ### Return Type `Result<&mut Self, Box>` ### Example ```rust builder.begin_render_pass( RenderPassBeginInfo { render_pass: render_pass.clone(), framebuffer: framebuffer.clone(), render_area: Rect2D { offset: [0, 0], extent: [800, 600], }, clear_values: vec![Some([0.0, 0.0, 0.0, 1.0].into())], }, SubpassContents::Inline, )?; ``` ``` -------------------------------- ### RenderPassBeginInfo Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-render-pass.md Information for beginning a render pass in a command buffer, including the render pass, framebuffer, render area, and clear values. ```APIDOC ## RenderPassBeginInfo ### Description Information for beginning a render pass in a command buffer. ### Fields - `render_pass` (Arc) - Required - Render pass to begin. - `framebuffer` (Arc) - Required - Framebuffer with attachments. - `render_area` (Rect2D) - Required - Rendering area (offset and extent). - `clear_values` (Vec>) - Optional - Empty - Clear values for load_op=Clear. ### Example ```rust use vulkano::render_pass::RenderPassBeginInfo; let render_pass_begin_info = RenderPassBeginInfo { render_pass: render_pass.clone(), framebuffer: framebuffer.clone(), render_area: Rect2D { offset: [0, 0], extent: [1920, 1080], }, clear_values: vec![ Some([0.0, 0.0, 0.0, 1.0].into()), Some(1.0f32.into()), ], }; ``` ``` -------------------------------- ### DeviceCreateInfo Source: https://github.com/vulkano-rs/vulkano/blob/master/_autodocs/api-reference-device.md Configuration for device creation, specifying queue families, extensions, and features. ```APIDOC ## DeviceCreateInfo ### Description Configuration for device creation, specifying queue families, extensions, and features. ### Struct Fields - **`queue_create_infos`** (`&'a [QueueCreateInfo]`) - Required - Queue family information for creation. - **`enabled_extensions`** (`&'a DeviceExtensions`) - Required - Device extensions to enable. - **`enabled_features`** (`&'a DeviceFeatures`) - Required - Device features to enable. - **`flags`** (`DeviceCreateFlags`) - Optional - Device creation flags. ### Example ```rust let create_info = DeviceCreateInfo { queue_create_infos: &[QueueCreateInfo { queue_family_index: 0, ..Default::default() }], enabled_extensions: &DeviceExtensions::empty(), enabled_features: &DeviceFeatures::empty(), ..Default::default() }; ``` ```