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

Partial gfx-0.6 upgrade #298

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
117 changes: 67 additions & 50 deletions command/src/buffer/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,10 @@ where
/// device limit.
///
/// See: https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/vkCmdBindVertexBuffers.html
pub unsafe fn bind_vertex_buffers<'b>(
&mut self,
first_binding: u32,
buffers: impl IntoIterator<Item = (&'b B::Buffer, u64)>,
) where
pub unsafe fn bind_vertex_buffers<'b, I>(&mut self, first_binding: u32, buffers: I)
where
I: IntoIterator<Item = (&'b B::Buffer, u64)>,
I::IntoIter: ExactSizeIterator,
C: Supports<Graphics>,
{
self.capability.assert();
Expand Down Expand Up @@ -168,13 +167,17 @@ where
/// # Safety
///
/// See: https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/vkCmdBindDescriptorSets.html
pub unsafe fn bind_graphics_descriptor_sets<'b>(
pub unsafe fn bind_graphics_descriptor_sets<'b, I, J>(
&mut self,
layout: &B::PipelineLayout,
first_set: u32,
sets: impl IntoIterator<Item = &'b B::DescriptorSet>,
offsets: impl IntoIterator<Item = u32>,
sets: I,
offsets: J,
) where
I: IntoIterator<Item = &'b B::DescriptorSet>,
I::IntoIter: ExactSizeIterator,
J: IntoIterator<Item = u32>,
J::IntoIter: ExactSizeIterator,
C: Supports<Graphics>,
{
self.capability.assert();
Expand Down Expand Up @@ -205,13 +208,17 @@ where
/// # Safety
///
/// See: https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/vkCmdBindDescriptorSets.html
pub unsafe fn bind_compute_descriptor_sets<'b>(
pub unsafe fn bind_compute_descriptor_sets<'b, I, J>(
&mut self,
layout: &B::PipelineLayout,
first_set: u32,
sets: impl IntoIterator<Item = &'b B::DescriptorSet>,
offsets: impl IntoIterator<Item = u32>,
sets: I,
offsets: J,
) where
I: IntoIterator<Item = &'b B::DescriptorSet>,
I::IntoIter: ExactSizeIterator,
J: IntoIterator<Item = u32>,
J::IntoIter: ExactSizeIterator,
C: Supports<Compute>,
{
self.capability.assert();
Expand Down Expand Up @@ -268,11 +275,10 @@ where
/// Set viewports
///
/// See: https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/vkCmdSetViewport.html
pub unsafe fn set_viewports<'b>(
&mut self,
first_viewport: u32,
viewports: impl IntoIterator<Item = &'b rendy_core::hal::pso::Viewport>,
) where
pub unsafe fn set_viewports<'b, I>(&mut self, first_viewport: u32, viewports: I)
where
I: IntoIterator<Item = &'b rendy_core::hal::pso::Viewport>,
I::IntoIter: ExactSizeIterator,
C: Supports<Graphics>,
{
self.capability.assert();
Expand All @@ -287,11 +293,10 @@ where
/// `maxViewports` device limit.
///
/// See: https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/vkCmdSetScissor.html
pub unsafe fn set_scissors<'b>(
&mut self,
first_scissor: u32,
rects: impl IntoIterator<Item = &'b rendy_core::hal::pso::Rect>,
) where
pub unsafe fn set_scissors<'b, I>(&mut self, first_scissor: u32, rects: I)
where
I: IntoIterator<Item = &'b rendy_core::hal::pso::Rect>,
I::IntoIter: ExactSizeIterator,
C: Supports<Graphics>,
{
self.capability.assert();
Expand Down Expand Up @@ -430,13 +435,15 @@ where
/// Clear regions within bound framebuffer attachments
///
/// See: https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/vkCmdClearAttachments.html#vkCmdBeginRenderPass
pub unsafe fn clear_attachments(
&mut self,
clears: impl IntoIterator<
Item = impl std::borrow::Borrow<rendy_core::hal::command::AttachmentClear>,
>,
rects: impl IntoIterator<Item = impl std::borrow::Borrow<rendy_core::hal::pso::ClearRect>>,
) {
pub unsafe fn clear_attachments<I, J>(&mut self, clears: I, rects: J)
where
I: IntoIterator,
I::Item: std::borrow::Borrow<rendy_core::hal::command::AttachmentClear>,
I::IntoIter: ExactSizeIterator,
J: IntoIterator,
J::Item: std::borrow::Borrow<rendy_core::hal::pso::ClearRect>,
J::IntoIter: ExactSizeIterator,
{
rendy_core::hal::command::CommandBuffer::clear_attachments(self.inner.raw, clears, rects);
}

Expand Down Expand Up @@ -631,10 +638,12 @@ where
B: rendy_core::hal::Backend,
{
/// Execute commands from secondary buffers.
pub fn execute_commands(
&mut self,
submittables: impl IntoIterator<Item = impl Submittable<B, SecondaryLevel, RenderPassContinue>>,
) {
pub fn execute_commands<I>(&mut self, submittables: I)
where
I: IntoIterator,
I::Item: Submittable<B, SecondaryLevel, RenderPassContinue>,
I::IntoIter: ExactSizeIterator,
{
let family = self.inner.family;
unsafe {
rendy_core::hal::command::CommandBuffer::execute_commands(
Expand Down Expand Up @@ -771,10 +780,12 @@ where
}

/// Execute commands from secondary buffers.
pub fn execute_commands(
&mut self,
submittables: impl IntoIterator<Item = impl Submittable<B, SecondaryLevel>>,
) {
pub fn execute_commands<I>(&mut self, submittables: I)
where
I: IntoIterator,
I::Item: Submittable<B, SecondaryLevel>,
I::IntoIter: ExactSizeIterator,
{
let family = self.inner.family;
unsafe {
rendy_core::hal::command::CommandBuffer::execute_commands(
Expand Down Expand Up @@ -811,12 +822,10 @@ where
/// length of the corresponding buffer.
///
/// See: https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/vkCmdCopyBuffer.html
pub unsafe fn copy_buffer(
&mut self,
src: &B::Buffer,
dst: &B::Buffer,
regions: impl IntoIterator<Item = rendy_core::hal::command::BufferCopy>,
) where
pub unsafe fn copy_buffer<I>(&mut self, src: &B::Buffer, dst: &B::Buffer, regions: I)
where
I: IntoIterator<Item = rendy_core::hal::command::BufferCopy>,
I::IntoIter: ExactSizeIterator,
C: Supports<Transfer>,
{
self.capability.assert();
Expand All @@ -831,13 +840,15 @@ where
/// Same as `copy_buffer()`
///
/// See: https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/vkCmdCopyBufferToImage.html
pub unsafe fn copy_buffer_to_image(
pub unsafe fn copy_buffer_to_image<I>(
&mut self,
src: &B::Buffer,
dst: &B::Image,
dst_layout: rendy_core::hal::image::Layout,
regions: impl IntoIterator<Item = rendy_core::hal::command::BufferImageCopy>,
regions: I,
) where
I: IntoIterator<Item = rendy_core::hal::command::BufferImageCopy>,
I::IntoIter: ExactSizeIterator,
C: Supports<Transfer>,
{
self.capability.assert();
Expand All @@ -858,14 +869,16 @@ where
/// Same as `copy_buffer()`
///
/// See: https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/vkCmdCopyImage.html
pub unsafe fn copy_image(
pub unsafe fn copy_image<I>(
&mut self,
src: &B::Image,
src_layout: rendy_core::hal::image::Layout,
dst: &B::Image,
dst_layout: rendy_core::hal::image::Layout,
regions: impl IntoIterator<Item = rendy_core::hal::command::ImageCopy>,
regions: I,
) where
I: IntoIterator<Item = rendy_core::hal::command::ImageCopy>,
I::IntoIter: ExactSizeIterator,
C: Supports<Transfer>,
{
self.capability.assert();
Expand All @@ -887,13 +900,15 @@ where
/// Same as `copy_buffer()`
///
/// See: https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/vkCmdCopyImageToBuffer.html
pub unsafe fn copy_image_to_buffer(
pub unsafe fn copy_image_to_buffer<I>(
&mut self,
src: &B::Image,
src_layout: rendy_core::hal::image::Layout,
dst: &B::Buffer,
regions: impl IntoIterator<Item = rendy_core::hal::command::BufferImageCopy>,
regions: I,
) where
I: IntoIterator<Item = rendy_core::hal::command::BufferImageCopy>,
I::IntoIter: ExactSizeIterator,
C: Supports<Transfer>,
{
self.capability.assert();
Expand All @@ -914,15 +929,17 @@ where
/// Same as `copy_buffer()`
///
/// See: https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/vkCmdBlitImage.html
pub unsafe fn blit_image(
pub unsafe fn blit_image<I>(
&mut self,
src: &B::Image,
src_layout: rendy_core::hal::image::Layout,
dst: &B::Image,
dst_layout: rendy_core::hal::image::Layout,
filter: rendy_core::hal::image::Filter,
regions: impl IntoIterator<Item = rendy_core::hal::command::ImageBlit>,
regions: I,
) where
I: IntoIterator<Item = rendy_core::hal::command::ImageBlit>,
I::IntoIter: ExactSizeIterator,
C: Supports<Graphics>,
{
self.capability.assert();
Expand Down
12 changes: 6 additions & 6 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ vulkan = ["gfx-backend-vulkan"]
no-slow-safety-checks = []

[dependencies]
gfx-hal = "0.5"
gfx-backend-empty = { version = "0.5", optional = true }
gfx-backend-gl = { version = "0.5", features = ["glutin"], default_features = false, optional = true }
gfx-hal = "0.6"
gfx-backend-empty = { version = "0.6", optional = true }
gfx-backend-gl = { version = "0.6", default_features = false, optional = true }
lazy_static = "1.4.0"
log = "0.4.11"
parking_lot = "0.11.1"
Expand All @@ -37,10 +37,10 @@ thread_profiler = "0.3.0"
raw-window-handle = "0.3.3"

[target.'cfg(all(target_os = "windows", not(target_arch = "wasm32")))'.dependencies]
gfx-backend-dx12 = { version = "0.5", optional = true }
gfx-backend-dx12 = { version = "0.6", optional = true }

[target.'cfg(any(all(not(target_arch = "wasm32"), target_os = "macos"), all(target_arch = "aarch64", target_os = "ios")))'.dependencies]
gfx-backend-metal = { version = "0.5", optional = true }
gfx-backend-metal = { version = "0.6", optional = true }

[target.'cfg(all(any(target_os = "windows", all(unix, not(any(target_os = "macos", target_os = "ios")))), not(target_arch = "wasm32")))'.dependencies]
gfx-backend-vulkan = { version = "0.5", features = ["x11"], optional = true }
gfx-backend-vulkan = { version = "0.6", features = ["x11"], optional = true }
2 changes: 1 addition & 1 deletion descriptor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ categories = ["rendering"]
description = "Rendy's descriptor allocator"

[dependencies]
gfx-hal = "0.5"
gfx-hal = "0.6"
log = "0.4.11"
relevant = { version = "0.4.2", features = ["log"] }
smallvec = "1.5.1"
3 changes: 1 addition & 2 deletions descriptor/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ unsafe fn allocate_from_pool<B: Backend>(
let sets_were = allocation.len();
raw.allocate(std::iter::repeat(layout).take(count as usize), allocation)
.map_err(|err| match err {
AllocationError::Host => OutOfMemory::Host,
AllocationError::Device => OutOfMemory::Device,
AllocationError::OutOfMemory(err) => err,
err => {
// We check pool for free descriptors and sets before calling this function,
// so it can't be exhausted.
Expand Down
12 changes: 12 additions & 0 deletions descriptor/src/ranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,15 @@ impl<'a> Iterator for DescriptorRangesIter<'a> {
}
}
}

impl<'a> ExactSizeIterator for DescriptorRangesIter<'a> {
fn len(&self) -> usize {
let (lower, upper) = self.size_hint();
// Note: This assertion is overly defensive, but it checks the invariant
// guaranteed by the trait. If this trait were rust-internal,
// we could use debug_assert!; assert_eq! will check all Rust user
// implementations too.
assert_eq!(upper, Some(lower));
lower
}
}
14 changes: 2 additions & 12 deletions factory/src/blitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ pub struct Blitter<B: rendy_core::hal::Backend> {
family_ops: Vec<Option<parking_lot::Mutex<FamilyGraphicsOps<B>>>>,
}

fn subresource_to_range(
sub: &rendy_core::hal::image::SubresourceLayers,
) -> rendy_core::hal::image::SubresourceRange {
rendy_core::hal::image::SubresourceRange {
aspects: sub.aspects,
levels: sub.level..sub.level + 1,
layers: sub.layers.clone(),
}
}

/// A region to be blitted including the source and destination images and states,
#[derive(Debug, Clone)]
pub struct BlitRegion {
Expand Down Expand Up @@ -331,7 +321,7 @@ pub unsafe fn blit_image<B, C, L>(
.map(|reg| {
read_barriers.add_image(
src_image.clone(),
subresource_to_range(&reg.src.subresource),
reg.src.subresource.clone().into(),
reg.src.last_stage,
reg.src.last_access,
reg.src.last_layout,
Expand All @@ -343,7 +333,7 @@ pub unsafe fn blit_image<B, C, L>(

write_barriers.add_image(
dst_image.clone(),
subresource_to_range(&reg.dst.subresource),
reg.dst.subresource.clone().into(),
reg.dst.last_stage,
reg.dst.last_access,
reg.dst.last_layout,
Expand Down
6 changes: 1 addition & 5 deletions factory/src/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,7 @@ where
let whole_level =
image_offset == rendy_core::hal::image::Offset::ZERO && image_extent == whole_extent;

let image_range = rendy_core::hal::image::SubresourceRange {
aspects: image_layers.aspects,
levels: image_layers.level..image_layers.level + 1,
layers: image_layers.layers.clone(),
};
let image_range = image_layers.clone().into();

let (last_stage, mut last_access, last_layout) = match last {
ImageStateOrLayout::State(last) => {
Expand Down
6 changes: 4 additions & 2 deletions graph/src/graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,10 @@ fn build_node<'a, B: Backend, T: ?Sized>(
id,
range: rendy_core::hal::image::SubresourceRange {
aspects: image.format().surface_desc().aspects,
levels: 0..image.levels(),
layers: 0..image.layers(),
level_start: 0,
level_count: Some(image.levels()),
layer_start: 0,
layer_count: Some(image.layers()),
},
layout: chains.images[&chain_id].links()[link]
.submission_state(submission.id())
Expand Down
Loading