Update gfx with image kind changes

This commit is contained in:
Dzmitry Malyshau 2018-03-27 13:38:49 -04:00
parent 1df436d581
commit 7a544eb46f
3 changed files with 54 additions and 52 deletions

View file

@ -25,19 +25,19 @@ optional = true
[dependencies.gfx-hal]
git = "https://github.com/gfx-rs/gfx"
rev = "eeb1a2effa079e72a48b24fafb163ab8548428ff"
rev = "eda7f3c570d09f2fd0bf942c3d945a1b62d72af8"
[target.'cfg(not(target_os = "macos"))'.dependencies.gfx-backend-vulkan]
git = "https://github.com/gfx-rs/gfx"
rev = "eeb1a2effa079e72a48b24fafb163ab8548428ff"
rev = "eda7f3c570d09f2fd0bf942c3d945a1b62d72af8"
optional = true
[target.'cfg(windows)'.dependencies.gfx-backend-dx12]
git = "https://github.com/gfx-rs/gfx"
rev = "eeb1a2effa079e72a48b24fafb163ab8548428ff"
rev = "eda7f3c570d09f2fd0bf942c3d945a1b62d72af8"
optional = true
[target.'cfg(target_os = "macos")'.dependencies.gfx-backend-metal]
git = "https://github.com/gfx-rs/gfx"
rev = "eeb1a2effa079e72a48b24fafb163ab8548428ff"
rev = "eda7f3c570d09f2fd0bf942c3d945a1b62d72af8"
optional = true

View file

@ -1,5 +1,4 @@
use hal::{buffer, command, error, format, image, memory, pass, pso, window};
use hal::device::Extent;
use hal::{PatchSize, Primitive};
use std::mem;
@ -170,37 +169,29 @@ fn map_aspect(aspects: VkImageAspectFlags) -> format::Aspects {
pub fn map_image_kind(
ty: VkImageType,
flags: VkImageCreateFlags,
extent: VkExtent3D,
array_layers: u32,
array_layers: image::Layer,
samples: VkSampleCountFlagBits,
) -> image::Kind {
debug_assert_ne!(array_layers, 0);
let is_cube = flags & VkImageCreateFlagBits::VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT as u32 != 0;
assert!(!is_cube || array_layers % 6 == 0);
match ty {
VkImageType::VK_IMAGE_TYPE_1D if array_layers == 1 => image::Kind::D1(extent.width as _),
VkImageType::VK_IMAGE_TYPE_1D => image::Kind::D1Array(extent.width as _, array_layers as _),
VkImageType::VK_IMAGE_TYPE_2D if array_layers == 1 => {
image::Kind::D2(extent.width as _, extent.height as _, map_aa_mode(samples))
}
VkImageType::VK_IMAGE_TYPE_2D if is_cube && array_layers == 6 => {
image::Kind::Cube(extent.width as _)
}
VkImageType::VK_IMAGE_TYPE_2D if is_cube => {
image::Kind::CubeArray(extent.width as _, (array_layers / 6) as _)
}
VkImageType::VK_IMAGE_TYPE_2D => image::Kind::D2Array(
extent.width as _,
extent.height as _,
array_layers as _,
map_aa_mode(samples),
),
VkImageType::VK_IMAGE_TYPE_3D => {
image::Kind::D3(extent.width as _, extent.height as _, extent.depth as _)
}
_ => unimplemented!(),
VkImageType::VK_IMAGE_TYPE_1D => image::Kind::D1(extent.width as _, array_layers),
VkImageType::VK_IMAGE_TYPE_2D => image::Kind::D2(extent.width as _, extent.height as _, array_layers, samples as _),
VkImageType::VK_IMAGE_TYPE_3D => image::Kind::D3(extent.width as _, extent.height as _, extent.depth as _),
_ => unreachable!()
}
}
pub fn map_view_kind(ty: VkImageViewType) -> image::ViewKind {
match ty {
VkImageViewType::VK_IMAGE_VIEW_TYPE_1D => image::ViewKind::D1,
VkImageViewType::VK_IMAGE_VIEW_TYPE_1D_ARRAY => image::ViewKind::D1Array,
VkImageViewType::VK_IMAGE_VIEW_TYPE_2D => image::ViewKind::D2,
VkImageViewType::VK_IMAGE_VIEW_TYPE_2D_ARRAY => image::ViewKind::D2Array,
VkImageViewType::VK_IMAGE_VIEW_TYPE_3D => image::ViewKind::D3,
VkImageViewType::VK_IMAGE_VIEW_TYPE_CUBE => image::ViewKind::Cube,
VkImageViewType::VK_IMAGE_VIEW_TYPE_CUBE_ARRAY => image::ViewKind::CubeArray,
_ => unreachable!()
}
}
@ -221,15 +212,6 @@ pub fn map_image_layout(layout: VkImageLayout) -> image::ImageLayout {
}
}
fn map_aa_mode(samples: VkSampleCountFlagBits) -> image::AaMode {
use VkSampleCountFlagBits::*;
match samples {
VK_SAMPLE_COUNT_1_BIT => image::AaMode::Single,
_ => image::AaMode::Multi(samples as _),
}
}
pub fn map_image_usage(usage: VkImageUsageFlags) -> image::Usage {
let mut flags = image::Usage::empty();
@ -596,6 +578,22 @@ pub fn map_cmd_buffer_usage(flags: VkCommandBufferUsageFlags) -> command::Comman
unsafe { mem::transmute(flags as u16) }
}
pub fn map_filter(filter: VkFilter) -> image::Filter {
match filter {
VkFilter::VK_FILTER_NEAREST => image::Filter::Nearest,
VkFilter::VK_FILTER_LINEAR => image::Filter::Linear,
_ => panic!("Unsupported filter {:?}", filter)
}
}
pub fn map_mipmap_filter(mode: VkSamplerMipmapMode) -> image::Filter {
match mode {
VkSamplerMipmapMode::VK_SAMPLER_MIPMAP_MODE_NEAREST => image::Filter::Nearest,
VkSamplerMipmapMode::VK_SAMPLER_MIPMAP_MODE_LINEAR => image::Filter::Linear,
_ => panic!("Unsupported mipmap mode {:?}", mode)
}
}
pub fn map_wrap_mode(mode: VkSamplerAddressMode) -> image::WrapMode {
use super::VkSamplerAddressMode::*;
match mode {
@ -618,8 +616,8 @@ pub fn map_offset(extent: VkOffset3D) -> image::Offset {
}
}
pub fn map_extent(extent: VkExtent3D) -> Extent {
Extent {
pub fn map_extent(extent: VkExtent3D) -> image::Extent {
image::Extent {
width: extent.width,
height: extent.height,
depth: extent.depth,

View file

@ -1041,14 +1041,14 @@ pub extern "C" fn gfxCreateImage(
.create_image(
conv::map_image_kind(
info.imageType,
info.flags,
info.extent,
info.arrayLayers,
info.arrayLayers as _,
info.samples,
),
info.mipLevels as _,
conv::map_format(info.format).unwrap(),
conv::map_image_usage(info.usage),
unsafe { mem::transmute(info.flags) },
)
.expect("Error on creating image");
@ -1098,6 +1098,7 @@ pub extern "C" fn gfxCreateImageView(
let view = gpu.device.create_image_view(
image,
conv::map_view_kind(info.viewType),
conv::map_format(info.format).unwrap(),
conv::map_swizzle(info.components),
conv::map_subresource_range(info.subresourceRange),
@ -1603,21 +1604,24 @@ pub extern "C" fn gfxCreateSampler(
_pAllocator: *const VkAllocationCallbacks,
pSampler: *mut VkSampler,
) -> VkResult {
let vk_info = unsafe { &*pCreateInfo };
let info = unsafe { &*pCreateInfo };
//TODO: fill all the sampler properties
let info = hal::image::SamplerInfo {
filter: hal::image::FilterMethod::Scale,
let gfx_info = hal::image::SamplerInfo {
min_filter: conv::map_filter(info.minFilter),
mag_filter: conv::map_filter(info.magFilter),
mip_filter: conv::map_mipmap_filter(info.mipmapMode),
wrap_mode: (
conv::map_wrap_mode(vk_info.addressModeU),
conv::map_wrap_mode(vk_info.addressModeV),
conv::map_wrap_mode(vk_info.addressModeW),
conv::map_wrap_mode(info.addressModeU),
conv::map_wrap_mode(info.addressModeV),
conv::map_wrap_mode(info.addressModeW),
),
lod_bias: 0.0.into(),
lod_range: 0.0.into() .. 1.0.into(),
comparison: None,
border: [0.0; 4].into(),
anisotropic: hal::image::Anisotropic::Off,
};
let sampler = gpu.device.create_sampler(info);
let sampler = gpu.device.create_sampler(gfx_info);
unsafe { *pSampler = Handle::new(sampler); }
VkResult::VK_SUCCESS
}
@ -1883,7 +1887,7 @@ pub extern "C" fn gfxCreateFramebuffer(
.into_iter()
.map(|attachment| &**attachment);
let extent = hal::device::Extent {
let extent = hal::image::Extent {
width: info.width,
height: info.height,
depth: info.layers,