Fruther prorgress to fix triangle perf issue
This commit is contained in:
parent
347dc2dc91
commit
757bb70fad
8 changed files with 215 additions and 145 deletions
|
@ -11,18 +11,19 @@ use std::cell::Cell;
|
|||
use std::path::Path;
|
||||
use vk_loader2 as vk;
|
||||
// use feature;
|
||||
use load;
|
||||
|
||||
type VkResult<T> = Result<T, vk::Result>;
|
||||
pub struct Device {
|
||||
pub struct Device<'r> {
|
||||
handle: vk::Device,
|
||||
device_fn: vk::DeviceFn,
|
||||
_lifetime: ::std::marker::PhantomData<&'r ()>,
|
||||
}
|
||||
impl Device {
|
||||
impl<'r> Device<'r> {
|
||||
pub unsafe fn from_raw(handle: vk::Device, device_fn: vk::DeviceFn) -> Self {
|
||||
Device {
|
||||
handle: handle,
|
||||
device_fn: device_fn,
|
||||
_lifetime: ::std::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
pub fn destroy_device(&self) {
|
||||
|
@ -108,6 +109,39 @@ impl Device {
|
|||
self.device_fn.destroy_semaphore(self.handle, semaphore, ptr::null());
|
||||
}
|
||||
}
|
||||
pub fn device_wait_idle(&self) -> VkResult<()> {
|
||||
unsafe {
|
||||
let err_code = self.device_fn.device_wait_idle(self.handle);
|
||||
match err_code {
|
||||
vk::Result::Success => Ok(()),
|
||||
_ => Err(err_code),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reset_command_buffer(&self,
|
||||
command_buffer: vk::CommandBuffer,
|
||||
flags: vk::CommandBufferResetFlags)
|
||||
-> VkResult<()> {
|
||||
unsafe {
|
||||
let err_code = self.device_fn
|
||||
.reset_command_buffer(command_buffer, flags);
|
||||
match err_code {
|
||||
vk::Result::Success => Ok(()),
|
||||
_ => Err(err_code),
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn reset_fences(&self, fences: &[vk::Fence]) -> VkResult<()> {
|
||||
unsafe {
|
||||
let err_code = self.device_fn
|
||||
.reset_fences(self.handle, fences.len() as u32, fences.as_ptr());
|
||||
match err_code {
|
||||
vk::Result::Success => Ok(()),
|
||||
_ => Err(err_code),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cmd_begin_render_pass(&self,
|
||||
command_buffer: vk::CommandBuffer,
|
||||
|
|
|
@ -1,17 +1,9 @@
|
|||
#![allow(dead_code)]
|
||||
use std::ptr;
|
||||
use std::ffi::*;
|
||||
|
||||
use std::error;
|
||||
use std::fmt;
|
||||
use std::mem;
|
||||
use std::sync::Arc;
|
||||
use std::os::raw::*;
|
||||
use std::cell::Cell;
|
||||
use std::path::Path;
|
||||
use vk_loader2 as vk;
|
||||
// use feature;
|
||||
use load;
|
||||
use device::Device;
|
||||
use shared_library::dynamic_library::DynamicLibrary;
|
||||
|
||||
|
@ -136,7 +128,7 @@ impl Entry {
|
|||
pub struct Instance<'r> {
|
||||
handle: vk::Instance,
|
||||
instance_fn: vk::InstanceFn,
|
||||
_lifetime: ::std::marker::PhantomData<&'r i32>,
|
||||
_lifetime: ::std::marker::PhantomData<&'r ()>,
|
||||
}
|
||||
impl<'r> Instance<'r> {
|
||||
pub fn destroy_instance(&self) {
|
||||
|
@ -144,7 +136,28 @@ impl<'r> Instance<'r> {
|
|||
self.instance_fn.destroy_instance(self.handle, ptr::null());
|
||||
}
|
||||
}
|
||||
pub fn destroy_debug_report_callback_ext(&self, debug: vk::DebugReportCallbackEXT) {
|
||||
unsafe {
|
||||
self.instance_fn.destroy_debug_report_callback_ext(self.handle, debug, ptr::null());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_debug_report_callback_ext(&self,
|
||||
create_info: &vk::DebugReportCallbackCreateInfoEXT)
|
||||
-> VkResult<vk::DebugReportCallbackEXT> {
|
||||
unsafe {
|
||||
let mut debug_cb = mem::uninitialized();
|
||||
let err_code = self.instance_fn
|
||||
.create_debug_report_callback_ext(self.handle,
|
||||
create_info,
|
||||
ptr::null(),
|
||||
&mut debug_cb);
|
||||
match err_code {
|
||||
vk::Result::Success => Ok(debug_cb),
|
||||
_ => Err(err_code),
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn get_physical_device_memory_properties(&self,
|
||||
physical_device: vk::PhysicalDevice)
|
||||
-> vk::PhysicalDeviceMemoryProperties {
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
extern crate shared_library;
|
||||
extern crate vk_loader;
|
||||
#[macro_use]
|
||||
extern crate vk_loader2;
|
||||
extern crate glfw;
|
||||
#[macro_use]
|
||||
extern crate bitflags;
|
||||
|
||||
pub mod load;
|
||||
//pub mod load;
|
||||
//pub mod extensions;
|
||||
//pub mod surface;
|
||||
pub mod instance;
|
||||
|
|
|
@ -16,56 +16,6 @@ use std::ptr;
|
|||
use shared_library;
|
||||
use vk_loader2 as vk;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref VK_LIB: Result<shared_library::dynamic_library::DynamicLibrary, LoadingError> = {
|
||||
#[cfg(windows)] fn get_path() -> &'static Path { Path::new("vulkan-1.dll") }
|
||||
#[cfg(all(unix, not(target_os = "android")))] fn get_path() -> &'static Path { Path::new("libvulkan.so.1") }
|
||||
#[cfg(target_os = "android")] fn get_path() -> &'static Path { Path::new("libvulkan.so") }
|
||||
let path = get_path();
|
||||
shared_library::dynamic_library::DynamicLibrary::open(Some(path))
|
||||
.map_err(|err| LoadingError::LibraryLoadFailure(err))
|
||||
};
|
||||
|
||||
// static ref VK_STATIC: Result<vk::Static, LoadingError> = {
|
||||
// match *VK_LIB {
|
||||
// Ok(ref lib) => {
|
||||
// let mut err = None;
|
||||
// let result = vk::Static::load(|name| unsafe {
|
||||
// let name = name.to_str().unwrap();
|
||||
// match lib.symbol(name) {
|
||||
// Ok(s) => s,
|
||||
// Err(_) => { // TODO: return error?
|
||||
// err = Some(LoadingError::MissingEntryPoint(name.to_owned()));
|
||||
// ptr::null()
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// if let Some(err) = err {
|
||||
// Err(err)
|
||||
// } else {
|
||||
// Ok(result)
|
||||
// }
|
||||
// },
|
||||
// Err(ref err) => Err(err.clone()),
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// static ref VK_ENTRY: Result<vk::EntryPoints, LoadingError> = {
|
||||
// match *VK_STATIC {
|
||||
// Ok(ref lib) => {
|
||||
// // At this point we assume that if one of the functions fails to load, it is an
|
||||
// // implementation bug and not a real-life situation that could be handled by
|
||||
// // an error.
|
||||
// Ok(vk::EntryPoints::load(|name| unsafe {
|
||||
// mem::transmute(lib.GetInstanceProcAddr(0, name.as_ptr()))
|
||||
// }))
|
||||
// },
|
||||
// Err(ref err) => Err(err.clone()),
|
||||
// }
|
||||
// };
|
||||
}
|
||||
|
||||
/// Returns the collection of static functions from the Vulkan loader, or an error if failed to
|
||||
/// open the loader.
|
||||
// pub fn static_functions() -> Result<&'static vk::Static, LoadingError> {
|
||||
|
|
42
examples/Cargo.lock
generated
42
examples/Cargo.lock
generated
|
@ -3,9 +3,8 @@ name = "example"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ash 0.1.0",
|
||||
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"glfw 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"owning_ref 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"vk_loader 0.1.0",
|
||||
"vk_loader2 0.1.0",
|
||||
]
|
||||
|
@ -70,6 +69,15 @@ dependencies = [
|
|||
"cmake 0.1.17 (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"
|
||||
|
@ -156,11 +164,6 @@ name = "num-traits"
|
|||
version = "0.1.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "owning_ref"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.3.14"
|
||||
|
@ -191,6 +194,16 @@ dependencies = [
|
|||
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.1.35"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"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)",
|
||||
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "vk_loader"
|
||||
version = "0.1.0"
|
||||
|
@ -205,6 +218,16 @@ dependencies = [
|
|||
"shared_library 0.1.5 (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 bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
|
||||
"checksum cmake 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "dfcf5bcece56ef953b8ea042509e9dcbdfe97820b7e20d86beb53df30ed94978"
|
||||
|
@ -212,6 +235,7 @@ dependencies = [
|
|||
"checksum gcc 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)" = "dcb000abd6df9df4c637f75190297ebe56c1d7e66b56bbf3b4aa7aece15f61a2"
|
||||
"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 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"
|
||||
|
@ -223,8 +247,10 @@ dependencies = [
|
|||
"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 owning_ref 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7ba6a14c7d6fb686c1c542663b2094934f1cbfbdb22b70305f09ed8eb2f2edf3"
|
||||
"checksum rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "2791d88c6defac799c3f20d74f094ca33b9332612d9aef9078519c82e4fe04a5"
|
||||
"checksum rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "6159e4e6e559c81bd706afe9c8fd68f547d3e851ce12e76b1de7914bab61691b"
|
||||
"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 time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "3c7ec6d62a20df54e07ab3b78b9a3932972f4b7981de295563686849eb3989af"
|
||||
"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"
|
||||
|
|
|
@ -5,8 +5,7 @@ authors = ["maik klein <maikklein@googlemail.com>"]
|
|||
|
||||
[dependencies]
|
||||
glfw = "0.9.1"
|
||||
time = "0.1"
|
||||
vk_loader = { version = "0.1.0", path = "../vk_loader"}
|
||||
vk_loader2 = { version = "0.1.0", path = "../vk_loader2"}
|
||||
ash = { version = "0.1.0", path = "../ash"}
|
||||
owning_ref = "0.2.0"
|
||||
bitflags = "0.7.0"
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
#![feature(conservative_impl_trait)]
|
||||
#![allow(dead_code)]
|
||||
extern crate owning_ref;
|
||||
extern crate ash;
|
||||
|
||||
#[macro_use]
|
||||
extern crate vk_loader2 as vk;
|
||||
extern crate glfw;
|
||||
extern crate time;
|
||||
|
||||
use std::default::Default;
|
||||
use glfw::*;
|
||||
|
@ -18,6 +19,19 @@ use std::fs::File;
|
|||
use std::io::Read;
|
||||
use std::os::raw::c_void;
|
||||
|
||||
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 {
|
||||
let s = CStr::from_ptr(p_message);
|
||||
println!("{:?}", s);
|
||||
1
|
||||
}
|
||||
fn handle_window_event(window: &mut glfw::Window, event: glfw::WindowEvent) {
|
||||
match event {
|
||||
glfw::WindowEvent::Key(Key::Escape, _, Action::Press, _) => window.set_should_close(true),
|
||||
|
@ -70,7 +84,8 @@ fn main() {
|
|||
.map(|raw_name| raw_name.as_ptr())
|
||||
.collect();
|
||||
let extension_names = [CString::new("VK_KHR_surface").unwrap(),
|
||||
CString::new("VK_KHR_xlib_surface").unwrap()];
|
||||
CString::new("VK_KHR_xlib_surface").unwrap(),
|
||||
CString::new("VK_EXT_debug_report").unwrap()];
|
||||
let extension_names_raw: Vec<*const i8> = extension_names.iter()
|
||||
.map(|raw_name| raw_name.as_ptr())
|
||||
.collect();
|
||||
|
@ -81,19 +96,29 @@ fn main() {
|
|||
application_version: 0,
|
||||
p_engine_name: raw_name,
|
||||
engine_version: 0,
|
||||
api_version: 0,
|
||||
api_version: vk_make_version!(1, 0, 36),
|
||||
};
|
||||
let create_info = vk::InstanceCreateInfo {
|
||||
s_type: vk::StructureType::InstanceCreateInfo,
|
||||
p_application_info: &appinfo,
|
||||
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,
|
||||
flags: Default::default(),
|
||||
};
|
||||
let 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_call_back = instance.create_debug_report_callback_ext(&debug_info).unwrap();
|
||||
// println!("{:?}", instance);
|
||||
let x11_display = window.glfw.get_x11_display();
|
||||
let x11_window = window.get_x11_window();
|
||||
let x11_create_info = vk::XlibSurfaceCreateInfoKHR {
|
||||
|
@ -175,7 +200,7 @@ fn main() {
|
|||
.expect("Unable to find suitable surface format.");
|
||||
let surface_capabilities =
|
||||
instance.get_physical_device_surface_capabilities_khr(pdevice, surface).unwrap();
|
||||
let desired_image_count = 2;
|
||||
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");
|
||||
|
@ -200,7 +225,7 @@ fn main() {
|
|||
let present_mode = present_modes.iter()
|
||||
.cloned()
|
||||
.find(|&mode| mode == vk::PresentModeKHR::Mailbox)
|
||||
.unwrap_or(vk::PresentModeKHR::Fifo);
|
||||
.unwrap_or(vk::PresentModeKHR::Immediate);
|
||||
let swapchain_create_info = vk::SwapchainCreateInfoKHR {
|
||||
s_type: vk::StructureType::SwapchainCreateInfoKhr,
|
||||
p_next: ptr::null(),
|
||||
|
@ -238,6 +263,7 @@ fn main() {
|
|||
command_pool: pool,
|
||||
level: vk::CommandBufferLevel::Primary,
|
||||
};
|
||||
// let draw_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];
|
||||
|
@ -320,7 +346,7 @@ fn main() {
|
|||
s_type: vk::StructureType::ImageMemoryBarrier,
|
||||
p_next: ptr::null(),
|
||||
// TODO Is this correct?
|
||||
src_access_mask: vk::AccessFlags::empty(),
|
||||
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,
|
||||
|
@ -394,8 +420,8 @@ fn main() {
|
|||
store_op: vk::AttachmentStoreOp::Store,
|
||||
stencil_load_op: vk::AttachmentLoadOp::DontCare,
|
||||
stencil_store_op: vk::AttachmentStoreOp::DontCare,
|
||||
initial_layout: vk::ImageLayout::ColorAttachmentOptimal,
|
||||
final_layout: vk::ImageLayout::ColorAttachmentOptimal,
|
||||
initial_layout: vk::ImageLayout::Undefined,
|
||||
final_layout: vk::ImageLayout::PresentSrcKhr,
|
||||
},
|
||||
vk::AttachmentDescription {
|
||||
format: depth_image_create_info.format,
|
||||
|
@ -417,6 +443,15 @@ fn main() {
|
|||
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,
|
||||
|
@ -438,8 +473,8 @@ fn main() {
|
|||
p_attachments: renderpass_attachments.as_ptr(),
|
||||
subpass_count: 1,
|
||||
p_subpasses: &subpass,
|
||||
dependency_count: 0,
|
||||
p_dependencies: ptr::null(),
|
||||
dependency_count: 1,
|
||||
p_dependencies: &dependency,
|
||||
};
|
||||
let renderpass = device.create_render_pass(&renderpass_create_info).unwrap();
|
||||
let framebuffers: Vec<vk::Framebuffer> = present_image_views.iter()
|
||||
|
@ -721,7 +756,6 @@ fn main() {
|
|||
|
||||
let graphic_pipeline = graphics_pipelines[0];
|
||||
|
||||
|
||||
let semaphore_create_info = vk::SemaphoreCreateInfo {
|
||||
s_type: vk::StructureType::SemaphoreCreateInfo,
|
||||
p_next: ptr::null(),
|
||||
|
@ -730,43 +764,55 @@ fn main() {
|
|||
let present_complete_semaphore = device.create_semaphore(&semaphore_create_info).unwrap();
|
||||
let rendering_complete_semaphore = device.create_semaphore(&semaphore_create_info).unwrap();
|
||||
|
||||
/// / println!("{:?}", present_image_views.len());
|
||||
let mut current = time::precise_time_ns();
|
||||
let mut last = current;
|
||||
device.reset_fences(&[submit_fence]).unwrap();
|
||||
while !window.should_close() {
|
||||
glfw.poll_events();
|
||||
|
||||
for (_, event) in glfw::flush_messages(&events) {
|
||||
handle_window_event(&mut window, event);
|
||||
}
|
||||
|
||||
current = time::precise_time_ns();
|
||||
let dt = current - last;
|
||||
last = current;
|
||||
println!("dt: {}ms", dt/1000000);
|
||||
let present_index = device.acquire_next_image_khr(swapchain,
|
||||
std::u64::MAX,
|
||||
present_complete_semaphore,
|
||||
vk::Fence::null())
|
||||
.unwrap();
|
||||
let draw_fence = submit_fence;
|
||||
device.reset_command_buffer(draw_command_buffer, Default::default()).unwrap();
|
||||
device.begin_command_buffer(draw_command_buffer, &command_buffer_begin_info).unwrap();
|
||||
let layout_to_color = vk::ImageMemoryBarrier {
|
||||
s_type: vk::StructureType::ImageMemoryBarrier,
|
||||
p_next: ptr::null(),
|
||||
src_access_mask: vk::AccessFlags::empty(),
|
||||
dst_access_mask: vk::ACCESS_COLOR_ATTACHMENT_READ_BIT |
|
||||
vk::ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
|
||||
old_layout: vk::ImageLayout::Undefined,
|
||||
new_layout: vk::ImageLayout::ColorAttachmentOptimal,
|
||||
src_queue_family_index: vk::VK_QUEUE_FAMILY_IGNORED,
|
||||
dst_queue_family_index: vk::VK_QUEUE_FAMILY_IGNORED,
|
||||
image: present_images[present_index as usize],
|
||||
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,
|
||||
},
|
||||
};
|
||||
device.cmd_pipeline_barrier(draw_command_buffer,
|
||||
vk::PIPELINE_STAGE_TOP_OF_PIPE_BIT,
|
||||
vk::PIPELINE_STAGE_TOP_OF_PIPE_BIT,
|
||||
vk::DependencyFlags::empty(),
|
||||
&[],
|
||||
&[],
|
||||
&[layout_to_color]);
|
||||
//let layout_to_color = vk::ImageMemoryBarrier {
|
||||
// s_type: vk::StructureType::ImageMemoryBarrier,
|
||||
// p_next: ptr::null(),
|
||||
// src_access_mask: Default::default(),
|
||||
// dst_access_mask: vk::ACCESS_COLOR_ATTACHMENT_READ_BIT |
|
||||
// vk::ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
|
||||
// old_layout: vk::ImageLayout::Undefined,
|
||||
// new_layout: vk::ImageLayout::ColorAttachmentOptimal,
|
||||
// src_queue_family_index: vk::VK_QUEUE_FAMILY_IGNORED,
|
||||
// dst_queue_family_index: vk::VK_QUEUE_FAMILY_IGNORED,
|
||||
// image: present_images[present_index as usize],
|
||||
// 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,
|
||||
// },
|
||||
//};
|
||||
//device.cmd_pipeline_barrier(draw_command_buffer,
|
||||
// vk::PIPELINE_STAGE_TOP_OF_PIPE_BIT,
|
||||
// vk::PIPELINE_STAGE_TOP_OF_PIPE_BIT,
|
||||
// vk::DependencyFlags::empty(),
|
||||
// &[],
|
||||
// &[],
|
||||
// &[layout_to_color]);
|
||||
let clear_values =
|
||||
[vk::ClearValue::new_color(vk::ClearColorValue::new_float32([1.0, 1.0, 1.0, 1.0])),
|
||||
vk::ClearValue::new_depth_stencil(vk::ClearDepthStencilValue {
|
||||
|
@ -797,31 +843,31 @@ fn main() {
|
|||
device.cmd_bind_vertex_buffers(draw_command_buffer, &[vertex_input_buffer], &0);
|
||||
device.cmd_draw(draw_command_buffer, 3, 1, 0, 0);
|
||||
device.cmd_end_render_pass(draw_command_buffer);
|
||||
let pre_present_barrier = vk::ImageMemoryBarrier {
|
||||
s_type: vk::StructureType::ImageMemoryBarrier,
|
||||
p_next: ptr::null(),
|
||||
src_access_mask: vk::ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
|
||||
dst_access_mask: vk::ACCESS_COLOR_ATTACHMENT_READ_BIT,
|
||||
old_layout: vk::ImageLayout::ColorAttachmentOptimal,
|
||||
new_layout: vk::ImageLayout::PresentSrcKhr,
|
||||
src_queue_family_index: vk::VK_QUEUE_FAMILY_IGNORED,
|
||||
dst_queue_family_index: vk::VK_QUEUE_FAMILY_IGNORED,
|
||||
image: present_images[present_index as usize],
|
||||
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,
|
||||
},
|
||||
};
|
||||
device.cmd_pipeline_barrier(draw_command_buffer,
|
||||
vk::PIPELINE_STAGE_ALL_COMMANDS_BIT,
|
||||
vk::PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
|
||||
vk::DependencyFlags::empty(),
|
||||
&[],
|
||||
&[],
|
||||
&[pre_present_barrier]);
|
||||
//let pre_present_barrier = vk::ImageMemoryBarrier {
|
||||
// s_type: vk::StructureType::ImageMemoryBarrier,
|
||||
// p_next: ptr::null(),
|
||||
// src_access_mask: vk::ACCESS_MEMORY_READ_BIT,
|
||||
// dst_access_mask: vk::ACCESS_COLOR_ATTACHMENT_READ_BIT,
|
||||
// old_layout: vk::ImageLayout::ColorAttachmentOptimal,
|
||||
// new_layout: vk::ImageLayout::PresentSrcKhr,
|
||||
// src_queue_family_index: vk::VK_QUEUE_FAMILY_IGNORED,
|
||||
// dst_queue_family_index: vk::VK_QUEUE_FAMILY_IGNORED,
|
||||
// image: present_images[present_index as usize],
|
||||
// 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,
|
||||
// },
|
||||
//};
|
||||
// device.cmd_pipeline_barrier(draw_command_buffer,
|
||||
// vk::PIPELINE_STAGE_ALL_COMMANDS_BIT,
|
||||
// vk::PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
|
||||
// vk::DependencyFlags::empty(),
|
||||
// &[],
|
||||
// &[],
|
||||
// &[pre_present_barrier]);
|
||||
device.end_command_buffer(draw_command_buffer).unwrap();
|
||||
let wait_render_mask = [vk::PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT];
|
||||
let submit_info = vk::SubmitInfo {
|
||||
|
@ -835,8 +881,9 @@ fn main() {
|
|||
signal_semaphore_count: 1,
|
||||
p_signal_semaphores: &rendering_complete_semaphore,
|
||||
};
|
||||
device.queue_submit(present_queue, &[submit_info], vk::Fence::null()).unwrap();
|
||||
device.queue_wait_idle(present_queue).unwrap();
|
||||
device.queue_submit(present_queue, &[submit_info], draw_fence)
|
||||
.unwrap();
|
||||
// device.queue_wait_idle(present_queue).unwrap();
|
||||
|
||||
let mut present_info_err = unsafe { mem::uninitialized() };
|
||||
let present_info = vk::PresentInfoKHR {
|
||||
|
@ -849,11 +896,14 @@ fn main() {
|
|||
p_image_indices: &present_index,
|
||||
p_results: &mut present_info_err,
|
||||
};
|
||||
|
||||
device.queue_present_khr(present_queue, &present_info).unwrap();
|
||||
device.queue_wait_idle(present_queue).unwrap();
|
||||
device.wait_for_fences(&[draw_fence], true, std::u64::MAX)
|
||||
.unwrap();
|
||||
device.reset_fences(&[draw_fence]).unwrap();
|
||||
// device.queue_wait_idle(present_queue).unwrap();
|
||||
}
|
||||
|
||||
device.device_wait_idle().unwrap();
|
||||
device.destroy_semaphore(present_complete_semaphore);
|
||||
device.destroy_semaphore(rendering_complete_semaphore);
|
||||
for pipeline in graphics_pipelines {
|
||||
|
@ -879,5 +929,6 @@ fn main() {
|
|||
device.destroy_swapchain_khr(swapchain);
|
||||
device.destroy_device();
|
||||
instance.destroy_surface_khr(surface);
|
||||
instance.destroy_debug_report_callback_ext(debug_call_back);
|
||||
instance.destroy_instance();
|
||||
}
|
||||
|
|
|
@ -180,7 +180,7 @@ macro_rules! vk_bitflags_wrapped {
|
|||
|
||||
#[macro_export]
|
||||
macro_rules! vk_make_version {
|
||||
($major: expr, $minor: expr, $patch: expr) => ((($major as uint32_t) << 22) | (($minor as uint32_t) << 12) | $patch as uint32_t)
|
||||
($major: expr, $minor: expr, $patch: expr) => ((($major as u32) << 22) | (($minor as u32) << 12) | $patch as u32)
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
|
|
Loading…
Add table
Reference in a new issue