-
Notifications
You must be signed in to change notification settings - Fork 13
Updated version to vulkano 0.30 #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,13 +12,13 @@ use egui::plot::{HLine, Line, Plot, Value, Values}; | |
| use egui::{Color32, ColorImage, Ui}; | ||
| use egui_vulkano::UpdateTexturesResult; | ||
| use vulkano::buffer::{BufferUsage, CpuAccessibleBuffer, TypedBufferAccess}; | ||
| use vulkano::command_buffer::{AutoCommandBufferBuilder, CommandBufferUsage, SubpassContents}; | ||
| use vulkano::command_buffer::{AutoCommandBufferBuilder, CommandBufferUsage, RenderPassBeginInfo, SubpassContents}; | ||
| use vulkano::device::physical::{PhysicalDevice, PhysicalDeviceType}; | ||
| use vulkano::device::{Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo}; | ||
| use vulkano::format::Format; | ||
| use vulkano::format::{ClearValue, Format}; | ||
| use vulkano::image::view::ImageView; | ||
| use vulkano::image::{ImageAccess, ImageUsage, SwapchainImage}; | ||
| use vulkano::instance::{Instance, InstanceCreateInfo}; | ||
| use vulkano::instance::{Instance, InstanceCreateInfo, InstanceExtensions}; | ||
| use vulkano::pipeline::graphics::input_assembly::InputAssemblyState; | ||
| use vulkano::pipeline::graphics::vertex_input::BuffersDefinition; | ||
| use vulkano::pipeline::graphics::viewport::Viewport; | ||
|
|
@@ -28,46 +28,48 @@ use vulkano::render_pass::{Framebuffer, FramebufferCreateInfo, RenderPass, Subpa | |
| use vulkano::swapchain::{AcquireError, Swapchain, SwapchainCreateInfo, SwapchainCreationError}; | ||
| use vulkano::sync::{FenceSignalFuture, FlushError, GpuFuture}; | ||
| use vulkano::{swapchain, sync}; | ||
| use vulkano::instance::debug::{DebugUtilsMessenger, DebugUtilsMessengerCreateInfo}; | ||
| use vulkano_win::VkSurfaceBuild; | ||
| use winit::event::{Event, WindowEvent}; | ||
| use winit::event_loop::{ControlFlow, EventLoop}; | ||
| use winit::window::{Fullscreen, Window, WindowBuilder}; | ||
|
|
||
| pub enum FrameEndFuture<F: GpuFuture + 'static> { | ||
| FenceSignalFuture(FenceSignalFuture<F>), | ||
| BoxedFuture(Box<dyn GpuFuture>), | ||
| } | ||
| pub struct FrameEndFuture(Box<dyn GpuFuture>); | ||
|
|
||
| impl<F: GpuFuture> FrameEndFuture<F> { | ||
| impl FrameEndFuture { | ||
| pub fn now(device: Arc<Device>) -> Self { | ||
| Self::BoxedFuture(sync::now(device).boxed()) | ||
| Self(sync::now(device).boxed()) | ||
| } | ||
|
|
||
| pub fn get(self) -> Box<dyn GpuFuture> { | ||
| match self { | ||
| FrameEndFuture::FenceSignalFuture(f) => f.boxed(), | ||
| FrameEndFuture::BoxedFuture(f) => f, | ||
| } | ||
| self.0 | ||
| } | ||
| } | ||
|
|
||
| impl<F: GpuFuture> AsMut<dyn GpuFuture> for FrameEndFuture<F> { | ||
| impl AsMut<dyn GpuFuture> for FrameEndFuture { | ||
| fn as_mut(&mut self) -> &mut (dyn GpuFuture + 'static) { | ||
| match self { | ||
| FrameEndFuture::FenceSignalFuture(f) => f, | ||
| FrameEndFuture::BoxedFuture(f) => f, | ||
| } | ||
| self.0.as_mut() | ||
| } | ||
| } | ||
|
|
||
| fn main() { | ||
| let required_extensions = vulkano_win::required_extensions(); | ||
| for layer in vulkano::instance::layers_list().unwrap() { | ||
| println!("Available layer: {}", layer.name()); | ||
| } | ||
| let instance = Instance::new(InstanceCreateInfo { | ||
| enabled_extensions: required_extensions, | ||
| enabled_layers: vec!["VK_LAYER_KHRONOS_validation".into()], | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not opposed to enabling this, but please check if it's available. I don't have it, so this just crashes with error
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that can be removed, i forgot to remove it when pushing. |
||
| ..Default::default() | ||
| }) | ||
| .unwrap(); | ||
|
|
||
| }).unwrap(); | ||
| let _callback = unsafe { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks confusing, because it just looks like an unused variable. Apparently this is supposed to work as long as the variable remains in scope? If so, maybe add a comment explaining this?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is my debug implementation i forgot to remove. it doesn't work properly anyway. |
||
| DebugUtilsMessenger::new( | ||
| instance.clone(), | ||
| DebugUtilsMessengerCreateInfo::user_callback(Arc::new(|msg| { | ||
| println!("Debug callback: {:?}", msg.description); | ||
| })), | ||
| ).ok() | ||
| }; | ||
| let physical = PhysicalDevice::enumerate(&instance).next().unwrap(); | ||
|
|
||
| println!( | ||
|
|
@@ -107,14 +109,12 @@ fn main() { | |
| let (device, mut queues) = Device::new( | ||
| physical_device, | ||
| DeviceCreateInfo { | ||
| enabled_extensions: physical_device | ||
| .required_extensions() | ||
| .union(&device_extensions), | ||
| enabled_extensions: device_extensions, | ||
| queue_create_infos: vec![QueueCreateInfo::family(queue_family)], | ||
| ..Default::default() | ||
| }, | ||
| ) | ||
| .unwrap(); | ||
| .unwrap(); | ||
|
|
||
| let queue = queues.next().unwrap(); | ||
|
|
||
|
|
@@ -140,7 +140,7 @@ fn main() { | |
| ..Default::default() | ||
| }, | ||
| ) | ||
| .unwrap() | ||
| .unwrap() | ||
| }; | ||
|
|
||
| #[derive(Default, Debug, Clone, Copy, Pod, Zeroable)] | ||
|
|
@@ -166,10 +166,10 @@ fn main() { | |
| position: [0.25, -0.1], | ||
| }, | ||
| ] | ||
| .iter() | ||
| .cloned(), | ||
| .iter() | ||
| .cloned(), | ||
| ) | ||
| .unwrap() | ||
| .unwrap() | ||
| }; | ||
|
|
||
| mod vs { | ||
|
|
@@ -220,7 +220,7 @@ fn main() { | |
| { color: [color], depth_stencil: {}, input: [] } // Create a second renderpass to draw egui | ||
| ] | ||
| ) | ||
| .unwrap(); | ||
| .unwrap(); | ||
|
|
||
| let pipeline = GraphicsPipeline::start() | ||
| .vertex_input_state(BuffersDefinition::new().vertex::<Vertex>()) | ||
|
|
@@ -242,7 +242,7 @@ fn main() { | |
|
|
||
| let mut recreate_swapchain = false; | ||
|
|
||
| let mut previous_frame_end = Some(FrameEndFuture::now(device.clone())); | ||
| let mut previous_frame_end: Option<Box<dyn GpuFuture>> = Some(sync::now(device.clone()).boxed()); | ||
|
|
||
| //Set up everything need to draw the gui | ||
| let window = surface.window(); | ||
|
|
@@ -254,7 +254,7 @@ fn main() { | |
| queue.clone(), | ||
| Subpass::from(render_pass.clone(), 1).unwrap(), | ||
| ) | ||
| .unwrap(); | ||
| .unwrap(); | ||
|
|
||
| //Set up some window to look at for the test | ||
|
|
||
|
|
@@ -326,13 +326,13 @@ fn main() { | |
| recreate_swapchain = true; | ||
| } | ||
|
|
||
| let clear_values = vec![[0.0, 0.0, 1.0, 1.0].into()]; | ||
| let clear_values = vec![ClearValue::Float([0.0, 0.0, 1.0, 1.0]).into()]; | ||
| let mut builder = AutoCommandBufferBuilder::primary( | ||
| device.clone(), | ||
| queue.family(), | ||
| CommandBufferUsage::OneTimeSubmit, | ||
| ) | ||
| .unwrap(); | ||
| .unwrap(); | ||
|
|
||
| let frame_start = Instant::now(); | ||
| egui_ctx.begin_frame(egui_winit.take_egui_input(surface.window())); | ||
|
|
@@ -367,18 +367,18 @@ fn main() { | |
| let platform_output = egui_output.platform_output; | ||
| egui_winit.handle_platform_output(surface.window(), &egui_ctx, platform_output); | ||
|
|
||
| let result = egui_painter | ||
| .update_textures(egui_output.textures_delta, &mut builder) | ||
| let tex_future = egui_painter | ||
| .update_textures(egui_output.textures_delta) | ||
| .expect("egui texture error"); | ||
|
|
||
| let wait_for_last_frame = result == UpdateTexturesResult::Changed; | ||
|
|
||
| // Do your usual rendering | ||
| builder | ||
| .begin_render_pass( | ||
| framebuffers[image_num].clone(), | ||
| RenderPassBeginInfo { | ||
| clear_values, | ||
| ..RenderPassBeginInfo::framebuffer(framebuffers[image_num].clone()) | ||
| }, | ||
| SubpassContents::Inline, | ||
| clear_values, | ||
| ) | ||
| .unwrap() | ||
| .set_viewport(0, [viewport.clone()]) | ||
|
|
@@ -390,12 +390,11 @@ fn main() { | |
| // Build your gui | ||
|
|
||
| // Automatically start the next render subpass and draw the gui | ||
| let size = surface.window().inner_size(); | ||
| let sf: f32 = surface.window().scale_factor() as f32; | ||
| let size = surface.window().inner_size().to_logical(surface.window().scale_factor()); | ||
| egui_painter | ||
| .draw( | ||
| &mut builder, | ||
| [(size.width as f32) / sf, (size.height as f32) / sf], | ||
| [size.width, size.height], | ||
| &egui_ctx, | ||
| egui_output.shapes, | ||
| ) | ||
|
|
@@ -407,34 +406,28 @@ fn main() { | |
| builder.end_render_pass().unwrap(); | ||
|
|
||
| let command_buffer = builder.build().unwrap(); | ||
|
|
||
| if wait_for_last_frame { | ||
| if let Some(FrameEndFuture::FenceSignalFuture(ref mut f)) = previous_frame_end { | ||
| f.wait(None).unwrap(); | ||
| } | ||
| let mut future_mut = acquire_future.join(tex_future).boxed(); | ||
| if let Some(future) = previous_frame_end.take() { | ||
| future_mut = future_mut.join(future).boxed(); | ||
| } | ||
|
|
||
| let future = previous_frame_end | ||
| .take() | ||
| .unwrap() | ||
| .get() | ||
| .join(acquire_future) | ||
| let future = future_mut | ||
| .then_execute(queue.clone(), command_buffer) | ||
| .unwrap() | ||
| .then_swapchain_present(queue.clone(), swapchain.clone(), image_num) | ||
| .then_signal_fence_and_flush(); | ||
|
|
||
| match future { | ||
| Ok(future) => { | ||
| previous_frame_end = Some(FrameEndFuture::FenceSignalFuture(future)); | ||
| future.wait(None).unwrap(); | ||
| previous_frame_end = Some(sync::now(device.clone()).boxed()); | ||
| } | ||
| Err(FlushError::OutOfDate) => { | ||
| recreate_swapchain = true; | ||
| previous_frame_end = Some(FrameEndFuture::now(device.clone())); | ||
| previous_frame_end = Some(sync::now(device.clone()).boxed()); | ||
| } | ||
| Err(e) => { | ||
| println!("Failed to flush future: {:?}", e); | ||
| previous_frame_end = Some(FrameEndFuture::now(device.clone())); | ||
| previous_frame_end = Some(sync::now(device.clone()).boxed()); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -462,7 +455,7 @@ fn window_size_dependent_setup( | |
| ..Default::default() | ||
| }, | ||
| ) | ||
| .unwrap() | ||
| .unwrap() | ||
| }) | ||
| .collect::<Vec<_>>() | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems this is not used any more and could be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed i forgot to remove it