Skip to content

Commit

Permalink
Use Ash builders for Vulkan struct construction + refactor (#2525)
Browse files Browse the repository at this point in the history
* Use Ash builders for Vulkan struct construction + refactor

* Use pointer for `from_qnx_screen`

* Workaround for Ash bug

* Fix vulkano-taskgraph

---------

Co-authored-by: marc0246 <40955683+marc0246@users.noreply.github.com>
  • Loading branch information
Rua and marc0246 authored Oct 2, 2024
1 parent bad11ee commit 9033311
Show file tree
Hide file tree
Showing 75 changed files with 10,096 additions and 8,218 deletions.
19 changes: 8 additions & 11 deletions vulkano-taskgraph/src/command_buffer/commands/clear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::{
resource::{AccessType, ImageLayoutType},
Id,
};
use ash::vk;
use smallvec::SmallVec;
use std::{ffi::c_void, mem};
use vulkano::{
Expand Down Expand Up @@ -43,31 +42,30 @@ impl RecordingCommandBuffer<'_> {
let cmd_clear_color_image = fns.v1_0.cmd_clear_color_image;

if regions.is_empty() {
let region_vk = image.subresource_range().into();
let region_vk = image.subresource_range().to_vk();

unsafe {
cmd_clear_color_image(
self.handle(),
image.handle(),
image_layout.into(),
&clear_value.into(),
&clear_value.to_vk(),
1,
&region_vk,
)
};
} else {
let regions_vk = regions
.iter()
.cloned()
.map(vk::ImageSubresourceRange::from)
.map(ImageSubresourceRange::to_vk)
.collect::<SmallVec<[_; 8]>>();

unsafe {
cmd_clear_color_image(
self.handle(),
image.handle(),
image_layout.into(),
&clear_value.into(),
&clear_value.to_vk(),
regions_vk.len() as u32,
regions_vk.as_ptr(),
)
Expand Down Expand Up @@ -104,31 +102,30 @@ impl RecordingCommandBuffer<'_> {
let cmd_clear_depth_stencil_image = fns.v1_0.cmd_clear_depth_stencil_image;

if regions.is_empty() {
let region_vk = image.subresource_range().into();
let region_vk = image.subresource_range().to_vk();

unsafe {
cmd_clear_depth_stencil_image(
self.handle(),
image.handle(),
image_layout.into(),
&clear_value.into(),
&clear_value.to_vk(),
1,
&region_vk,
)
};
} else {
let regions_vk = regions
.iter()
.cloned()
.map(vk::ImageSubresourceRange::from)
.map(ImageSubresourceRange::to_vk)
.collect::<SmallVec<[_; 8]>>();

unsafe {
cmd_clear_depth_stencil_image(
self.handle(),
image.handle(),
image_layout.into(),
&clear_value.into(),
&clear_value.to_vk(),
regions_vk.len() as u32,
regions_vk.as_ptr(),
)
Expand Down
64 changes: 32 additions & 32 deletions vulkano-taskgraph/src/command_buffer/commands/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,15 @@ impl RecordingCommandBuffer<'_> {
array_layers: 0..min_array_layers,
..src_image.subresource_layers()
}
.into(),
.to_vk(),
)
.src_offset(convert_offset([0; 3]))
.dst_subresource(
ImageSubresourceLayers {
array_layers: 0..min_array_layers,
..dst_image.subresource_layers()
}
.into(),
.to_vk(),
)
.dst_offset(convert_offset([0; 3]))
.extent(convert_extent([
Expand Down Expand Up @@ -235,9 +235,9 @@ impl RecordingCommandBuffer<'_> {
} = region;

vk::ImageCopy2::default()
.src_subresource(src_subresource.into())
.src_subresource(src_subresource.to_vk())
.src_offset(convert_offset(src_offset))
.dst_subresource(dst_subresource.into())
.dst_subresource(dst_subresource.to_vk())
.dst_offset(convert_offset(dst_offset))
.extent(convert_extent(extent))
})
Expand All @@ -264,13 +264,13 @@ impl RecordingCommandBuffer<'_> {
array_layers: 0..min_array_layers,
..src_image.subresource_layers()
}
.into(),
.to_vk(),
src_offset: convert_offset([0; 3]),
dst_subresource: ImageSubresourceLayers {
array_layers: 0..min_array_layers,
..dst_image.subresource_layers()
}
.into(),
.to_vk(),
dst_offset: convert_offset([0; 3]),
extent: convert_extent([
cmp::min(src_extent[0], dst_extent[0]),
Expand Down Expand Up @@ -304,9 +304,9 @@ impl RecordingCommandBuffer<'_> {
} = region;

vk::ImageCopy {
src_subresource: src_subresource.into(),
src_subresource: src_subresource.to_vk(),
src_offset: convert_offset(src_offset),
dst_subresource: dst_subresource.into(),
dst_subresource: dst_subresource.to_vk(),
dst_offset: convert_offset(dst_offset),
extent: convert_extent(extent),
}
Expand Down Expand Up @@ -370,7 +370,7 @@ impl RecordingCommandBuffer<'_> {
.buffer_offset(0)
.buffer_row_length(0)
.buffer_image_height(0)
.image_subresource(dst_image.subresource_layers().into())
.image_subresource(dst_image.subresource_layers().to_vk())
.image_offset(convert_offset([0; 3]))
.image_extent(convert_extent(dst_image.extent()))];

Expand Down Expand Up @@ -399,7 +399,7 @@ impl RecordingCommandBuffer<'_> {
.buffer_offset(buffer_offset)
.buffer_row_length(buffer_row_length)
.buffer_image_height(buffer_image_height)
.image_subresource(image_subresource.into())
.image_subresource(image_subresource.to_vk())
.image_offset(convert_offset(image_offset))
.image_extent(convert_extent(image_extent))
})
Expand All @@ -421,7 +421,7 @@ impl RecordingCommandBuffer<'_> {
buffer_offset: 0,
buffer_row_length: 0,
buffer_image_height: 0,
image_subresource: dst_image.subresource_layers().into(),
image_subresource: dst_image.subresource_layers().to_vk(),
image_offset: convert_offset([0; 3]),
image_extent: convert_extent(dst_image.extent()),
};
Expand Down Expand Up @@ -454,7 +454,7 @@ impl RecordingCommandBuffer<'_> {
buffer_offset,
buffer_row_length,
buffer_image_height,
image_subresource: image_subresource.into(),
image_subresource: image_subresource.to_vk(),
image_offset: convert_offset(image_offset),
image_extent: convert_extent(image_extent),
}
Expand Down Expand Up @@ -517,7 +517,7 @@ impl RecordingCommandBuffer<'_> {
.buffer_offset(0)
.buffer_row_length(0)
.buffer_image_height(0)
.image_subresource(src_image.subresource_layers().into())
.image_subresource(src_image.subresource_layers().to_vk())
.image_offset(convert_offset([0; 3]))
.image_extent(convert_extent(src_image.extent()))];

Expand Down Expand Up @@ -546,7 +546,7 @@ impl RecordingCommandBuffer<'_> {
.buffer_offset(buffer_offset)
.buffer_row_length(buffer_row_length)
.buffer_image_height(buffer_image_height)
.image_subresource(image_subresource.into())
.image_subresource(image_subresource.to_vk())
.image_offset(convert_offset(image_offset))
.image_extent(convert_extent(image_extent))
})
Expand All @@ -568,7 +568,7 @@ impl RecordingCommandBuffer<'_> {
buffer_offset: 0,
buffer_row_length: 0,
buffer_image_height: 0,
image_subresource: src_image.subresource_layers().into(),
image_subresource: src_image.subresource_layers().to_vk(),
image_offset: convert_offset([0; 3]),
image_extent: convert_extent(src_image.extent()),
};
Expand Down Expand Up @@ -601,7 +601,7 @@ impl RecordingCommandBuffer<'_> {
buffer_offset,
buffer_row_length,
buffer_image_height,
image_subresource: image_subresource.into(),
image_subresource: image_subresource.to_vk(),
image_offset: convert_offset(image_offset),
image_extent: convert_extent(image_extent),
}
Expand Down Expand Up @@ -692,15 +692,15 @@ impl RecordingCommandBuffer<'_> {
array_layers: 0..min_array_layers,
..src_image.subresource_layers()
}
.into(),
.to_vk(),
)
.src_offsets([[0; 3], src_image.extent()].map(convert_offset))
.dst_subresource(
ImageSubresourceLayers {
array_layers: 0..min_array_layers,
..src_image.subresource_layers()
}
.into(),
.to_vk(),
)
.dst_offsets([[0; 3], dst_image.extent()].map(convert_offset))];

Expand All @@ -726,9 +726,9 @@ impl RecordingCommandBuffer<'_> {
} = region;

vk::ImageBlit2::default()
.src_subresource(src_subresource.into())
.src_subresource(src_subresource.to_vk())
.src_offsets(src_offsets.map(convert_offset))
.dst_subresource(dst_subresource.into())
.dst_subresource(dst_subresource.to_vk())
.dst_offsets(dst_offsets.map(convert_offset))
})
.collect::<SmallVec<[_; 8]>>();
Expand All @@ -753,13 +753,13 @@ impl RecordingCommandBuffer<'_> {
array_layers: 0..min_array_layers,
..src_image.subresource_layers()
}
.into(),
.to_vk(),
src_offsets: [[0; 3], src_image.extent()].map(convert_offset),
dst_subresource: ImageSubresourceLayers {
array_layers: 0..min_array_layers,
..dst_image.subresource_layers()
}
.into(),
.to_vk(),
dst_offsets: [[0; 3], dst_image.extent()].map(convert_offset),
};

Expand Down Expand Up @@ -788,9 +788,9 @@ impl RecordingCommandBuffer<'_> {
} = region;

vk::ImageBlit {
src_subresource: src_subresource.into(),
src_subresource: src_subresource.to_vk(),
src_offsets: src_offsets.map(convert_offset),
dst_subresource: dst_subresource.into(),
dst_subresource: dst_subresource.to_vk(),
dst_offsets: dst_offsets.map(convert_offset),
}
})
Expand Down Expand Up @@ -861,15 +861,15 @@ impl RecordingCommandBuffer<'_> {
array_layers: 0..min_array_layers,
..src_image.subresource_layers()
}
.into(),
.to_vk(),
)
.src_offset(convert_offset([0; 3]))
.dst_subresource(
ImageSubresourceLayers {
array_layers: 0..min_array_layers,
..src_image.subresource_layers()
}
.into(),
.to_vk(),
)
.dst_offset(convert_offset([0; 3]))
.extent(convert_extent([
Expand Down Expand Up @@ -900,9 +900,9 @@ impl RecordingCommandBuffer<'_> {
} = region;

vk::ImageResolve2::default()
.src_subresource(src_subresource.into())
.src_subresource(src_subresource.to_vk())
.src_offset(convert_offset(src_offset))
.dst_subresource(dst_subresource.into())
.dst_subresource(dst_subresource.to_vk())
.dst_offset(convert_offset(dst_offset))
.extent(convert_extent(extent))
})
Expand All @@ -929,13 +929,13 @@ impl RecordingCommandBuffer<'_> {
array_layers: 0..min_array_layers,
..src_image.subresource_layers()
}
.into(),
.to_vk(),
src_offset: convert_offset([0; 3]),
dst_subresource: ImageSubresourceLayers {
array_layers: 0..min_array_layers,
..dst_image.subresource_layers()
}
.into(),
.to_vk(),
dst_offset: convert_offset([0; 3]),
extent: convert_extent([
cmp::min(src_extent[0], dst_extent[0]),
Expand Down Expand Up @@ -969,9 +969,9 @@ impl RecordingCommandBuffer<'_> {
} = region;

vk::ImageResolve {
src_subresource: src_subresource.into(),
src_subresource: src_subresource.to_vk(),
src_offset: convert_offset(src_offset),
dst_subresource: dst_subresource.into(),
dst_subresource: dst_subresource.to_vk(),
dst_offset: convert_offset(dst_offset),
extent: convert_extent(extent),
}
Expand Down
Loading

0 comments on commit 9033311

Please sign in to comment.