Skip to content

Commit

Permalink
Change preferred_antialiasing_method setting to a struct
Browse files Browse the repository at this point in the history
Instead of passing in a single optional mode to enable, the caller can
now specify which set of AA methods to compile.
armansito committed Nov 1, 2023
1 parent fba8317 commit ea29d30
Showing 5 changed files with 40 additions and 18 deletions.
2 changes: 1 addition & 1 deletion examples/headless/src/main.rs
Original file line number Diff line number Diff line change
@@ -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"))?;
2 changes: 1 addition & 1 deletion examples/with_bevy/src/main.rs
Original file line number Diff line number Diff line change
@@ -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(),
4 changes: 2 additions & 2 deletions examples/with_winit/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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")
33 changes: 29 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -62,14 +62,39 @@ pub type Error = Box<dyn std::error::Error>;
/// Specialization of `Result` for our catch-all error type.
pub type Result<T> = std::result::Result<T, Error>;

/// Possible configurations for antialiasing.
/// Represents the antialiasing method to use during a render pass.
#[derive(Copy, Clone, PartialEq, Eq)]
pub enum AaConfig {
Area,
Msaa8,
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<AaConfig>,
/// 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")]
17 changes: 7 additions & 10 deletions src/shaders.rs
Original file line number Diff line number Diff line change
@@ -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 {

0 comments on commit ea29d30

Please sign in to comment.