Skip to content
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

Update Winit and Fix crash on x11 Linux #481

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ash-window/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ raw-window-handle = "0.3"
raw-window-metal = "0.1"

[dev-dependencies]
winit = "0.19.4"
winit = "0.25.0"
41 changes: 21 additions & 20 deletions ash-window/examples/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

use ash::vk;
use std::error::Error;
use winit::dpi::LogicalSize;
use winit::event::Event;

fn main() -> Result<(), Box<dyn Error>> {
let mut events_loop = winit::EventsLoop::new();
let window = winit::WindowBuilder::new()
.with_dimensions((800, 600).into())
.build(&events_loop)?;
let mut event_loop = winit::event_loop::EventLoop::new();
let window = winit::window::WindowBuilder::new()
.with_inner_size(LogicalSize::new(800, 600))
.build(&event_loop)?;

unsafe {
let entry = ash::Entry::new();
Expand All @@ -33,21 +35,20 @@ fn main() -> Result<(), Box<dyn Error>> {
let surface_fn = ash::extensions::khr::Surface::new(&entry, &instance);
println!("surface: {:?}", surface);

let mut running = true;
while running {
events_loop.poll_events(|event| {
if let winit::Event::WindowEvent {
event: winit::WindowEvent::CloseRequested,
..
} = event
{
running = false;
}
});
}

surface_fn.destroy_surface(surface, None);
event_loop.run(move |event, _, control_flow| match event {
winit::event::Event::WindowEvent {
event: winit::event::WindowEvent::CloseRequested,
..
} => {
*control_flow = winit::event_loop::ControlFlow::Exit;
}
winit::event::Event::WindowEvent {
event: winit::event::WindowEvent::Destroyed,
..
} => {
surface_fn.destroy_surface(surface, None);
Copy link
Contributor

@i509VCB i509VCB Oct 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hydos this is wrong, needs to be moved to the winit::event::Event::LoopDestroyed branch

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait I can't read. Ignore me

}
_ => {}
});
}

Ok(())
}
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["maik klein <maikklein@googlemail.com>"]
edition = "2018"

[dependencies]
winit = "0.19.5"
winit = "0.25.0"
image = "0.10.4"
ash = { path = "../ash" }
ash-window = { path = "../ash-window" }
278 changes: 148 additions & 130 deletions examples/src/bin/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ pub struct Vector3 {
pub _pad: f32,
}

#[derive(Debug)]
struct TextureState {
framebuffers: Vec<vk::Framebuffer>,
graphics_pipelines: Vec<vk::Pipeline>,
}

fn main() {
unsafe {
let base = ExampleBase::new(1920, 1080);
let (event_loop, base) = ExampleBase::new(1920, 1080);

let renderpass_attachments = [
vk::AttachmentDescription {
Expand Down Expand Up @@ -701,136 +707,148 @@ fn main() {

let graphic_pipeline = graphics_pipelines[0];

base.render_loop(|| {
let (present_index, _) = base
.swapchain_loader
.acquire_next_image(
base.swapchain,
std::u64::MAX,
base.present_complete_semaphore,
vk::Fence::null(),
)
.unwrap();
let clear_values = [
vk::ClearValue {
color: vk::ClearColorValue {
float32: [0.0, 0.0, 0.0, 0.0],
let texture_state = TextureState {
framebuffers,
graphics_pipelines,
};

ExampleBase::run(
event_loop,
base,
texture_state,
move |base, state| {
let (present_index, _) = base
.swapchain_loader
.acquire_next_image(
base.swapchain,
std::u64::MAX,
base.present_complete_semaphore,
vk::Fence::null(),
)
.unwrap();
let clear_values = [
vk::ClearValue {
color: vk::ClearColorValue {
float32: [0.0, 0.0, 0.0, 0.0],
},
},
},
vk::ClearValue {
depth_stencil: vk::ClearDepthStencilValue {
depth: 1.0,
stencil: 0,
vk::ClearValue {
depth_stencil: vk::ClearDepthStencilValue {
depth: 1.0,
stencil: 0,
},
},
},
];

let render_pass_begin_info = vk::RenderPassBeginInfo::builder()
.render_pass(renderpass)
.framebuffer(framebuffers[present_index as usize])
.render_area(vk::Rect2D {
offset: vk::Offset2D { x: 0, y: 0 },
extent: base.surface_resolution,
})
.clear_values(&clear_values);

record_submit_commandbuffer(
&base.device,
base.draw_command_buffer,
base.draw_commands_reuse_fence,
base.present_queue,
&[vk::PipelineStageFlags::BOTTOM_OF_PIPE],
&[base.present_complete_semaphore],
&[base.rendering_complete_semaphore],
|device, draw_command_buffer| {
device.cmd_begin_render_pass(
draw_command_buffer,
&render_pass_begin_info,
vk::SubpassContents::INLINE,
);
device.cmd_bind_descriptor_sets(
draw_command_buffer,
vk::PipelineBindPoint::GRAPHICS,
pipeline_layout,
0,
&descriptor_sets[..],
&[],
);
device.cmd_bind_pipeline(
draw_command_buffer,
vk::PipelineBindPoint::GRAPHICS,
graphic_pipeline,
);
device.cmd_set_viewport(draw_command_buffer, 0, &viewports);
device.cmd_set_scissor(draw_command_buffer, 0, &scissors);
device.cmd_bind_vertex_buffers(
draw_command_buffer,
0,
&[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 = mem::zeroed();
let present_info = vk::PresentInfoKHR {
wait_semaphore_count: 1,
p_wait_semaphores: &base.rendering_complete_semaphore,
swapchain_count: 1,
p_swapchains: &base.swapchain,
p_image_indices: &present_index,
..Default::default()
};
base.swapchain_loader
.queue_present(base.present_queue, &present_info)
.unwrap();
});
base.device.device_wait_idle().unwrap();

for pipeline in graphics_pipelines {
base.device.destroy_pipeline(pipeline, None);
}
base.device.destroy_pipeline_layout(pipeline_layout, None);
base.device
.destroy_shader_module(vertex_shader_module, None);
base.device
.destroy_shader_module(fragment_shader_module, None);
base.device.free_memory(image_buffer_memory, None);
base.device.destroy_buffer(image_buffer, None);
base.device.free_memory(texture_memory, None);
base.device.destroy_image_view(tex_image_view, None);
base.device.destroy_image(texture_image, None);
base.device.free_memory(index_buffer_memory, None);
base.device.destroy_buffer(index_buffer, None);
base.device.free_memory(uniform_color_buffer_memory, None);
base.device.destroy_buffer(uniform_color_buffer, None);
base.device.free_memory(vertex_input_buffer_memory, None);
base.device.destroy_buffer(vertex_input_buffer, None);
for &descriptor_set_layout in desc_set_layouts.iter() {
base.device
.destroy_descriptor_set_layout(descriptor_set_layout, None);
}
base.device.destroy_descriptor_pool(descriptor_pool, None);
base.device.destroy_sampler(sampler, None);
for framebuffer in framebuffers {
base.device.destroy_framebuffer(framebuffer, None);
}
base.device.destroy_render_pass(renderpass, None);
];

let render_pass_begin_info = vk::RenderPassBeginInfo::builder()
.render_pass(renderpass)
.framebuffer(state.framebuffers[present_index as usize])
.render_area(vk::Rect2D {
offset: vk::Offset2D { x: 0, y: 0 },
extent: base.surface_resolution,
})
.clear_values(&clear_values);

record_submit_commandbuffer(
&base.device,
base.draw_command_buffer,
base.draw_commands_reuse_fence,
base.present_queue,
&[vk::PipelineStageFlags::BOTTOM_OF_PIPE],
&[base.present_complete_semaphore],
&[base.rendering_complete_semaphore],
|device, draw_command_buffer| {
device.cmd_begin_render_pass(
draw_command_buffer,
&render_pass_begin_info,
vk::SubpassContents::INLINE,
);
device.cmd_bind_descriptor_sets(
draw_command_buffer,
vk::PipelineBindPoint::GRAPHICS,
pipeline_layout,
0,
&descriptor_sets[..],
&[],
);
device.cmd_bind_pipeline(
draw_command_buffer,
vk::PipelineBindPoint::GRAPHICS,
graphic_pipeline,
);
device.cmd_set_viewport(draw_command_buffer, 0, &viewports);
device.cmd_set_scissor(draw_command_buffer, 0, &scissors);
device.cmd_bind_vertex_buffers(
draw_command_buffer,
0,
&[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 = mem::zeroed();
let present_info = vk::PresentInfoKHR {
wait_semaphore_count: 1,
p_wait_semaphores: &base.rendering_complete_semaphore,
swapchain_count: 1,
p_swapchains: &base.swapchain,
p_image_indices: &present_index,
..Default::default()
};
base.swapchain_loader
.queue_present(base.present_queue, &present_info)
.unwrap();
},
move |base, state| {
base.device.device_wait_idle().unwrap();

for pipeline in &mut state.graphics_pipelines.drain(..) {
base.device.destroy_pipeline(pipeline, None);
}
base.device.destroy_pipeline_layout(pipeline_layout, None);
base.device
.destroy_shader_module(vertex_shader_module, None);
base.device
.destroy_shader_module(fragment_shader_module, None);
base.device.free_memory(image_buffer_memory, None);
base.device.destroy_buffer(image_buffer, None);
base.device.free_memory(texture_memory, None);
base.device.destroy_image_view(tex_image_view, None);
base.device.destroy_image(texture_image, None);
base.device.free_memory(index_buffer_memory, None);
base.device.destroy_buffer(index_buffer, None);
base.device.free_memory(uniform_color_buffer_memory, None);
base.device.destroy_buffer(uniform_color_buffer, None);
base.device.free_memory(vertex_input_buffer_memory, None);
base.device.destroy_buffer(vertex_input_buffer, None);
for &descriptor_set_layout in desc_set_layouts.iter() {
base.device
.destroy_descriptor_set_layout(descriptor_set_layout, None);
}
base.device.destroy_descriptor_pool(descriptor_pool, None);
base.device.destroy_sampler(sampler, None);
for framebuffer in &mut state.framebuffers.drain(..) {
base.device.destroy_framebuffer(framebuffer, None);
}
base.device.destroy_render_pass(renderpass, None);
},
);
}
}
Loading