shader: Store uniforms in Rc instead of Vec
Browse files at this commit9e73beb165e51dcb8f1c0168e355baed0d9bc85cParent: 4fca6146 changed files +20 -15
- src/layout/closing_window.rs +3 -2
- src/layout/opening_window.rs +3 -2
- src/render_helpers/border.rs +3 -2
- src/render_helpers/resize.rs +3 -2
- src/render_helpers/shader_element.rs +5 -5
- src/render_helpers/shadow.rs +3 -2
src/layout/closing_window.rsmodified+3 -2
| @@ -1,4 +1,5 @@ | |||
| 1 | use std::collections::HashMap; | 1 | use std::collections::HashMap; |
| 2 | +use std::rc::Rc; | ||
| 2 | 3 | ||
| 3 | use anyhow::Context as _; | 4 | use anyhow::Context as _; |
| 4 | use glam::{Mat3, Vec2}; | 5 | use glam::{Mat3, Vec2}; |
| @@ -229,14 +230,14 @@ impl ClosingWindow { | |||
| 229 | None, | 230 | None, |
| 230 | scale.x as f32, | 231 | scale.x as f32, |
| 231 | 1., | 232 | 1., |
| 232 | - vec![ | 233 | + Rc::new([ |
| 233 | mat3_uniform("niri_input_to_geo", input_to_geo), | 234 | mat3_uniform("niri_input_to_geo", input_to_geo), |
| 234 | Uniform::new("niri_geo_size", geo_size.to_array()), | 235 | Uniform::new("niri_geo_size", geo_size.to_array()), |
| 235 | mat3_uniform("niri_geo_to_tex", geo_to_tex), | 236 | mat3_uniform("niri_geo_to_tex", geo_to_tex), |
| 236 | Uniform::new("niri_progress", progress as f32), | 237 | Uniform::new("niri_progress", progress as f32), |
| 237 | Uniform::new("niri_clamped_progress", clamped_progress as f32), | 238 | Uniform::new("niri_clamped_progress", clamped_progress as f32), |
| 238 | Uniform::new("niri_random_seed", self.random_seed), | 239 | Uniform::new("niri_random_seed", self.random_seed), |
| 239 | - ], | 240 | + ]), |
| 240 | HashMap::from([(String::from("niri_tex"), buffer.texture().clone())]), | 241 | HashMap::from([(String::from("niri_tex"), buffer.texture().clone())]), |
| 241 | Kind::Unspecified, | 242 | Kind::Unspecified, |
| 242 | ) | 243 | ) |
src/layout/opening_window.rsmodified+3 -2
| @@ -1,4 +1,5 @@ | |||
| 1 | use std::collections::HashMap; | 1 | use std::collections::HashMap; |
| 2 | +use std::rc::Rc; | ||
| 2 | 3 | ||
| 3 | use anyhow::Context as _; | 4 | use anyhow::Context as _; |
| 4 | use glam::{Mat3, Vec2}; | 5 | use glam::{Mat3, Vec2}; |
| @@ -104,14 +105,14 @@ impl OpenAnimation { | |||
| 104 | None, | 105 | None, |
| 105 | scale.x as f32, | 106 | scale.x as f32, |
| 106 | alpha, | 107 | alpha, |
| 107 | - vec![ | 108 | + Rc::new([ |
| 108 | mat3_uniform("niri_input_to_geo", input_to_geo), | 109 | mat3_uniform("niri_input_to_geo", input_to_geo), |
| 109 | Uniform::new("niri_geo_size", geo_size.to_array()), | 110 | Uniform::new("niri_geo_size", geo_size.to_array()), |
| 110 | mat3_uniform("niri_geo_to_tex", geo_to_tex), | 111 | mat3_uniform("niri_geo_to_tex", geo_to_tex), |
| 111 | Uniform::new("niri_progress", progress as f32), | 112 | Uniform::new("niri_progress", progress as f32), |
| 112 | Uniform::new("niri_clamped_progress", clamped_progress as f32), | 113 | Uniform::new("niri_clamped_progress", clamped_progress as f32), |
| 113 | Uniform::new("niri_random_seed", self.random_seed), | 114 | Uniform::new("niri_random_seed", self.random_seed), |
| 114 | - ], | 115 | + ]), |
| 115 | HashMap::from([(String::from("niri_tex"), texture.clone())]), | 116 | HashMap::from([(String::from("niri_tex"), texture.clone())]), |
| 116 | Kind::Unspecified, | 117 | Kind::Unspecified, |
| 117 | ) | 118 | ) |
src/render_helpers/border.rsmodified+3 -2
| @@ -1,4 +1,5 @@ | |||
| 1 | use std::collections::HashMap; | 1 | use std::collections::HashMap; |
| 2 | +use std::rc::Rc; | ||
| 2 | 3 | ||
| 3 | use glam::{Mat3, Vec2}; | 4 | use glam::{Mat3, Vec2}; |
| 4 | use niri_config::{ | 5 | use niri_config::{ |
| @@ -197,7 +198,7 @@ impl BorderRenderElement { | |||
| 197 | None, | 198 | None, |
| 198 | scale, | 199 | scale, |
| 199 | alpha, | 200 | alpha, |
| 200 | - vec![ | 201 | + Rc::new([ |
| 201 | Uniform::new("colorspace", colorspace), | 202 | Uniform::new("colorspace", colorspace), |
| 202 | Uniform::new("hue_interpolation", hue_interpolation), | 203 | Uniform::new("hue_interpolation", hue_interpolation), |
| 203 | Uniform::new("color_from", color_from.to_array_unpremul()), | 204 | Uniform::new("color_from", color_from.to_array_unpremul()), |
| @@ -209,7 +210,7 @@ impl BorderRenderElement { | |||
| 209 | Uniform::new("geo_size", geo_size.to_array()), | 210 | Uniform::new("geo_size", geo_size.to_array()), |
| 210 | Uniform::new("outer_radius", <[f32; 4]>::from(corner_radius)), | 211 | Uniform::new("outer_radius", <[f32; 4]>::from(corner_radius)), |
| 211 | Uniform::new("border_width", border_width), | 212 | Uniform::new("border_width", border_width), |
| 212 | - ], | 213 | + ]), |
| 213 | HashMap::new(), | 214 | HashMap::new(), |
| 214 | ); | 215 | ); |
| 215 | } | 216 | } |
src/render_helpers/resize.rsmodified+3 -2
| @@ -1,4 +1,5 @@ | |||
| 1 | use std::collections::HashMap; | 1 | use std::collections::HashMap; |
| 2 | +use std::rc::Rc; | ||
| 2 | 3 | ||
| 3 | use glam::{Mat3, Vec2}; | 4 | use glam::{Mat3, Vec2}; |
| 4 | use niri_config::CornerRadius; | 5 | use niri_config::CornerRadius; |
| @@ -90,7 +91,7 @@ impl ResizeRenderElement { | |||
| 90 | None, | 91 | None, |
| 91 | scale.x, | 92 | scale.x, |
| 92 | result_alpha, | 93 | result_alpha, |
| 93 | - vec![ | 94 | + Rc::new([ |
| 94 | mat3_uniform("niri_input_to_curr_geo", input_to_curr_geo), | 95 | mat3_uniform("niri_input_to_curr_geo", input_to_curr_geo), |
| 95 | mat3_uniform("niri_curr_geo_to_prev_geo", curr_geo_to_prev_geo), | 96 | mat3_uniform("niri_curr_geo_to_prev_geo", curr_geo_to_prev_geo), |
| 96 | mat3_uniform("niri_curr_geo_to_next_geo", curr_geo_to_next_geo), | 97 | mat3_uniform("niri_curr_geo_to_next_geo", curr_geo_to_next_geo), |
| @@ -101,7 +102,7 @@ impl ResizeRenderElement { | |||
| 101 | Uniform::new("niri_clamped_progress", clamped_progress), | 102 | Uniform::new("niri_clamped_progress", clamped_progress), |
| 102 | Uniform::new("niri_corner_radius", <[f32; 4]>::from(corner_radius)), | 103 | Uniform::new("niri_corner_radius", <[f32; 4]>::from(corner_radius)), |
| 103 | Uniform::new("niri_clip_to_geometry", clip_to_geometry), | 104 | Uniform::new("niri_clip_to_geometry", clip_to_geometry), |
| 104 | - ], | 105 | + ]), |
| 105 | HashMap::from([ | 106 | HashMap::from([ |
| 106 | (String::from("niri_tex_prev"), texture_prev), | 107 | (String::from("niri_tex_prev"), texture_prev), |
| 107 | (String::from("niri_tex_next"), texture_next), | 108 | (String::from("niri_tex_next"), texture_next), |
src/render_helpers/shader_element.rsmodified+5 -5
| @@ -28,7 +28,7 @@ pub struct ShaderRenderElement { | |||
| 28 | // Should only be used for visual improvements, i.e. corner radius anti-aliasing. | 28 | // Should only be used for visual improvements, i.e. corner radius anti-aliasing. |
| 29 | scale: f32, | 29 | scale: f32, |
| 30 | alpha: f32, | 30 | alpha: f32, |
| 31 | - additional_uniforms: Vec<Uniform<'static>>, | 31 | + additional_uniforms: Rc<[Uniform<'static>]>, |
| 32 | textures: HashMap<String, GlesTexture>, | 32 | textures: HashMap<String, GlesTexture>, |
| 33 | kind: Kind, | 33 | kind: Kind, |
| 34 | } | 34 | } |
| @@ -185,7 +185,7 @@ impl ShaderRenderElement { | |||
| 185 | // Should only be used for visual improvements, i.e. corner radius anti-aliasing. | 185 | // Should only be used for visual improvements, i.e. corner radius anti-aliasing. |
| 186 | scale: f32, | 186 | scale: f32, |
| 187 | alpha: f32, | 187 | alpha: f32, |
| 188 | - additional_uniforms: Vec<Uniform<'static>>, | 188 | + additional_uniforms: Rc<[Uniform<'static>]>, |
| 189 | textures: HashMap<String, GlesTexture>, | 189 | textures: HashMap<String, GlesTexture>, |
| 190 | kind: Kind, | 190 | kind: Kind, |
| 191 | ) -> Self { | 191 | ) -> Self { |
| @@ -212,7 +212,7 @@ impl ShaderRenderElement { | |||
| 212 | opaque_regions: vec![], | 212 | opaque_regions: vec![], |
| 213 | scale: 1., | 213 | scale: 1., |
| 214 | alpha: 1., | 214 | alpha: 1., |
| 215 | - additional_uniforms: vec![], | 215 | + additional_uniforms: Rc::new([]), |
| 216 | textures: HashMap::new(), | 216 | textures: HashMap::new(), |
| 217 | kind, | 217 | kind, |
| 218 | } | 218 | } |
| @@ -228,7 +228,7 @@ impl ShaderRenderElement { | |||
| 228 | opaque_regions: Option<Vec<Rectangle<f64, Logical>>>, | 228 | opaque_regions: Option<Vec<Rectangle<f64, Logical>>>, |
| 229 | scale: f32, | 229 | scale: f32, |
| 230 | alpha: f32, | 230 | alpha: f32, |
| 231 | - uniforms: Vec<Uniform<'static>>, | 231 | + uniforms: Rc<[Uniform<'static>]>, |
| 232 | textures: HashMap<String, GlesTexture>, | 232 | textures: HashMap<String, GlesTexture>, |
| 233 | ) { | 233 | ) { |
| 234 | self.area.size = size; | 234 | self.area.size = size; |
| @@ -425,7 +425,7 @@ impl RenderElement<GlesRenderer> for ShaderRenderElement { | |||
| 425 | gl.Uniform1f(shader.0.uniform_tint, tint); | 425 | gl.Uniform1f(shader.0.uniform_tint, tint); |
| 426 | } | 426 | } |
| 427 | 427 | ||
| 428 | - for uniform in &self.additional_uniforms { | 428 | + for uniform in &*self.additional_uniforms { |
| 429 | let desc = | 429 | let desc = |
| 430 | program | 430 | program |
| 431 | .additional_uniforms | 431 | .additional_uniforms |
src/render_helpers/shadow.rsmodified+3 -2
| @@ -1,4 +1,5 @@ | |||
| 1 | use std::collections::HashMap; | 1 | use std::collections::HashMap; |
| 2 | +use std::rc::Rc; | ||
| 2 | 3 | ||
| 3 | use glam::{Mat3, Vec2}; | 4 | use glam::{Mat3, Vec2}; |
| 4 | use niri_config::{Color, CornerRadius}; | 5 | use niri_config::{Color, CornerRadius}; |
| @@ -153,7 +154,7 @@ impl ShadowRenderElement { | |||
| 153 | None, | 154 | None, |
| 154 | scale, | 155 | scale, |
| 155 | alpha, | 156 | alpha, |
| 156 | - vec![ | 157 | + Rc::new([ |
| 157 | Uniform::new("shadow_color", color.to_array_premul()), | 158 | Uniform::new("shadow_color", color.to_array_premul()), |
| 158 | Uniform::new("sigma", sigma), | 159 | Uniform::new("sigma", sigma), |
| 159 | mat3_uniform("input_to_geo", input_to_geo), | 160 | mat3_uniform("input_to_geo", input_to_geo), |
| @@ -165,7 +166,7 @@ impl ShadowRenderElement { | |||
| 165 | "window_corner_radius", | 166 | "window_corner_radius", |
| 166 | <[f32; 4]>::from(window_corner_radius), | 167 | <[f32; 4]>::from(window_corner_radius), |
| 167 | ), | 168 | ), |
| 168 | - ], | 169 | + ]), |
| 169 | HashMap::new(), | 170 | HashMap::new(), |
| 170 | ); | 171 | ); |
| 171 | } | 172 | } |