Restructure examples

This commit is contained in:
maik klein 2016-12-25 14:38:26 +01:00
parent 40576acb95
commit 32f74cc619
17 changed files with 1115 additions and 1516 deletions

View file

@ -1,5 +1,5 @@
[root] [root]
name = "example" name = "examples"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"ash 0.2.0", "ash 0.2.0",

View file

@ -1,9 +1,9 @@
[package] [package]
name = "example" name = "examples"
version = "0.1.0" version = "0.1.0"
authors = ["maik klein <maikklein@googlemail.com>"] authors = ["maik klein <maikklein@googlemail.com>"]
[dependencies] [dependencies]
glfw = "0.9.1" glfw = "0.9.1"
winit = "0.5.6" winit = "0.5.6"
ash = { version = "*", path = "../../"} ash = { version = "*", path = "../"}

View file

@ -0,0 +1,516 @@
#![allow(dead_code)]
#[macro_use]
extern crate ash;
extern crate winit;
extern crate examples;
use ash::vk;
use std::default::Default;
use ash::entry::Entry;
use ash::instance::Instance;
use ash::extensions::{Swapchain, XlibSurface, Surface, DebugReport};
use ash::device::Device;
use std::ptr;
use std::ffi::{CStr, CString};
use std::mem;
use std::path::Path;
use std::fs::File;
use std::io::Read;
use winit::os::unix::WindowExt;
use examples::*;
#[derive(Clone, Debug, Copy)]
struct Vertex {
pos: [f32; 4],
color: [f32; 4],
}
fn main() {
unsafe {
let base = ExampleBase::new(1920, 1080);
let fence_create_info = vk::FenceCreateInfo {
s_type: vk::StructureType::FenceCreateInfo,
p_next: ptr::null(),
flags: vk::FenceCreateFlags::empty(),
};
let command_buffer_begin_info = vk::CommandBufferBeginInfo {
s_type: vk::StructureType::CommandBufferBeginInfo,
p_next: ptr::null(),
p_inheritance_info: ptr::null(),
flags: vk::COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
};
let renderpass_attachments =
[vk::AttachmentDescription {
format: base.surface_format.format,
flags: vk::AttachmentDescriptionFlags::empty(),
samples: vk::SAMPLE_COUNT_1_BIT,
load_op: vk::AttachmentLoadOp::Clear,
store_op: vk::AttachmentStoreOp::Store,
stencil_load_op: vk::AttachmentLoadOp::DontCare,
stencil_store_op: vk::AttachmentStoreOp::DontCare,
initial_layout: vk::ImageLayout::Undefined,
final_layout: vk::ImageLayout::PresentSrcKhr,
},
vk::AttachmentDescription {
format: vk::Format::D16Unorm,
flags: vk::AttachmentDescriptionFlags::empty(),
samples: vk::SAMPLE_COUNT_1_BIT,
load_op: vk::AttachmentLoadOp::Clear,
store_op: vk::AttachmentStoreOp::DontCare,
stencil_load_op: vk::AttachmentLoadOp::DontCare,
stencil_store_op: vk::AttachmentStoreOp::DontCare,
initial_layout: vk::ImageLayout::DepthStencilAttachmentOptimal,
final_layout: vk::ImageLayout::DepthStencilAttachmentOptimal,
}];
let color_attachment_ref = vk::AttachmentReference {
attachment: 0,
layout: vk::ImageLayout::ColorAttachmentOptimal,
};
let depth_attachment_ref = vk::AttachmentReference {
attachment: 1,
layout: vk::ImageLayout::DepthStencilAttachmentOptimal,
};
let dependency = vk::SubpassDependency {
dependency_flags: Default::default(),
src_subpass: vk::VK_SUBPASS_EXTERNAL,
dst_subpass: Default::default(),
src_stage_mask: vk::PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
src_access_mask: Default::default(),
dst_access_mask: vk::ACCESS_COLOR_ATTACHMENT_READ_BIT |
vk::ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
dst_stage_mask: vk::PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
};
let subpass = vk::SubpassDescription {
color_attachment_count: 1,
p_color_attachments: &color_attachment_ref,
p_depth_stencil_attachment: &depth_attachment_ref,
// TODO: Why is there no wrapper?
flags: Default::default(),
pipeline_bind_point: vk::PipelineBindPoint::Graphics,
input_attachment_count: 0,
p_input_attachments: ptr::null(),
p_resolve_attachments: ptr::null(),
preserve_attachment_count: 0,
p_preserve_attachments: ptr::null(),
};
let renderpass_create_info = vk::RenderPassCreateInfo {
s_type: vk::StructureType::RenderPassCreateInfo,
flags: Default::default(),
p_next: ptr::null(),
attachment_count: renderpass_attachments.len() as u32,
p_attachments: renderpass_attachments.as_ptr(),
subpass_count: 1,
p_subpasses: &subpass,
dependency_count: 1,
p_dependencies: &dependency,
};
let renderpass = base.device.create_render_pass(&renderpass_create_info).unwrap();
let framebuffers: Vec<vk::Framebuffer> = base.present_image_views
.iter()
.map(|&present_image_view| {
let framebuffer_attachments = [present_image_view, base.depth_image_view];
let frame_buffer_create_info = vk::FramebufferCreateInfo {
s_type: vk::StructureType::FramebufferCreateInfo,
p_next: ptr::null(),
flags: Default::default(),
render_pass: renderpass,
attachment_count: framebuffer_attachments.len() as u32,
p_attachments: framebuffer_attachments.as_ptr(),
width: base.surface_resolution.width,
height: base.surface_resolution.height,
layers: 1,
};
base.device.create_framebuffer(&frame_buffer_create_info).unwrap()
})
.collect();
let index_buffer_data = [0u32, 1, 2];
let index_buffer_info = vk::BufferCreateInfo {
s_type: vk::StructureType::BufferCreateInfo,
p_next: ptr::null(),
flags: vk::BufferCreateFlags::empty(),
size: std::mem::size_of_val(&index_buffer_data) as u64,
usage: vk::BUFFER_USAGE_INDEX_BUFFER_BIT,
sharing_mode: vk::SharingMode::Exclusive,
queue_family_index_count: 0,
p_queue_family_indices: ptr::null(),
};
let index_buffer = base.device.create_buffer(&index_buffer_info).unwrap();
let index_buffer_memory_req = base.device.get_buffer_memory_requirements(index_buffer);
let index_buffer_memory_index = find_memorytype_index(&index_buffer_memory_req,
&base.device_memory_properties,
vk::MEMORY_PROPERTY_HOST_VISIBLE_BIT)
.expect("Unable to find suitable memorytype for the index buffer.");
let index_allocate_info = vk::MemoryAllocateInfo {
s_type: vk::StructureType::MemoryAllocateInfo,
p_next: ptr::null(),
allocation_size: index_buffer_memory_req.size,
memory_type_index: index_buffer_memory_index,
};
let index_buffer_memory = base.device.allocate_memory(&index_allocate_info).unwrap();
let index_slice = base.device
.map_memory::<u32>(index_buffer_memory,
0,
index_buffer_info.size,
vk::MemoryMapFlags::empty())
.unwrap();
index_slice.copy_from_slice(&index_buffer_data);
base.device.unmap_memory(index_buffer_memory);
base.device.bind_buffer_memory(index_buffer, index_buffer_memory, 0).unwrap();
let vertex_input_buffer_info = vk::BufferCreateInfo {
s_type: vk::StructureType::BufferCreateInfo,
p_next: ptr::null(),
flags: vk::BufferCreateFlags::empty(),
size: 3 * std::mem::size_of::<Vertex>() as u64,
usage: vk::BUFFER_USAGE_VERTEX_BUFFER_BIT,
sharing_mode: vk::SharingMode::Exclusive,
queue_family_index_count: 0,
p_queue_family_indices: ptr::null(),
};
let vertex_input_buffer = base.device.create_buffer(&vertex_input_buffer_info).unwrap();
let vertex_input_buffer_memory_req = base.device
.get_buffer_memory_requirements(vertex_input_buffer);
let vertex_input_buffer_memory_index =
find_memorytype_index(&vertex_input_buffer_memory_req,
&base.device_memory_properties,
vk::MEMORY_PROPERTY_HOST_VISIBLE_BIT)
.expect("Unable to find suitable memorytype for the vertex buffer.");
let vertex_buffer_allocate_info = vk::MemoryAllocateInfo {
s_type: vk::StructureType::MemoryAllocateInfo,
p_next: ptr::null(),
allocation_size: vertex_input_buffer_memory_req.size,
memory_type_index: vertex_input_buffer_memory_index,
};
let vertex_input_buffer_memory = base.device
.allocate_memory(&vertex_buffer_allocate_info)
.unwrap();
let vertices = [Vertex {
pos: [-1.0, 1.0, 0.0, 1.0],
color: [0.0, 1.0, 0.0, 1.0],
},
Vertex {
pos: [1.0, 1.0, 0.0, 1.0],
color: [0.0, 0.0, 1.0, 1.0],
},
Vertex {
pos: [0.0, -1.0, 0.0, 1.0],
color: [1.0, 0.0, 0.0, 1.0],
}];
let slice = base.device
.map_memory::<Vertex>(vertex_input_buffer_memory,
0,
vertex_input_buffer_info.size,
vk::MemoryMapFlags::empty())
.unwrap();
slice.copy_from_slice(&vertices);
base.device.unmap_memory(vertex_input_buffer_memory);
base.device.bind_buffer_memory(vertex_input_buffer, vertex_input_buffer_memory, 0).unwrap();
let vertex_spv_file = File::open(Path::new("shader/vert.spv"))
.expect("Could not find vert.spv.");
let frag_spv_file = File::open(Path::new("shader/frag.spv"))
.expect("Could not find frag.spv.");
let vertex_bytes: Vec<u8> = vertex_spv_file.bytes().filter_map(|byte| byte.ok()).collect();
let vertex_shader_info = vk::ShaderModuleCreateInfo {
s_type: vk::StructureType::ShaderModuleCreateInfo,
p_next: ptr::null(),
flags: Default::default(),
code_size: vertex_bytes.len(),
p_code: vertex_bytes.as_ptr() as *const u32,
};
let frag_bytes: Vec<u8> = frag_spv_file.bytes().filter_map(|byte| byte.ok()).collect();
let frag_shader_info = vk::ShaderModuleCreateInfo {
s_type: vk::StructureType::ShaderModuleCreateInfo,
p_next: ptr::null(),
flags: Default::default(),
code_size: frag_bytes.len(),
p_code: frag_bytes.as_ptr() as *const u32,
};
let vertex_shader_module = base.device
.create_shader_module(&vertex_shader_info)
.expect("Vertex shader module error");
let fragment_shader_module = base.device
.create_shader_module(&frag_shader_info)
.expect("Fragment shader module error");
let layout_create_info = vk::PipelineLayoutCreateInfo {
s_type: vk::StructureType::PipelineLayoutCreateInfo,
p_next: ptr::null(),
flags: Default::default(),
set_layout_count: 0,
p_set_layouts: ptr::null(),
push_constant_range_count: 0,
p_push_constant_ranges: ptr::null(),
};
let pipeline_layout = base.device.create_pipeline_layout(&layout_create_info).unwrap();
let shader_entry_name = CString::new("main").unwrap();
let shader_stage_create_infos =
[vk::PipelineShaderStageCreateInfo {
s_type: vk::StructureType::PipelineShaderStageCreateInfo,
p_next: ptr::null(),
flags: Default::default(),
module: vertex_shader_module,
p_name: shader_entry_name.as_ptr(),
p_specialization_info: ptr::null(),
stage: vk::SHADER_STAGE_VERTEX_BIT,
},
vk::PipelineShaderStageCreateInfo {
s_type: vk::StructureType::PipelineShaderStageCreateInfo,
p_next: ptr::null(),
flags: Default::default(),
module: fragment_shader_module,
p_name: shader_entry_name.as_ptr(),
p_specialization_info: ptr::null(),
stage: vk::SHADER_STAGE_FRAGMENT_BIT,
}];
let vertex_input_binding_descriptions = [vk::VertexInputBindingDescription {
binding: 0,
stride: mem::size_of::<Vertex>() as u32,
input_rate: vk::VertexInputRate::Vertex,
}];
let vertex_input_attribute_descriptions = [vk::VertexInputAttributeDescription {
location: 0,
binding: 0,
format: vk::Format::R32g32b32a32Sfloat,
offset: offset_of!(Vertex, pos) as u32,
},
vk::VertexInputAttributeDescription {
location: 1,
binding: 0,
format: vk::Format::R32g32b32a32Sfloat,
offset: offset_of!(Vertex, color) as u32,
}];
let vertex_input_state_info = vk::PipelineVertexInputStateCreateInfo {
s_type: vk::StructureType::PipelineVertexInputStateCreateInfo,
p_next: ptr::null(),
flags: Default::default(),
vertex_attribute_description_count: vertex_input_attribute_descriptions.len() as u32,
p_vertex_attribute_descriptions: vertex_input_attribute_descriptions.as_ptr(),
vertex_binding_description_count: vertex_input_binding_descriptions.len() as u32,
p_vertex_binding_descriptions: vertex_input_binding_descriptions.as_ptr(),
};
let vertex_input_assembly_state_info = vk::PipelineInputAssemblyStateCreateInfo {
s_type: vk::StructureType::PipelineInputAssemblyStateCreateInfo,
flags: Default::default(),
p_next: ptr::null(),
primitive_restart_enable: 0,
topology: vk::PrimitiveTopology::TriangleList,
};
let viewports = [vk::Viewport {
x: 0.0,
y: 0.0,
width: base.surface_resolution.width as f32,
height: base.surface_resolution.height as f32,
min_depth: 0.0,
max_depth: 1.0,
}];
let scissors = [vk::Rect2D {
offset: vk::Offset2D { x: 0, y: 0 },
extent: base.surface_resolution.clone(),
}];
let viewport_state_info = vk::PipelineViewportStateCreateInfo {
s_type: vk::StructureType::PipelineViewportStateCreateInfo,
p_next: ptr::null(),
flags: Default::default(),
scissor_count: scissors.len() as u32,
p_scissors: scissors.as_ptr(),
viewport_count: viewports.len() as u32,
p_viewports: viewports.as_ptr(),
};
let rasterization_info = vk::PipelineRasterizationStateCreateInfo {
s_type: vk::StructureType::PipelineRasterizationStateCreateInfo,
p_next: ptr::null(),
flags: Default::default(),
cull_mode: vk::CULL_MODE_NONE,
depth_bias_clamp: 0.0,
depth_bias_constant_factor: 0.0,
depth_bias_enable: 0,
depth_bias_slope_factor: 0.0,
depth_clamp_enable: 0,
front_face: vk::FrontFace::CounterClockwise,
line_width: 1.0,
polygon_mode: vk::PolygonMode::Fill,
rasterizer_discard_enable: 0,
};
let multisample_state_info = vk::PipelineMultisampleStateCreateInfo {
s_type: vk::StructureType::PipelineMultisampleStateCreateInfo,
flags: Default::default(),
p_next: ptr::null(),
rasterization_samples: vk::SAMPLE_COUNT_1_BIT,
sample_shading_enable: 0,
min_sample_shading: 0.0,
p_sample_mask: ptr::null(),
alpha_to_one_enable: 0,
alpha_to_coverage_enable: 0,
};
let noop_stencil_state = vk::StencilOpState {
fail_op: vk::StencilOp::Keep,
pass_op: vk::StencilOp::Keep,
depth_fail_op: vk::StencilOp::Keep,
compare_op: vk::CompareOp::Always,
compare_mask: 0,
write_mask: 0,
reference: 0,
};
let depth_state_info = vk::PipelineDepthStencilStateCreateInfo {
s_type: vk::StructureType::PipelineDepthStencilStateCreateInfo,
p_next: ptr::null(),
flags: Default::default(),
depth_test_enable: 1,
depth_write_enable: 1,
depth_compare_op: vk::CompareOp::LessOrEqual,
depth_bounds_test_enable: 0,
stencil_test_enable: 0,
front: noop_stencil_state.clone(),
back: noop_stencil_state.clone(),
max_depth_bounds: 1.0,
min_depth_bounds: 0.0,
};
let color_blend_attachment_states = [vk::PipelineColorBlendAttachmentState {
blend_enable: 0,
src_color_blend_factor: vk::BlendFactor::SrcColor,
dst_color_blend_factor:
vk::BlendFactor::OneMinusDstColor,
color_blend_op: vk::BlendOp::Add,
src_alpha_blend_factor: vk::BlendFactor::Zero,
dst_alpha_blend_factor: vk::BlendFactor::Zero,
alpha_blend_op: vk::BlendOp::Add,
color_write_mask: vk::ColorComponentFlags::all(),
}];
let color_blend_state = vk::PipelineColorBlendStateCreateInfo {
s_type: vk::StructureType::PipelineColorBlendStateCreateInfo,
p_next: ptr::null(),
flags: Default::default(),
logic_op_enable: 0,
logic_op: vk::LogicOp::Clear,
attachment_count: color_blend_attachment_states.len() as u32,
p_attachments: color_blend_attachment_states.as_ptr(),
blend_constants: [0.0, 0.0, 0.0, 0.0],
};
let dynamic_state = [vk::DynamicState::Viewport, vk::DynamicState::Scissor];
let dynamic_state_info = vk::PipelineDynamicStateCreateInfo {
s_type: vk::StructureType::PipelineDynamicStateCreateInfo,
p_next: ptr::null(),
flags: Default::default(),
dynamic_state_count: dynamic_state.len() as u32,
p_dynamic_states: dynamic_state.as_ptr(),
};
let graphic_pipeline_info = vk::GraphicsPipelineCreateInfo {
s_type: vk::StructureType::GraphicsPipelineCreateInfo,
p_next: ptr::null(),
flags: vk::PipelineCreateFlags::empty(),
stage_count: shader_stage_create_infos.len() as u32,
p_stages: shader_stage_create_infos.as_ptr(),
p_vertex_input_state: &vertex_input_state_info,
p_input_assembly_state: &vertex_input_assembly_state_info,
p_tessellation_state: ptr::null(),
p_viewport_state: &viewport_state_info,
p_rasterization_state: &rasterization_info,
p_multisample_state: &multisample_state_info,
p_depth_stencil_state: &depth_state_info,
p_color_blend_state: &color_blend_state,
p_dynamic_state: &dynamic_state_info,
layout: pipeline_layout,
render_pass: renderpass,
subpass: 0,
base_pipeline_handle: vk::Pipeline::null(),
base_pipeline_index: 0,
};
let graphics_pipelines = base.device
.create_graphics_pipelines(vk::PipelineCache::null(), &[graphic_pipeline_info])
.unwrap();
let graphic_pipeline = graphics_pipelines[0];
base.render_loop(|| {
let present_index = base.swapchain_loader
.acquire_next_image_khr(base.swapchain,
std::u64::MAX,
base.present_complete_semaphore,
vk::Fence::null())
.unwrap();
record_submit_commandbuffer(&base.device,
base.draw_command_buffer,
base.present_queue,
&[vk::PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT],
&[base.present_complete_semaphore],
&[base.rendering_complete_semaphore],
|device, draw_command_buffer| {
let clear_values =
[vk::ClearValue::new_color(vk::ClearColorValue::new_float32([0.0, 0.0, 0.0,
0.0])),
vk::ClearValue::new_depth_stencil(vk::ClearDepthStencilValue {
depth: 1.0,
stencil: 0,
})];
let render_pass_begin_info = vk::RenderPassBeginInfo {
s_type: vk::StructureType::RenderPassBeginInfo,
p_next: ptr::null(),
render_pass: renderpass,
framebuffer: framebuffers[present_index as usize],
render_area: vk::Rect2D {
offset: vk::Offset2D { x: 0, y: 0 },
extent: base.surface_resolution.clone(),
},
clear_value_count: clear_values.len() as u32,
p_clear_values: clear_values.as_ptr(),
};
device.cmd_begin_render_pass(draw_command_buffer,
&render_pass_begin_info,
vk::SubpassContents::Inline);
device.cmd_bind_pipeline(draw_command_buffer,
vk::PipelineBindPoint::Graphics,
graphic_pipeline);
device.cmd_set_viewport(draw_command_buffer, &viewports);
device.cmd_set_scissor(draw_command_buffer, &scissors);
device.cmd_bind_vertex_buffers(draw_command_buffer, &[vertex_input_buffer], &0);
device.cmd_bind_index_buffer(draw_command_buffer,
index_buffer,
0,
vk::IndexType::Uint32);
device.cmd_draw_indexed(draw_command_buffer,
index_buffer_data.len() as u32,
1,
0,
0,
1);
// Or draw without the index buffer
// device.cmd_draw(draw_command_buffer, 3, 1, 0, 0);
device.cmd_end_render_pass(draw_command_buffer);
});
let mut present_info_err = unsafe { mem::uninitialized() };
let present_info = vk::PresentInfoKHR {
s_type: vk::StructureType::PresentInfoKhr,
p_next: ptr::null(),
wait_semaphore_count: 1,
p_wait_semaphores: &base.rendering_complete_semaphore,
swapchain_count: 1,
p_swapchains: &base.swapchain,
p_image_indices: &present_index,
p_results: &mut present_info_err,
};
base.device.queue_present_khr(base.present_queue, &present_info).unwrap();
});
for pipeline in graphics_pipelines {
base.device.destroy_pipeline(pipeline);
}
base.device.destroy_pipeline_layout(pipeline_layout);
base.device.destroy_shader_module(vertex_shader_module);
base.device.destroy_shader_module(fragment_shader_module);
base.device.free_memory(index_buffer_memory);
base.device.destroy_buffer(index_buffer);
base.device.free_memory(vertex_input_buffer_memory);
base.device.destroy_buffer(vertex_input_buffer);
for framebuffer in framebuffers {
base.device.destroy_framebuffer(framebuffer);
}
base.device.destroy_render_pass(renderpass);
}
}

596
examples/src/lib.rs Normal file
View file

@ -0,0 +1,596 @@
#![allow(dead_code)]
#[macro_use]
extern crate ash;
extern crate winit;
use ash::vk;
use std::default::Default;
use ash::entry::Entry;
use ash::instance::Instance;
use ash::extensions::{Swapchain, XlibSurface, Surface, DebugReport};
use ash::device::Device;
use std::ptr;
use std::ffi::{CStr, CString};
use std::mem;
use std::path::Path;
use std::fs::File;
use std::io::Read;
use winit::os::unix::WindowExt;
use std::ops::Drop;
// Simple offset_of macro akin to C++ offsetof
#[macro_export]
macro_rules! offset_of{
($base: path, $field: ident) => {
unsafe{
let b: $base = mem::uninitialized();
(&b.$field as *const _ as isize) - (&b as *const _ as isize)
}
}
}
pub fn record_submit_commandbuffer<F: FnOnce(&Device, vk::CommandBuffer)>(device: &Device,
command_buffer: vk::CommandBuffer,
submit_queue: vk::Queue,
wait_mask: &[vk::PipelineStageFlags],
wait_semaphores: &[vk::Semaphore],
signal_semaphores: &[vk::Semaphore],
f: F) {
unsafe {
device.reset_command_buffer(command_buffer,
vk::COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT);
let command_buffer_begin_info = vk::CommandBufferBeginInfo {
s_type: vk::StructureType::CommandBufferBeginInfo,
p_next: ptr::null(),
p_inheritance_info: ptr::null(),
flags: vk::COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
};
device.begin_command_buffer(command_buffer, &command_buffer_begin_info)
.expect("Begin commandbuffer");
f(device, command_buffer);
device.end_command_buffer(command_buffer).expect("End commandbuffer");
let fence_create_info = vk::FenceCreateInfo {
s_type: vk::StructureType::FenceCreateInfo,
p_next: ptr::null(),
flags: vk::FenceCreateFlags::empty(),
};
let submit_fence = device.create_fence(&fence_create_info).unwrap();
let submit_info = vk::SubmitInfo {
s_type: vk::StructureType::SubmitInfo,
p_next: ptr::null(),
wait_semaphore_count: wait_semaphores.len() as u32,
p_wait_semaphores: wait_semaphores.as_ptr(),
p_wait_dst_stage_mask: wait_mask.as_ptr(),
command_buffer_count: 1,
p_command_buffers: &command_buffer,
signal_semaphore_count: signal_semaphores.len() as u32,
p_signal_semaphores: signal_semaphores.as_ptr(),
};
device.queue_submit(submit_queue, &[submit_info], submit_fence);
device.wait_for_fences(&[submit_fence], true, std::u64::MAX);
device.destroy_fence(submit_fence);
}
}
#[cfg(all(unix, not(target_os = "android")))]
fn create_surface(instance: &Instance,
entry: &Entry,
window: &winit::Window)
-> Result<vk::SurfaceKHR, vk::Result> {
let x11_display = window.get_xlib_display().unwrap();
let x11_window = window.get_xlib_window().unwrap();
let x11_create_info = vk::XlibSurfaceCreateInfoKHR {
s_type: vk::StructureType::XlibSurfaceCreateInfoKhr,
p_next: ptr::null(),
flags: Default::default(),
window: x11_window as vk::Window,
dpy: x11_display as *mut vk::Display,
};
let xlib_surface_loader = XlibSurface::new(&entry, &instance)
.expect("Unable to load xlib surface");
xlib_surface_loader.create_xlib_surface_khr(&x11_create_info)
}
#[cfg(all(unix, not(target_os = "android")))]
fn extension_names() -> Vec<CString> {
vec![CString::new("VK_KHR_surface").unwrap(),
CString::new("VK_KHR_xlib_surface").unwrap(),
CString::new("VK_EXT_debug_report").unwrap()]
}
#[cfg(all(windows))]
fn extension_names() -> Vec<CString> {
vec![CString::new("VK_KHR_surface").unwrap(),
CString::new("VK_KHR_win32_surface").unwrap(),
CString::new("VK_EXT_debug_report").unwrap()]
}
unsafe extern "system" fn vulkan_debug_callback(flags: vk::DebugReportFlagsEXT,
obj_type: vk::DebugReportObjectTypeEXT,
obj: u64,
loc: usize,
message: i32,
p_layer_prefix: *const i8,
p_message: *const i8,
data: *mut ())
-> u32 {
println!("{:?}", CStr::from_ptr(p_message));
1
}
pub fn find_memorytype_index(memory_req: &vk::MemoryRequirements,
memory_prop: &vk::PhysicalDeviceMemoryProperties,
flags: vk::MemoryPropertyFlags)
-> Option<u32> {
let mut memory_type_bits = memory_req.memory_type_bits;
for (index, ref memory_type) in memory_prop.memory_types.iter().enumerate() {
if (memory_type.property_flags & flags) == flags {
return Some(index as u32);
}
memory_type_bits = memory_type_bits >> 1;
}
None
}
fn resize_callback(width: u32, height: u32) {
println!("Window resized to {}x{}", width, height);
}
pub struct ExampleBase {
pub entry: Entry,
pub instance: Instance,
pub device: Device,
pub surface_loader: Surface,
pub swapchain_loader: Swapchain,
pub debug_report_loader: DebugReport,
pub window: winit::Window,
pub debug_call_back: vk::DebugReportCallbackEXT,
pub pdevice: vk::PhysicalDevice,
pub device_memory_properties: vk::PhysicalDeviceMemoryProperties,
pub queue_family_index: u32,
pub present_queue: vk::Queue,
pub surface: vk::SurfaceKHR,
pub surface_format: vk::SurfaceFormatKHR,
pub surface_resolution: vk::Extent2D,
pub swapchain: vk::SwapchainKHR,
pub present_images: Vec<vk::Image>,
pub present_image_views: Vec<vk::ImageView>,
pub pool: vk::CommandPool,
pub draw_command_buffer: vk::CommandBuffer,
pub setup_command_buffer: vk::CommandBuffer,
pub depth_image: vk::Image,
pub depth_image_view: vk::ImageView,
pub depth_image_memory: vk::DeviceMemory,
pub present_complete_semaphore: vk::Semaphore,
pub rendering_complete_semaphore: vk::Semaphore,
}
impl ExampleBase {
pub fn render_loop<F: Fn()>(&self, f: F) {
'render: loop {
for event in self.window.poll_events() {
match event {
winit::Event::KeyboardInput(_, _, Some(winit::VirtualKeyCode::Escape)) |
winit::Event::Closed => break 'render,
_ => (),
}
}
f();
}
}
pub fn new(window_width: u32, window_height: u32) -> Self {
unsafe {
let window = winit::WindowBuilder::new()
.with_title("A fantastic window!")
.with_dimensions(window_width, window_height)
.with_window_resize_callback(resize_callback)
.build()
.unwrap();
let entry = Entry::load_vulkan().unwrap();
let instance_ext_props = entry.enumerate_instance_extension_properties().unwrap();
let app_name = CString::new("VulkanTriangle").unwrap();
let raw_name = app_name.as_ptr();
let layer_names = [CString::new("VK_LAYER_LUNARG_standard_validation").unwrap()];
let layers_names_raw: Vec<*const i8> = layer_names.iter()
.map(|raw_name| raw_name.as_ptr())
.collect();
let extension_names = extension_names();
let extension_names_raw: Vec<*const i8> = extension_names.iter()
.map(|raw_name| raw_name.as_ptr())
.collect();
let appinfo = vk::ApplicationInfo {
p_application_name: raw_name,
s_type: vk::StructureType::ApplicationInfo,
p_next: ptr::null(),
application_version: 0,
p_engine_name: raw_name,
engine_version: 0,
api_version: vk_make_version!(1, 0, 36),
};
let create_info = vk::InstanceCreateInfo {
s_type: vk::StructureType::InstanceCreateInfo,
p_next: ptr::null(),
flags: Default::default(),
p_application_info: &appinfo,
pp_enabled_layer_names: layers_names_raw.as_ptr(),
enabled_layer_count: layers_names_raw.len() as u32,
pp_enabled_extension_names: extension_names_raw.as_ptr(),
enabled_extension_count: extension_names_raw.len() as u32,
};
let instance: Instance = entry.create_instance(&create_info)
.expect("Instance creation error");
let debug_info = vk::DebugReportCallbackCreateInfoEXT {
s_type: vk::StructureType::DebugReportCallbackCreateInfoExt,
p_next: ptr::null(),
flags: vk::DEBUG_REPORT_ERROR_BIT_EXT | vk::DEBUG_REPORT_WARNING_BIT_EXT |
vk::DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
pfn_callback: vulkan_debug_callback,
p_user_data: ptr::null_mut(),
};
let debug_report_loader = DebugReport::new(&entry, &instance)
.expect("Unable to load debug report");
let debug_call_back = debug_report_loader.create_debug_report_callback_ext(&debug_info)
.unwrap();
let surface = create_surface(&instance, &entry, &window).unwrap();
let pdevices = instance.enumerate_physical_devices().expect("Physical device error");
let surface_loader = Surface::new(&entry, &instance)
.expect("Unable to load the Surface extension");
let (pdevice, queue_family_index) = pdevices.iter()
.map(|pdevice| {
instance.get_physical_device_queue_family_properties(*pdevice)
.iter()
.enumerate()
.filter_map(|(index, ref info)| {
let supports_graphic_and_surface =
info.queue_flags.subset(vk::QUEUE_GRAPHICS_BIT) &&
surface_loader.get_physical_device_surface_support_khr(*pdevice,
index as u32,
surface);
match supports_graphic_and_surface {
true => Some((*pdevice, index)),
_ => None,
}
})
.nth(0)
})
.filter_map(|v| v)
.nth(0)
.expect("Couldn't find suitable device.");
let queue_family_index = queue_family_index as u32;
let device_extension_names = [CString::new("VK_KHR_swapchain").unwrap()];
let device_extension_names_raw: Vec<*const i8> = device_extension_names.iter()
.map(|raw_name| raw_name.as_ptr())
.collect();
let features =
vk::PhysicalDeviceFeatures { shader_clip_distance: 1, ..Default::default() };
let priorities = [1.0];
let queue_info = vk::DeviceQueueCreateInfo {
s_type: vk::StructureType::DeviceQueueCreateInfo,
p_next: ptr::null(),
flags: Default::default(),
queue_family_index: queue_family_index as u32,
p_queue_priorities: priorities.as_ptr(),
queue_count: priorities.len() as u32,
};
let device_create_info = vk::DeviceCreateInfo {
s_type: vk::StructureType::DeviceCreateInfo,
p_next: ptr::null(),
flags: Default::default(),
queue_create_info_count: 1,
p_queue_create_infos: &queue_info,
enabled_layer_count: 0,
pp_enabled_layer_names: ptr::null(),
enabled_extension_count: device_extension_names_raw.len() as u32,
pp_enabled_extension_names: device_extension_names_raw.as_ptr(),
p_enabled_features: &features,
};
let device: Device = instance.create_device(pdevice, &device_create_info)
.unwrap();
let present_queue = device.get_device_queue(queue_family_index as u32, 0);
let surface_formats =
surface_loader.get_physical_device_surface_formats_khr(pdevice, surface)
.unwrap();
let surface_format = surface_formats.iter()
.map(|sfmt| {
match sfmt.format {
vk::Format::Undefined => {
vk::SurfaceFormatKHR {
format: vk::Format::B8g8r8Unorm,
color_space: sfmt.color_space,
}
}
_ => sfmt.clone(),
}
})
.nth(0)
.expect("Unable to find suitable surface format.");
let surface_capabilities =
surface_loader.get_physical_device_surface_capabilities_khr(pdevice, surface)
.unwrap();
let desired_image_count = surface_capabilities.min_image_count + 1;
assert!(surface_capabilities.min_image_count <= desired_image_count &&
surface_capabilities.max_image_count >= desired_image_count,
"Image count err");
let surface_resolution = match surface_capabilities.current_extent.width {
std::u32::MAX => {
vk::Extent2D {
width: window_width,
height: window_height,
}
}
_ => surface_capabilities.current_extent,
};
let pre_transform = if surface_capabilities.supported_transforms
.subset(vk::SURFACE_TRANSFORM_IDENTITY_BIT_KHR) {
vk::SURFACE_TRANSFORM_IDENTITY_BIT_KHR
} else {
surface_capabilities.current_transform
};
let present_modes =
surface_loader.get_physical_device_surface_present_modes_khr(pdevice, surface)
.unwrap();
let present_mode = present_modes.iter()
.cloned()
.find(|&mode| mode == vk::PresentModeKHR::Mailbox)
.unwrap_or(vk::PresentModeKHR::Fifo);
let swapchain_loader = Swapchain::new(&instance, &device)
.expect("Unable to load swapchain");
let swapchain_create_info = vk::SwapchainCreateInfoKHR {
s_type: vk::StructureType::SwapchainCreateInfoKhr,
p_next: ptr::null(),
flags: Default::default(),
surface: surface,
min_image_count: desired_image_count,
image_color_space: surface_format.color_space,
image_format: surface_format.format,
image_extent: surface_resolution.clone(),
image_usage: vk::IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
image_sharing_mode: vk::SharingMode::Exclusive,
pre_transform: pre_transform,
composite_alpha: vk::COMPOSITE_ALPHA_OPAQUE_BIT_KHR,
present_mode: present_mode,
clipped: 1,
old_swapchain: vk::SwapchainKHR::null(),
image_array_layers: 1,
p_queue_family_indices: ptr::null(),
queue_family_index_count: 0,
};
let swapchain = swapchain_loader.create_swapchain_khr(&swapchain_create_info).unwrap();
let pool_create_info = vk::CommandPoolCreateInfo {
s_type: vk::StructureType::CommandPoolCreateInfo,
p_next: ptr::null(),
flags: vk::COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,
queue_family_index: queue_family_index,
};
let pool = device.create_command_pool(&pool_create_info).unwrap();
let command_buffer_allocate_info = vk::CommandBufferAllocateInfo {
s_type: vk::StructureType::CommandBufferAllocateInfo,
p_next: ptr::null(),
command_buffer_count: 2,
command_pool: pool,
level: vk::CommandBufferLevel::Primary,
};
let command_buffer_allocate_info = vk::CommandBufferAllocateInfo {
s_type: vk::StructureType::CommandBufferAllocateInfo,
p_next: ptr::null(),
command_buffer_count: 2,
command_pool: pool,
level: vk::CommandBufferLevel::Primary,
};
let command_buffers = device.allocate_command_buffers(&command_buffer_allocate_info)
.unwrap();
let setup_command_buffer = command_buffers[0];
let draw_command_buffer = command_buffers[1];
let present_images = swapchain_loader.get_swapchain_images_khr(swapchain).unwrap();
let present_image_views: Vec<vk::ImageView> = present_images.iter()
.map(|&image| {
let create_view_info = vk::ImageViewCreateInfo {
s_type: vk::StructureType::ImageViewCreateInfo,
p_next: ptr::null(),
flags: Default::default(),
view_type: vk::ImageViewType::Type2d,
format: surface_format.format,
components: vk::ComponentMapping {
r: vk::ComponentSwizzle::R,
g: vk::ComponentSwizzle::G,
b: vk::ComponentSwizzle::B,
a: vk::ComponentSwizzle::A,
},
subresource_range: vk::ImageSubresourceRange {
aspect_mask: vk::IMAGE_ASPECT_COLOR_BIT,
base_mip_level: 0,
level_count: 1,
base_array_layer: 0,
layer_count: 1,
},
image: image,
};
device.create_image_view(&create_view_info).unwrap()
})
.collect();
let device_memory_properties = instance.get_physical_device_memory_properties(pdevice);
let depth_image_create_info = vk::ImageCreateInfo {
s_type: vk::StructureType::ImageCreateInfo,
p_next: ptr::null(),
flags: vk::IMAGE_CREATE_SPARSE_BINDING_BIT,
image_type: vk::ImageType::Type2d,
format: vk::Format::D16Unorm,
extent: vk::Extent3D {
width: surface_resolution.width,
height: surface_resolution.height,
depth: 1,
},
mip_levels: 1,
array_layers: 1,
samples: vk::SAMPLE_COUNT_1_BIT,
tiling: vk::ImageTiling::Optimal,
usage: vk::IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
sharing_mode: vk::SharingMode::Exclusive,
queue_family_index_count: 0,
p_queue_family_indices: ptr::null(),
initial_layout: vk::ImageLayout::Undefined,
};
let depth_image = device.create_image(&depth_image_create_info).unwrap();
let depth_image_memory_req = device.get_image_memory_requirements(depth_image);
let depth_image_memory_index =
find_memorytype_index(&depth_image_memory_req,
&device_memory_properties,
vk::MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
.expect("Unable to find suitable memory index for depth image.");
let depth_image_allocate_info = vk::MemoryAllocateInfo {
s_type: vk::StructureType::MemoryAllocateInfo,
p_next: ptr::null(),
allocation_size: depth_image_memory_req.size,
memory_type_index: depth_image_memory_index,
};
let depth_image_memory = device.allocate_memory(&depth_image_allocate_info).unwrap();
device.bind_image_memory(depth_image, depth_image_memory, 0)
.expect("Unable to bind depth image memory");
let command_buffer_begin_info = vk::CommandBufferBeginInfo {
s_type: vk::StructureType::CommandBufferBeginInfo,
p_next: ptr::null(),
p_inheritance_info: ptr::null(),
flags: vk::COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
};
device.begin_command_buffer(setup_command_buffer, &command_buffer_begin_info).unwrap();
let layout_transition_barrier = vk::ImageMemoryBarrier {
s_type: vk::StructureType::ImageMemoryBarrier,
p_next: ptr::null(),
src_access_mask: Default::default(),
dst_access_mask: vk::ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
vk::ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
old_layout: vk::ImageLayout::Undefined,
new_layout: vk::ImageLayout::DepthStencilAttachmentOptimal,
src_queue_family_index: vk::VK_QUEUE_FAMILY_IGNORED,
dst_queue_family_index: vk::VK_QUEUE_FAMILY_IGNORED,
image: depth_image,
subresource_range: vk::ImageSubresourceRange {
aspect_mask: vk::IMAGE_ASPECT_DEPTH_BIT,
base_mip_level: 0,
level_count: 1,
base_array_layer: 0,
layer_count: 1,
},
};
device.cmd_pipeline_barrier(setup_command_buffer,
vk::PIPELINE_STAGE_TOP_OF_PIPE_BIT,
vk::PIPELINE_STAGE_TOP_OF_PIPE_BIT,
vk::DependencyFlags::empty(),
&[],
&[],
&[layout_transition_barrier]);
let wait_stage_mask = [vk::PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT];
let fence_create_info = vk::FenceCreateInfo {
s_type: vk::StructureType::FenceCreateInfo,
p_next: ptr::null(),
flags: vk::FenceCreateFlags::empty(),
};
let submit_fence = device.create_fence(&fence_create_info).unwrap();
let submit_info = vk::SubmitInfo {
s_type: vk::StructureType::SubmitInfo,
p_next: ptr::null(),
wait_semaphore_count: 0,
p_wait_semaphores: ptr::null(),
signal_semaphore_count: 0,
p_signal_semaphores: ptr::null(),
p_wait_dst_stage_mask: wait_stage_mask.as_ptr(),
command_buffer_count: 1,
p_command_buffers: &setup_command_buffer,
};
device.end_command_buffer(setup_command_buffer).unwrap();
device.queue_submit(present_queue, &[submit_info], submit_fence).unwrap();
device.wait_for_fences(&[submit_fence], true, std::u64::MAX).unwrap();
let depth_image_view_info = vk::ImageViewCreateInfo {
s_type: vk::StructureType::ImageViewCreateInfo,
p_next: ptr::null(),
flags: Default::default(),
view_type: vk::ImageViewType::Type2d,
format: depth_image_create_info.format,
components: vk::ComponentMapping {
r: vk::ComponentSwizzle::Identity,
g: vk::ComponentSwizzle::Identity,
b: vk::ComponentSwizzle::Identity,
a: vk::ComponentSwizzle::Identity,
},
subresource_range: vk::ImageSubresourceRange {
aspect_mask: vk::IMAGE_ASPECT_DEPTH_BIT,
base_mip_level: 0,
level_count: 1,
base_array_layer: 0,
layer_count: 1,
},
image: depth_image,
};
let depth_image_view = device.create_image_view(&depth_image_view_info).unwrap();
let semaphore_create_info = vk::SemaphoreCreateInfo {
s_type: vk::StructureType::SemaphoreCreateInfo,
p_next: ptr::null(),
flags: Default::default(),
};
let present_complete_semaphore = device.create_semaphore(&semaphore_create_info)
.unwrap();
let rendering_complete_semaphore = device.create_semaphore(&semaphore_create_info)
.unwrap();
ExampleBase {
entry: entry,
instance: instance,
device: device,
queue_family_index: queue_family_index,
pdevice: pdevice,
device_memory_properties: device_memory_properties,
window: window,
surface_loader: surface_loader,
surface_format: surface_format,
present_queue: present_queue,
surface_resolution: surface_resolution,
swapchain_loader: swapchain_loader,
swapchain: swapchain,
present_images: present_images,
present_image_views: present_image_views,
pool: pool,
draw_command_buffer: draw_command_buffer,
setup_command_buffer: setup_command_buffer,
depth_image: depth_image,
depth_image_view: depth_image_view,
present_complete_semaphore: present_complete_semaphore,
rendering_complete_semaphore: rendering_complete_semaphore,
surface: surface,
debug_call_back: debug_call_back,
debug_report_loader: debug_report_loader,
depth_image_memory: depth_image_memory,
}
}
}
}
impl Drop for ExampleBase {
fn drop(&mut self) {
unsafe {
self.device.device_wait_idle().unwrap();
self.device.destroy_semaphore(self.present_complete_semaphore);
self.device.destroy_semaphore(self.rendering_complete_semaphore);
self.device.destroy_image_view(self.depth_image_view);
self.device.destroy_image(self.depth_image);
self.device.free_memory(self.depth_image_memory);
for &image_view in self.present_image_views.iter() {
self.device.destroy_image_view(image_view);
}
self.device.destroy_command_pool(self.pool);
self.swapchain_loader.destroy_swapchain_khr(self.swapchain);
self.device.destroy_device();
self.surface_loader.destroy_surface_khr(self.surface);
self.debug_report_loader.destroy_debug_report_callback_ext(self.debug_call_back);
self.instance.destroy_instance();
}
}
}

View file

@ -1,428 +0,0 @@
[root]
name = "example"
version = "0.1.0"
dependencies = [
"ash 0.1.0",
"glfw 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
"image 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ash"
version = "0.1.0"
dependencies = [
"shared_library 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"sharedlib 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "backtrace"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"backtrace-sys 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-demangle 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "backtrace-sys"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"gcc 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bitflags"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "byteorder"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cfg-if"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cmake"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"gcc 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "color_quant"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "dbghelp-sys"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "deque"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "enum_primitive"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "error-chain"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"backtrace 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "flate2"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"miniz-sys 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "gcc"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "gif"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"color_quant 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "glfw"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"enum_primitive 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"glfw-sys 3.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"num 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
"semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "glfw-sys"
version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cmake 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "glob"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "image"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
"enum_primitive 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gif 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"jpeg-decoder 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"num-iter 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
"num-rational 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
"png 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"scoped_threadpool 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "inflate"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "jpeg-decoder"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rayon 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "kernel32-sys"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "lazy_static"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libc"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "log"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "lzw"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "miniz-sys"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"gcc 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "nom"
version = "1.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "num"
version = "0.1.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-bigint 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
"num-complex 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
"num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
"num-iter 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
"num-rational 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-bigint"
version = "0.1.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-complex"
version = "0.1.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-traits 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-integer"
version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-traits 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-iter"
version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-rational"
version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-bigint 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
"num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-traits"
version = "0.1.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "num_cpus"
version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "png"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"flate2 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
"inflate 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"num-iter 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rayon"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rustc-demangle"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rustc-serialize"
version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "scoped_threadpool"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "semver"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"nom 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "shared_library"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "sharedlib"
version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"error-chain 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-build"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum backtrace 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "346d7644f0b5f9bc73082d3b2236b69a05fd35cce0cfa3724e184e6a5c9e2a2f"
"checksum backtrace-sys 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3602e8d8c43336088a8505fa55cae2b3884a9be29440863a11528a42f46f6bb7"
"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
"checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855"
"checksum cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de1e760d7b6535af4241fca8bd8adf68e2e7edacc6b29f5d399050c5e48cf88c"
"checksum cmake 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "dfcf5bcece56ef953b8ea042509e9dcbdfe97820b7e20d86beb53df30ed94978"
"checksum color_quant 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a475fc4af42d83d28adf72968d9bcfaf035a1a9381642d8e85d8a04957767b0d"
"checksum dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850"
"checksum deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1614659040e711785ed8ea24219140654da1729f3ec8a47a9719d041112fe7bf"
"checksum enum_primitive 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f79eff5be92a4d7d5bddf7daa7d650717ea71628634efe6ca7bcda85b2183c23"
"checksum error-chain 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bd5c82c815138e278b8dcdeffc49f27ea6ffb528403e9dea4194f2e3dd40b143"
"checksum flate2 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "3eeb481e957304178d2e782f2da1257f1434dfecbae883bafb61ada2a9fea3bb"
"checksum gcc 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)" = "dcb000abd6df9df4c637f75190297ebe56c1d7e66b56bbf3b4aa7aece15f61a2"
"checksum gif 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "01c7c19a035de94bd7afbaa62c241aadfbdf1a70f560b348d2312eafa566ca16"
"checksum glfw 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b14e68c4ccefdf293ecb65390a5761971b83fcfc54d153a5b73d438327633965"
"checksum glfw-sys 3.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eaff144079cb22d6f17009e29e87c02f5fd6c4669093ce12b0b2faa6027f0d23"
"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
"checksum image 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)" = "76df2dce95fef56fd35dbc41c36e37b19aede703c6be7739e8b65d5788ffc728"
"checksum inflate 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e7e0062d2dc2f17d2f13750d95316ae8a2ff909af0fda957084f5defd87c43bb"
"checksum jpeg-decoder 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f1a2c12387f1adb21a9a2a096b5bc5f424a21729ea8e535fdf58681d396b6bbe"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
"checksum lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "49247ec2a285bb3dcb23cbd9c35193c025e7251bfce77c1d5da97e6362dffe7f"
"checksum libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)" = "23e3757828fa702a20072c37ff47938e9dd331b92fac6e223d26d4b7a55f7ee2"
"checksum log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ab83497bf8bf4ed2a74259c1c802351fcd67a65baa86394b6ba73c36f4838054"
"checksum lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d947cbb889ed21c2a84be6ffbaebf5b4e0f4340638cba0444907e38b56be084"
"checksum miniz-sys 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9d1f4d337a01c32e1f2122510fed46393d53ca35a7f429cb0450abaedfa3ed54"
"checksum nom 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b8c256fd9471521bcb84c3cdba98921497f1a331cbc15b8030fc63b82050ce"
"checksum num 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)" = "d2ee34a0338c16ae67afb55824aaf8852700eb0f77ccd977807ccb7606b295f6"
"checksum num-bigint 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)" = "fbc450723a2fe91d332a29edd8660e099b937d29e1a3ebe914e0da3f77ac1ad3"
"checksum num-complex 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)" = "8aabbc079e1855ce8415141fee0ebebf171f56505373b3a966e2716ad7c0e555"
"checksum num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "fb24d9bfb3f222010df27995441ded1e954f8f69cd35021f6bef02ca9552fb92"
"checksum num-iter 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "287a1c9969a847055e1122ec0ea7a5c5d6f72aad97934e131c83d5c08ab4e45c"
"checksum num-rational 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "48cdcc9ff4ae2a8296805ac15af88b3d88ce62128ded0cb74ffb63a587502a84"
"checksum num-traits 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)" = "95e58eac34596aac30ab134c8a8da9aa2dc99caa4b4b4838e6fc6e298016278f"
"checksum num_cpus 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "cee7e88156f3f9e19bdd598f8d6c9db7bf4078f99f8381f43a55b09648d1a6e3"
"checksum png 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "06208e2ee243e3118a55dda9318f821f206d8563fb8d4df258767f8e62bb0997"
"checksum rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "2791d88c6defac799c3f20d74f094ca33b9332612d9aef9078519c82e4fe04a5"
"checksum rayon 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "655df67c314c30fa3055a365eae276eb88aa4f3413a352a1ab32c1320eda41ea"
"checksum rustc-demangle 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1430d286cadb237c17c885e25447c982c97113926bb579f4379c0eca8d9586dc"
"checksum rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "6159e4e6e559c81bd706afe9c8fd68f547d3e851ce12e76b1de7914bab61691b"
"checksum scoped_threadpool 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "3ef399c8893e8cb7aa9696e895427fab3a6bf265977bb96e126f24ddd2cda85a"
"checksum semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2d5b7638a1f03815d94e88cb3b3c08e87f0db4d683ef499d1836aaf70a45623f"
"checksum shared_library 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fb04126b6fcfd2710fb5b6d18f4207b6c535f2850a7e1a43bcd526d44f30a79a"
"checksum sharedlib 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5182b4b49a0ff319bc69d23ca9e9f8e40dfb3b88abb895805a54e69325a092c7"
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"

View file

@ -1,9 +0,0 @@
[package]
name = "example"
version = "0.1.0"
authors = ["maik klein <maikklein@googlemail.com>"]
[dependencies]
glfw = "0.9.1"
image = "*"
ash = { version = "0.1.0", path = "../../"}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

View file

@ -1,18 +0,0 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
layout (binding = 1) uniform sampler2D samplerColor;
layout (binding = 0) uniform UBO{
vec3 color;
} ubo;
layout (location = 0) in vec2 o_uv;
layout (location = 0) out vec4 uFragColor;
void main() {
vec4 color = texture(samplerColor, o_uv);
uFragColor = color;
}

View file

@ -1,13 +0,0 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
layout (location = 0) in vec4 pos;
layout (location = 1) in vec2 uv;
layout (location = 0) out vec2 o_uv;
void main() {
o_uv = uv;
gl_Position = pos;
}

Binary file not shown.

File diff suppressed because it is too large Load diff