Skip to content

Commit

Permalink
Create module gpu_bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Apr 14, 2023
1 parent 3b43653 commit f6a42aa
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 17 deletions.
23 changes: 23 additions & 0 deletions crates/re_viewer/src/gpu_bridge/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//! Bridge to `re_renderer`
mod tensor_to_gpu;
pub use tensor_to_gpu::tensor_to_gpu;

// ----------------------------------------------------------------------------

use re_renderer::{
resource_managers::{GpuTexture2DHandle, Texture2DCreationDesc},
RenderContext,
};

pub fn get_or_create_texture<'a, Err>(
render_ctx: &mut RenderContext,
texture_key: u64,
try_create_texture_desc: impl FnOnce() -> Result<Texture2DCreationDesc<'a>, Err>,
) -> Result<GpuTexture2DHandle, Err> {
render_ctx.texture_manager_2d.get_or_create_with(
texture_key,
&mut render_ctx.gpu_resources.textures,
try_create_texture_desc,
)
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Upload [`Tensor`] to [`re_renderer`].
use std::borrow::Cow;

use bytemuck::{allocation::pod_collect_to_vec, cast_slice, Pod};
Expand All @@ -7,11 +9,13 @@ use wgpu::TextureFormat;
use re_log_types::component_types::{Tensor, TensorData};
use re_renderer::{
renderer::{ColorMapper, ColormappedTexture},
resource_managers::{GpuTexture2DHandle, Texture2DCreationDesc},
resource_managers::Texture2DCreationDesc,
RenderContext,
};

use super::caches::TensorStats;
use crate::misc::caches::TensorStats;

use super::get_or_create_texture;

// ----------------------------------------------------------------------------

Expand Down Expand Up @@ -382,18 +386,6 @@ fn general_texture_creation_desc_from_tensor<'a>(
})
}

pub fn get_or_create_texture<'a, Err>(
render_ctx: &mut RenderContext,
texture_key: u64,
try_create_texture_desc: impl FnOnce() -> Result<Texture2DCreationDesc<'a>, Err>,
) -> Result<GpuTexture2DHandle, Err> {
render_ctx.texture_manager_2d.get_or_create_with(
texture_key,
&mut render_ctx.gpu_resources.textures,
try_create_texture_desc,
)
}

fn cast_slice_to_cow<From: Pod>(slice: &[From]) -> Cow<'_, [u8]> {
cast_slice(slice).into()
}
Expand Down
1 change: 1 addition & 0 deletions crates/re_viewer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
mod app;
pub mod env_vars;
pub(crate) mod gpu_bridge;
pub mod math;
mod misc;
mod remote_viewer_app;
Expand Down
1 change: 0 additions & 1 deletion crates/re_viewer/src/misc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pub(crate) mod mesh_loader;
pub mod queries;
mod selection_state;
pub(crate) mod space_info;
pub mod tensor_to_gpu;
pub(crate) mod time_control;
pub(crate) mod time_control_ui;
mod transform_cache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn push_tensor_texture(
let debug_name = entity_path.to_string();
let tensor_stats = ctx.cache.tensor_stats(tensor);

match crate::misc::tensor_to_gpu::tensor_to_gpu(
match crate::gpu_bridge::tensor_to_gpu(
ctx.render_ctx,
&debug_name,
tensor,
Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewer/src/ui/view_tensor/gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn upload_texture_slice_to_gpu(
) -> Result<re_renderer::resource_managers::GpuTexture2DHandle, TensorUploadError> {
let id = egui::util::hash((tensor.id(), slice_selection));

crate::misc::tensor_to_gpu::get_or_create_texture(render_ctx, id, || {
crate::gpu_bridge::get_or_create_texture(render_ctx, id, || {
texture_desc_from_tensor(tensor, slice_selection)
})
}
Expand Down

0 comments on commit f6a42aa

Please sign in to comment.