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

Low level interop with Vulkan backend #3762

Merged
merged 1 commit into from
May 20, 2021
Merged
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
74 changes: 44 additions & 30 deletions src/backend/vulkan/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1216,37 +1216,12 @@ impl d::Device<B> for super::Device {
let is_cube = image
.flags
.intersects(vk::ImageCreateFlags::CUBE_COMPATIBLE);
let mut image_view_info;
let mut info = vk::ImageViewCreateInfo::builder()
.flags(vk::ImageViewCreateFlags::empty())
.image(image.raw)
.view_type(match conv::map_view_kind(kind, image.ty, is_cube) {
Some(ty) => ty,
None => return Err(image::ViewCreationError::BadKind(kind)),
})
.format(conv::map_format(format))
.components(conv::map_swizzle(swizzle))
.subresource_range(conv::map_subresource_range(&range));

if self.shared.image_view_usage {
image_view_info = vk::ImageViewUsageCreateInfo::builder()
.usage(conv::map_image_usage(usage))
.build();
info = info.push_next(&mut image_view_info);
}

let result = self.shared.raw.create_image_view(&info, None);
let view_type = match conv::map_view_kind(kind, image.ty, is_cube) {
Some(ty) => ty,
None => return Err(image::ViewCreationError::BadKind(kind)),
};

match result {
Ok(raw) => Ok(n::ImageView {
image: image.raw,
raw,
range,
}),
Err(vk::Result::ERROR_OUT_OF_HOST_MEMORY) => Err(d::OutOfMemory::Host.into()),
Err(vk::Result::ERROR_OUT_OF_DEVICE_MEMORY) => Err(d::OutOfMemory::Device.into()),
_ => unreachable!(),
}
self.image_view_from_raw(image.raw, view_type, format, swizzle, usage, range)
}

unsafe fn create_descriptor_pool<T>(
Expand Down Expand Up @@ -2030,6 +2005,45 @@ impl super::Device {

Ok((swapchain, images))
}

pub unsafe fn image_view_from_raw(
&self,
raw_image: vk::Image,
view_type: vk::ImageViewType,
format: format::Format,
swizzle: format::Swizzle,
usage: image::Usage,
range: image::SubresourceRange,
) -> Result<n::ImageView, image::ViewCreationError> {
Comment on lines +2009 to +2017
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would have preferred adding a Device::image_from_raw() method, but in my case it is OpenXR that creates the Vulkan images and it hides some details needed to construct gfx images.

let mut image_view_info;
let mut info = vk::ImageViewCreateInfo::builder()
.flags(vk::ImageViewCreateFlags::empty())
.image(raw_image)
.view_type(view_type)
.format(conv::map_format(format))
.components(conv::map_swizzle(swizzle))
.subresource_range(conv::map_subresource_range(&range));

if self.shared.image_view_usage {
image_view_info = vk::ImageViewUsageCreateInfo::builder()
.usage(conv::map_image_usage(usage))
.build();
info = info.push_next(&mut image_view_info);
}

let result = self.shared.raw.create_image_view(&info, None);

match result {
Ok(raw) => Ok(n::ImageView {
image: raw_image,
raw,
range,
}),
Err(vk::Result::ERROR_OUT_OF_HOST_MEMORY) => Err(d::OutOfMemory::Host.into()),
Err(vk::Result::ERROR_OUT_OF_DEVICE_MEMORY) => Err(d::OutOfMemory::Device.into()),
_ => unreachable!(),
}
}
}

#[test]
Expand Down
Loading