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