Skip to content

Commit

Permalink
[vk] better anisotropy sampling checks
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Feb 23, 2018
1 parent 58e931e commit e302712
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
14 changes: 7 additions & 7 deletions src/backend/vulkan/src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ pub fn map_image_usage(usage: image::Usage) -> vk::ImageUsageFlags {
if usage.contains(Usage::INPUT_ATTACHMENT) {
flags |= vk::IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
}

flags
}

Expand Down Expand Up @@ -444,14 +444,14 @@ pub fn map_stage_flags(stages: pso::ShaderStageFlags) -> vk::ShaderStageFlags {
}


pub fn map_filter(filter: image::FilterMethod) -> (vk::Filter, vk::Filter, vk::SamplerMipmapMode, f32) {
pub fn map_filter(filter: image::FilterMethod) -> (vk::Filter, vk::Filter, vk::SamplerMipmapMode) {
use hal::image::FilterMethod as Fm;
match filter {
Fm::Scale => (vk::Filter::Nearest, vk::Filter::Nearest, vk::SamplerMipmapMode::Nearest, 1.0),
Fm::Mipmap => (vk::Filter::Nearest, vk::Filter::Nearest, vk::SamplerMipmapMode::Linear, 1.0),
Fm::Bilinear => (vk::Filter::Linear, vk::Filter::Linear, vk::SamplerMipmapMode::Nearest, 1.0),
Fm::Trilinear => (vk::Filter::Linear, vk::Filter::Linear, vk::SamplerMipmapMode::Linear, 1.0),
Fm::Anisotropic(a) => (vk::Filter::Linear, vk::Filter::Linear, vk::SamplerMipmapMode::Linear, a as f32),
Fm::Scale => (vk::Filter::Nearest, vk::Filter::Nearest, vk::SamplerMipmapMode::Nearest),
Fm::Mipmap => (vk::Filter::Nearest, vk::Filter::Nearest, vk::SamplerMipmapMode::Linear),
Fm::Bilinear => (vk::Filter::Linear, vk::Filter::Linear, vk::SamplerMipmapMode::Nearest),
Fm::Trilinear => (vk::Filter::Linear, vk::Filter::Linear, vk::SamplerMipmapMode::Linear),
Fm::Anisotropic(_) => (vk::Filter::Linear, vk::Filter::Linear, vk::SamplerMipmapMode::Linear),
}
}

Expand Down
19 changes: 15 additions & 4 deletions src/backend/vulkan/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ash::version::DeviceV1_0;
use smallvec::SmallVec;

use hal::{buffer, device as d, format, image, mapping, pass, pso, query, queue};
use hal::{Backbuffer, MemoryTypeId, SwapchainConfig};
use hal::{Backbuffer, Features, MemoryTypeId, SwapchainConfig};
use hal::error::HostExecutionError;
use hal::memory::Requirements;
use hal::pool::CommandPoolCreateFlags;
Expand Down Expand Up @@ -768,7 +768,18 @@ impl d::Device<B> for Device {
fn create_sampler(&self, sampler_info: image::SamplerInfo) -> n::Sampler {
use hal::pso::Comparison;

let (min_filter, mag_filter, mipmap_mode, aniso) = conv::map_filter(sampler_info.filter);
let (min_filter, mag_filter, mipmap_mode) = conv::map_filter(sampler_info.filter);
let (anisotropy_enable, max_anisotropy) = match sampler_info.filter {
image::FilterMethod::Anisotropic(aniso) => {
if self.raw.1.contains(Features::SAMPLER_ANISOTROPY) {
(vk::VK_TRUE, aniso as f32)
} else {
warn!("Anisotropy({}) was requested on a device with disabled anisotropy feature", aniso);
(vk::VK_FALSE, 0.0)
}
}
_ => (vk::VK_FALSE, 0.0)
};
let info = vk::SamplerCreateInfo {
s_type: vk::StructureType::SamplerCreateInfo,
p_next: ptr::null(),
Expand All @@ -780,8 +791,8 @@ impl d::Device<B> for Device {
address_mode_v: conv::map_wrap(sampler_info.wrap_mode.1),
address_mode_w: conv::map_wrap(sampler_info.wrap_mode.2),
mip_lod_bias: sampler_info.lod_bias.into(),
anisotropy_enable: if aniso > 1.0 { vk::VK_TRUE } else { vk::VK_FALSE },
max_anisotropy: aniso,
anisotropy_enable,
max_anisotropy,
compare_enable: if sampler_info.comparison.is_some() { vk::VK_TRUE } else { vk::VK_FALSE },
compare_op: conv::map_comparison(sampler_info.comparison.unwrap_or(Comparison::Never)),
min_lod: sampler_info.lod_range.start.into(),
Expand Down
12 changes: 8 additions & 4 deletions src/backend/vulkan/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ impl hal::PhysicalDevice<Backend> for PhysicalDevice {
})
.collect::<Vec<_>>();

// enabled features mask
let features = Features::empty();

// Create device
let device_raw = {
let cstrings = DEVICE_EXTENSIONS
Expand All @@ -341,7 +344,8 @@ impl hal::PhysicalDevice<Backend> for PhysicalDevice {
.map(|s| s.as_ptr())
.collect::<Vec<_>>();

let features = unsafe { mem::zeroed() };
// TODO: derive from `features`
let enabled_features = unsafe { mem::zeroed() };
let info = vk::DeviceCreateInfo {
s_type: vk::StructureType::DeviceCreateInfo,
p_next: ptr::null(),
Expand All @@ -352,7 +356,7 @@ impl hal::PhysicalDevice<Backend> for PhysicalDevice {
pp_enabled_layer_names: ptr::null(),
enabled_extension_count: str_pointers.len() as u32,
pp_enabled_extension_names: str_pointers.as_ptr(),
p_enabled_features: &features,
p_enabled_features: &enabled_features,
};

unsafe {
Expand Down Expand Up @@ -380,7 +384,7 @@ impl hal::PhysicalDevice<Backend> for PhysicalDevice {
}).unwrap();

let device = Device {
raw: Arc::new(RawDevice(device_raw)),
raw: Arc::new(RawDevice(device_raw, features)),
};

let device_arc = device.raw.clone();
Expand Down Expand Up @@ -572,7 +576,7 @@ impl hal::PhysicalDevice<Backend> for PhysicalDevice {
}

#[doc(hidden)]
pub struct RawDevice(pub ash::Device<V1_0>);
pub struct RawDevice(pub ash::Device<V1_0>, Features);
impl fmt::Debug for RawDevice {
fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
unimplemented!()
Expand Down

0 comments on commit e302712

Please sign in to comment.