diff --git a/crates/re_viewer/src/gpu_bridge/mod.rs b/crates/re_viewer/src/gpu_bridge/mod.rs new file mode 100644 index 000000000000..139f83513f3b --- /dev/null +++ b/crates/re_viewer/src/gpu_bridge/mod.rs @@ -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, Err>, +) -> Result { + render_ctx.texture_manager_2d.get_or_create_with( + texture_key, + &mut render_ctx.gpu_resources.textures, + try_create_texture_desc, + ) +} diff --git a/crates/re_viewer/src/misc/tensor_to_gpu.rs b/crates/re_viewer/src/gpu_bridge/tensor_to_gpu.rs similarity index 97% rename from crates/re_viewer/src/misc/tensor_to_gpu.rs rename to crates/re_viewer/src/gpu_bridge/tensor_to_gpu.rs index f6882cd2c203..ad8713a829f7 100644 --- a/crates/re_viewer/src/misc/tensor_to_gpu.rs +++ b/crates/re_viewer/src/gpu_bridge/tensor_to_gpu.rs @@ -1,3 +1,5 @@ +//! Upload [`Tensor`] to [`re_renderer`]. + use std::borrow::Cow; use bytemuck::{allocation::pod_collect_to_vec, cast_slice, Pod}; @@ -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; // ---------------------------------------------------------------------------- @@ -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, Err>, -) -> Result { - 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(slice: &[From]) -> Cow<'_, [u8]> { cast_slice(slice).into() } diff --git a/crates/re_viewer/src/lib.rs b/crates/re_viewer/src/lib.rs index 10ceb56ce0c6..85a2939b3160 100644 --- a/crates/re_viewer/src/lib.rs +++ b/crates/re_viewer/src/lib.rs @@ -5,6 +5,7 @@ mod app; pub mod env_vars; +pub(crate) mod gpu_bridge; pub mod math; mod misc; mod remote_viewer_app; diff --git a/crates/re_viewer/src/misc/mod.rs b/crates/re_viewer/src/misc/mod.rs index 023aafc3d6e9..7ba4a8e82f05 100644 --- a/crates/re_viewer/src/misc/mod.rs +++ b/crates/re_viewer/src/misc/mod.rs @@ -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; diff --git a/crates/re_viewer/src/ui/view_spatial/scene/scene_part/images.rs b/crates/re_viewer/src/ui/view_spatial/scene/scene_part/images.rs index 16dc90f6ad64..0c2c29156e50 100644 --- a/crates/re_viewer/src/ui/view_spatial/scene/scene_part/images.rs +++ b/crates/re_viewer/src/ui/view_spatial/scene/scene_part/images.rs @@ -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, diff --git a/crates/re_viewer/src/ui/view_tensor/gpu.rs b/crates/re_viewer/src/ui/view_tensor/gpu.rs index 761b07517587..3eec620720e4 100644 --- a/crates/re_viewer/src/ui/view_tensor/gpu.rs +++ b/crates/re_viewer/src/ui/view_tensor/gpu.rs @@ -72,7 +72,7 @@ fn upload_texture_slice_to_gpu( ) -> Result { 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) }) }