Skip to content

Commit e302712

Browse files
committed
[vk] better anisotropy sampling checks
1 parent 58e931e commit e302712

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

src/backend/vulkan/src/conv.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ pub fn map_image_usage(usage: image::Usage) -> vk::ImageUsageFlags {
393393
if usage.contains(Usage::INPUT_ATTACHMENT) {
394394
flags |= vk::IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
395395
}
396-
396+
397397
flags
398398
}
399399

@@ -444,14 +444,14 @@ pub fn map_stage_flags(stages: pso::ShaderStageFlags) -> vk::ShaderStageFlags {
444444
}
445445

446446

447-
pub fn map_filter(filter: image::FilterMethod) -> (vk::Filter, vk::Filter, vk::SamplerMipmapMode, f32) {
447+
pub fn map_filter(filter: image::FilterMethod) -> (vk::Filter, vk::Filter, vk::SamplerMipmapMode) {
448448
use hal::image::FilterMethod as Fm;
449449
match filter {
450-
Fm::Scale => (vk::Filter::Nearest, vk::Filter::Nearest, vk::SamplerMipmapMode::Nearest, 1.0),
451-
Fm::Mipmap => (vk::Filter::Nearest, vk::Filter::Nearest, vk::SamplerMipmapMode::Linear, 1.0),
452-
Fm::Bilinear => (vk::Filter::Linear, vk::Filter::Linear, vk::SamplerMipmapMode::Nearest, 1.0),
453-
Fm::Trilinear => (vk::Filter::Linear, vk::Filter::Linear, vk::SamplerMipmapMode::Linear, 1.0),
454-
Fm::Anisotropic(a) => (vk::Filter::Linear, vk::Filter::Linear, vk::SamplerMipmapMode::Linear, a as f32),
450+
Fm::Scale => (vk::Filter::Nearest, vk::Filter::Nearest, vk::SamplerMipmapMode::Nearest),
451+
Fm::Mipmap => (vk::Filter::Nearest, vk::Filter::Nearest, vk::SamplerMipmapMode::Linear),
452+
Fm::Bilinear => (vk::Filter::Linear, vk::Filter::Linear, vk::SamplerMipmapMode::Nearest),
453+
Fm::Trilinear => (vk::Filter::Linear, vk::Filter::Linear, vk::SamplerMipmapMode::Linear),
454+
Fm::Anisotropic(_) => (vk::Filter::Linear, vk::Filter::Linear, vk::SamplerMipmapMode::Linear),
455455
}
456456
}
457457

src/backend/vulkan/src/device.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use ash::version::DeviceV1_0;
44
use smallvec::SmallVec;
55

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

771-
let (min_filter, mag_filter, mipmap_mode, aniso) = conv::map_filter(sampler_info.filter);
771+
let (min_filter, mag_filter, mipmap_mode) = conv::map_filter(sampler_info.filter);
772+
let (anisotropy_enable, max_anisotropy) = match sampler_info.filter {
773+
image::FilterMethod::Anisotropic(aniso) => {
774+
if self.raw.1.contains(Features::SAMPLER_ANISOTROPY) {
775+
(vk::VK_TRUE, aniso as f32)
776+
} else {
777+
warn!("Anisotropy({}) was requested on a device with disabled anisotropy feature", aniso);
778+
(vk::VK_FALSE, 0.0)
779+
}
780+
}
781+
_ => (vk::VK_FALSE, 0.0)
782+
};
772783
let info = vk::SamplerCreateInfo {
773784
s_type: vk::StructureType::SamplerCreateInfo,
774785
p_next: ptr::null(),
@@ -780,8 +791,8 @@ impl d::Device<B> for Device {
780791
address_mode_v: conv::map_wrap(sampler_info.wrap_mode.1),
781792
address_mode_w: conv::map_wrap(sampler_info.wrap_mode.2),
782793
mip_lod_bias: sampler_info.lod_bias.into(),
783-
anisotropy_enable: if aniso > 1.0 { vk::VK_TRUE } else { vk::VK_FALSE },
784-
max_anisotropy: aniso,
794+
anisotropy_enable,
795+
max_anisotropy,
785796
compare_enable: if sampler_info.comparison.is_some() { vk::VK_TRUE } else { vk::VK_FALSE },
786797
compare_op: conv::map_comparison(sampler_info.comparison.unwrap_or(Comparison::Never)),
787798
min_lod: sampler_info.lod_range.start.into(),

src/backend/vulkan/src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,9 @@ impl hal::PhysicalDevice<Backend> for PhysicalDevice {
329329
})
330330
.collect::<Vec<_>>();
331331

332+
// enabled features mask
333+
let features = Features::empty();
334+
332335
// Create device
333336
let device_raw = {
334337
let cstrings = DEVICE_EXTENSIONS
@@ -341,7 +344,8 @@ impl hal::PhysicalDevice<Backend> for PhysicalDevice {
341344
.map(|s| s.as_ptr())
342345
.collect::<Vec<_>>();
343346

344-
let features = unsafe { mem::zeroed() };
347+
// TODO: derive from `features`
348+
let enabled_features = unsafe { mem::zeroed() };
345349
let info = vk::DeviceCreateInfo {
346350
s_type: vk::StructureType::DeviceCreateInfo,
347351
p_next: ptr::null(),
@@ -352,7 +356,7 @@ impl hal::PhysicalDevice<Backend> for PhysicalDevice {
352356
pp_enabled_layer_names: ptr::null(),
353357
enabled_extension_count: str_pointers.len() as u32,
354358
pp_enabled_extension_names: str_pointers.as_ptr(),
355-
p_enabled_features: &features,
359+
p_enabled_features: &enabled_features,
356360
};
357361

358362
unsafe {
@@ -380,7 +384,7 @@ impl hal::PhysicalDevice<Backend> for PhysicalDevice {
380384
}).unwrap();
381385

382386
let device = Device {
383-
raw: Arc::new(RawDevice(device_raw)),
387+
raw: Arc::new(RawDevice(device_raw, features)),
384388
};
385389

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

574578
#[doc(hidden)]
575-
pub struct RawDevice(pub ash::Device<V1_0>);
579+
pub struct RawDevice(pub ash::Device<V1_0>, Features);
576580
impl fmt::Debug for RawDevice {
577581
fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
578582
unimplemented!()

0 commit comments

Comments
 (0)