diff --git a/examples/headless/src/main.rs b/examples/headless/src/main.rs index 01fd6cee4..a48d41cb0 100644 --- a/examples/headless/src/main.rs +++ b/examples/headless/src/main.rs @@ -91,7 +91,7 @@ async fn render(mut scenes: SceneSet, index: usize, args: &Args) -> Result<()> { surface_format: None, timestamp_period: queue.get_timestamp_period(), use_cpu: false, - preferred_antialiasing_method: Some(vello::AaConfig::Area), + antialiasing_support: vello::AaSupport::area_only(), }, ) .or_else(|_| bail!("Got non-Send/Sync error from creating renderer"))?; diff --git a/examples/with_bevy/src/main.rs b/examples/with_bevy/src/main.rs index 0c3d694cc..9ddf875c7 100644 --- a/examples/with_bevy/src/main.rs +++ b/examples/with_bevy/src/main.rs @@ -30,7 +30,7 @@ impl FromWorld for VelloRenderer { &RendererOptions { surface_format: None, timestamp_period: queue.0.get_timestamp_period(), - preferred_antialiasing_method: Some(vello::AaConfig::Area), + antialiasing_support: vello::AaSupport::area_only(), }, ) .unwrap(), diff --git a/examples/with_winit/src/lib.rs b/examples/with_winit/src/lib.rs index 646f74ec3..49f561028 100644 --- a/examples/with_winit/src/lib.rs +++ b/examples/with_winit/src/lib.rs @@ -89,7 +89,7 @@ fn run( surface_format: Some(render_state.surface.format), timestamp_period: render_cx.devices[id].queue.get_timestamp_period(), use_cpu: use_cpu, - preferred_antialiasing_method: None, + antialiasing_support: vello::AaSupport::all(), }, ) .expect("Could create renderer"), @@ -518,7 +518,7 @@ fn run( .queue .get_timestamp_period(), use_cpu, - preferred_antialiasing_method: None, + antialiasing_support: vello::AaSupport::all(), }, ) .expect("Could create renderer") diff --git a/src/lib.rs b/src/lib.rs index 918f6216e..8acf3ea19 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -62,7 +62,7 @@ pub type Error = Box; /// Specialization of `Result` for our catch-all error type. pub type Result = std::result::Result; -/// Possible configurations for antialiasing. +/// Represents the antialiasing method to use during a render pass. #[derive(Copy, Clone, PartialEq, Eq)] pub enum AaConfig { Area, @@ -70,6 +70,31 @@ pub enum AaConfig { Msaa16, } +/// Represents the set of antialiasing configurations to enable during pipeline creation. +pub struct AaSupport { + pub area: bool, + pub msaa8: bool, + pub msaa16: bool, +} + +impl AaSupport { + pub fn all() -> Self { + Self { + area: true, + msaa8: true, + msaa16: true, + } + } + + pub fn area_only() -> Self { + Self { + area: true, + msaa8: false, + msaa16: false, + } + } +} + /// Renders a scene into a texture or surface. #[cfg(feature = "wgpu")] pub struct Renderer { @@ -114,9 +139,9 @@ pub struct RendererOptions { // `RenderParams`. pub use_cpu: bool, - /// The anti-aliasing specialization that should be used when creating the pipelines. `None` - /// initializes all variants. - pub preferred_antialiasing_method: Option, + /// Represents the enabled set of AA configurations. This will be used to determine which + /// pipeline permutations should be compiled at startup. + pub antialiasing_support: AaSupport, } #[cfg(feature = "wgpu")] diff --git a/src/shaders.rs b/src/shaders.rs index 38662842f..11c6ba2bd 100644 --- a/src/shaders.rs +++ b/src/shaders.rs @@ -26,7 +26,6 @@ use wgpu::Device; use crate::{ cpu_shader, engine::{BindType, Error, ImageFormat, ShaderId}, - AaConfig, }; #[cfg(feature = "wgpu")] @@ -284,17 +283,15 @@ pub fn full_shaders( BindType::BufReadOnly, ]; let [fine_area, fine_msaa8, fine_msaa16] = { - const AA_MODES: [(AaConfig, Option<(&str, &str)>); 3] = [ - (AaConfig::Area, None), - (AaConfig::Msaa8, Some(("fine_msaa8", "msaa8"))), - (AaConfig::Msaa16, Some(("fine_msaa16", "msaa16"))), + let aa_support = &options.antialiasing_support; + let aa_modes = [ + (aa_support.area, None), + (aa_support.msaa8, Some(("fine_msaa8", "msaa8"))), + (aa_support.msaa16, Some(("fine_msaa16", "msaa16"))), ]; let mut pipelines = [None, None, None]; - for (i, (aa_mode, msaa_info)) in AA_MODES.iter().enumerate() { - if options - .preferred_antialiasing_method - .map_or(false, |m| m != *aa_mode) - { + for (i, (enabled, msaa_info)) in aa_modes.iter().enumerate() { + if !enabled { continue; } let (range_end_offset, label, aa_config) = match *msaa_info {