Treat dynamic offset UBOs better

This commit is contained in:
mars 2022-05-08 15:32:45 -06:00
parent 26ddd7820b
commit b291e7f82e
2 changed files with 12 additions and 7 deletions

View File

@ -18,6 +18,7 @@ impl<T: Clone + Pod> GpuVec<T> {
usage: wgpu::BufferUsages,
initial_capacity: usize,
label: Option<String>,
uses_dynamic_offsets: bool,
) -> Self {
let capacity_bytes = initial_capacity * std::mem::size_of::<T>();
let usage = usage | wgpu::BufferUsages::COPY_DST;
@ -30,10 +31,14 @@ impl<T: Clone + Pod> GpuVec<T> {
let data = Vec::with_capacity(initial_capacity);
let realign = if usage.contains(wgpu::BufferUsages::STORAGE) {
Some(device.limits().min_storage_buffer_offset_alignment as usize)
} else if usage.contains(wgpu::BufferUsages::UNIFORM) {
Some(device.limits().min_uniform_buffer_offset_alignment as usize)
let realign = if uses_dynamic_offsets {
if usage.contains(wgpu::BufferUsages::STORAGE) {
Some(device.limits().min_storage_buffer_offset_alignment as usize)
} else if usage.contains(wgpu::BufferUsages::UNIFORM) {
Some(device.limits().min_uniform_buffer_offset_alignment as usize)
} else {
None
}
} else {
None
};

View File

@ -153,7 +153,7 @@ impl MeshPass {
let example_mesh = mesh_pool.load(example_mesh).unwrap();
let mut instances = Vec::new();
let r = 10;
let r = 4;
for x in -r..r {
for y in -r..r {
for z in -r..r {
@ -318,12 +318,14 @@ impl RenderPass for MeshPass {
Vertex::get_usages(),
1024 * 128,
Some("Skinned Vertices".to_string()),
false,
),
skinning_uniforms: GpuVec::new(
self.device.clone(),
wgpu::BufferUsages::STORAGE,
1024 * 128,
Some("Skinning Uniforms".to_string()),
true,
),
groups: Default::default(),
}
@ -427,8 +429,6 @@ impl RenderPass for MeshPass {
data.groups.push(group);
}
println!("commands: {:#?}", data.groups);
data.skinned_vertices.reserve(skinned_cursor);
data.skinned_vertices.write(&queue);
data.skinning_uniforms.write(&queue);