Merge pull request #914 from yusdacra/feat/expose_draw_cache_multithread
feat: expose draw_cache_multithread as a feature
This commit is contained in:
commit
a2b1ba522a
8 changed files with 55 additions and 11 deletions
|
|
@ -24,7 +24,12 @@ pub struct Backend {
|
||||||
impl Backend {
|
impl Backend {
|
||||||
/// Creates a new [`Backend`].
|
/// Creates a new [`Backend`].
|
||||||
pub fn new(gl: &glow::Context, settings: Settings) -> Self {
|
pub fn new(gl: &glow::Context, settings: Settings) -> Self {
|
||||||
let text_pipeline = text::Pipeline::new(gl, settings.default_font);
|
let text_pipeline = text::Pipeline::new(
|
||||||
|
gl,
|
||||||
|
settings.default_font,
|
||||||
|
settings.text_multithreading,
|
||||||
|
);
|
||||||
|
|
||||||
let quad_pipeline = quad::Pipeline::new(gl);
|
let quad_pipeline = quad::Pipeline::new(gl);
|
||||||
let triangle_pipeline = triangle::Pipeline::new(gl);
|
let triangle_pipeline = triangle::Pipeline::new(gl);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,15 @@ pub struct Settings {
|
||||||
/// By default, it will be set to 20.
|
/// By default, it will be set to 20.
|
||||||
pub default_text_size: u16,
|
pub default_text_size: u16,
|
||||||
|
|
||||||
|
/// If enabled, spread text workload in multiple threads when multiple cores
|
||||||
|
/// are available.
|
||||||
|
///
|
||||||
|
/// By default, it is disabled.
|
||||||
|
pub text_multithreading: bool,
|
||||||
|
|
||||||
/// The antialiasing strategy that will be used for triangle primitives.
|
/// The antialiasing strategy that will be used for triangle primitives.
|
||||||
|
///
|
||||||
|
/// By default, it is `None`.
|
||||||
pub antialiasing: Option<Antialiasing>,
|
pub antialiasing: Option<Antialiasing>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -25,6 +33,7 @@ impl Default for Settings {
|
||||||
Settings {
|
Settings {
|
||||||
default_font: None,
|
default_font: None,
|
||||||
default_text_size: 20,
|
default_text_size: 20,
|
||||||
|
text_multithreading: false,
|
||||||
antialiasing: None,
|
antialiasing: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,11 @@ pub struct Pipeline {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pipeline {
|
impl Pipeline {
|
||||||
pub fn new(gl: &glow::Context, default_font: Option<&[u8]>) -> Self {
|
pub fn new(
|
||||||
|
gl: &glow::Context,
|
||||||
|
default_font: Option<&[u8]>,
|
||||||
|
multithreading: bool,
|
||||||
|
) -> Self {
|
||||||
let default_font = default_font.map(|slice| slice.to_vec());
|
let default_font = default_font.map(|slice| slice.to_vec());
|
||||||
|
|
||||||
// TODO: Font customization
|
// TODO: Font customization
|
||||||
|
|
@ -41,7 +45,7 @@ impl Pipeline {
|
||||||
let draw_brush =
|
let draw_brush =
|
||||||
glow_glyph::GlyphBrushBuilder::using_font(font.clone())
|
glow_glyph::GlyphBrushBuilder::using_font(font.clone())
|
||||||
.initial_cache_size((2048, 2048))
|
.initial_cache_size((2048, 2048))
|
||||||
.draw_cache_multithread(false) // TODO: Expose as a configuration flag
|
.draw_cache_multithread(multithreading)
|
||||||
.build(&gl);
|
.build(&gl);
|
||||||
|
|
||||||
let measure_brush =
|
let measure_brush =
|
||||||
|
|
|
||||||
|
|
@ -215,6 +215,7 @@ pub trait Application: Sized {
|
||||||
let renderer_settings = crate::renderer::Settings {
|
let renderer_settings = crate::renderer::Settings {
|
||||||
default_font: settings.default_font,
|
default_font: settings.default_font,
|
||||||
default_text_size: settings.default_text_size,
|
default_text_size: settings.default_text_size,
|
||||||
|
text_multithreading: settings.text_multithreading,
|
||||||
antialiasing: if settings.antialiasing {
|
antialiasing: if settings.antialiasing {
|
||||||
Some(crate::renderer::settings::Antialiasing::MSAAx4)
|
Some(crate::renderer::settings::Antialiasing::MSAAx4)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,11 @@ pub struct Settings<Flags> {
|
||||||
/// The default value is 20.
|
/// The default value is 20.
|
||||||
pub default_text_size: u16,
|
pub default_text_size: u16,
|
||||||
|
|
||||||
/// Whether the [`Application`] should exit when the user requests the
|
/// If enabled, spread text workload in multiple threads when multiple cores
|
||||||
/// window to close (e.g. the user presses the close button).
|
/// are available.
|
||||||
pub exit_on_close_request: bool,
|
///
|
||||||
|
/// By default, it is disabled.
|
||||||
|
pub text_multithreading: bool,
|
||||||
|
|
||||||
/// If set to true, the renderer will try to perform antialiasing for some
|
/// If set to true, the renderer will try to perform antialiasing for some
|
||||||
/// primitives.
|
/// primitives.
|
||||||
|
|
@ -39,6 +41,12 @@ pub struct Settings<Flags> {
|
||||||
///
|
///
|
||||||
/// [`Canvas`]: crate::widget::Canvas
|
/// [`Canvas`]: crate::widget::Canvas
|
||||||
pub antialiasing: bool,
|
pub antialiasing: bool,
|
||||||
|
|
||||||
|
/// Whether the [`Application`] should exit when the user requests the
|
||||||
|
/// window to close (e.g. the user presses the close button).
|
||||||
|
///
|
||||||
|
/// By default, it is enabled.
|
||||||
|
pub exit_on_close_request: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Flags> Settings<Flags> {
|
impl<Flags> Settings<Flags> {
|
||||||
|
|
@ -53,8 +61,9 @@ impl<Flags> Settings<Flags> {
|
||||||
window: default_settings.window,
|
window: default_settings.window,
|
||||||
default_font: default_settings.default_font,
|
default_font: default_settings.default_font,
|
||||||
default_text_size: default_settings.default_text_size,
|
default_text_size: default_settings.default_text_size,
|
||||||
exit_on_close_request: default_settings.exit_on_close_request,
|
text_multithreading: default_settings.text_multithreading,
|
||||||
antialiasing: default_settings.antialiasing,
|
antialiasing: default_settings.antialiasing,
|
||||||
|
exit_on_close_request: default_settings.exit_on_close_request,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -69,8 +78,9 @@ where
|
||||||
window: Default::default(),
|
window: Default::default(),
|
||||||
default_font: Default::default(),
|
default_font: Default::default(),
|
||||||
default_text_size: 20,
|
default_text_size: 20,
|
||||||
exit_on_close_request: true,
|
text_multithreading: false,
|
||||||
antialiasing: false,
|
antialiasing: false,
|
||||||
|
exit_on_close_request: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,13 @@ pub struct Backend {
|
||||||
impl Backend {
|
impl Backend {
|
||||||
/// Creates a new [`Backend`].
|
/// Creates a new [`Backend`].
|
||||||
pub fn new(device: &wgpu::Device, settings: Settings) -> Self {
|
pub fn new(device: &wgpu::Device, settings: Settings) -> Self {
|
||||||
let text_pipeline =
|
let text_pipeline = text::Pipeline::new(
|
||||||
text::Pipeline::new(device, settings.format, settings.default_font);
|
device,
|
||||||
|
settings.format,
|
||||||
|
settings.default_font,
|
||||||
|
settings.text_multithreading,
|
||||||
|
);
|
||||||
|
|
||||||
let quad_pipeline = quad::Pipeline::new(device, settings.format);
|
let quad_pipeline = quad::Pipeline::new(device, settings.format);
|
||||||
let triangle_pipeline = triangle::Pipeline::new(
|
let triangle_pipeline = triangle::Pipeline::new(
|
||||||
device,
|
device,
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,15 @@ pub struct Settings {
|
||||||
/// By default, it will be set to 20.
|
/// By default, it will be set to 20.
|
||||||
pub default_text_size: u16,
|
pub default_text_size: u16,
|
||||||
|
|
||||||
|
/// If enabled, spread text workload in multiple threads when multiple cores
|
||||||
|
/// are available.
|
||||||
|
///
|
||||||
|
/// By default, it is disabled.
|
||||||
|
pub text_multithreading: bool,
|
||||||
|
|
||||||
/// The antialiasing strategy that will be used for triangle primitives.
|
/// The antialiasing strategy that will be used for triangle primitives.
|
||||||
|
///
|
||||||
|
/// By default, it is `None`.
|
||||||
pub antialiasing: Option<Antialiasing>,
|
pub antialiasing: Option<Antialiasing>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,6 +73,7 @@ impl Default for Settings {
|
||||||
internal_backend: wgpu::BackendBit::PRIMARY,
|
internal_backend: wgpu::BackendBit::PRIMARY,
|
||||||
default_font: None,
|
default_font: None,
|
||||||
default_text_size: 20,
|
default_text_size: 20,
|
||||||
|
text_multithreading: false,
|
||||||
antialiasing: None,
|
antialiasing: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ impl Pipeline {
|
||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
format: wgpu::TextureFormat,
|
format: wgpu::TextureFormat,
|
||||||
default_font: Option<&[u8]>,
|
default_font: Option<&[u8]>,
|
||||||
|
multithreading: bool,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let default_font = default_font.map(|slice| slice.to_vec());
|
let default_font = default_font.map(|slice| slice.to_vec());
|
||||||
|
|
||||||
|
|
@ -46,7 +47,7 @@ impl Pipeline {
|
||||||
let draw_brush =
|
let draw_brush =
|
||||||
wgpu_glyph::GlyphBrushBuilder::using_font(font.clone())
|
wgpu_glyph::GlyphBrushBuilder::using_font(font.clone())
|
||||||
.initial_cache_size((2048, 2048))
|
.initial_cache_size((2048, 2048))
|
||||||
.draw_cache_multithread(false) // TODO: Expose as a configuration flag
|
.draw_cache_multithread(multithreading)
|
||||||
.build(device, format);
|
.build(device, format);
|
||||||
|
|
||||||
let measure_brush =
|
let measure_brush =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue