Add buffer extension trait
This commit is contained in:
parent
132bc99540
commit
f5c503a3aa
|
@ -1,3 +1,5 @@
|
||||||
|
use std::ops::RangeBounds;
|
||||||
|
|
||||||
use bytemuck::NoUninit;
|
use bytemuck::NoUninit;
|
||||||
use wgpu::util::DeviceExt;
|
use wgpu::util::DeviceExt;
|
||||||
|
|
||||||
|
@ -71,3 +73,27 @@ impl<'a> BulkBufferBuilder<'a> {
|
||||||
buffers
|
buffers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait BufferExt {
|
||||||
|
fn get_mapped_range<S: RangeBounds<wgpu::BufferAddress>, T: bytemuck::Pod>(
|
||||||
|
&self,
|
||||||
|
context: &Context,
|
||||||
|
bounds: S,
|
||||||
|
) -> Vec<T>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BufferExt for wgpu::Buffer {
|
||||||
|
fn get_mapped_range<S: RangeBounds<wgpu::BufferAddress>, T: bytemuck::Pod>(
|
||||||
|
&self,
|
||||||
|
context: &Context,
|
||||||
|
bounds: S,
|
||||||
|
) -> Vec<T> {
|
||||||
|
let slice = self.slice(bounds);
|
||||||
|
slice.map_async(wgpu::MapMode::Read, |_| {});
|
||||||
|
context.device.poll(wgpu::Maintain::Wait);
|
||||||
|
let data: Vec<T> = bytemuck::cast_slice(slice.get_mapped_range().as_ref()).to_vec();
|
||||||
|
self.unmap();
|
||||||
|
|
||||||
|
data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ mod texture;
|
||||||
|
|
||||||
pub use self::{
|
pub use self::{
|
||||||
bind_group::{BindGroupBuilder, BindGroupLayoutBuilder},
|
bind_group::{BindGroupBuilder, BindGroupLayoutBuilder},
|
||||||
buffer::BulkBufferBuilder,
|
buffer::{BufferExt, BulkBufferBuilder},
|
||||||
context::Context,
|
context::Context,
|
||||||
renderer::Renderer,
|
renderer::Renderer,
|
||||||
texture::{Texture, TextureBuilder},
|
texture::{Texture, TextureBuilder},
|
||||||
|
|
Loading…
Reference in New Issue