mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-21 02:01:55 +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::rc::Rc;
|
||||
|
||||
use anyhow::Context as _;
|
||||
use glam::{Mat3, Vec2};
|
||||
@@ -229,14 +230,14 @@ impl ClosingWindow {
|
||||
None,
|
||||
scale.x as f32,
|
||||
1.,
|
||||
vec![
|
||||
Rc::new([
|
||||
mat3_uniform("niri_input_to_geo", input_to_geo),
|
||||
Uniform::new("niri_geo_size", geo_size.to_array()),
|
||||
mat3_uniform("niri_geo_to_tex", geo_to_tex),
|
||||
Uniform::new("niri_progress", progress as f32),
|
||||
Uniform::new("niri_clamped_progress", clamped_progress as f32),
|
||||
Uniform::new("niri_random_seed", self.random_seed),
|
||||
],
|
||||
]),
|
||||
HashMap::from([(String::from("niri_tex"), buffer.texture().clone())]),
|
||||
Kind::Unspecified,
|
||||
)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
|
||||
use anyhow::Context as _;
|
||||
use glam::{Mat3, Vec2};
|
||||
@@ -104,14 +105,14 @@ impl OpenAnimation {
|
||||
None,
|
||||
scale.x as f32,
|
||||
alpha,
|
||||
vec![
|
||||
Rc::new([
|
||||
mat3_uniform("niri_input_to_geo", input_to_geo),
|
||||
Uniform::new("niri_geo_size", geo_size.to_array()),
|
||||
mat3_uniform("niri_geo_to_tex", geo_to_tex),
|
||||
Uniform::new("niri_progress", progress as f32),
|
||||
Uniform::new("niri_clamped_progress", clamped_progress as f32),
|
||||
Uniform::new("niri_random_seed", self.random_seed),
|
||||
],
|
||||
]),
|
||||
HashMap::from([(String::from("niri_tex"), texture.clone())]),
|
||||
Kind::Unspecified,
|
||||
)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
|
||||
use glam::{Mat3, Vec2};
|
||||
use niri_config::{
|
||||
@@ -197,7 +198,7 @@ impl BorderRenderElement {
|
||||
None,
|
||||
scale,
|
||||
alpha,
|
||||
vec![
|
||||
Rc::new([
|
||||
Uniform::new("colorspace", colorspace),
|
||||
Uniform::new("hue_interpolation", hue_interpolation),
|
||||
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("outer_radius", <[f32; 4]>::from(corner_radius)),
|
||||
Uniform::new("border_width", border_width),
|
||||
],
|
||||
]),
|
||||
HashMap::new(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
|
||||
use glam::{Mat3, Vec2};
|
||||
use niri_config::CornerRadius;
|
||||
@@ -90,7 +91,7 @@ impl ResizeRenderElement {
|
||||
None,
|
||||
scale.x,
|
||||
result_alpha,
|
||||
vec![
|
||||
Rc::new([
|
||||
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_next_geo", curr_geo_to_next_geo),
|
||||
@@ -101,7 +102,7 @@ impl ResizeRenderElement {
|
||||
Uniform::new("niri_clamped_progress", clamped_progress),
|
||||
Uniform::new("niri_corner_radius", <[f32; 4]>::from(corner_radius)),
|
||||
Uniform::new("niri_clip_to_geometry", clip_to_geometry),
|
||||
],
|
||||
]),
|
||||
HashMap::from([
|
||||
(String::from("niri_tex_prev"), texture_prev),
|
||||
(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.
|
||||
scale: f32,
|
||||
alpha: f32,
|
||||
additional_uniforms: Vec<Uniform<'static>>,
|
||||
additional_uniforms: Rc<[Uniform<'static>]>,
|
||||
textures: HashMap<String, GlesTexture>,
|
||||
kind: Kind,
|
||||
}
|
||||
@@ -185,7 +185,7 @@ impl ShaderRenderElement {
|
||||
// Should only be used for visual improvements, i.e. corner radius anti-aliasing.
|
||||
scale: f32,
|
||||
alpha: f32,
|
||||
additional_uniforms: Vec<Uniform<'static>>,
|
||||
additional_uniforms: Rc<[Uniform<'static>]>,
|
||||
textures: HashMap<String, GlesTexture>,
|
||||
kind: Kind,
|
||||
) -> Self {
|
||||
@@ -212,7 +212,7 @@ impl ShaderRenderElement {
|
||||
opaque_regions: vec![],
|
||||
scale: 1.,
|
||||
alpha: 1.,
|
||||
additional_uniforms: vec![],
|
||||
additional_uniforms: Rc::new([]),
|
||||
textures: HashMap::new(),
|
||||
kind,
|
||||
}
|
||||
@@ -228,7 +228,7 @@ impl ShaderRenderElement {
|
||||
opaque_regions: Option<Vec<Rectangle<f64, Logical>>>,
|
||||
scale: f32,
|
||||
alpha: f32,
|
||||
uniforms: Vec<Uniform<'static>>,
|
||||
uniforms: Rc<[Uniform<'static>]>,
|
||||
textures: HashMap<String, GlesTexture>,
|
||||
) {
|
||||
self.area.size = size;
|
||||
@@ -425,7 +425,7 @@ impl RenderElement<GlesRenderer> for ShaderRenderElement {
|
||||
gl.Uniform1f(shader.0.uniform_tint, tint);
|
||||
}
|
||||
|
||||
for uniform in &self.additional_uniforms {
|
||||
for uniform in &*self.additional_uniforms {
|
||||
let desc =
|
||||
program
|
||||
.additional_uniforms
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
|
||||
use glam::{Mat3, Vec2};
|
||||
use niri_config::{Color, CornerRadius};
|
||||
@@ -153,7 +154,7 @@ impl ShadowRenderElement {
|
||||
None,
|
||||
scale,
|
||||
alpha,
|
||||
vec![
|
||||
Rc::new([
|
||||
Uniform::new("shadow_color", color.to_array_premul()),
|
||||
Uniform::new("sigma", sigma),
|
||||
mat3_uniform("input_to_geo", input_to_geo),
|
||||
@@ -165,7 +166,7 @@ impl ShadowRenderElement {
|
||||
"window_corner_radius",
|
||||
<[f32; 4]>::from(window_corner_radius),
|
||||
),
|
||||
],
|
||||
]),
|
||||
HashMap::new(),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user