Refactor triangle::Pipeline into prepare and render architecture
And get rid of the staging belt! 🎉
This commit is contained in:
parent
23ed352e83
commit
b8c1809ea1
7 changed files with 358 additions and 291 deletions
|
|
@ -112,25 +112,8 @@ impl<T: ShaderType + WriteInto> Buffer<T> {
|
|||
}
|
||||
|
||||
/// Write the contents of this dynamic buffer to the GPU via staging belt command.
|
||||
pub fn write(
|
||||
&mut self,
|
||||
device: &wgpu::Device,
|
||||
staging_belt: &mut wgpu::util::StagingBelt,
|
||||
encoder: &mut wgpu::CommandEncoder,
|
||||
) {
|
||||
let size = self.cpu.get_ref().len();
|
||||
|
||||
if let Some(buffer_size) = wgpu::BufferSize::new(size as u64) {
|
||||
let mut buffer = staging_belt.write_buffer(
|
||||
encoder,
|
||||
&self.gpu,
|
||||
0,
|
||||
buffer_size,
|
||||
device,
|
||||
);
|
||||
|
||||
buffer.copy_from_slice(self.cpu.get_ref());
|
||||
}
|
||||
pub fn write(&mut self, queue: &wgpu::Queue) {
|
||||
queue.write_buffer(&self.gpu, 0, self.cpu.get_ref());
|
||||
}
|
||||
|
||||
// Gets the aligned offset at the given index from the CPU buffer.
|
||||
|
|
@ -184,7 +167,7 @@ impl Internal {
|
|||
}
|
||||
|
||||
/// Returns bytearray of aligned CPU buffer.
|
||||
pub(super) fn get_ref(&self) -> &Vec<u8> {
|
||||
pub(super) fn get_ref(&self) -> &[u8] {
|
||||
match self {
|
||||
Internal::Uniform(buf) => buf.as_ref(),
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use std::marker::PhantomData;
|
|||
use std::mem;
|
||||
|
||||
//128 triangles/indices
|
||||
const DEFAULT_STATIC_BUFFER_COUNT: wgpu::BufferAddress = 128;
|
||||
const DEFAULT_STATIC_BUFFER_COUNT: wgpu::BufferAddress = 1_000;
|
||||
|
||||
/// A generic buffer struct useful for items which have no alignment requirements
|
||||
/// (e.g. Vertex, Index buffers) & no dynamic offsets.
|
||||
|
|
@ -71,28 +71,15 @@ impl<T: Pod + Zeroable> Buffer<T> {
|
|||
/// Returns the size of the written bytes.
|
||||
pub fn write(
|
||||
&mut self,
|
||||
device: &wgpu::Device,
|
||||
staging_belt: &mut wgpu::util::StagingBelt,
|
||||
encoder: &mut wgpu::CommandEncoder,
|
||||
queue: &wgpu::Queue,
|
||||
offset: u64,
|
||||
content: &[T],
|
||||
) -> u64 {
|
||||
let bytes = bytemuck::cast_slice(content);
|
||||
let bytes_size = bytes.len() as u64;
|
||||
|
||||
if let Some(buffer_size) = wgpu::BufferSize::new(bytes_size) {
|
||||
let mut buffer = staging_belt.write_buffer(
|
||||
encoder,
|
||||
&self.gpu,
|
||||
offset,
|
||||
buffer_size,
|
||||
device,
|
||||
);
|
||||
|
||||
buffer.copy_from_slice(bytes);
|
||||
|
||||
self.offsets.push(offset);
|
||||
}
|
||||
queue.write_buffer(&self.gpu, offset, bytes);
|
||||
self.offsets.push(offset);
|
||||
|
||||
bytes_size
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue