Skip to content

Commit

Permalink
flatten out shared renderer data struct
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf committed Dec 6, 2023
1 parent 41a82cc commit c658527
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 78 deletions.
28 changes: 9 additions & 19 deletions crates/re_renderer/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ pub struct RenderContext {
pub device: Arc<wgpu::Device>,
pub queue: Arc<wgpu::Queue>,

pub(crate) shared_renderer_data: SharedRendererData,
pub(crate) config: RenderContextConfig,

/// Global bindings, always bound to 0 bind group slot zero.
/// [`Renderer`] are not allowed to use bind group 0 themselves!
pub(crate) global_bindings: GlobalBindings,

renderers: RwLock<Renderers>,
pub(crate) resolver: RecommendedFileResolver,
#[cfg(all(not(target_arch = "wasm32"), debug_assertions))] // native debug build
Expand All @@ -41,15 +46,6 @@ pub struct RenderContext {
pub gpu_resources: WgpuResourcePools, // Last due to drop order.
}

/// Immutable data that is shared between all [`Renderer`]
pub struct SharedRendererData {
pub(crate) config: RenderContextConfig,

/// Global bindings, always bound to 0 bind group slot zero.
/// [`Renderer`] are not allowed to use bind group 0 themselves!
pub(crate) global_bindings: GlobalBindings,
}

/// Struct owning *all* [`Renderer`].
/// [`Renderer`] are created lazily and stay around indefinitely.
pub(crate) struct Renderers {
Expand Down Expand Up @@ -162,11 +158,6 @@ impl RenderContext {
err_tracker
};

let shared_renderer_data = SharedRendererData {
config,
global_bindings,
};

let resolver = crate::new_recommended_file_resolver();
let mesh_manager = RwLock::new(MeshManager::new());
let texture_manager_2d =
Expand Down Expand Up @@ -197,7 +188,8 @@ impl RenderContext {
device,
queue,

shared_renderer_data,
config,
global_bindings,

renderers: RwLock::new(Renderers {
renderers: TypeMap::new(),
Expand Down Expand Up @@ -240,9 +232,7 @@ impl RenderContext {
// knowing that we're not _actually_ blocking.
//
// For more details check https://github.com/gfx-rs/wgpu/issues/3601
if cfg!(target_arch = "wasm32")
&& self.shared_renderer_data.config.device_caps.tier == DeviceTier::Gles
{
if cfg!(target_arch = "wasm32") && self.config.device_caps.tier == DeviceTier::Gles {
self.device.poll(wgpu::Maintain::Wait);
return;
}
Expand Down
3 changes: 1 addition & 2 deletions crates/re_renderer/src/draw_phases/outlines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ impl OutlineMaskProcessor {
// ------------- Textures -------------
let texture_pool = &ctx.gpu_resources.textures;

let mask_sample_count =
Self::mask_sample_count(&ctx.shared_renderer_data.config.device_caps);
let mask_sample_count = Self::mask_sample_count(&ctx.config.device_caps);
let mask_texture_desc = crate::wgpu_resources::TextureDesc {
label: format!("{instance_label}::mask_texture").into(),
size: wgpu::Extent3d {
Expand Down
13 changes: 3 additions & 10 deletions crates/re_renderer/src/draw_phases/picking_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,7 @@ impl PickingLayerProcessor {
},
);

let direct_depth_readback = ctx
.shared_renderer_data
.config
.device_caps
.support_depth_readback();
let direct_depth_readback = ctx.config.device_caps.support_depth_readback();

let picking_depth_target = ctx.gpu_resources.textures.alloc(
&ctx.device,
Expand Down Expand Up @@ -259,7 +255,7 @@ impl PickingLayerProcessor {
frame_uniform_buffer_content,
);

let bind_group_0 = ctx.shared_renderer_data.global_bindings.create_bind_group(
let bind_group_0 = ctx.global_bindings.create_bind_group(
&ctx.gpu_resources,
&ctx.device,
frame_uniform_buffer,
Expand Down Expand Up @@ -542,10 +538,7 @@ impl DepthReadbackWorkaround {
ctx,
&PipelineLayoutDesc {
label: "DepthCopyWorkaround::render_pipeline".into(),
entries: vec![
ctx.shared_renderer_data.global_bindings.layout,
bind_group_layout,
],
entries: vec![ctx.global_bindings.layout, bind_group_layout],
},
),
vertex_entrypoint: "main".into(),
Expand Down
9 changes: 2 additions & 7 deletions crates/re_renderer/src/renderer/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,7 @@ impl Renderer for Compositor {
ctx,
&PipelineLayoutDesc {
label: "compositor".into(),
entries: vec![
ctx.shared_renderer_data.global_bindings.layout,
bind_group_layout,
],
entries: vec![ctx.global_bindings.layout, bind_group_layout],
},
),
vertex_entrypoint: "main".into(),
Expand All @@ -164,9 +161,7 @@ impl Renderer for Compositor {
.shader_modules
.get_or_create(ctx, &include_shader_module!("../../shader/composite.wgsl")),
vertex_buffers: smallvec![],
render_targets: smallvec![Some(
ctx.shared_renderer_data.config.output_format_color.into()
)],
render_targets: smallvec![Some(ctx.config.output_format_color.into())],
primitive: wgpu::PrimitiveState::default(),
depth_stencil: None,
multisample: wgpu::MultisampleState::default(),
Expand Down
9 changes: 2 additions & 7 deletions crates/re_renderer/src/renderer/debug_overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,20 +199,15 @@ impl Renderer for DebugOverlayRenderer {
ctx,
&PipelineLayoutDesc {
label: "DebugOverlay".into(),
entries: vec![
ctx.shared_renderer_data.global_bindings.layout,
bind_group_layout,
],
entries: vec![ctx.global_bindings.layout, bind_group_layout],
},
),
vertex_entrypoint: "main_vs".into(),
vertex_handle: shader_module,
fragment_entrypoint: "main_fs".into(),
fragment_handle: shader_module,
vertex_buffers: smallvec![],
render_targets: smallvec![Some(
ctx.shared_renderer_data.config.output_format_color.into()
)],
render_targets: smallvec![Some(ctx.config.output_format_color.into())],
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleStrip,
cull_mode: None,
Expand Down
9 changes: 2 additions & 7 deletions crates/re_renderer/src/renderer/depth_cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,7 @@ impl Renderer for DepthCloudRenderer {
ctx,
&PipelineLayoutDesc {
label: "depth_cloud_rp_layout".into(),
entries: vec![
ctx.shared_renderer_data.global_bindings.layout,
bind_group_layout,
],
entries: vec![ctx.global_bindings.layout, bind_group_layout],
},
);

Expand Down Expand Up @@ -463,9 +460,7 @@ impl Renderer for DepthCloudRenderer {
render_targets: smallvec![Some(OutlineMaskProcessor::MASK_FORMAT.into())],
depth_stencil: OutlineMaskProcessor::MASK_DEPTH_STATE,
// Alpha to coverage doesn't work with the mask integer target.
multisample: OutlineMaskProcessor::mask_default_msaa_state(
&ctx.shared_renderer_data.config.device_caps,
),
multisample: OutlineMaskProcessor::mask_default_msaa_state(&ctx.config.device_caps),
..render_pipeline_desc_color
},
);
Expand Down
2 changes: 1 addition & 1 deletion crates/re_renderer/src/renderer/generic_skybox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl Renderer for GenericSkybox {
ctx,
&PipelineLayoutDesc {
label: "GenericSkybox::render_pipeline".into(),
entries: vec![ctx.shared_renderer_data.global_bindings.layout],
entries: vec![ctx.global_bindings.layout],
},
),

Expand Down
6 changes: 2 additions & 4 deletions crates/re_renderer/src/renderer/lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ impl Renderer for LineRenderer {
&PipelineLayoutDesc {
label: "LineRenderer::pipeline_layout".into(),
entries: vec![
ctx.shared_renderer_data.global_bindings.layout,
ctx.global_bindings.layout,
bind_group_layout_all_lines,
bind_group_layout_batch,
],
Expand Down Expand Up @@ -926,9 +926,7 @@ impl Renderer for LineRenderer {
},
depth_stencil: OutlineMaskProcessor::MASK_DEPTH_STATE,
// Alpha to coverage doesn't work with the mask integer target.
multisample: OutlineMaskProcessor::mask_default_msaa_state(
&ctx.shared_renderer_data.config.device_caps,
),
multisample: OutlineMaskProcessor::mask_default_msaa_state(&ctx.config.device_caps),
},
);

Expand Down
9 changes: 2 additions & 7 deletions crates/re_renderer/src/renderer/mesh_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,7 @@ impl Renderer for MeshRenderer {
ctx,
&PipelineLayoutDesc {
label: "MeshRenderer::pipeline_layout".into(),
entries: vec![
ctx.shared_renderer_data.global_bindings.layout,
bind_group_layout,
],
entries: vec![ctx.global_bindings.layout, bind_group_layout],
},
);

Expand Down Expand Up @@ -382,9 +379,7 @@ impl Renderer for MeshRenderer {
fragment_entrypoint: "fs_main_outline_mask".into(),
render_targets: smallvec![Some(OutlineMaskProcessor::MASK_FORMAT.into())],
depth_stencil: OutlineMaskProcessor::MASK_DEPTH_STATE,
multisample: OutlineMaskProcessor::mask_default_msaa_state(
&ctx.shared_renderer_data.config.device_caps,
),
multisample: OutlineMaskProcessor::mask_default_msaa_state(&ctx.config.device_caps),
..render_pipeline_shaded_desc
},
);
Expand Down
6 changes: 2 additions & 4 deletions crates/re_renderer/src/renderer/point_cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ impl Renderer for PointCloudRenderer {
&PipelineLayoutDesc {
label: "PointCloudRenderer::pipeline_layout".into(),
entries: vec![
ctx.shared_renderer_data.global_bindings.layout,
ctx.global_bindings.layout,
bind_group_layout_all_points,
bind_group_layout_batch,
],
Expand Down Expand Up @@ -674,9 +674,7 @@ impl Renderer for PointCloudRenderer {
render_targets: smallvec![Some(OutlineMaskProcessor::MASK_FORMAT.into())],
depth_stencil: OutlineMaskProcessor::MASK_DEPTH_STATE,
// Alpha to coverage doesn't work with the mask integer target.
multisample: OutlineMaskProcessor::mask_default_msaa_state(
&ctx.shared_renderer_data.config.device_caps,
),
multisample: OutlineMaskProcessor::mask_default_msaa_state(&ctx.config.device_caps),
..render_pipeline_desc_color
},
);
Expand Down
9 changes: 2 additions & 7 deletions crates/re_renderer/src/renderer/rectangles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,7 @@ impl Renderer for RectangleRenderer {
ctx,
&(PipelineLayoutDesc {
label: "RectangleRenderer::pipeline_layout".into(),
entries: vec![
ctx.shared_renderer_data.global_bindings.layout,
bind_group_layout,
],
entries: vec![ctx.global_bindings.layout, bind_group_layout],
}),
);

Expand Down Expand Up @@ -628,9 +625,7 @@ impl Renderer for RectangleRenderer {
fragment_entrypoint: "fs_main_outline_mask".into(),
render_targets: smallvec![Some(OutlineMaskProcessor::MASK_FORMAT.into())],
depth_stencil: OutlineMaskProcessor::MASK_DEPTH_STATE,
multisample: OutlineMaskProcessor::mask_default_msaa_state(
&ctx.shared_renderer_data.config.device_caps,
),
multisample: OutlineMaskProcessor::mask_default_msaa_state(&ctx.config.device_caps),
..render_pipeline_desc_color
}),
);
Expand Down
2 changes: 1 addition & 1 deletion crates/re_renderer/src/renderer/test_triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Renderer for TestTriangle {
ctx,
&PipelineLayoutDesc {
label: "global only".into(),
entries: vec![ctx.shared_renderer_data.global_bindings.layout],
entries: vec![ctx.global_bindings.layout],
},
),
vertex_entrypoint: "vs_main".into(),
Expand Down
4 changes: 2 additions & 2 deletions crates/re_renderer/src/view_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,15 +449,15 @@ impl ViewBuilder {
auto_size_points: auto_size_points.0,
auto_size_lines: auto_size_lines.0,

device_tier: (ctx.shared_renderer_data.config.device_caps.tier as u32).into(),
device_tier: (ctx.config.device_caps.tier as u32).into(),
};
let frame_uniform_buffer = create_and_fill_uniform_buffer(
ctx,
format!("{:?} - frame uniform buffer", config.name).into(),
frame_uniform_buffer_content,
);

let bind_group_0 = ctx.shared_renderer_data.global_bindings.create_bind_group(
let bind_group_0 = ctx.global_bindings.create_bind_group(
&ctx.gpu_resources,
&ctx.device,
frame_uniform_buffer,
Expand Down

0 comments on commit c658527

Please sign in to comment.