### Run transitions example Source: https://github.com/attackgoat/screen-13/blob/main/examples/README.md Run the transitions example with cargo. ```bash cargo run --example transitions ``` -------------------------------- ### Run vr example Source: https://github.com/attackgoat/screen-13/blob/main/examples/README.md Run the vr example with cargo. ```bash cargo run -p vr ``` -------------------------------- ### Run shader-toy example Source: https://github.com/attackgoat/screen-13/blob/main/examples/README.md Run the shader-toy example with cargo. ```bash cargo run -p shader-toy ``` -------------------------------- ### Run imgui example Source: https://github.com/attackgoat/screen-13/blob/main/examples/README.md Run the imgui example with cargo. ```bash cargo run --example imgui ``` -------------------------------- ### Run ray_tracing example Source: https://github.com/attackgoat/screen-13/blob/main/examples/README.md Run the ray_tracing example with cargo. ```bash cargo run --example ray_tracing ``` -------------------------------- ### Run egui example Source: https://github.com/attackgoat/screen-13/blob/main/examples/README.md Run the egui example with cargo. ```bash cargo run --example egui ``` -------------------------------- ### Run vertex_layout example Source: https://github.com/attackgoat/screen-13/blob/main/examples/README.md Run the vertex_layout example with cargo. ```bash cargo run --example vertex_layout ``` -------------------------------- ### Run app example Source: https://github.com/attackgoat/screen-13/blob/main/examples/README.md Run the app example with cargo. ```bash cargo run --example app ``` -------------------------------- ### Run bindless example Source: https://github.com/attackgoat/screen-13/blob/main/examples/README.md Run the bindless example with cargo. ```bash cargo run --example bindless ``` -------------------------------- ### Run image_sampler example Source: https://github.com/attackgoat/screen-13/blob/main/examples/README.md Run the image_sampler example with cargo. ```bash cargo run --example image_sampler ``` -------------------------------- ### Run hello_world example Source: https://github.com/attackgoat/screen-13/blob/main/crates/vk-graph-window/README.md Use this command to run the hello_world example, which demonstrates window creation and frame rendering with vk-graph. ```sh cargo run --example hello_world ``` -------------------------------- ### Run mip_graphics example Source: https://github.com/attackgoat/screen-13/blob/main/examples/README.md Run the mip_graphics example with cargo. ```bash cargo run --example mip_graphics ``` -------------------------------- ### Run cpu_readback example Source: https://github.com/attackgoat/screen-13/blob/main/examples/README.md Run the cpu_readback example with cargo. ```bash cargo run --example cpu_readback ``` -------------------------------- ### Run rt_triangle example Source: https://github.com/attackgoat/screen-13/blob/main/examples/README.md Run the rt_triangle example with cargo. ```bash cargo run --example rt_triangle ``` -------------------------------- ### Run triangle example Source: https://github.com/attackgoat/screen-13/blob/main/examples/README.md Run the triangle example with cargo. ```bash cargo run --example triangle ``` -------------------------------- ### Run min_max example Source: https://github.com/attackgoat/screen-13/blob/main/examples/README.md Run the min_max example with cargo. ```bash cargo run --example min_max ``` -------------------------------- ### Run multipass example Source: https://github.com/attackgoat/screen-13/blob/main/examples/README.md Run the multipass example with cargo. ```bash cargo run --example multipass ``` -------------------------------- ### Run mip_compute example Source: https://github.com/attackgoat/screen-13/blob/main/examples/README.md Run the mip_compute example with cargo. ```bash cargo run --example mip_compute ``` -------------------------------- ### Run font_bmp example Source: https://github.com/attackgoat/screen-13/blob/main/examples/README.md Run the font_bmp example with cargo. ```bash cargo run --example font_bmp ``` -------------------------------- ### Install cargo-fuzz Source: https://github.com/attackgoat/screen-13/blob/main/fuzz/README.md Installs the cargo-fuzz tool via cargo install. ```sh cargo install cargo-fuzz ``` -------------------------------- ### Run subgroup_ops example Source: https://github.com/attackgoat/screen-13/blob/main/examples/README.md Run the subgroup_ops example with cargo. ```bash cargo run --example subgroup_ops ``` -------------------------------- ### Run baked example Source: https://github.com/attackgoat/screen-13/blob/main/examples/README.md Run the baked example with cargo. ```bash cargo run --example baked ``` -------------------------------- ### Run ray_omni example Source: https://github.com/attackgoat/screen-13/blob/main/examples/README.md Run the ray_omni example with cargo. Demonstrates ray query for omni/point lights. ```bash cargo run --example ray_omni ``` -------------------------------- ### Run multithread example in release mode Source: https://github.com/attackgoat/screen-13/blob/main/examples/README.md Run the multithread example with cargo in release mode. ```bash cargo run --example multithread --release ``` -------------------------------- ### Borrow resource from graph using node handle Source: https://github.com/attackgoat/screen-13/blob/main/guide/src/usage.md Shows borrowing a bound resource from a graph using its node handle. The example uses graph.resource(image) to get a &Arc and asserts the image width is 320. ```rust # use vk_graph::Graph; # use vk_graph::driver::image::Image; # use vk_graph::node::ImageNode; # use std::sync::Arc; # fn test( # graph: &mut Graph, # image: ImageNode, # ) { let shared_image: &Arc = graph.resource(image); assert_eq!(shared_image.info.width, 320); # } ``` -------------------------------- ### Run msaa example Source: https://github.com/attackgoat/screen-13/blob/main/examples/README.md Run the msaa example with cargo. Demonstrates multisample anti-aliasing. ```bash cargo run --example msaa ``` -------------------------------- ### Run aliasing example Source: https://github.com/attackgoat/screen-13/blob/main/examples/README.md Run the aliasing example with cargo. ```bash cargo run --example aliasing ``` -------------------------------- ### Run vsm_omni example Source: https://github.com/attackgoat/screen-13/blob/main/examples/README.md Run the vsm_omni example with cargo. Demonstrates variance shadow mapping for omni/point lights. ```bash cargo run --example vsm_omni ``` -------------------------------- ### Run glsl example Source: https://github.com/attackgoat/screen-13/blob/main/crates/vk-graph-hot/examples/README.md Command to run the glsl example using cargo. ```bash cargo run --example glsl ``` -------------------------------- ### Run debugger example Source: https://github.com/attackgoat/screen-13/blob/main/examples/README.md Run the debugger example with cargo. ```bash cargo run --example debugger ``` -------------------------------- ### Run hlsl example Source: https://github.com/attackgoat/screen-13/blob/main/crates/vk-graph-hot/examples/README.md Command to run the hlsl example using cargo. ```bash cargo run --example hlsl ``` -------------------------------- ### Install mdbook with cargo Source: https://github.com/attackgoat/screen-13/blob/main/guide/guide-helper/README.md Run this command to install the mdbook tool, which is required to build the book. ```bash cargo install mdbook ``` -------------------------------- ### Rust: shader_resource_access example Source: https://github.com/attackgoat/screen-13/blob/main/guide/src/pipeline_sync.md Rust example using vk_graph to create a graph, bind a compute pipeline, and call shader_resource_access with binding 42 and AccessType::ComputeShaderWrite, then dispatch a 32x32 grid. ```rust # macro_rules! include_bytes { ($path:expr) => { [0u8] }; } # use vk_graph::Graph; # use vk_graph::driver::{DriverError, ash::vk, device::Device, sync::AccessType}; # use vk_graph::driver::compute::{ComputePipeline, ComputePipelineInfo}; # use vk_graph::driver::image::{Image, ImageInfo}; # fn test(device: &Device) -> Result<(), DriverError> { let mut graph = Graph::default(); let fmt = vk::Format::R8G8B8A8_UNORM; let usage = vk::ImageUsageFlags::STORAGE; let info = ImageInfo::image_2d(32, 32, fmt, usage); let image = graph.bind_resource(Image::create( device, info, )?); graph .begin_cmd() .bind_pipeline(ComputePipeline::create( device, ComputePipelineInfo::default(), include_bytes!("clear_image.spv").as_slice(), )?) .shader_resource_access(42, image, AccessType::ComputeShaderWrite) .record_cmd(|cmd| { cmd.dispatch(32, 32, 1); }); # Ok(()) } ``` -------------------------------- ### Run skeletal-anim example Source: https://github.com/attackgoat/screen-13/blob/main/examples/README.md Run the skeletal-anim example with cargo. Demonstrates skeletal mesh animation using glTF. ```bash cargo run -p skeletal-anim ``` -------------------------------- ### Create a window and run a frame loop with vk_graph_window Source: https://github.com/attackgoat/screen-13/blob/main/README.md Shows the minimal setup for windowed rendering using the accessory crate vk-graph-window. The closure receives a frame and is where graphics commands are recorded. ```rust use vk_graph_window::{Window, WindowError}; fn main() -> Result<(), WindowError> { Window::new()?.run(|frame| { // It's time to do some graphics! 😲 }) } ``` -------------------------------- ### Rust: shader_subresource_access example Source: https://github.com/attackgoat/screen-13/blob/main/guide/src/pipeline_sync.md Rust example using vk_graph to create a graph, bind a compute pipeline, and call shader_subresource_access with binding 42, the image, its info, and AccessType::ComputeShaderWrite, then dispatch a 32x32 grid. ```rust # macro_rules! include_bytes { ($path:expr) => { [0u8] }; } # use vk_graph::Graph; # use vk_graph::driver::{DriverError, ash::vk, device::Device, sync::AccessType}; # use vk_graph::driver::compute::{ComputePipeline, ComputePipelineInfo}; # use vk_graph::driver::image::{Image, ImageInfo}; # fn test(device: &Device) -> Result<(), DriverError> { let mut graph = Graph::default(); let fmt = vk::Format::R8G8B8A8_UNORM; let usage = vk::ImageUsageFlags::STORAGE; let info = ImageInfo::image_2d(32, 32, fmt, usage); let image = graph.bind_resource(Image::create( device, info, )?); graph .begin_cmd() .bind_pipeline(ComputePipeline::create( device, ComputePipelineInfo::default(), include_bytes!("clear_image.spv").as_slice(), )?) .shader_subresource_access(42, image, info, AccessType::ComputeShaderWrite) .record_cmd(|cmd| { cmd.dispatch(32, 32, 1); }); # Ok(()) } ``` -------------------------------- ### Run vsm_omni example with puffin profiling Source: https://github.com/attackgoat/screen-13/blob/main/README.md Compiles with the profile-with-puffin feature and runs the vsm_omni example in release mode to enable performance profiling. ```bash cargo run --features profile-with-puffin --release --example vsm_omni ``` -------------------------------- ### Create a device for headless operation Source: https://github.com/attackgoat/screen-13/blob/main/guide/src/usage_device.md Creates a default DeviceInfo and a logical device with Device::create. The example asserts that the debug flag is false. This is production-ready code for server-based rendering without a display. ```rust # use vk_graph::driver::DriverError; # use vk_graph::driver::device::{Device, DeviceInfo}; # fn test() -> Result<(), DriverError> { let info = DeviceInfo::default(); let device = Device::create(info)?; assert_eq!(device.physical.instance.info.debug, false); # Ok(()) } ``` -------------------------------- ### Sample debug log output from vk_graph driver Source: https://github.com/attackgoat/screen-13/blob/main/README.md Example output showing trace and debug log messages from the vk_graph driver, including Vulkan instance creation and physical device details. ```text TRACE vk_graph::driver::instance > created a Vulkan instance DEBUG vk_graph::driver::physical_device > physical device: NVIDIA GeForce RTX 3090 DEBUG vk_graph::driver::physical_device > extension "VK_KHR_16bit_storage" v1 DEBUG vk_graph::driver::physical_device > extension "VK_KHR_8bit_storage" v1 DEBUG vk_graph::driver::physical_device > extension "VK_KHR_acceleration_structure" v13 ... ``` -------------------------------- ### Filter RUST_LOG for vk_graph driver and run ray_tracing example Source: https://github.com/attackgoat/screen-13/blob/main/README.md Sets RUST_LOG to trace for vk_graph::driver and warn for vk_graph, then runs the ray_tracing example. Useful for filtering log messages by module. ```bash RUST_LOG=vk_graph::driver=trace,vk_graph=warn cargo run --example ray_tracing ``` -------------------------------- ### Custom command with begin_cmd, resource_access, and record_cmd Source: https://github.com/attackgoat/screen-13/blob/main/guide/src/usage.md Demonstrates a custom command that records arbitrary Vulkan code using ash::Device. It sets resource access types, moves resources into the closure, and calls cmd_copy_image_to_buffer2. The comment notes this is for example only and safe versions should be used. ```rust # use vk_graph::Graph; # use vk_graph::cmd::ClearColorValue; # use vk_graph::driver::{ash::vk, sync::AccessType}; # use vk_graph::node::{BufferNode, ImageNode}; # use std::sync::Arc; # fn test( # graph: &mut Graph, # buffer: BufferNode, # image: ImageNode, # ) { graph .begin_cmd() .resource_access(image, AccessType::TransferRead) .resource_access(buffer, AccessType::TransferWrite) .record_cmd(move |cmd| { // Borrow resources from nodes we move into the closure let buffer = cmd.resource(buffer); let image = cmd.resource(image); // Run *any* Vulkan code using ash::Device unsafe { // Note: for example only, use safe versions! cmd.device.cmd_copy_image_to_buffer2( cmd.handle, &vk::CopyImageToBufferInfo2::default() .src_image(image.handle) .dst_buffer(buffer.handle), ); } }) .end_cmd(); # } ``` -------------------------------- ### Record multiple graph commands with pipeline switching Source: https://github.com/attackgoat/screen-13/blob/main/guide/src/pipeline.md Shows how to record multiple graph commands in physical order, switching pipelines between record_cmd calls. Graph::end_cmd is optional; two commands are built in this example. ```rust # macro_rules! include_bytes { ($path:expr) => { [0u8] }; } # use vk_graph::Graph; # use vk_graph::driver::{DriverError, device::Device}; # use vk_graph::driver::compute::{ComputePipeline, ComputePipelineInfo}; # fn test(device: &Device) -> Result<(), DriverError> { let info = ComputePipelineInfo::default(); let fire = include_bytes!("fire.spv"); let fire = ComputePipeline::create(device, info, fire.as_slice())?; let water = include_bytes!("water.spv"); let water = ComputePipeline::create(device, info, water.as_slice())?; let mut graph = Graph::default(); graph .begin_cmd() .bind_pipeline(&fire) .record_cmd(|cmd| { println!("1st"); }) .bind_pipeline(&water) .record_cmd(|cmd| { println!("2nd"); }) .bind_pipeline(&fire) .record_cmd(|cmd| { println!("3rd"); }) .end_cmd() .begin_cmd() .bind_pipeline(&water) .record_cmd(|cmd| { println!("4th"); }); # Ok(()) } ``` -------------------------------- ### Direct draw with bind_vertex_buffers, bind_index_buffer, and draw_indexed Source: https://github.com/attackgoat/screen-13/blob/main/guide/src/cmd_graphic.md Shows the typical pattern for direct drawing: bind vertex and index buffers, then issue draw_indexed. The example creates a color image, vertex and index buffers, a graphics pipeline, and records a command that binds the buffers and draws 36 indices. ```rust # use vk_graph::Graph; # use vk_graph::cmd::{LoadOp, StoreOp}; # use vk_graph::driver::ash::vk; # use vk_graph::cmd::ClearColorValue; # use vk_graph::driver::{DriverError, sync::AccessType}; # use vk_graph::driver::buffer::{Buffer, BufferInfo}; # use vk_graph::driver::device::{Device, DeviceInfo}; # use vk_graph::driver::graphic::{GraphicsPipeline, GraphicsPipelineInfo}; # use vk_graph::driver::image::{Image, ImageInfo}; # use vk_graph::driver::shader::Shader; # fn main() -> Result<(), DriverError> { # let device = Device::create(DeviceInfo::default())?; let mut graph = Graph::default(); let color = graph.bind_resource(Image::create( &device, ImageInfo::image_2d( 1280, 720, vk::Format::R8G8B8A8_UNORM, vk::ImageUsageFlags::COLOR_ATTACHMENT | vk::ImageUsageFlags::TRANSFER_SRC, ), )?); let vertices = graph.bind_resource(Buffer::create( &device, BufferInfo::device_mem(4096, vk::BufferUsageFlags::VERTEX_BUFFER), )?); let indices = graph.bind_resource(Buffer::create( &device, BufferInfo::device_mem(1024, vk::BufferUsageFlags::INDEX_BUFFER), )?); let pipeline = GraphicsPipeline::create( &device, GraphicsPipelineInfo::default(), [ Shader::new_vertex([0u8; 4].as_slice()), Shader::new_fragment([0u8; 4].as_slice()), ], )?; graph .begin_cmd() .debug_name("main geometry pass") .bind_pipeline(&pipeline) .color_attachment_image( 0, color, LoadOp::Clear(ClearColorValue::Float32([0.0, 0.0, 0.0, 1.0])), StoreOp::Store, ) .resource_access(vertices, AccessType::VertexBuffer) .resource_access(indices, AccessType::IndexBuffer) .record_cmd(move |cmd| { cmd .bind_vertex_buffers(0, [(vertices, 0)]) .bind_index_buffer(indices, 0, vk::IndexType::UINT32) .draw_indexed(36, 1, 0, 0, 0); }); # Ok(()) } ``` -------------------------------- ### Record command buffer with resource access and attachments Source: https://github.com/attackgoat/screen-13/blob/main/README.md Shows how to use the vk-graph API to record a command buffer, declaring shader resource accesses, color and depth attachments, and issuing a draw call. The example uses a pipeline, images, and a uniform buffer, with push constants and a draw of 6 vertices. ```rust graph .begin_cmd() .debug_name("Fancy new algorithm for shading a moving character who is actively on fire") .bind_pipeline(&gfx_pipeline) .shader_resource_access(0, prev_image, AccessType::FragmentShaderReadColorInputAttachment) .shader_resource_access(1, some_image, AccessType::FragmentShaderReadOther) .shader_resource_access(3, fire_buffer, AccessType::FragmentShaderReadUniformBuffer) .color_attachment_image(0, swapchain_image, LoadOp::CLEAR_BLACK_ALPHA_ZERO, StoreOp::Store) .depth_stencil_attachment_image(depth_image, LoadOp::Load, StoreOp::DontCare) .record_cmd(move |cmd| { cmd .push_constants(0, some_u8_slice) .draw(6, 1, 0, 0); }); ``` -------------------------------- ### Use GraphicsCommandRef::push_constants to push constants and draw Source: https://github.com/attackgoat/screen-13/blob/main/guide/src/cmd_graphic.md Records a command that binds a pipeline, sets a color attachment, and pushes constants with a draw call. The example uses a placeholder shader and image, and is intended for CPU-driven rendering where per-draw state fits within the device's push-constant limit. ```rust graph .begin_cmd() .bind_pipeline(&pipeline) .color_attachment_image(0, image, LoadOp::DontCare, StoreOp::Store) .record_cmd(move |cmd| { cmd.push_constants(0, &[42]) .draw(3, 1, 0, 0); }); ``` -------------------------------- ### Typical usage: borrow Device Source: https://github.com/attackgoat/screen-13/blob/main/guide/src/usage.md Shows the typical usage pattern of vk-graph: a borrow of Device is an argument to many vk-graph functions. The example imports vk and Device and creates a device reference. ```rust # use vk_graph::driver::DriverError; # struct Foo { device: vk_graph::driver::device::Device } # impl Foo { # fn test( # &self, # ) { use vk_graph::driver::ash::vk; use vk_graph::driver::device::Device; // A borrow of Device is an argument of many vk-graph functions let device: &Device = &self.device; # } } ``` -------------------------------- ### Configure MSAA resolve with color_attachment_resolve_image Source: https://github.com/attackgoat/screen-13/blob/main/guide/src/cmd_graphic.md Sets up a multisampled color attachment and a single-sampled resolve target using `color_attachment_image` and `color_attachment_resolve_image`. The example creates a 4x MSAA color image and a single-sampled resolve image, binds them to the graph, and records a draw command. The resolve image must be single-sampled and match the dimensions and format of the multisampled target. ```rust graph .begin_cmd() .bind_pipeline(&pipeline) .color_attachment_image(0, msaa_color, LoadOp::DontCare, StoreOp::DontCare) .color_attachment_resolve_image(0, 1, resolve_color) .record_cmd(|cmd| { cmd.draw(3, 1, 0, 0); }); ``` -------------------------------- ### Explicit-region copy_buffer with begin_cmd Source: https://github.com/attackgoat/screen-13/blob/main/guide/src/cmd.md Use this snippet to perform a partial buffer copy with explicit offsets and sizes. It binds source and destination buffers, then records a copy command with a debug name. The example uses host memory for the source and device memory for the destination, both 4096 bytes, copying 256 bytes from offset 512 to offset 1024. ```rust # use vk_graph::Graph; # use vk_graph::driver::DriverError; # use vk_graph::driver::ash::vk; # use vk_graph::driver::buffer::{Buffer, BufferInfo}; # use vk_graph::driver::device::{Device, DeviceInfo}; # fn main() -> Result<(), DriverError> { # let device = Device::create(DeviceInfo::default())?; let mut graph = Graph::default(); let src = graph.bind_resource(Buffer::create( &device, BufferInfo::host_mem(4096, vk::BufferUsageFlags::TRANSFER_SRC), )?); let dst = graph.bind_resource(Buffer::create( &device, BufferInfo::device_mem(4096, vk::BufferUsageFlags::TRANSFER_DST), )?); graph .begin_cmd() .debug_name("copy buffer region") .copy_buffer( src, dst, [vk::BufferCopy { src_offset: 512, dst_offset: 1024, size: 256, }], ) .end_cmd(); # Ok(()) } ``` -------------------------------- ### Query build sizes and create BLAS acceleration structure Source: https://github.com/attackgoat/screen-13/blob/main/guide/src/resource_accel_struct.md Shows how to query build sizes for a bottom-level acceleration structure and create it. The geometry uses an opaque triangles description with an index type of UINT16, 99 vertices, and a stride of 12. The build size query uses the DEVICE build type and ALLOW_UPDATE flag, with a maximum primitive count of 120. The example also demonstrates creating AccelerationStructureInfo via direct struct, the blas constructor, and the builder pattern, then creating the acceleration structure and asserting its fields. ```rust # use vk_graph::driver::{DriverError, ash::vk, device::Device}; # use vk_graph::driver::accel_struct::{ # AccelerationStructure, AccelerationStructureGeometry, AccelerationStructureGeometryData, # AccelerationStructureInfo, AccelerationStructureInfoBuilder # }; # fn test( # device: &Device, # ) -> Result<(), DriverError> { // Size queries do not dereference input addresses. let geometries = [AccelerationStructureGeometry::opaque( AccelerationStructureGeometryData::triangles( 0, vk::IndexType::UINT16, 99, 0, 0, vk::Format::R32G32B32_SFLOAT, 12, ), )]; let ty = vk::AccelerationStructureTypeKHR::BOTTOM_LEVEL; // No micromap handles are attached here. The caller ensures geometry/count metadata, // flags, and device limits satisfy Vulkan's build-size query constraints. let sizes = unsafe { AccelerationStructure::build_sizes( device, vk::AccelerationStructureBuildTypeKHR::DEVICE, ty, vk::BuildAccelerationStructureFlagsKHR::ALLOW_UPDATE, &geometries, &[120], // One maximum primitive count per geometry, in the same order. ) }; // Create acceleration structure info multiple ways: let info = AccelerationStructureInfo { acceleration_structure_type: ty, size: sizes.acceleration_structure_size, }; let other_info = AccelerationStructureInfo::blas(sizes.acceleration_structure_size); assert_eq!(info, other_info); // Builder pattern let same_info = AccelerationStructureInfoBuilder::default() .acceleration_structure_type(ty) .size(sizes.acceleration_structure_size); // Create directly from info let blas = AccelerationStructure::create(device, info)?; // The provided fields are helpful: assert_eq!(blas.buffer.device, *device); assert_eq!(blas.info, info); assert_ne!(blas.buffer.handle, vk::Buffer::null()); assert_ne!(blas.handle, vk::AccelerationStructureKHR::null()); // Acceleration structures have no "subresources" and are bound whole # Ok(()) } ``` -------------------------------- ### Create images and image views with vk_graph Source: https://github.com/attackgoat/screen-13/blob/main/guide/src/resource_image.md Shows how to construct ImageInfo, create images, and create image views. Includes multiple ways to build ImageInfo, the builder pattern, creating images from info, and creating image views. ```rust # use vk_graph::Graph; # use vk_graph::driver::{DriverError, ash::vk, device::Device}; # use vk_graph::driver::image::{Image, ImageInfo, ImageInfoBuilder, SampleCount}; # use vk_graph::driver::image::{ImageViewInfo, ImageViewInfoBuilder}; # fn test( # device: &Device, # ) -> Result<(), DriverError> { let (width, height) = (320, 200); let usage = vk::ImageUsageFlags::SAMPLED; let fmt = vk::Format::R8G8B8A8_UNORM; // Create image info multiple ways let info = ImageInfo { array_layer_count: 1, alloc_dedicated: false, depth: 1, flags: vk::ImageCreateFlags::empty(), format: fmt, height, host_readable: false, host_writable: false, mip_level_count: 1, sample_count: SampleCount::Type1, sharing_mode: vk::SharingMode::EXCLUSIVE, tiling: vk::ImageTiling::OPTIMAL, image_type: vk::ImageType::TYPE_2D, usage, width, }; let other_info = ImageInfo::image_2d(width, height, fmt, usage); let cube_info = ImageInfo::cube(width, fmt, usage); assert_eq!(info, other_info); assert_ne!(info, cube_info); // Builder pattern let same_info = ImageInfoBuilder::default() .width(width) .height(height) .depth(1) .format(fmt) .usage(usage) .image_type(vk::ImageType::TYPE_2D); // Info built from other info let array_info = cube_info .into_builder() .flags(vk::ImageCreateFlags::TYPE_2D_ARRAY_COMPATIBLE) .build(); // Images are created simply let image = Image::create(device, info)?; // For interop this may be handy: let image = unsafe { Image::from_raw(device, vk::Image::null(), info) }; // The provided fields are helpful: assert_eq!(image.device, *device); assert_eq!(image.info, info); assert_ne!(image.handle, vk::Image::null()); // Image "subresources" are the native type: let my_subresource = vk::ImageSubresourceRange { aspect_mask: vk::ImageAspectFlags::COLOR, base_mip_level: 0, level_count: 1, base_array_layer: 0, layer_count: 1, }; // Image views are also subresources: let image_view = ImageViewInfo { array_layer_count: 1, aspect_mask: vk::ImageAspectFlags::COLOR, base_array_layer: 0, base_mip_level: 0, format: fmt, mip_level_count: 1, view_type: vk::ImageViewType::TYPE_2D, }; // Image views have the same builder functionality: let other_view = ImageViewInfoBuilder::default(); // Image views can be inferred from the whole image info: let addl_view = info.into_image_view(); assert_eq!(image_view, addl_view); # Ok(()) } ``` -------------------------------- ### Enumerate physical devices and select a suitable Device Source: https://github.com/attackgoat/screen-13/blob/main/guide/src/usage_device.md Creates an Instance, enumerates physical devices, and filters for those supporting the VK_KHR_swapchain and VK_KHR_ray_tracing_pipeline extensions with ray tracing pipeline feature. Converts the first matching physical device into a Device. ```rust # use vk_graph::driver::DriverError; # use vk_graph::driver::device::Device; # use vk_graph::driver::instance::{Instance, InstanceInfo}; # fn test() -> Result<(), DriverError> { let instance = Instance::create(InstanceInfo::default())?; let physical_devices = Instance::physical_devices(&instance)?; for physical_device in physical_devices { // We are looking for a device with support for these features if !physical_device.vk_khr_swapchain || !physical_device .vk_khr_ray_tracing_pipeline .as_ref() .is_some_and(|ext| ext.features.ray_tracing_pipeline) { continue; } let _: Device = physical_device.try_into_device()?; } # Ok(()) } ``` -------------------------------- ### Clear color image with ClearColorValue::BLACK_ALPHA_ZERO Source: https://github.com/attackgoat/screen-13/blob/main/guide/src/usage.md Use graph.clear_color_image to clear an image to a specified color. The example uses ClearColorValue::BLACK_ALPHA_ZERO. ```rust # use vk_graph::Graph; # use vk_graph::cmd::ClearColorValue; # use vk_graph::node::ImageNode; # use std::sync::Arc; # fn test( # graph: &mut Graph, # image: ImageNode, # ) { graph.clear_color_image(image, ClearColorValue::BLACK_ALPHA_ZERO); # } ``` -------------------------------- ### Typical flow: stage, upload, blit, clear, copy back, fill Source: https://github.com/attackgoat/screen-13/blob/main/guide/src/cmd.md Shows the common pattern of creating a staging buffer, uploading data to an image, blitting to a mip preview, clearing it, copying back to a readback buffer, and filling a region. Uses built-in commands like update_buffer, copy_buffer_to_image, blit_image, clear_color_image, copy_image_to_buffer, and fill_buffer. ```rust # use vk_graph::Graph; # use vk_graph::driver::DriverError; # use vk_graph::driver::ash::vk; # use vk_graph::driver::buffer::{Buffer, BufferInfo}; # use vk_graph::driver::device::{Device, DeviceInfo}; # use vk_graph::driver::image::{Image, ImageInfo}; # fn main() -> Result<(), DriverError> { # let device = Device::create(DeviceInfo::default())?; let mut graph = Graph::default(); let staging = Buffer::create( &device, BufferInfo::host_mem( 256 * 256 * 4, vk::BufferUsageFlags::TRANSFER_SRC | vk::BufferUsageFlags::TRANSFER_DST, ), )?; let upload_image = Image::create( &device, ImageInfo::image_2d( 256, 256, vk::Format::R8G8B8A8_UNORM, vk::ImageUsageFlags::TRANSFER_DST | vk::ImageUsageFlags::TRANSFER_SRC | vk::ImageUsageFlags::SAMPLED, ), )?; let mip_preview = Image::create( &device, ImageInfo::image_2d( 128, 128, vk::Format::R8G8B8A8_UNORM, vk::ImageUsageFlags::TRANSFER_DST | vk::ImageUsageFlags::SAMPLED, ), )?; let readback = Buffer::create( &device, BufferInfo::host_mem( 128 * 128 * 4, vk::BufferUsageFlags::TRANSFER_DST, ), )?; let staging = graph.bind_resource(staging); let upload_image = graph.bind_resource(upload_image); let mip_preview = graph.bind_resource(mip_preview); let readback = graph.bind_resource(readback); graph .update_buffer(staging, 0, [0xff; 64]) .copy_buffer_to_image(staging, upload_image) .blit_image(upload_image, mip_preview, vk::Filter::LINEAR) .clear_color_image(mip_preview, [0.1, 0.2, 0.3, 1.0]) .copy_image_to_buffer(mip_preview, readback) .fill_buffer(readback, 0..64, 0); # Ok(()) } ``` -------------------------------- ### Create a Device with WindowBuilder and run a window Source: https://github.com/attackgoat/screen-13/blob/main/guide/src/usage_device.md Uses WindowBuilder to create a window and access the Device before and during the run loop. The window.device is available before run, and frame.device is available during each frame. ```rust # use vk_graph::driver::device::Device; # use vk_graph_window::WindowError; # fn test() -> Result<(), WindowError> { use vk_graph_window::WindowBuilder; let window = WindowBuilder::default().build()?; // Before run let _: &Device = &window.device; window.run(|frame| { // During any frame let _: &Device = frame.device; })?; # Ok(()) } ``` -------------------------------- ### Creating and using buffers with BufferInfo and BufferInfoBuilder Source: https://github.com/attackgoat/screen-13/blob/main/guide/src/resource_buffer.md Shows multiple ways to create BufferInfo, use the builder pattern, create buffers from slices, copy data, and inspect buffer properties. Includes hidden imports and test wrapper. ```rust # use vk_graph::Graph; # use vk_graph::driver::{DriverError, ash::vk, device::Device}; # use vk_graph::driver::buffer::{Buffer, BufferInfo, BufferInfoBuilder}; # fn test( # device: &Device, # ) -> Result<(), DriverError> { let size = 1_024; let usage = vk::BufferUsageFlags::STORAGE_BUFFER; // Create buffer info multiple ways: let info = BufferInfo { alignment: 1, alloc_dedicated: false, host_readable: false, host_writable: false, sharing_mode: vk::SharingMode::EXCLUSIVE, size, usage, }; let device_mem = BufferInfo::device_mem(size, usage); let host_mem = BufferInfo::host_mem(size, usage); assert_eq!(info, device_mem); assert_ne!(info, host_mem); // Builder pattern let same_info = BufferInfoBuilder::default() .size(size) .usage(usage); // Info built from other info let more_info = host_mem .into_builder() .usage(usage | vk::BufferUsageFlags::INDIRECT_BUFFER) .build(); // There is a helper function for creating buffers from a slice let data = [1u8, 2, 3, 4]; let buffer = Buffer::create_from_slice(device, usage, &data)?; // This is equivalent to: let mut buffer = Buffer::create(device, host_mem)?; buffer.copy_from_slice(0, &data); // Or use the std copy_from_slice (it panics if size != range) let mut buffer = Buffer::create(device, host_mem)?; buffer.mapped_slice_mut().copy_from_slice(&data); // The provided fields are helpful: assert_eq!(buffer.device, *device); assert_eq!(buffer.info, host_mem); assert_ne!(buffer.handle, vk::Buffer::null()); // Buffer "subresources" are just ranges of that buffer let my_subresource = 0..size; # Ok(()) } ``` -------------------------------- ### GLSL compute shader for clearing an image (clear_image.glsl) Source: https://github.com/attackgoat/screen-13/blob/main/guide/src/pipeline_sync.md GLSL compute shader that writes zero to an image at binding 42. Used with the Rust examples that bind a compute pipeline and dispatch a 32x32 grid. ```glsl // clear_image.glsl #version 460 core #pragma shader_stage(compute) layout(binding = 42, rgba8) writeonly uniform image2D dstImage; void main() { imageStore( dstImage, ivec2(gl_GlobalInvocationID.x, gl_GlobalInvocationID.y), vec4(0) ); } ``` -------------------------------- ### Disable CPU thermal throttling for consistent profiling Source: https://github.com/attackgoat/screen-13/blob/main/guide/src/usage_debugging.md On Intel Linux machines, set the min_perf_pct to 100 to disable CPU thermal throttling, which helps get consistent profiling results. Requires sudo. ```bash echo 100 | sudo tee /sys/devices/system/cpu/intel_pstate/min_perf_pct ``` -------------------------------- ### Graph::builder() chainable helpers with build() Source: https://github.com/attackgoat/screen-13/blob/main/guide/src/cmd.md Use Graph::builder() to chain whole-resource helpers like update_buffer and copy_buffer_to_image, then call build() to finalize. The example shows updating a buffer with data and copying it to an image. ```rust # use vk_graph::Graph; # use vk_graph::driver::ash::vk; # use vk_graph::node::{BufferNode, ImageNode}; # fn test(buffer: BufferNode, image: ImageNode) { let graph = Graph::builder() .update_buffer(buffer, 0, [1, 2, 3, 4]) .copy_buffer_to_image(buffer, image) .build(); # } ``` -------------------------------- ### Check device extension support for ray tracing and synchronization2 Source: https://github.com/attackgoat/screen-13/blob/main/README.md Shows how to query the physical device for optional Vulkan extensions. The ray tracing extension exposes properties like max_ray_recursion_depth, while synchronization2 is a boolean flag. ```rust if let Some(ray_tracing) = &device.physical.vk_khr_ray_tracing_pipeline { println!("max recursion depth: {}", ray_tracing.properties.max_ray_recursion_depth); } if device.physical.vk_khr_synchronization2 { println!("synchronization2 is available"); } ``` -------------------------------- ### Create a Device from native ash types Source: https://github.com/attackgoat/screen-13/blob/main/guide/src/usage_device.md Shows how to wrap native ash types (Entry, Instance, PhysicalDevice) into vk-graph types and create an ash::Device via a custom callback, then create a vk-graph Device from the native device. Useful for OpenXR or other external Vulkan creation. ```rust # use vk_graph::Graph; # use vk_graph::driver::DriverError; # use vk_graph::driver::ash::{self, vk}; # use vk_graph::driver::device::Device; # use vk_graph::driver::instance::Instance; # use vk_graph::driver::physical_device::PhysicalDevice; # fn test() -> Result<(), DriverError> { // Native ash types from somewhere else let entry: ash::Entry = todo!(); let instance: vk::Instance = todo!(); let physical_device: vk::PhysicalDevice = todo!(); // vk-graph types let instance = Instance::try_from_entry(entry, instance)?; let physical_device = unsafe { PhysicalDevice::try_from_ash(&instance, physical_device) }?; // Use our PhysicalDevice to create a native ash::Device (OpenXR requires this) let device: ash::Device = unsafe { physical_device .create_ash_device(|create_info| { // Somewhere else also provides the logical device! let device: vk::Device = todo!(); let device: ash::Device = unsafe { ash::Device::load(instance.fp_v1_0(), device) }; Ok(device) }) }.unwrap(); // Create a Device from their native stuff let device = unsafe { Device::try_from_ash(device, physical_device) }?; # Ok(()) } ``` -------------------------------- ### Push constants with ComputeCommandRef::push_constants Source: https://github.com/attackgoat/screen-13/blob/main/guide/src/cmd_compute.md Use ComputeCommandRef::push_constants for small, frequently changing values such as frame indices or dispatch parameters. This example binds a compute pipeline and issues a dispatch with push constants, showing the minimal command recording pattern. ```rust # use vk_graph::Graph; # use vk_graph::driver::DriverError; # use vk_graph::driver::device::{Device, DeviceInfo}; # use vk_graph::driver::compute::{ComputePipeline, ComputePipelineInfo}; # use vk_graph::driver::shader::Shader; # fn main() -> Result<(), DriverError> { # let device = Device::create(DeviceInfo::default())?; # let pipeline = ComputePipeline::create( # &device, # ComputePipelineInfo::default(), # Shader::new_compute([0u8; 4].as_slice()), # )?; # let mut graph = Graph::default(); graph .begin_cmd() .bind_pipeline(&pipeline) .record_cmd(move |cmd| { cmd.push_constants(0, &[42]) .dispatch(1, 1, 1); }); # Ok(()) } ``` -------------------------------- ### Push constants with RayTracingCommandRef::push_constants Source: https://github.com/attackgoat/screen-13/blob/main/guide/src/cmd_ray_trace.md Use RayTracingCommandRef::push_constants to pass small ray tracing state such as frame counters or camera parameters. The example records a command that binds a ray tracing pipeline and pushes a constant value (42) before tracing rays with default address regions. ```rust # use vk_graph::driver::{ash::vk, DriverError}; # use vk_graph::driver::device::{Device, DeviceInfo}; # use vk_graph::driver::image::{Image, ImageInfo}; # use vk_graph::driver::ray_tracing::{RayTracingPipeline, RayTracingPipelineInfo, RayTracingShaderGroup}; # use vk_graph::driver::shader::Shader; # use vk_graph::Graph; # fn main() -> Result<(), DriverError> { # let device = Device::create(DeviceInfo::default())?; # let pipeline = RayTracingPipeline::create( # &device, # RayTracingPipelineInfo::default(), # [Shader::new_ray_gen([0u8; 4].as_slice())], # [RayTracingShaderGroup::new_general(0)], # )?; # let output = Image::create( # &device, # ImageInfo::image_2d( # 1280, 720, vk::Format::R16G16B16A16_SFLOAT, vk::ImageUsageFlags::STORAGE, ), )?; # let mut graph = Graph::default(); # let output = graph.bind_resource(output); graph .begin_cmd() .bind_pipeline(&pipeline) .record_cmd(move |cmd| { cmd.push_constants(0, &[42]) .trace_rays( &vk::StridedDeviceAddressRegionKHR::default(), &vk::StridedDeviceAddressRegionKHR::default(), &vk::StridedDeviceAddressRegionKHR::default(), &vk::StridedDeviceAddressRegionKHR::default(), 1280, 720, 1, ); }); # Ok(()) } ``` -------------------------------- ### Create buffer and image from Info structs Source: https://github.com/attackgoat/screen-13/blob/main/guide/src/usage.md Shows creating a buffer and an image from their respective Info structs (BufferInfo::device_mem and ImageInfo::image_2d). The buffer uses TRANSFER_SRC usage, the image uses SAMPLED | TRANSFER_DST usage and R8G8B8A8_UNORM format. ```rust # use vk_graph::Graph; # use vk_graph::driver::{DriverError, ash::vk, device::Device, sync::AccessType}; # use vk_graph::driver::buffer::{Buffer, BufferInfo}; # use vk_graph::driver::image::{Image, ImageInfo}; # fn test( # device: &Device, # ) -> Result<(), DriverError> { let usage = vk::BufferUsageFlags::TRANSFER_SRC; let buffer_info = BufferInfo::device_mem(320 * 200 * 4, usage); let buffer = Buffer::create(device, buffer_info)?; let usage = vk::ImageUsageFlags::SAMPLED | vk::ImageUsageFlags::TRANSFER_DST; let image_info = ImageInfo::image_2d(320, 200, vk::Format::R8G8B8A8_UNORM, usage); let image = Image::create(device, image_info)?; # Ok(()) } ``` -------------------------------- ### Create and bind compute pipeline (Rust) Source: https://github.com/attackgoat/screen-13/blob/main/guide/src/usage.md Creates a compute pipeline from SPIR-V bytes, binds it, sets shader resource access, and dispatches a 320x200x1 grid. ```rust # macro_rules! include_bytes { ($path:expr) => { [0u8] }; } # use vk_graph::Graph; # use vk_graph::driver::{DriverError, device::Device, sync::AccessType}; # use vk_graph::driver::compute::{ComputePipeline, ComputePipelineInfo}; # use vk_graph::node::ImageNode; # fn test( # graph: &mut Graph, # device: &Device, # image: ImageNode, # ) -> Result<(), DriverError> { let pipeline = ComputePipeline::create( device, ComputePipelineInfo::default(), include_bytes!("compute.spv").as_slice(), )?; graph .begin_cmd() .bind_pipeline(&pipeline) .shader_resource_access(0, image, AccessType::ComputeShaderWrite) .record_cmd(|cmd| { cmd.dispatch(320, 200, 1); }); # Ok(()) } ``` -------------------------------- ### build_acceleration_structures (direct) Source: https://github.com/attackgoat/screen-13/blob/main/guide/src/cmd_ray_trace.md Records a direct acceleration structure build command. Takes build geometry info and ranges for each geometry. ```APIDOC ## build_acceleration_structures (direct) ### Description Records a direct acceleration structure build command. Takes build geometry info and ranges for each geometry. ### Method Command ### Command `cmd.build_acceleration_structures(&infos, &[&ranges])` ### Parameters - `infos` (array of `AccelerationStructureBuildGeometryInfo`) - Required - Build geometry info for each build. - `ranges` (array of `&[vk::AccelerationStructureBuildRangeInfoKHR]`) - Required - One range slice per build and one range per geometry. ### Safety Unsafe. Caller must guarantee valid input contents, allocation sizes/alignment, and lifetimes. ### Example ```rust let geometries = [AccelerationStructureGeometry::opaque( AccelerationStructureGeometryData::triangles( 0, vk::IndexType::NONE_KHR, 2, 0, cmd.resource(vertices).device_address(), vk::Format::R32G32B32_SFLOAT, 12, ), )]; let infos = [AccelerationStructureBuildGeometryInfo::build( vk::AccelerationStructureTypeKHR::BOTTOM_LEVEL, vk::BuildAccelerationStructureFlagsKHR::ALLOW_UPDATE, blas, &geometries, scratch_addr, )]; let ranges = [vk::AccelerationStructureBuildRangeInfoKHR { primitive_count: 1, ..Default::default() }]; unsafe { cmd.build_acceleration_structures(&infos, &[&ranges]); } ``` ``` -------------------------------- ### Touch pak.toml to trigger build script re-pack Source: https://github.com/attackgoat/screen-13/blob/main/examples/shader-toy/README.md Run this command to force the build script to re-scan the glob in pak.toml and pack newly added files. After building, new files will be packed and bindings generated in the Rust code. ```bash touch res/pak.toml ```