Switch branches/tags
Nothing to show
Find file Copy path
736d3fb Oct 28, 2018
2 contributors

Users who have contributed to this file

@rukai @tomaka
68 lines (54 sloc) 2.56 KB
// Copyright (c) 2017 The vulkano developers
// Licensed under the Apache License, Version 2.0
//> or the MIT
// license <LICENSE-MIT or>,
// at your option. All files in the project carrying such
// notice may not be copied, modified, or distributed except
// according to those terms.
//! This example contains the source code of the first part of the guide at
//! It is not commented, as the explanations can be found in the guide itself.
extern crate vulkano;
use vulkano::buffer::BufferUsage;
use vulkano::buffer::CpuAccessibleBuffer;
use vulkano::command_buffer::AutoCommandBufferBuilder;
use vulkano::command_buffer::CommandBuffer;
use vulkano::device::Device;
use vulkano::device::DeviceExtensions;
use vulkano::device::Features;
use vulkano::instance::Instance;
use vulkano::instance::InstanceExtensions;
use vulkano::instance::PhysicalDevice;
use vulkano::sync::GpuFuture;
fn main() {
// Initialization
let instance = Instance::new(None, &InstanceExtensions::none(), None)
.expect("failed to create instance");
let physical = PhysicalDevice::enumerate(&instance).next().expect("no device available");
// Device creation
let queue_family = physical.queue_families()
.find(|&q| q.supports_graphics())
.expect("couldn't find a graphical queue family");
let (device, mut queues) = {
Device::new(physical, &Features::none(), &DeviceExtensions::none(),
[(queue_family, 0.5)].iter().cloned()).expect("failed to create device")
let queue =;
// Example operation
let source_content = 0 .. 64;
let source = CpuAccessibleBuffer::from_iter(device.clone(), BufferUsage::all(),
source_content).expect("failed to create buffer");
let dest_content = (0 .. 64).map(|_| 0);
let dest = CpuAccessibleBuffer::from_iter(device.clone(), BufferUsage::all(),
dest_content).expect("failed to create buffer");
let command_buffer = AutoCommandBufferBuilder::new(device.clone(),
.copy_buffer(source.clone(), dest.clone()).unwrap()
let finished = command_buffer.execute(queue.clone()).unwrap();
let src_content =;
let dest_content =;
assert_eq!(&*src_content, &*dest_content);