Skip to content
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
1 change: 1 addition & 0 deletions blade-graphics/src/gles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ impl Context {
pub fn capabilities(&self) -> crate::Capabilities {
crate::Capabilities {
ray_query: crate::ShaderVisibility::empty(),
sample_count_mask: 0x1 | 0x4, //TODO: accurate info
}
}

Expand Down
2 changes: 2 additions & 0 deletions blade-graphics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ impl From<PlatformError> for NotSupportedError {
pub struct Capabilities {
/// Which shader stages support ray queries
pub ray_query: ShaderVisibility,
/// Bit mask of supported MSAA sample counts.
pub sample_count_mask: u32,
}

#[derive(Clone, Debug, Default)]
Expand Down
11 changes: 5 additions & 6 deletions blade-graphics/src/metal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ impl Context {
pub fn capabilities(&self) -> crate::Capabilities {
use metal::MTLDevice as _;
let device = self.device.lock().unwrap();

crate::Capabilities {
ray_query: if device.supportsFamily(metal::MTLGPUFamily::Apple6) {
crate::ShaderVisibility::all()
Expand All @@ -527,6 +528,10 @@ impl Context {
} else {
crate::ShaderVisibility::empty()
},
sample_count_mask: (0u32..7)
.map(|v| 1 << v)
.filter(|&count| device.supportsTextureSampleCount(count as _))
.sum(),
}
}

Expand All @@ -539,12 +544,6 @@ impl Context {
pub fn metal_device(&self) -> Retained<ProtocolObject<dyn metal::MTLDevice>> {
self.device.lock().unwrap().clone()
}

/// Check if the device supports a specific texture sample count.
pub fn supports_texture_sample_count(&self, sample_count: u32) -> bool {
self.metal_device()
.supportsTextureSampleCount(sample_count as _)
}
}

#[hidden_trait::expose]
Expand Down
9 changes: 9 additions & 0 deletions blade-graphics/src/vulkan/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,14 @@ impl super::Context {
naga_flags,
shader_debug_path,
min_buffer_alignment,
sample_count_flags: capabilities
.properties
.limits
.framebuffer_color_sample_counts
& capabilities
.properties
.limits
.framebuffer_depth_sample_counts,
instance,
entry,
})
Expand All @@ -761,6 +769,7 @@ impl super::Context {
Some(_) => crate::ShaderVisibility::all(),
None => crate::ShaderVisibility::empty(),
},
sample_count_mask: self.sample_count_flags.as_raw(),
}
}

Expand Down
26 changes: 1 addition & 25 deletions blade-graphics/src/vulkan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,35 +156,11 @@
naga_flags: naga::back::spv::WriterFlags,
shader_debug_path: Option<PathBuf>,
min_buffer_alignment: u64,
sample_count_flags: vk::SampleCountFlags,
instance: Instance,
entry: ash::Entry,
}

impl Context {
/// Check if the device supports a specific texture sample count.
pub fn supports_texture_sample_count(&self, sample_count: u32) -> bool {
let properties = unsafe {
self.instance
.core
.get_physical_device_properties(self.physical_device)
};

let max_count = properties.limits.framebuffer_color_sample_counts
& properties.limits.framebuffer_depth_sample_counts;

match sample_count {
1 => true,
2 => max_count.contains(vk::SampleCountFlags::TYPE_2),
4 => max_count.contains(vk::SampleCountFlags::TYPE_4),
8 => max_count.contains(vk::SampleCountFlags::TYPE_8),
16 => max_count.contains(vk::SampleCountFlags::TYPE_16),
32 => max_count.contains(vk::SampleCountFlags::TYPE_32),
64 => max_count.contains(vk::SampleCountFlags::TYPE_64),
_ => false,
}
}
}

#[derive(Clone, Copy, Debug, Hash, PartialEq)]
pub struct Buffer {
raw: vk::Buffer,
Expand Down Expand Up @@ -709,7 +685,7 @@
}

fn map_acceleration_structure_meshes(
&self,

Check warning on line 688 in blade-graphics/src/vulkan/mod.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu, true)

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 688 in blade-graphics/src/vulkan/mod.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu, true)

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 688 in blade-graphics/src/vulkan/mod.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu, true)

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 688 in blade-graphics/src/vulkan/mod.rs

View workflow job for this annotation

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc, true)

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 688 in blade-graphics/src/vulkan/mod.rs

View workflow job for this annotation

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc, true)

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 688 in blade-graphics/src/vulkan/mod.rs

View workflow job for this annotation

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc, true)

hiding a lifetime that's elided elsewhere is confusing
meshes: &[crate::AccelerationStructureMesh],
) -> BottomLevelAccelerationStructureInput {
let mut total_primitive_count = 0;
Expand Down
15 changes: 8 additions & 7 deletions examples/particle/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,11 @@ impl Example {
.unwrap();
let surface_info = surface.info();

let caps = context.capabilities();
let sample_count = [4, 2, 1]
.into_iter()
.find(|&n| context.supports_texture_sample_count(n))
.unwrap_or(1);
.find(|&n| (caps.sample_count_mask & n) != 0)
.unwrap();

let gui_painter = blade_egui::GuiPainter::new(surface_info, &context);
let particle_system = particle::System::new(
Expand Down Expand Up @@ -275,16 +276,16 @@ impl Example {
ui.heading("Particle System");
self.particle_system.add_gui(ui);

let supported_samples = [1, 2, 4]
.into_iter()
.filter(|&n| self.context.supports_texture_sample_count(n))
.collect::<Vec<_>>();

ui.add_space(5.0);
ui.heading("Rendering Settings");
egui::ComboBox::new("msaa dropdown", "MSAA samples")
.selected_text(format!("x{}", self.sample_count))
.show_ui(ui, |ui| {
let caps = self.context.capabilities();
let supported_samples = [1, 2, 4]
.into_iter()
.filter(|&n| (caps.sample_count_mask & n) != 0)
.collect::<Vec<_>>();
for i in supported_samples {
if ui
.selectable_value(&mut self.sample_count, i, format!("x{i}"))
Expand Down
Loading