writing brick to gpu

This commit is contained in:
Piotrek
2021-04-23 13:34:18 +02:00
parent 6239e145e9
commit 936c0f2e18
2 changed files with 29 additions and 11 deletions
+22 -9
View File
@@ -1,14 +1,14 @@
use wgpu::util::DeviceExt;
use std::convert::TryInto;
const BRICK_SIZE : usize = 32; // 32x32x32 brick size
const BRICK_NUM : usize = 64; // 64 bricks in texture
const BRICK_NUM : usize = 10000; // 64 bricks in texture
const BRICK_LEN : usize = BRICK_SIZE*BRICK_SIZE*BRICK_SIZE;
const DATA_LEN : usize = BRICK_LEN * BRICK_NUM;
struct BrickData {
data: Box<[u8]>
pub data: Box<[u8]>
}
impl BrickData {
@@ -24,11 +24,6 @@ impl BrickData {
let offset = brick * BRICK_LEN;
self.data[offset + local_idx] = value;
}
pub fn get_1024(&mut self, offset: usize) -> [u8; 1024]
{
self.data[offset..offset+1024].try_into().expect("wrong size")
}
}
@@ -44,7 +39,7 @@ impl BrickBuffer {
pub fn new(device: &wgpu::Device) -> Self {
// Create texture
let size = wgpu::Extent3d { width: (BRICK_SIZE*BRICK_NUM) as u32, height: BRICK_SIZE as u32, depth: BRICK_SIZE as u32 };
let size = wgpu::Extent3d { width: BRICK_SIZE as u32, height: BRICK_SIZE as u32, depth: (BRICK_SIZE*BRICK_NUM) as u32 };
let texture = device.create_texture(
&wgpu::TextureDescriptor {
size: size,
@@ -107,6 +102,24 @@ impl BrickBuffer {
}
// Done
println!("Brick buffer size: {} MB", DATA_LEN as f32 / 1024.0 / 1024.0);
Self { bricks, texture, size, bind_layout, bind_group }
}
pub fn write(&mut self, queue: &wgpu::Queue)
{
return ();
// Get first brick
let brick_bytes : [u8;BRICK_LEN] = self.bricks.data[0..BRICK_LEN].try_into().unwrap();
let brick_size = wgpu::Extent3d{ width: BRICK_SIZE as u32, height: BRICK_SIZE as u32, depth: BRICK_SIZE as u32 };
// Write
queue.write_texture(
wgpu::TextureCopyView { texture: &self.texture, mip_level: 0, origin: wgpu::Origin3d::ZERO },
&brick_bytes,
wgpu::TextureDataLayout { offset: 0, bytes_per_row: self.size.width, rows_per_image: self.size.height },
brick_size
);
}
}