mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-23 02:05:33 +07:00
shader: Store uniforms in Rc instead of Vec
It's frequently cloned (e.g. every border piece every render) and we don't change it.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
use anyhow::Context as _;
|
use anyhow::Context as _;
|
||||||
use glam::{Mat3, Vec2};
|
use glam::{Mat3, Vec2};
|
||||||
@@ -229,14 +230,14 @@ impl ClosingWindow {
|
|||||||
None,
|
None,
|
||||||
scale.x as f32,
|
scale.x as f32,
|
||||||
1.,
|
1.,
|
||||||
vec![
|
Rc::new([
|
||||||
mat3_uniform("niri_input_to_geo", input_to_geo),
|
mat3_uniform("niri_input_to_geo", input_to_geo),
|
||||||
Uniform::new("niri_geo_size", geo_size.to_array()),
|
Uniform::new("niri_geo_size", geo_size.to_array()),
|
||||||
mat3_uniform("niri_geo_to_tex", geo_to_tex),
|
mat3_uniform("niri_geo_to_tex", geo_to_tex),
|
||||||
Uniform::new("niri_progress", progress as f32),
|
Uniform::new("niri_progress", progress as f32),
|
||||||
Uniform::new("niri_clamped_progress", clamped_progress as f32),
|
Uniform::new("niri_clamped_progress", clamped_progress as f32),
|
||||||
Uniform::new("niri_random_seed", self.random_seed),
|
Uniform::new("niri_random_seed", self.random_seed),
|
||||||
],
|
]),
|
||||||
HashMap::from([(String::from("niri_tex"), buffer.texture().clone())]),
|
HashMap::from([(String::from("niri_tex"), buffer.texture().clone())]),
|
||||||
Kind::Unspecified,
|
Kind::Unspecified,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
use anyhow::Context as _;
|
use anyhow::Context as _;
|
||||||
use glam::{Mat3, Vec2};
|
use glam::{Mat3, Vec2};
|
||||||
@@ -104,14 +105,14 @@ impl OpenAnimation {
|
|||||||
None,
|
None,
|
||||||
scale.x as f32,
|
scale.x as f32,
|
||||||
alpha,
|
alpha,
|
||||||
vec![
|
Rc::new([
|
||||||
mat3_uniform("niri_input_to_geo", input_to_geo),
|
mat3_uniform("niri_input_to_geo", input_to_geo),
|
||||||
Uniform::new("niri_geo_size", geo_size.to_array()),
|
Uniform::new("niri_geo_size", geo_size.to_array()),
|
||||||
mat3_uniform("niri_geo_to_tex", geo_to_tex),
|
mat3_uniform("niri_geo_to_tex", geo_to_tex),
|
||||||
Uniform::new("niri_progress", progress as f32),
|
Uniform::new("niri_progress", progress as f32),
|
||||||
Uniform::new("niri_clamped_progress", clamped_progress as f32),
|
Uniform::new("niri_clamped_progress", clamped_progress as f32),
|
||||||
Uniform::new("niri_random_seed", self.random_seed),
|
Uniform::new("niri_random_seed", self.random_seed),
|
||||||
],
|
]),
|
||||||
HashMap::from([(String::from("niri_tex"), texture.clone())]),
|
HashMap::from([(String::from("niri_tex"), texture.clone())]),
|
||||||
Kind::Unspecified,
|
Kind::Unspecified,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
use glam::{Mat3, Vec2};
|
use glam::{Mat3, Vec2};
|
||||||
use niri_config::{
|
use niri_config::{
|
||||||
@@ -197,7 +198,7 @@ impl BorderRenderElement {
|
|||||||
None,
|
None,
|
||||||
scale,
|
scale,
|
||||||
alpha,
|
alpha,
|
||||||
vec![
|
Rc::new([
|
||||||
Uniform::new("colorspace", colorspace),
|
Uniform::new("colorspace", colorspace),
|
||||||
Uniform::new("hue_interpolation", hue_interpolation),
|
Uniform::new("hue_interpolation", hue_interpolation),
|
||||||
Uniform::new("color_from", color_from.to_array_unpremul()),
|
Uniform::new("color_from", color_from.to_array_unpremul()),
|
||||||
@@ -209,7 +210,7 @@ impl BorderRenderElement {
|
|||||||
Uniform::new("geo_size", geo_size.to_array()),
|
Uniform::new("geo_size", geo_size.to_array()),
|
||||||
Uniform::new("outer_radius", <[f32; 4]>::from(corner_radius)),
|
Uniform::new("outer_radius", <[f32; 4]>::from(corner_radius)),
|
||||||
Uniform::new("border_width", border_width),
|
Uniform::new("border_width", border_width),
|
||||||
],
|
]),
|
||||||
HashMap::new(),
|
HashMap::new(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
use glam::{Mat3, Vec2};
|
use glam::{Mat3, Vec2};
|
||||||
use niri_config::CornerRadius;
|
use niri_config::CornerRadius;
|
||||||
@@ -90,7 +91,7 @@ impl ResizeRenderElement {
|
|||||||
None,
|
None,
|
||||||
scale.x,
|
scale.x,
|
||||||
result_alpha,
|
result_alpha,
|
||||||
vec![
|
Rc::new([
|
||||||
mat3_uniform("niri_input_to_curr_geo", input_to_curr_geo),
|
mat3_uniform("niri_input_to_curr_geo", input_to_curr_geo),
|
||||||
mat3_uniform("niri_curr_geo_to_prev_geo", curr_geo_to_prev_geo),
|
mat3_uniform("niri_curr_geo_to_prev_geo", curr_geo_to_prev_geo),
|
||||||
mat3_uniform("niri_curr_geo_to_next_geo", curr_geo_to_next_geo),
|
mat3_uniform("niri_curr_geo_to_next_geo", curr_geo_to_next_geo),
|
||||||
@@ -101,7 +102,7 @@ impl ResizeRenderElement {
|
|||||||
Uniform::new("niri_clamped_progress", clamped_progress),
|
Uniform::new("niri_clamped_progress", clamped_progress),
|
||||||
Uniform::new("niri_corner_radius", <[f32; 4]>::from(corner_radius)),
|
Uniform::new("niri_corner_radius", <[f32; 4]>::from(corner_radius)),
|
||||||
Uniform::new("niri_clip_to_geometry", clip_to_geometry),
|
Uniform::new("niri_clip_to_geometry", clip_to_geometry),
|
||||||
],
|
]),
|
||||||
HashMap::from([
|
HashMap::from([
|
||||||
(String::from("niri_tex_prev"), texture_prev),
|
(String::from("niri_tex_prev"), texture_prev),
|
||||||
(String::from("niri_tex_next"), texture_next),
|
(String::from("niri_tex_next"), texture_next),
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ pub struct ShaderRenderElement {
|
|||||||
// Should only be used for visual improvements, i.e. corner radius anti-aliasing.
|
// Should only be used for visual improvements, i.e. corner radius anti-aliasing.
|
||||||
scale: f32,
|
scale: f32,
|
||||||
alpha: f32,
|
alpha: f32,
|
||||||
additional_uniforms: Vec<Uniform<'static>>,
|
additional_uniforms: Rc<[Uniform<'static>]>,
|
||||||
textures: HashMap<String, GlesTexture>,
|
textures: HashMap<String, GlesTexture>,
|
||||||
kind: Kind,
|
kind: Kind,
|
||||||
}
|
}
|
||||||
@@ -185,7 +185,7 @@ impl ShaderRenderElement {
|
|||||||
// Should only be used for visual improvements, i.e. corner radius anti-aliasing.
|
// Should only be used for visual improvements, i.e. corner radius anti-aliasing.
|
||||||
scale: f32,
|
scale: f32,
|
||||||
alpha: f32,
|
alpha: f32,
|
||||||
additional_uniforms: Vec<Uniform<'static>>,
|
additional_uniforms: Rc<[Uniform<'static>]>,
|
||||||
textures: HashMap<String, GlesTexture>,
|
textures: HashMap<String, GlesTexture>,
|
||||||
kind: Kind,
|
kind: Kind,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
@@ -212,7 +212,7 @@ impl ShaderRenderElement {
|
|||||||
opaque_regions: vec![],
|
opaque_regions: vec![],
|
||||||
scale: 1.,
|
scale: 1.,
|
||||||
alpha: 1.,
|
alpha: 1.,
|
||||||
additional_uniforms: vec![],
|
additional_uniforms: Rc::new([]),
|
||||||
textures: HashMap::new(),
|
textures: HashMap::new(),
|
||||||
kind,
|
kind,
|
||||||
}
|
}
|
||||||
@@ -228,7 +228,7 @@ impl ShaderRenderElement {
|
|||||||
opaque_regions: Option<Vec<Rectangle<f64, Logical>>>,
|
opaque_regions: Option<Vec<Rectangle<f64, Logical>>>,
|
||||||
scale: f32,
|
scale: f32,
|
||||||
alpha: f32,
|
alpha: f32,
|
||||||
uniforms: Vec<Uniform<'static>>,
|
uniforms: Rc<[Uniform<'static>]>,
|
||||||
textures: HashMap<String, GlesTexture>,
|
textures: HashMap<String, GlesTexture>,
|
||||||
) {
|
) {
|
||||||
self.area.size = size;
|
self.area.size = size;
|
||||||
@@ -425,7 +425,7 @@ impl RenderElement<GlesRenderer> for ShaderRenderElement {
|
|||||||
gl.Uniform1f(shader.0.uniform_tint, tint);
|
gl.Uniform1f(shader.0.uniform_tint, tint);
|
||||||
}
|
}
|
||||||
|
|
||||||
for uniform in &self.additional_uniforms {
|
for uniform in &*self.additional_uniforms {
|
||||||
let desc =
|
let desc =
|
||||||
program
|
program
|
||||||
.additional_uniforms
|
.additional_uniforms
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
use glam::{Mat3, Vec2};
|
use glam::{Mat3, Vec2};
|
||||||
use niri_config::{Color, CornerRadius};
|
use niri_config::{Color, CornerRadius};
|
||||||
@@ -153,7 +154,7 @@ impl ShadowRenderElement {
|
|||||||
None,
|
None,
|
||||||
scale,
|
scale,
|
||||||
alpha,
|
alpha,
|
||||||
vec![
|
Rc::new([
|
||||||
Uniform::new("shadow_color", color.to_array_premul()),
|
Uniform::new("shadow_color", color.to_array_premul()),
|
||||||
Uniform::new("sigma", sigma),
|
Uniform::new("sigma", sigma),
|
||||||
mat3_uniform("input_to_geo", input_to_geo),
|
mat3_uniform("input_to_geo", input_to_geo),
|
||||||
@@ -165,7 +166,7 @@ impl ShadowRenderElement {
|
|||||||
"window_corner_radius",
|
"window_corner_radius",
|
||||||
<[f32; 4]>::from(window_corner_radius),
|
<[f32; 4]>::from(window_corner_radius),
|
||||||
),
|
),
|
||||||
],
|
]),
|
||||||
HashMap::new(),
|
HashMap::new(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user