Skip to content

Commit

Permalink
remove lots and lots of &mut
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf committed Dec 4, 2023
1 parent 3b9ceb0 commit 3d84895
Show file tree
Hide file tree
Showing 23 changed files with 52 additions and 59 deletions.
4 changes: 2 additions & 2 deletions crates/re_renderer/examples/2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl framework::Example for Render2D {
"2D Rendering"
}

fn new(re_ctx: &mut re_renderer::RenderContext) -> Self {
fn new(re_ctx: &re_renderer::RenderContext) -> Self {
let rerun_logo =
image::load_from_memory(include_bytes!("../../re_ui/data/logo_dark_mode.png")).unwrap();

Expand Down Expand Up @@ -53,7 +53,7 @@ impl framework::Example for Render2D {

fn draw(
&mut self,
re_ctx: &mut re_renderer::RenderContext,
re_ctx: &re_renderer::RenderContext,
resolution: [u32; 2],
time: &framework::Time,
pixels_from_point: f32,
Expand Down
8 changes: 4 additions & 4 deletions crates/re_renderer/examples/depth_cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl RenderDepthClouds {
/// Manually backproject the depth texture into a point cloud and render it.
fn draw_backprojected_point_cloud<FD, ID>(
&mut self,
re_ctx: &mut re_renderer::RenderContext,
re_ctx: &re_renderer::RenderContext,
pixels_from_point: f32,
resolution_in_pixel: [u32; 2],
target_location: glam::Vec2,
Expand Down Expand Up @@ -143,7 +143,7 @@ impl RenderDepthClouds {
/// Pass the depth texture to our native depth cloud renderer.
fn draw_depth_cloud<FD, ID>(
&mut self,
re_ctx: &mut re_renderer::RenderContext,
re_ctx: &re_renderer::RenderContext,
pixels_from_point: f32,
resolution_in_pixel: [u32; 2],
target_location: glam::Vec2,
Expand Down Expand Up @@ -226,7 +226,7 @@ impl framework::Example for RenderDepthClouds {
"Depth clouds"
}

fn new(re_ctx: &mut re_renderer::RenderContext) -> Self {
fn new(re_ctx: &re_renderer::RenderContext) -> Self {
re_log::info!("Stop camera movement by pressing 'Space'");

let depth = DepthTexture::spiral(re_ctx, glam::uvec2(640, 480));
Expand Down Expand Up @@ -260,7 +260,7 @@ impl framework::Example for RenderDepthClouds {

fn draw(
&mut self,
re_ctx: &mut re_renderer::RenderContext,
re_ctx: &re_renderer::RenderContext,
resolution: [u32; 2],
time: &framework::Time,
pixels_from_point: f32,
Expand Down
4 changes: 2 additions & 2 deletions crates/re_renderer/examples/depth_offset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl framework::Example for Render2D {
"Depth Offset"
}

fn new(_re_ctx: &mut re_renderer::RenderContext) -> Self {
fn new(_re_ctx: &re_renderer::RenderContext) -> Self {
Render2D {
distance_scale: 100.0,
near_plane: 0.1,
Expand All @@ -34,7 +34,7 @@ impl framework::Example for Render2D {

fn draw(
&mut self,
re_ctx: &mut re_renderer::RenderContext,
re_ctx: &re_renderer::RenderContext,
resolution: [u32; 2],
_time: &framework::Time,
pixels_from_point: f32,
Expand Down
13 changes: 7 additions & 6 deletions crates/re_renderer/examples/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ pub struct ViewDrawResult {
pub trait Example {
fn title() -> &'static str;

fn new(re_ctx: &mut RenderContext) -> Self;
fn new(re_ctx: &RenderContext) -> Self;

fn draw(
&mut self,
re_ctx: &mut RenderContext,
re_ctx: &RenderContext,
resolution: [u32; 2],
time: &Time,
pixels_from_point: f32,
Expand Down Expand Up @@ -160,7 +160,7 @@ impl<E: Example + 'static> Application<E> {
};
surface.configure(&device, &surface_config);

let mut re_ctx = RenderContext::new(
let re_ctx = RenderContext::new(
&adapter,
device,
queue,
Expand All @@ -170,7 +170,7 @@ impl<E: Example + 'static> Application<E> {
},
);

let example = E::new(&mut re_ctx);
let example = E::new(&re_ctx);

Ok(Self {
event_loop,
Expand Down Expand Up @@ -263,7 +263,7 @@ impl<E: Example + 'static> Application<E> {
.create_view(&wgpu::TextureViewDescriptor::default());

let draw_results = self.example.draw(
&mut self.re_ctx,
&self.re_ctx,
[self.surface_config.width, self.surface_config.height],
&self.time,
self.window.scale_factor() as f32,
Expand All @@ -277,7 +277,8 @@ impl<E: Example + 'static> Application<E> {

{
// Lock render pipelines for the lifetime of the composite pass.
let render_pipelines = self.re_ctx.gpu_resources.render_pipelines.resources();
let render_pipelines =
self.re_ctx.gpu_resources.render_pipelines.resources();

let mut composite_pass =
composite_cmd_encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
Expand Down
10 changes: 5 additions & 5 deletions crates/re_renderer/examples/multiview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use winit::event::{ElementState, VirtualKeyCode};
mod framework;

fn build_mesh_instances(
re_ctx: &mut RenderContext,
re_ctx: &RenderContext,
model_mesh_instances: &[MeshInstance],
mesh_instance_positions_and_colors: &[(glam::Vec3, Color32)],
seconds_since_startup: f32,
Expand Down Expand Up @@ -80,7 +80,7 @@ fn lorenz_points(seconds_since_startup: f32) -> Vec<glam::Vec3> {
.collect()
}

fn build_lines(re_ctx: &mut RenderContext, seconds_since_startup: f32) -> LineDrawData {
fn build_lines(re_ctx: &RenderContext, seconds_since_startup: f32) -> LineDrawData {
// Calculate some points that look nice for an animated line.
let lorenz_points = lorenz_points(seconds_since_startup);

Expand Down Expand Up @@ -211,7 +211,7 @@ fn handle_incoming_screenshots(re_ctx: &RenderContext) {
impl Multiview {
fn draw_view<D: 'static + re_renderer::renderer::DrawData + Sync + Send + Clone>(
&mut self,
re_ctx: &mut RenderContext,
re_ctx: &RenderContext,
target_cfg: TargetConfiguration,
skybox: GenericSkyboxDrawData,
draw_data: D,
Expand Down Expand Up @@ -244,7 +244,7 @@ impl Example for Multiview {
"Multiple Views"
}

fn new(re_ctx: &mut RenderContext) -> Self {
fn new(re_ctx: &RenderContext) -> Self {
re_log::info!("Switch between orthographic & perspective by pressing 'O'");
re_log::info!("Stop camera movement by pressing 'Space'");

Expand Down Expand Up @@ -298,7 +298,7 @@ impl Example for Multiview {

fn draw(
&mut self,
re_ctx: &mut RenderContext,
re_ctx: &RenderContext,
resolution: [u32; 2],
time: &framework::Time,
pixels_from_point: f32,
Expand Down
4 changes: 2 additions & 2 deletions crates/re_renderer/examples/outlines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl framework::Example for Outlines {
"Outlines"
}

fn new(re_ctx: &mut re_renderer::RenderContext) -> Self {
fn new(re_ctx: &re_renderer::RenderContext) -> Self {
Outlines {
is_paused: false,
seconds_since_startup: 0.0,
Expand All @@ -35,7 +35,7 @@ impl framework::Example for Outlines {

fn draw(
&mut self,
re_ctx: &mut re_renderer::RenderContext,
re_ctx: &re_renderer::RenderContext,
resolution: [u32; 2],
time: &framework::Time,
pixels_from_point: f32,
Expand Down
4 changes: 2 additions & 2 deletions crates/re_renderer/examples/picking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl framework::Example for Picking {
self.picking_position = position_in_pixel;
}

fn new(re_ctx: &mut re_renderer::RenderContext) -> Self {
fn new(re_ctx: &re_renderer::RenderContext) -> Self {
let mut rnd = <rand::rngs::StdRng as rand::SeedableRng>::seed_from_u64(42);
let random_point_range = -5.0_f32..5.0_f32;
let point_count = 1000;
Expand Down Expand Up @@ -93,7 +93,7 @@ impl framework::Example for Picking {

fn draw(
&mut self,
re_ctx: &mut re_renderer::RenderContext,
re_ctx: &re_renderer::RenderContext,
resolution: [u32; 2],
_time: &framework::Time,
pixels_from_point: f32,
Expand Down
15 changes: 5 additions & 10 deletions crates/re_renderer/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,16 @@ impl RenderContext {
global_bindings,
};

let mut resolver = crate::new_recommended_file_resolver();
let resolver = crate::new_recommended_file_resolver();
let mut renderers = RwLock::new(Renderers {
renderers: TypeMap::new(),
});

let mesh_manager = RwLock::new(MeshManager::new(renderers.get_mut().get_or_create(
&shared_renderer_data,
&mut gpu_resources,
&gpu_resources,
&device,
&mut resolver,
&resolver,
)));
let texture_manager_2d =
TextureManager2D::new(device.clone(), queue.clone(), &gpu_resources.textures);
Expand Down Expand Up @@ -325,7 +325,7 @@ impl RenderContext {
// The set of files on disk that were modified in any way since last frame,
// ignoring deletions.
// Always an empty set in release builds.
let modified_paths = FileServer::get_mut(|fs| fs.collect(&mut self.resolver));
let modified_paths = FileServer::get_mut(|fs| fs.collect(&self.resolver));
if !modified_paths.is_empty() {
re_log::debug!(?modified_paths, "got some filesystem events");
}
Expand All @@ -348,12 +348,7 @@ impl RenderContext {

// Shader module maintenance must come before render pipelines because render pipeline
// recompilation picks up all shaders that have been recompiled this frame.
shader_modules.begin_frame(
&self.device,
&mut self.resolver,
frame_index,
&modified_paths,
);
shader_modules.begin_frame(&self.device, &self.resolver, frame_index, &modified_paths);
render_pipelines.begin_frame(
&self.device,
frame_index,
Expand Down
4 changes: 2 additions & 2 deletions crates/re_renderer/src/draw_phases/outlines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl OutlineMaskProcessor {
}

pub fn new(
ctx: &mut RenderContext,
ctx: &RenderContext,
config: &OutlineConfig,
view_name: &DebugLabel,
resolution_in_pixel: [u32; 2],
Expand Down Expand Up @@ -265,7 +265,7 @@ impl OutlineMaskProcessor {
// ------------- Render Pipelines -------------

let screen_triangle_vertex_shader =
screen_triangle_vertex_shader(&mut ctx.gpu_resources, &ctx.device, &mut ctx.resolver);
screen_triangle_vertex_shader(&ctx.gpu_resources, &ctx.device, &ctx.resolver);
let jumpflooding_init_shader_module = if mask_sample_count == 1 {
include_shader_module!("../../shader/outlines/jumpflooding_init.wgsl")
} else {
Expand Down
8 changes: 4 additions & 4 deletions crates/re_renderer/src/draw_phases/picking_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl PickingLayerProcessor {
/// It allows to sample the picking layer texture in a shader.
#[allow(clippy::too_many_arguments)]
pub fn new<T: 'static + Send + Sync>(
ctx: &mut RenderContext,
ctx: &RenderContext,
view_name: &DebugLabel,
screen_resolution: glam::UVec2,
picking_rect: RectInt,
Expand Down Expand Up @@ -485,7 +485,7 @@ impl DepthReadbackWorkaround {
const READBACK_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba32Float;

fn new(
ctx: &mut RenderContext,
ctx: &RenderContext,
extent: glam::UVec2,
depth_target_handle: GpuTextureHandle,
) -> DepthReadbackWorkaround {
Expand Down Expand Up @@ -551,13 +551,13 @@ impl DepthReadbackWorkaround {
vertex_entrypoint: "main".into(),
vertex_handle: ctx.gpu_resources.shader_modules.get_or_create(
&ctx.device,
&mut ctx.resolver,
&ctx.resolver,
&include_shader_module!("../../shader/screen_triangle.wgsl"),
),
fragment_entrypoint: "main".into(),
fragment_handle: ctx.gpu_resources.shader_modules.get_or_create(
&ctx.device,
&mut ctx.resolver,
&ctx.resolver,
&include_shader_module!("../../shader/copy_texture.wgsl"),
),
vertex_buffers: smallvec![],
Expand Down
2 changes: 1 addition & 1 deletion crates/re_renderer/src/file_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ mod tests_file_resolver {
.unwrap();
}

let mut resolver = FileResolver::new(fs);
let resolver = FileResolver::new(fs);

resolver
.populate("/shaders3/shader1.wgsl")
Expand Down
2 changes: 1 addition & 1 deletion crates/re_renderer/src/line_strip_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl LineStripSeriesBuilder {
/// Finalizes the builder and returns a line draw data with all the lines added so far.
pub fn into_draw_data(
self,
ctx: &mut crate::context::RenderContext,
ctx: &crate::context::RenderContext,
) -> Result<LineDrawData, LineDrawDataError> {
LineDrawData::new(ctx, self)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/re_renderer/src/point_cloud_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl PointCloudBuilder {
/// Finalizes the builder and returns a point cloud draw data with all the points added so far.
pub fn into_draw_data(
self,
ctx: &mut crate::context::RenderContext,
ctx: &crate::context::RenderContext,
) -> Result<PointCloudDrawData, PointCloudDrawDataError> {
PointCloudDrawData::new(ctx, self)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/re_renderer/src/renderer/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl DrawData for CompositorDrawData {

impl CompositorDrawData {
pub fn new(
ctx: &mut RenderContext,
ctx: &RenderContext,
color_texture: &GpuTexture,
outline_final_voronoi: Option<&GpuTexture>,
outline_config: &Option<OutlineConfig>,
Expand Down
2 changes: 1 addition & 1 deletion crates/re_renderer/src/renderer/debug_overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl DrawData for DebugOverlayDrawData {

impl DebugOverlayDrawData {
pub fn new(
ctx: &mut RenderContext,
ctx: &RenderContext,
debug_texture: &GpuTexture,
screen_resolution: glam::UVec2,
overlay_rect: RectInt,
Expand Down
2 changes: 1 addition & 1 deletion crates/re_renderer/src/renderer/depth_cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ pub enum DepthCloudDrawDataError {

impl DepthCloudDrawData {
pub fn new(
ctx: &mut RenderContext,
ctx: &RenderContext,
depth_clouds: &DepthClouds,
) -> Result<Self, DepthCloudDrawDataError> {
re_tracing::profile_function!();
Expand Down
4 changes: 2 additions & 2 deletions crates/re_renderer/src/renderer/generic_skybox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ impl DrawData for GenericSkyboxDrawData {
}

impl GenericSkyboxDrawData {
pub fn new(ctx: &mut RenderContext) -> Self {
ctx.get_renderer::<GenericSkybox>();
pub fn new(ctx: &RenderContext) -> Self {
let _ = ctx.get_renderer::<GenericSkybox>(); // TODO(andreas): This should happen automatically.
GenericSkyboxDrawData {}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/re_renderer/src/renderer/mesh_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl MeshDrawData {
/// Try bundling all mesh instances into a single draw data instance whenever possible.
/// If you pass zero mesh instances, subsequent drawing will do nothing.
/// Mesh data itself is gpu uploaded if not already present.
pub fn new(ctx: &mut RenderContext, instances: &[MeshInstance]) -> anyhow::Result<Self> {
pub fn new(ctx: &RenderContext, instances: &[MeshInstance]) -> anyhow::Result<Self> {
re_tracing::profile_function!();

let _mesh_renderer = ctx.get_renderer::<MeshRenderer>();
Expand Down
2 changes: 1 addition & 1 deletion crates/re_renderer/src/renderer/point_cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl PointCloudDrawData {
///
/// If no batches are passed, all points are assumed to be in a single batch with identity transform.
pub fn new(
ctx: &mut RenderContext,
ctx: &RenderContext,
mut builder: PointCloudBuilder,
) -> Result<Self, PointCloudDrawDataError> {
re_tracing::profile_function!();
Expand Down
5 changes: 1 addition & 4 deletions crates/re_renderer/src/renderer/rectangles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,7 @@ impl DrawData for RectangleDrawData {
}

impl RectangleDrawData {
pub fn new(
ctx: &mut RenderContext,
rectangles: &[TexturedRect],
) -> Result<Self, RectangleError> {
pub fn new(ctx: &RenderContext, rectangles: &[TexturedRect]) -> Result<Self, RectangleError> {
re_tracing::profile_function!();

let rectangle_renderer = ctx.get_renderer::<RectangleRenderer>();
Expand Down
Loading

0 comments on commit 3d84895

Please sign in to comment.