Skip to content

Commit f6a42aa

Browse files
committed
Create module gpu_bridge
1 parent 3b43653 commit f6a42aa

File tree

6 files changed

+32
-17
lines changed

6 files changed

+32
-17
lines changed
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//! Bridge to `re_renderer`
2+
3+
mod tensor_to_gpu;
4+
pub use tensor_to_gpu::tensor_to_gpu;
5+
6+
// ----------------------------------------------------------------------------
7+
8+
use re_renderer::{
9+
resource_managers::{GpuTexture2DHandle, Texture2DCreationDesc},
10+
RenderContext,
11+
};
12+
13+
pub fn get_or_create_texture<'a, Err>(
14+
render_ctx: &mut RenderContext,
15+
texture_key: u64,
16+
try_create_texture_desc: impl FnOnce() -> Result<Texture2DCreationDesc<'a>, Err>,
17+
) -> Result<GpuTexture2DHandle, Err> {
18+
render_ctx.texture_manager_2d.get_or_create_with(
19+
texture_key,
20+
&mut render_ctx.gpu_resources.textures,
21+
try_create_texture_desc,
22+
)
23+
}

crates/re_viewer/src/misc/tensor_to_gpu.rs crates/re_viewer/src/gpu_bridge/tensor_to_gpu.rs

+6-14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Upload [`Tensor`] to [`re_renderer`].
2+
13
use std::borrow::Cow;
24

35
use bytemuck::{allocation::pod_collect_to_vec, cast_slice, Pod};
@@ -7,11 +9,13 @@ use wgpu::TextureFormat;
79
use re_log_types::component_types::{Tensor, TensorData};
810
use re_renderer::{
911
renderer::{ColorMapper, ColormappedTexture},
10-
resource_managers::{GpuTexture2DHandle, Texture2DCreationDesc},
12+
resource_managers::Texture2DCreationDesc,
1113
RenderContext,
1214
};
1315

14-
use super::caches::TensorStats;
16+
use crate::misc::caches::TensorStats;
17+
18+
use super::get_or_create_texture;
1519

1620
// ----------------------------------------------------------------------------
1721

@@ -382,18 +386,6 @@ fn general_texture_creation_desc_from_tensor<'a>(
382386
})
383387
}
384388

385-
pub fn get_or_create_texture<'a, Err>(
386-
render_ctx: &mut RenderContext,
387-
texture_key: u64,
388-
try_create_texture_desc: impl FnOnce() -> Result<Texture2DCreationDesc<'a>, Err>,
389-
) -> Result<GpuTexture2DHandle, Err> {
390-
render_ctx.texture_manager_2d.get_or_create_with(
391-
texture_key,
392-
&mut render_ctx.gpu_resources.textures,
393-
try_create_texture_desc,
394-
)
395-
}
396-
397389
fn cast_slice_to_cow<From: Pod>(slice: &[From]) -> Cow<'_, [u8]> {
398390
cast_slice(slice).into()
399391
}

crates/re_viewer/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
mod app;
77
pub mod env_vars;
8+
pub(crate) mod gpu_bridge;
89
pub mod math;
910
mod misc;
1011
mod remote_viewer_app;

crates/re_viewer/src/misc/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ pub(crate) mod mesh_loader;
66
pub mod queries;
77
mod selection_state;
88
pub(crate) mod space_info;
9-
pub mod tensor_to_gpu;
109
pub(crate) mod time_control;
1110
pub(crate) mod time_control_ui;
1211
mod transform_cache;

crates/re_viewer/src/ui/view_spatial/scene/scene_part/images.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn push_tensor_texture(
4545
let debug_name = entity_path.to_string();
4646
let tensor_stats = ctx.cache.tensor_stats(tensor);
4747

48-
match crate::misc::tensor_to_gpu::tensor_to_gpu(
48+
match crate::gpu_bridge::tensor_to_gpu(
4949
ctx.render_ctx,
5050
&debug_name,
5151
tensor,

crates/re_viewer/src/ui/view_tensor/gpu.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn upload_texture_slice_to_gpu(
7272
) -> Result<re_renderer::resource_managers::GpuTexture2DHandle, TensorUploadError> {
7373
let id = egui::util::hash((tensor.id(), slice_selection));
7474

75-
crate::misc::tensor_to_gpu::get_or_create_texture(render_ctx, id, || {
75+
crate::gpu_bridge::get_or_create_texture(render_ctx, id, || {
7676
texture_desc_from_tensor(tensor, slice_selection)
7777
})
7878
}

0 commit comments

Comments
 (0)