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

Code cleanup #2497

Merged
merged 16 commits into from
Mar 13, 2024
Merged
2 changes: 1 addition & 1 deletion examples/debug/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ fn main() {
})
.expect("no device available");

let (_device, mut _queues) = Device::new(
let (_device, _queues) = Device::new(
physical_device,
DeviceCreateInfo {
enabled_extensions: device_extensions,
Expand Down
4 changes: 2 additions & 2 deletions examples/gl-interop/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,11 @@ mod linux {
}
Err(VulkanError::OutOfDate) => {
recreate_swapchain = true;
previous_frame_end = Some(vulkano::sync::now(device.clone()).boxed());
previous_frame_end = Some(now(device.clone()).boxed());
}
Err(e) => {
println!("failed to flush future: {e}");
previous_frame_end = Some(vulkano::sync::now(device.clone()).boxed());
previous_frame_end = Some(now(device.clone()).boxed());
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion examples/interactive-fractal/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ impl InputState {
}

/// Update toggle julia state (if right mouse is clicked)
fn on_mouse_click_event(&mut self, state: ElementState, mouse_btn: winit::event::MouseButton) {
fn on_mouse_click_event(&mut self, state: ElementState, mouse_btn: MouseButton) {
if mouse_btn == MouseButton::Right {
self.toggle_c = state_is_pressed(state)
}
Expand Down
10 changes: 5 additions & 5 deletions examples/interactive-fractal/fractal_compute_pipeline.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use glam::f32::Vec2;
use rand::Rng;
use rand::random;
use std::sync::Arc;
use vulkano::{
buffer::{Buffer, BufferCreateInfo, BufferUsage, Subbuffer},
Expand Down Expand Up @@ -103,10 +103,10 @@ impl FractalComputePipeline {
pub fn randomize_palette(&mut self) {
let mut colors = vec![];
for _ in 0..self.palette_size {
let r = rand::thread_rng().gen::<f32>();
let g = rand::thread_rng().gen::<f32>();
let b = rand::thread_rng().gen::<f32>();
let a = rand::thread_rng().gen::<f32>();
let r = random::<f32>();
let g = random::<f32>();
let b = random::<f32>();
let a = random::<f32>();
colors.push([r, g, b, a]);
}
self.palette = Buffer::from_iter(
Expand Down
9 changes: 3 additions & 6 deletions vulkano-util/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub struct VulkanoWindowRenderer {
recreate_swapchain: bool,
previous_frame_end: Option<Box<dyn GpuFuture>>,
image_index: u32,
present_mode: vulkano::swapchain::PresentMode,
present_mode: PresentMode,
}

impl VulkanoWindowRenderer {
Expand All @@ -44,7 +44,7 @@ impl VulkanoWindowRenderer {
/// [`SwapchainCreateInfo`] parameters.
pub fn new(
vulkano_context: &VulkanoContext,
window: winit::window::Window,
window: Window,
descriptor: &WindowDescriptor,
swapchain_create_info_modify: fn(&mut SwapchainCreateInfo),
) -> VulkanoWindowRenderer {
Expand Down Expand Up @@ -315,10 +315,7 @@ impl VulkanoWindowRenderer {
match future.map_err(Validated::unwrap) {
Ok(mut future) => {
if wait_future {
match future.wait(None) {
Ok(x) => x,
Err(e) => println!("{e}"),
}
future.wait(None).unwrap_or_else(|e| println!("{e}"))
// wait allows you to organize resource waiting yourself.
} else {
future.cleanup_finished();
Expand Down
27 changes: 11 additions & 16 deletions vulkano-util/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ use winit::{
/// ```
#[derive(Default)]
pub struct VulkanoWindows {
windows: HashMap<winit::window::WindowId, VulkanoWindowRenderer>,
primary: Option<winit::window::WindowId>,
windows: HashMap<WindowId, VulkanoWindowRenderer>,
primary: Option<WindowId>,
}

impl VulkanoWindows {
Expand All @@ -50,7 +50,7 @@ impl VulkanoWindows {
vulkano_context: &VulkanoContext,
window_descriptor: &WindowDescriptor,
swapchain_create_info_modify: fn(&mut SwapchainCreateInfo),
) -> winit::window::WindowId {
) -> WindowId {
let mut winit_window_builder = winit::window::WindowBuilder::new();

winit_window_builder = match window_descriptor.mode {
Expand Down Expand Up @@ -96,12 +96,10 @@ impl VulkanoWindows {
}
}
if let Some(sf) = scale_factor_override {
winit_window_builder.with_inner_size(
winit::dpi::LogicalSize::new(*width, *height).to_physical::<f64>(*sf),
)
} else {
winit_window_builder
.with_inner_size(winit::dpi::LogicalSize::new(*width, *height))
.with_inner_size(LogicalSize::new(*width, *height).to_physical::<f64>(*sf))
} else {
winit_window_builder.with_inner_size(LogicalSize::new(*width, *height))
}
}
.with_resizable(window_descriptor.resizable)
Expand Down Expand Up @@ -193,34 +191,31 @@ impl VulkanoWindows {

/// Get a mutable reference to the renderer by winit window id.
#[inline]
pub fn get_renderer_mut(
&mut self,
id: winit::window::WindowId,
) -> Option<&mut VulkanoWindowRenderer> {
pub fn get_renderer_mut(&mut self, id: WindowId) -> Option<&mut VulkanoWindowRenderer> {
self.windows.get_mut(&id)
}

/// Get a reference to the renderer by winit window id.
#[inline]
pub fn get_renderer(&self, id: winit::window::WindowId) -> Option<&VulkanoWindowRenderer> {
pub fn get_renderer(&self, id: WindowId) -> Option<&VulkanoWindowRenderer> {
self.windows.get(&id)
}

/// Get a reference to the winit window by winit window id.
#[inline]
pub fn get_window(&self, id: winit::window::WindowId) -> Option<&winit::window::Window> {
pub fn get_window(&self, id: WindowId) -> Option<&winit::window::Window> {
self.windows.get(&id).map(|v_window| v_window.window())
}

/// Return primary window id.
#[inline]
pub fn primary_window_id(&self) -> Option<winit::window::WindowId> {
pub fn primary_window_id(&self) -> Option<WindowId> {
self.primary
}

/// Remove renderer by window id.
#[inline]
pub fn remove_renderer(&mut self, id: winit::window::WindowId) {
pub fn remove_renderer(&mut self, id: WindowId) {
self.windows.remove(&id);
if let Some(primary) = self.primary {
if primary == id {
Expand Down
58 changes: 31 additions & 27 deletions vulkano/autogen/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,29 +108,33 @@ fn device_extensions_output(members: &[ExtensionsMember]) -> TokenStream {
instance_extensions,
device_features: _,
}| {
let condition_items = (api_version.iter().map(|version| {
let version = format_ident!("V{}_{}", version.0, version.1);
quote! { api_version >= crate::Version::#version }
}))
.chain(instance_extensions.iter().map(|ext_name| {
let ident = format_ident!("{}", ext_name);
quote! { instance_extensions.#ident }
}));
let requires_one_of_items = (api_version.iter().map(|(major, minor)| {
let version = format_ident!("V{}_{}", major, minor);
quote! {
crate::RequiresAllOf(&[
crate::Requires::APIVersion(crate::Version::#version),
]),
}
}))
.chain(instance_extensions.iter().map(|ext_name| {
quote! {
crate::RequiresAllOf(&[
crate::Requires::InstanceExtension(#ext_name),
]),
}
}));
let condition_items = api_version
.iter()
.map(|version| {
let version = format_ident!("V{}_{}", version.0, version.1);
quote! { api_version >= crate::Version::#version }
})
.chain(instance_extensions.iter().map(|ext_name| {
let ident = format_ident!("{}", ext_name);
quote! { instance_extensions.#ident }
}));
let requires_one_of_items = api_version
.iter()
.map(|(major, minor)| {
let version = format_ident!("V{}_{}", major, minor);
quote! {
crate::RequiresAllOf(&[
crate::Requires::APIVersion(crate::Version::#version),
]),
}
})
.chain(instance_extensions.iter().map(|ext_name| {
quote! {
crate::RequiresAllOf(&[
crate::Requires::InstanceExtension(#ext_name),
]),
}
}));
let problem = format!("contains `{}`", name_string);

quote! {
Expand Down Expand Up @@ -173,7 +177,7 @@ fn device_extensions_output(members: &[ExtensionsMember]) -> TokenStream {
name: _,
requires_all_of,
..
}| (!requires_all_of.is_empty()),
}| !requires_all_of.is_empty(),
)
.map(
|ExtensionsMember {
Expand All @@ -191,7 +195,7 @@ fn device_extensions_output(members: &[ExtensionsMember]) -> TokenStream {
device_extensions,
instance_extensions: _,
device_features: _,
}| (!device_extensions.is_empty()),
}| !device_extensions.is_empty(),
)
.map(
|RequiresOneOf {
Expand Down Expand Up @@ -364,7 +368,7 @@ fn instance_extensions_output(members: &[ExtensionsMember]) -> TokenStream {
name: _,
requires_all_of,
..
}| (!requires_all_of.is_empty()),
}| !requires_all_of.is_empty(),
)
.map(
|ExtensionsMember {
Expand All @@ -382,7 +386,7 @@ fn instance_extensions_output(members: &[ExtensionsMember]) -> TokenStream {
device_extensions: _,
instance_extensions,
device_features: _,
}| (!instance_extensions.is_empty()),
}| !instance_extensions.is_empty(),
)
.map(
|RequiresOneOf {
Expand Down
87 changes: 47 additions & 40 deletions vulkano/autogen/formats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ fn formats_output(members: &[FormatMember]) -> TokenStream {
.filter(
|&FormatMember {
texels_per_block, ..
}| (*texels_per_block != 1),
}| *texels_per_block != 1,
)
.map(
|FormatMember {
Expand Down Expand Up @@ -257,7 +257,7 @@ fn formats_output(members: &[FormatMember]) -> TokenStream {
type_cgmath,
..
}| {
(type_cgmath.as_ref().or(type_std_array.as_ref())).map(|ty| {
type_cgmath.as_ref().or(type_std_array.as_ref()).map(|ty| {
quote! { (cgmath, #name) => { #ty }; }
})
},
Expand All @@ -269,7 +269,7 @@ fn formats_output(members: &[FormatMember]) -> TokenStream {
type_glam,
..
}| {
(type_glam.as_ref().or(type_std_array.as_ref())).map(|ty| {
type_glam.as_ref().or(type_std_array.as_ref()).map(|ty| {
quote! { (glam, #name) => { #ty }; }
})
},
Expand All @@ -281,9 +281,12 @@ fn formats_output(members: &[FormatMember]) -> TokenStream {
type_nalgebra,
..
}| {
(type_nalgebra.as_ref().or(type_std_array.as_ref())).map(|ty| {
quote! { (nalgebra, #name) => { #ty }; }
})
type_nalgebra
.as_ref()
.or(type_std_array.as_ref())
.map(|ty| {
quote! { (nalgebra, #name) => { #ty }; }
})
},
);

Expand All @@ -300,41 +303,45 @@ fn formats_output(members: &[FormatMember]) -> TokenStream {
instance_extensions,
device_features: _,
}| {
let condition_items = (api_version.iter().map(|(major, minor)| {
let version = format_ident!("V{}_{}", major, minor);
quote! { device_api_version >= crate::Version::#version }
}))
.chain(device_extensions.iter().map(|ext_name| {
let ident = format_ident!("{}", ext_name);
quote! { device_extensions.#ident }
}))
.chain(instance_extensions.iter().map(|ext_name| {
let ident = format_ident!("{}", ext_name);
quote! { instance_extensions.#ident }
}));
let condition_items = api_version
.iter()
.map(|(major, minor)| {
let version = format_ident!("V{}_{}", major, minor);
quote! { device_api_version >= crate::Version::#version }
})
.chain(device_extensions.iter().map(|ext_name| {
let ident = format_ident!("{}", ext_name);
quote! { device_extensions.#ident }
}))
.chain(instance_extensions.iter().map(|ext_name| {
let ident = format_ident!("{}", ext_name);
quote! { instance_extensions.#ident }
}));
let required_for = format!("is `Format::{}`", name);
let requires_one_of_items = (api_version.iter().map(|(major, minor)| {
let version = format_ident!("V{}_{}", major, minor);
quote! {
crate::RequiresAllOf(&[
crate::Requires::APIVersion(crate::Version::#version),
]),
}
}))
.chain(device_extensions.iter().map(|ext_name| {
quote! {
crate::RequiresAllOf(&[
crate::Requires::DeviceExtension(#ext_name),
]),
}
}))
.chain(instance_extensions.iter().map(|ext_name| {
quote! {
crate::RequiresAllOf(&[
crate::Requires::InstanceExtension(#ext_name),
]),
}
}));
let requires_one_of_items = api_version
.iter()
.map(|(major, minor)| {
let version = format_ident!("V{}_{}", major, minor);
quote! {
crate::RequiresAllOf(&[
crate::Requires::APIVersion(crate::Version::#version),
]),
}
})
.chain(device_extensions.iter().map(|ext_name| {
quote! {
crate::RequiresAllOf(&[
crate::Requires::DeviceExtension(#ext_name),
]),
}
}))
.chain(instance_extensions.iter().map(|ext_name| {
quote! {
crate::RequiresAllOf(&[
crate::Requires::InstanceExtension(#ext_name),
]),
}
}));

quote! {
if !(#(#condition_items)||*) {
Expand Down
Loading
Loading