Skip to content

Commit

Permalink
Fixup lifted lifetime constraints, remove `StaticResourcePoolMemMoveA…
Browse files Browse the repository at this point in the history
…ccessor` and associated trait as a consequence
  • Loading branch information
Wumpf committed Sep 25, 2024
1 parent 6055fb1 commit acf1e7f
Show file tree
Hide file tree
Showing 22 changed files with 66 additions and 211 deletions.
18 changes: 1 addition & 17 deletions crates/viewer/re_renderer/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
global_bindings::GlobalBindings,
renderer::Renderer,
resource_managers::{MeshManager, TextureManager2D},
wgpu_resources::{GpuRenderPipelinePoolMoveAccessor, WgpuResourcePools},
wgpu_resources::WgpuResourcePools,
FileServer, RecommendedFileResolver,
};

Expand Down Expand Up @@ -224,7 +224,6 @@ impl RenderContext {

let active_frame = ActiveFrameContext {
before_view_builder_encoder: Mutex::new(FrameGlobalCommandEncoder::new(&device)),
pinned_render_pipelines: None,
frame_index: STARTUP_FRAME_IDX,
top_level_error_scope,
};
Expand Down Expand Up @@ -341,13 +340,6 @@ This means, either a call to RenderContext::before_submit was omitted, or the pr
// Map all read staging buffers.
self.gpu_readback_belt.get_mut().after_queue_submit();

// Give back moved render pipelines to the pool if any were moved out.
if let Some(moved_render_pipelines) = self.active_frame.pinned_render_pipelines.take() {
self.gpu_resources
.render_pipelines
.return_resources(moved_render_pipelines);
}

// Close previous' frame error scope.
if let Some(top_level_error_scope) = self.active_frame.top_level_error_scope.take() {
let frame_index_for_uncaptured_errors = self.frame_index_for_uncaptured_errors.clone();
Expand All @@ -373,7 +365,6 @@ This means, either a call to RenderContext::before_submit was omitted, or the pr
// New active frame!
self.active_frame = ActiveFrameContext {
before_view_builder_encoder: Mutex::new(FrameGlobalCommandEncoder::new(&self.device)),
pinned_render_pipelines: None,
frame_index: self.active_frame.frame_index.wrapping_add(1),
top_level_error_scope: Some(WgpuErrorScope::start(&self.device)),
};
Expand Down Expand Up @@ -524,13 +515,6 @@ pub struct ActiveFrameContext {
/// (i.e. typically in [`crate::renderer::DrawData`] creation!)
pub before_view_builder_encoder: Mutex<FrameGlobalCommandEncoder>,

/// Render pipelines that were moved out of the resource pool.
///
/// Will be moved back to the resource pool at the start of the frame.
/// This is needed for accessing the render pipelines without keeping a reference
/// to the resource pool lock during the lifetime of a render pass.
pub pinned_render_pipelines: Option<GpuRenderPipelinePoolMoveAccessor>,

/// Index of this frame. Is incremented for every render frame.
///
/// Keep in mind that all operations on WebGPU are asynchronous:
Expand Down
6 changes: 3 additions & 3 deletions crates/viewer/re_renderer/src/queueable_draw_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ pub enum QueueableDrawDataError {

type DrawFn = dyn for<'a, 'b> Fn(
&Renderers,
&'b GpuRenderPipelinePoolAccessor<'b>,
&GpuRenderPipelinePoolAccessor<'a>,
DrawPhase,
&'a mut wgpu::RenderPass<'b>,
&'b dyn std::any::Any,
&mut wgpu::RenderPass<'b>,
&dyn std::any::Any,
) -> Result<(), QueueableDrawDataError>
+ Sync
+ Send;
Expand Down
8 changes: 4 additions & 4 deletions crates/viewer/re_renderer/src/renderer/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,12 @@ impl Renderer for Compositor {
}
}

fn draw<'a>(
fn draw(
&self,
render_pipelines: &'a GpuRenderPipelinePoolAccessor<'a>,
render_pipelines: &GpuRenderPipelinePoolAccessor<'_>,
phase: DrawPhase,
pass: &mut wgpu::RenderPass<'a>,
draw_data: &'a CompositorDrawData,
pass: &mut wgpu::RenderPass<'_>,
draw_data: &CompositorDrawData,
) -> Result<(), DrawError> {
let pipeline_handle = match phase {
DrawPhase::Compositing => self.render_pipeline_regular,
Expand Down
8 changes: 4 additions & 4 deletions crates/viewer/re_renderer/src/renderer/debug_overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,12 @@ impl Renderer for DebugOverlayRenderer {
}
}

fn draw<'a>(
fn draw(
&self,
render_pipelines: &'a GpuRenderPipelinePoolAccessor<'a>,
render_pipelines: &GpuRenderPipelinePoolAccessor<'_>,
_phase: DrawPhase,
pass: &mut wgpu::RenderPass<'a>,
draw_data: &'a DebugOverlayDrawData,
pass: &mut wgpu::RenderPass<'_>,
draw_data: &DebugOverlayDrawData,
) -> Result<(), DrawError> {
let pipeline = render_pipelines.get(self.render_pipeline)?;

Expand Down
8 changes: 4 additions & 4 deletions crates/viewer/re_renderer/src/renderer/depth_cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,12 @@ impl Renderer for DepthCloudRenderer {
}
}

fn draw<'a>(
fn draw(
&self,
render_pipelines: &'a GpuRenderPipelinePoolAccessor<'a>,
render_pipelines: &GpuRenderPipelinePoolAccessor<'_>,
phase: DrawPhase,
pass: &mut wgpu::RenderPass<'a>,
draw_data: &'a Self::RendererDrawData,
pass: &mut wgpu::RenderPass<'_>,
draw_data: &Self::RendererDrawData,
) -> Result<(), DrawError> {
re_tracing::profile_function!();
if draw_data.instances.is_empty() {
Expand Down
8 changes: 4 additions & 4 deletions crates/viewer/re_renderer/src/renderer/generic_skybox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ impl Renderer for GenericSkybox {
}
}

fn draw<'a>(
fn draw(
&self,
render_pipelines: &'a GpuRenderPipelinePoolAccessor<'a>,
render_pipelines: &GpuRenderPipelinePoolAccessor<'_>,
_phase: DrawPhase,
pass: &mut wgpu::RenderPass<'a>,
draw_data: &'a Self::RendererDrawData,
pass: &mut wgpu::RenderPass<'_>,
draw_data: &Self::RendererDrawData,
) -> Result<(), DrawError> {
re_tracing::profile_function!();

Expand Down
8 changes: 4 additions & 4 deletions crates/viewer/re_renderer/src/renderer/lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,12 +744,12 @@ impl Renderer for LineRenderer {
}
}

fn draw<'a>(
fn draw(
&self,
render_pipelines: &'a GpuRenderPipelinePoolAccessor<'a>,
render_pipelines: &GpuRenderPipelinePoolAccessor<'_>,
phase: DrawPhase,
pass: &mut wgpu::RenderPass<'a>,
draw_data: &'a Self::RendererDrawData,
pass: &mut wgpu::RenderPass<'_>,
draw_data: &Self::RendererDrawData,
) -> Result<(), DrawError> {
let (pipeline_handle, bind_group_all_lines) = match phase {
DrawPhase::OutlineMask => (
Expand Down
8 changes: 4 additions & 4 deletions crates/viewer/re_renderer/src/renderer/mesh_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,12 +395,12 @@ impl Renderer for MeshRenderer {
}
}

fn draw<'a>(
fn draw(
&self,
render_pipelines: &'a GpuRenderPipelinePoolAccessor<'a>,
render_pipelines: &GpuRenderPipelinePoolAccessor<'_>,
phase: DrawPhase,
pass: &mut wgpu::RenderPass<'a>,
draw_data: &'a Self::RendererDrawData,
pass: &mut wgpu::RenderPass<'_>,
draw_data: &Self::RendererDrawData,
) -> Result<(), DrawError> {
re_tracing::profile_function!();

Expand Down
8 changes: 4 additions & 4 deletions crates/viewer/re_renderer/src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ pub trait Renderer {
// TODO(andreas): Some Renderers need to create their own passes, need something like this for that.

/// Called once per phase given by [`Renderer::participated_phases`].
fn draw<'a>(
fn draw(
&self,
render_pipelines: &'a GpuRenderPipelinePoolAccessor<'a>,
render_pipelines: &GpuRenderPipelinePoolAccessor<'_>,
phase: DrawPhase,
pass: &mut wgpu::RenderPass<'a>,
draw_data: &'a Self::RendererDrawData,
pass: &mut wgpu::RenderPass<'_>,
draw_data: &Self::RendererDrawData,
) -> Result<(), DrawError>;

/// Combination of flags indicating in which phases [`Renderer::draw`] should be called.
Expand Down
8 changes: 4 additions & 4 deletions crates/viewer/re_renderer/src/renderer/point_cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,12 +571,12 @@ impl Renderer for PointCloudRenderer {
}
}

fn draw<'a>(
fn draw(
&self,
render_pipelines: &'a GpuRenderPipelinePoolAccessor<'a>,
render_pipelines: &GpuRenderPipelinePoolAccessor<'_>,
phase: DrawPhase,
pass: &mut wgpu::RenderPass<'a>,
draw_data: &'a Self::RendererDrawData,
pass: &mut wgpu::RenderPass<'_>,
draw_data: &Self::RendererDrawData,
) -> Result<(), DrawError> {
let (pipeline_handle, bind_group_all_points) = match phase {
DrawPhase::OutlineMask => (
Expand Down
8 changes: 4 additions & 4 deletions crates/viewer/re_renderer/src/renderer/rectangles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,12 +653,12 @@ impl Renderer for RectangleRenderer {
}
}

fn draw<'a>(
fn draw(
&self,
render_pipelines: &'a GpuRenderPipelinePoolAccessor<'a>,
render_pipelines: &GpuRenderPipelinePoolAccessor<'_>,
phase: DrawPhase,
pass: &mut wgpu::RenderPass<'a>,
draw_data: &'a Self::RendererDrawData,
pass: &mut wgpu::RenderPass<'_>,
draw_data: &Self::RendererDrawData,
) -> Result<(), DrawError> {
re_tracing::profile_function!();
if draw_data.instances.is_empty() {
Expand Down
6 changes: 3 additions & 3 deletions crates/viewer/re_renderer/src/renderer/test_triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ impl Renderer for TestTriangle {
Self { render_pipeline }
}

fn draw<'a>(
fn draw(
&self,
render_pipelines: &'a GpuRenderPipelinePoolAccessor<'a>,
render_pipelines: &GpuRenderPipelinePoolAccessor<'_>,
_phase: DrawPhase,
pass: &mut wgpu::RenderPass<'a>,
pass: &mut wgpu::RenderPass<'_>,
_draw_data: &TestTriangleDrawData,
) -> Result<(), DrawError> {
let pipeline = render_pipelines.get(self.render_pipeline)?;
Expand Down
18 changes: 7 additions & 11 deletions crates/viewer/re_renderer/src/view_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,12 +481,12 @@ impl ViewBuilder {
self.setup.resolution_in_pixel
}

fn draw_phase<'a>(
&'a self,
fn draw_phase(
&self,
renderers: &Renderers,
render_pipelines: &'a GpuRenderPipelinePoolAccessor<'a>,
render_pipelines: &GpuRenderPipelinePoolAccessor<'_>,
phase: DrawPhase,
pass: &mut wgpu::RenderPass<'a>,
pass: &mut wgpu::RenderPass<'_>,
) {
re_tracing::profile_function!();

Expand Down Expand Up @@ -764,18 +764,14 @@ impl ViewBuilder {
///
/// The bound surface(s) on the `RenderPass` are expected to be the same format as specified on `Context` creation.
/// `screen_position` specifies where on the output pass the view is placed.
pub fn composite<'a>(
&'a self,
ctx: &RenderContext,
render_pipelines: &'a GpuRenderPipelinePoolAccessor<'a>,
pass: &mut wgpu::RenderPass<'a>,
) {
pub fn composite(&self, ctx: &RenderContext, pass: &mut wgpu::RenderPass<'_>) {
re_tracing::profile_function!();

pass.set_bind_group(0, &self.setup.bind_group_0, &[]);

self.draw_phase(
&ctx.read_lock_renderers(),
render_pipelines,
&ctx.gpu_resources.render_pipelines.resources(),
DrawPhase::Compositing,
pass,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use super::{
buffer_pool::{GpuBuffer, GpuBufferHandle, GpuBufferPool},
dynamic_resource_pool::{DynamicResource, DynamicResourcePool, DynamicResourcesDesc},
sampler_pool::{GpuSamplerHandle, GpuSamplerPool},
static_resource_pool::StaticResourcePoolAccessor as _,
texture_pool::{GpuTexture, GpuTextureHandle, GpuTexturePool},
WgpuResourcePools,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/viewer/re_renderer/src/wgpu_resources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub use pipeline_layout_pool::{GpuPipelineLayoutPool, PipelineLayoutDesc};
mod render_pipeline_pool;
pub use render_pipeline_pool::{
GpuRenderPipelineHandle, GpuRenderPipelinePool, GpuRenderPipelinePoolAccessor,
GpuRenderPipelinePoolMoveAccessor, RenderPipelineDesc, VertexBufferLayout,
RenderPipelineDesc, VertexBufferLayout,
};

mod sampler_pool;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use crate::{debug_label::DebugLabel, RenderContext};

use super::{
bind_group_layout_pool::GpuBindGroupLayoutHandle,
static_resource_pool::{
StaticResourcePool, StaticResourcePoolAccessor as _, StaticResourcePoolReadLockAccessor,
},
static_resource_pool::{StaticResourcePool, StaticResourcePoolReadLockAccessor},
};

slotmap::new_key_type! { pub struct GpuPipelineLayoutHandle; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ use super::{
pipeline_layout_pool::{GpuPipelineLayoutHandle, GpuPipelineLayoutPool},
resource::PoolError,
shader_module_pool::{GpuShaderModuleHandle, GpuShaderModulePool},
static_resource_pool::{
StaticResourcePool, StaticResourcePoolAccessor, StaticResourcePoolMemMoveAccessor,
StaticResourcePoolReadLockAccessor,
},
static_resource_pool::{StaticResourcePool, StaticResourcePoolReadLockAccessor},
};

slotmap::new_key_type! { pub struct GpuRenderPipelineHandle; }
Expand Down Expand Up @@ -171,10 +168,7 @@ impl RenderPipelineDesc {
}

pub type GpuRenderPipelinePoolAccessor<'a> =
dyn StaticResourcePoolAccessor<GpuRenderPipelineHandle, wgpu::RenderPipeline> + 'a;

pub type GpuRenderPipelinePoolMoveAccessor =
StaticResourcePoolMemMoveAccessor<GpuRenderPipelineHandle, wgpu::RenderPipeline>;
StaticResourcePoolReadLockAccessor<'a, GpuRenderPipelineHandle, wgpu::RenderPipeline>;

#[derive(Default)]
pub struct GpuRenderPipelinePool {
Expand Down Expand Up @@ -256,22 +250,6 @@ impl GpuRenderPipelinePool {
self.pool.resources()
}

/// Takes out all resources from the pool.
///
/// This is useful when the existing resources need to be accessed without
/// taking a lock on the pool.
/// Resource can be put with `return_resources`.
pub fn take_resources(&mut self) -> GpuRenderPipelinePoolMoveAccessor {
self.pool.take_resources()
}

/// Counterpart to `take_resources`.
///
/// Logs an error if resources were added to the pool since `take_resources` was called.
pub fn return_resources(&mut self, resources: GpuRenderPipelinePoolMoveAccessor) {
self.pool.return_resources(resources);
}

pub fn num_resources(&self) -> usize {
self.pool.num_resources()
}
Expand Down
Loading

0 comments on commit acf1e7f

Please sign in to comment.