another unsafe function pass

This commit is contained in:
maik klein 2016-12-24 02:28:28 +01:00
parent c8d2e22b21
commit 8c7a459b90
3 changed files with 928 additions and 1004 deletions

View file

@ -12,30 +12,6 @@ version = "0.2.0"
dependencies = [
"lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"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.18 (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.40 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -43,11 +19,6 @@ name = "bitflags"
version = "0.7.0"
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.20"
@ -56,15 +27,6 @@ dependencies = [
"gcc 0.3.40 (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 = "enum_primitive"
version = "0.1.0"
@ -73,14 +35,6 @@ dependencies = [
"num 0.1.36 (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 = "gcc"
version = "0.3.40"
@ -108,15 +62,6 @@ dependencies = [
"cmake 0.1.20 (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.2"
@ -211,11 +156,6 @@ dependencies = [
"libc 0.2.18 (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.22"
@ -238,40 +178,13 @@ dependencies = [
"libc 0.2.18 (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.2 (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 cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de1e760d7b6535af4241fca8bd8adf68e2e7edacc6b29f5d399050c5e48cf88c"
"checksum cmake 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "a3a6805df695087e7c1bcd9a82e03ad6fb864c8e67ac41b1348229ce5b7f0407"
"checksum dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850"
"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 gcc 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)" = "872db9e59486ef2b14f8e8c10e9ef02de2bccef6363d7f34835dedb386b3d950"
"checksum glfw 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b14e68c4ccefdf293ecb65390a5761971b83fcfc54d153a5b73d438327633965"
"checksum glfw-sys 3.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0031461ad52978b865d3e9bafa2be2825052ddec12c56bbf2da2cf1c0274d6ea"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
"checksum lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6abe0ee2e758cd6bc8a2cd56726359007748fbf4128da998b65d0b70f881e19b"
"checksum libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "a51822fc847e7a8101514d1d44e354ba2ffa7d4c194dcab48870740e327cac70"
"checksum log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ab83497bf8bf4ed2a74259c1c802351fcd67a65baa86394b6ba73c36f4838054"
@ -284,10 +197,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum num-rational 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "54ff603b8334a72fbb27fe66948aac0abaaa40231b3cecd189e76162f6f38aaf"
"checksum num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "a16a42856a256b39c6d3484f097f6713e14feacd9bfb02290917904fae46c81c"
"checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d"
"checksum rustc-demangle 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1430d286cadb237c17c885e25447c982c97113926bb579f4379c0eca8d9586dc"
"checksum rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "237546c689f20bb44980270c73c3b9edd0891c1be49cc1274406134a66d3957b"
"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

@ -42,7 +42,8 @@ fn create_surface(instance: &Instance,
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");
let xlib_surface_loader = XlibSurface::new(&entry, &instance)
.expect("Unable to load xlib surface");
xlib_surface_loader.create_xlib_surface_khr(&x11_create_info)
}
@ -99,6 +100,7 @@ struct Vertex {
color: [f32; 4],
}
fn main() {
unsafe {
let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
let window_width = 1920;
@ -145,7 +147,8 @@ fn main() {
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 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(),
@ -154,7 +157,8 @@ fn main() {
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_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();
@ -213,7 +217,8 @@ fn main() {
.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)
let surface_formats =
surface_loader.get_physical_device_surface_formats_khr(pdevice, surface)
.unwrap();
let surface_format = surface_formats.iter()
.map(|sfmt| {
@ -258,7 +263,8 @@ fn main() {
.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_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(),
@ -294,7 +300,8 @@ fn main() {
command_pool: pool,
level: vk::CommandBufferLevel::Primary,
};
let command_buffers = device.allocate_command_buffers(&command_buffer_allocate_info).unwrap();
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];
@ -440,7 +447,8 @@ fn main() {
image: depth_image,
};
let depth_image_view = device.create_image_view(&depth_image_view_info).unwrap();
let renderpass_attachments = [vk::AttachmentDescription {
let renderpass_attachments =
[vk::AttachmentDescription {
format: surface_format.format,
flags: vk::AttachmentDescriptionFlags::empty(),
samples: vk::SAMPLE_COUNT_1_BIT,
@ -459,8 +467,7 @@ fn main() {
store_op: vk::AttachmentStoreOp::DontCare,
stencil_load_op: vk::AttachmentLoadOp::DontCare,
stencil_store_op: vk::AttachmentStoreOp::DontCare,
initial_layout:
vk::ImageLayout::DepthStencilAttachmentOptimal,
initial_layout: vk::ImageLayout::DepthStencilAttachmentOptimal,
final_layout: vk::ImageLayout::DepthStencilAttachmentOptimal,
}];
let color_attachment_ref = vk::AttachmentReference {
@ -567,7 +574,8 @@ fn main() {
p_queue_family_indices: ptr::null(),
};
let vertex_input_buffer = device.create_buffer(&vertex_input_buffer_info).unwrap();
let vertex_input_buffer_memory_req = device.get_buffer_memory_requirements(vertex_input_buffer);
let vertex_input_buffer_memory_req =
device.get_buffer_memory_requirements(vertex_input_buffer);
let vertex_input_buffer_memory_index =
find_memorytype_index(&vertex_input_buffer_memory_req,
&device_memory_properties,
@ -580,7 +588,8 @@ fn main() {
allocation_size: vertex_input_buffer_memory_req.size,
memory_type_index: vertex_input_buffer_memory_index,
};
let vertex_input_buffer_memory = device.allocate_memory(&vertex_buffer_allocate_info).unwrap();
let vertex_input_buffer_memory = 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],
@ -603,7 +612,8 @@ fn main() {
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 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 {
@ -640,7 +650,8 @@ fn main() {
let pipeline_layout = device.create_pipeline_layout(&layout_create_info).unwrap();
let shader_entry_name = CString::new("main").unwrap();
let shader_stage_create_infos = [vk::PipelineShaderStageCreateInfo {
let shader_stage_create_infos =
[vk::PipelineShaderStageCreateInfo {
s_type: vk::StructureType::PipelineShaderStageCreateInfo,
p_next: ptr::null(),
flags: Default::default(),
@ -940,3 +951,4 @@ fn main() {
debug_report_loader.destroy_debug_report_callback_ext(debug_call_back);
instance.destroy_instance();
}
}

View file

@ -14,7 +14,6 @@ pub struct Device {
}
impl Device {
pub unsafe fn from_raw(handle: vk::Device, device_fn: vk::DeviceFn) -> Self {
Device {
handle: handle,
@ -202,7 +201,7 @@ impl Device {
}
}
pub fn allocate_descriptor_sets(&self,
pub unsafe fn allocate_descriptor_sets(&self,
create_info: &vk::DescriptorSetAllocateInfo)
-> VkResult<Vec<vk::DescriptorSet>> {
unsafe {
@ -344,7 +343,9 @@ impl Device {
}
}
pub unsafe fn cmd_set_scissor(&self, command_buffer: vk::CommandBuffer, scissors: &[vk::Rect2D]) {
pub unsafe fn cmd_set_scissor(&self,
command_buffer: vk::CommandBuffer,
scissors: &[vk::Rect2D]) {
unsafe {
self.device_fn
.cmd_set_scissor(command_buffer,
@ -388,7 +389,9 @@ impl Device {
}
}
pub unsafe fn cmd_set_viewport(&self, command_buffer: vk::CommandBuffer, viewports: &[vk::Viewport]) {
pub unsafe fn cmd_set_viewport(&self,
command_buffer: vk::CommandBuffer,
viewports: &[vk::Viewport]) {
unsafe {
self.device_fn.cmd_set_viewport(command_buffer,
0,
@ -515,7 +518,7 @@ impl Device {
}
}
pub fn cmd_pipeline_barrier(&self,
pub unsafe fn cmd_pipeline_barrier(&self,
command_buffer: vk::CommandBuffer,
src_stage_mask: vk::PipelineStageFlags,
dst_stage_mask: vk::PipelineStageFlags,
@ -652,7 +655,7 @@ impl Device {
}
pub fn allocate_command_buffers(&self,
pub unsafe fn allocate_command_buffers(&self,
create_info: &vk::CommandBufferAllocateInfo)
-> VkResult<Vec<vk::CommandBuffer>> {
unsafe {