copy graphical data

This commit is contained in:
2026-03-26 14:10:21 -07:00
parent 77fcb52731
commit 1fab9524bd

View File

@@ -147,7 +147,9 @@ fn training() {
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT
| wgpu::TextureUsages::TEXTURE_BINDING
| wgpu::TextureUsages::COPY_SRC,
view_formats: &[],
});
let graphics_texture_view = graphics_texture.create_view(&wgpu::TextureViewDescriptor {
@@ -272,7 +274,7 @@ fn training() {
// copy the depth texture into ram
encoder.copy_texture_to_buffer(
wgpu::TexelCopyTextureInfo {
texture: graphics.depth_texture(),
texture: &graphics_texture,
mip_level: 0,
origin: wgpu::Origin3d::ZERO,
aspect: wgpu::TextureAspect::All,
@@ -317,20 +319,16 @@ fn training() {
texture_data[(stride_size * y) as usize
..(stride_size * y + size.x * size_of::<f32>() as u32) as usize]
.chunks_exact(4)
.map(|b| f32::from_le_bytes(b.try_into().unwrap())),
.map(|b| b[0] as f32 + b[1] as f32 + b[2] as f32),
)
}
fn sigmoid(x: f32) -> f32 {
1.0 / (1.0 + (-x).exp())
}
// write a png
output_image_native(
&inputs[i * INPUT..(i + 1) * INPUT]
.iter()
.copied()
.map(|f| (sigmoid(f / 32.0) * 255.0) as u8)
.map(|f| (f * 255.0) as u8)
.collect::<Vec<u8>>(),
(SIZE_X, SIZE_Y),
format!("depth_images/{i}.png").into(),