forge
Explore
Log in

Don't you dare go Hollow

shader: Store uniforms in Rc instead of Vec

Browse files at this commit

9e73beb165e51dcb8f1c0168e355baed0d9bc85cIvan MolodetskikhParent: 4fca614
It's frequently cloned (e.g. every border piece every render) and we
don't change it.
src/layout/closing_window.rsmodified+3 -2
@@ -1,4 +1,5 @@
11 use std::collections::HashMap;
2+use std::rc::Rc;
23
34 use anyhow::Context as _;
45 use glam::{Mat3, Vec2};
@@ -229,14 +230,14 @@ impl ClosingWindow {
229230 None,
230231 scale.x as f32,
231232 1.,
232- vec![
233+ Rc::new([
233234 mat3_uniform("niri_input_to_geo", input_to_geo),
234235 Uniform::new("niri_geo_size", geo_size.to_array()),
235236 mat3_uniform("niri_geo_to_tex", geo_to_tex),
236237 Uniform::new("niri_progress", progress as f32),
237238 Uniform::new("niri_clamped_progress", clamped_progress as f32),
238239 Uniform::new("niri_random_seed", self.random_seed),
239- ],
240+ ]),
240241 HashMap::from([(String::from("niri_tex"), buffer.texture().clone())]),
241242 Kind::Unspecified,
242243 )
src/layout/opening_window.rsmodified+3 -2
@@ -1,4 +1,5 @@
11 use std::collections::HashMap;
2+use std::rc::Rc;
23
34 use anyhow::Context as _;
45 use glam::{Mat3, Vec2};
@@ -104,14 +105,14 @@ impl OpenAnimation {
104105 None,
105106 scale.x as f32,
106107 alpha,
107- vec![
108+ Rc::new([
108109 mat3_uniform("niri_input_to_geo", input_to_geo),
109110 Uniform::new("niri_geo_size", geo_size.to_array()),
110111 mat3_uniform("niri_geo_to_tex", geo_to_tex),
111112 Uniform::new("niri_progress", progress as f32),
112113 Uniform::new("niri_clamped_progress", clamped_progress as f32),
113114 Uniform::new("niri_random_seed", self.random_seed),
114- ],
115+ ]),
115116 HashMap::from([(String::from("niri_tex"), texture.clone())]),
116117 Kind::Unspecified,
117118 )
src/render_helpers/border.rsmodified+3 -2
@@ -1,4 +1,5 @@
11 use std::collections::HashMap;
2+use std::rc::Rc;
23
34 use glam::{Mat3, Vec2};
45 use niri_config::{
@@ -197,7 +198,7 @@ impl BorderRenderElement {
197198 None,
198199 scale,
199200 alpha,
200- vec![
201+ Rc::new([
201202 Uniform::new("colorspace", colorspace),
202203 Uniform::new("hue_interpolation", hue_interpolation),
203204 Uniform::new("color_from", color_from.to_array_unpremul()),
@@ -209,7 +210,7 @@ impl BorderRenderElement {
209210 Uniform::new("geo_size", geo_size.to_array()),
210211 Uniform::new("outer_radius", <[f32; 4]>::from(corner_radius)),
211212 Uniform::new("border_width", border_width),
212- ],
213+ ]),
213214 HashMap::new(),
214215 );
215216 }
src/render_helpers/resize.rsmodified+3 -2
@@ -1,4 +1,5 @@
11 use std::collections::HashMap;
2+use std::rc::Rc;
23
34 use glam::{Mat3, Vec2};
45 use niri_config::CornerRadius;
@@ -90,7 +91,7 @@ impl ResizeRenderElement {
9091 None,
9192 scale.x,
9293 result_alpha,
93- vec![
94+ Rc::new([
9495 mat3_uniform("niri_input_to_curr_geo", input_to_curr_geo),
9596 mat3_uniform("niri_curr_geo_to_prev_geo", curr_geo_to_prev_geo),
9697 mat3_uniform("niri_curr_geo_to_next_geo", curr_geo_to_next_geo),
@@ -101,7 +102,7 @@ impl ResizeRenderElement {
101102 Uniform::new("niri_clamped_progress", clamped_progress),
102103 Uniform::new("niri_corner_radius", <[f32; 4]>::from(corner_radius)),
103104 Uniform::new("niri_clip_to_geometry", clip_to_geometry),
104- ],
105+ ]),
105106 HashMap::from([
106107 (String::from("niri_tex_prev"), texture_prev),
107108 (String::from("niri_tex_next"), texture_next),
src/render_helpers/shader_element.rsmodified+5 -5
@@ -28,7 +28,7 @@ pub struct ShaderRenderElement {
2828 // Should only be used for visual improvements, i.e. corner radius anti-aliasing.
2929 scale: f32,
3030 alpha: f32,
31- additional_uniforms: Vec<Uniform<'static>>,
31+ additional_uniforms: Rc<[Uniform<'static>]>,
3232 textures: HashMap<String, GlesTexture>,
3333 kind: Kind,
3434 }
@@ -185,7 +185,7 @@ impl ShaderRenderElement {
185185 // Should only be used for visual improvements, i.e. corner radius anti-aliasing.
186186 scale: f32,
187187 alpha: f32,
188- additional_uniforms: Vec<Uniform<'static>>,
188+ additional_uniforms: Rc<[Uniform<'static>]>,
189189 textures: HashMap<String, GlesTexture>,
190190 kind: Kind,
191191 ) -> Self {
@@ -212,7 +212,7 @@ impl ShaderRenderElement {
212212 opaque_regions: vec![],
213213 scale: 1.,
214214 alpha: 1.,
215- additional_uniforms: vec![],
215+ additional_uniforms: Rc::new([]),
216216 textures: HashMap::new(),
217217 kind,
218218 }
@@ -228,7 +228,7 @@ impl ShaderRenderElement {
228228 opaque_regions: Option<Vec<Rectangle<f64, Logical>>>,
229229 scale: f32,
230230 alpha: f32,
231- uniforms: Vec<Uniform<'static>>,
231+ uniforms: Rc<[Uniform<'static>]>,
232232 textures: HashMap<String, GlesTexture>,
233233 ) {
234234 self.area.size = size;
@@ -425,7 +425,7 @@ impl RenderElement<GlesRenderer> for ShaderRenderElement {
425425 gl.Uniform1f(shader.0.uniform_tint, tint);
426426 }
427427
428- for uniform in &self.additional_uniforms {
428+ for uniform in &*self.additional_uniforms {
429429 let desc =
430430 program
431431 .additional_uniforms
src/render_helpers/shadow.rsmodified+3 -2
@@ -1,4 +1,5 @@
11 use std::collections::HashMap;
2+use std::rc::Rc;
23
34 use glam::{Mat3, Vec2};
45 use niri_config::{Color, CornerRadius};
@@ -153,7 +154,7 @@ impl ShadowRenderElement {
153154 None,
154155 scale,
155156 alpha,
156- vec![
157+ Rc::new([
157158 Uniform::new("shadow_color", color.to_array_premul()),
158159 Uniform::new("sigma", sigma),
159160 mat3_uniform("input_to_geo", input_to_geo),
@@ -165,7 +166,7 @@ impl ShadowRenderElement {
165166 "window_corner_radius",
166167 <[f32; 4]>::from(window_corner_radius),
167168 ),
168- ],
169+ ]),
169170 HashMap::new(),
170171 );
171172 }