Skip to content

Commit

Permalink
Update naga, fix index buffer alignment in blade-render
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Feb 2, 2025
1 parent 4588302 commit 7dffb3c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ glam = { version = "0.28", features = ["mint"] }
gltf = { version = "1.1", default-features = false }
log = "0.4"
mint = "0.5"
naga = { version = "23.1.0", features = ["wgsl-in"] }
naga = { version = "24.0", features = ["wgsl-in"] }
profiling = "1"
slab = "0.4"
strum = { version = "0.25", features = ["derive"] }
strum = { version = "0.26", features = ["derive"] }
web-sys = "0.3.60"
winit = { version = "0.30" }

Expand Down Expand Up @@ -59,7 +59,7 @@ log = { workspace = true }
mint = { workspace = true, features = ["serde"] }
num_cpus = "1"
profiling = { workspace = true }
rapier3d = { version = "0.22", features = ["debug-render"] }
rapier3d = { version = "0.23", features = ["debug-render"] }
serde = { version = "1", features = ["serde_derive"] }
slab = "0.4"
winit = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion blade-egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl GuiPainter {
let belt = BufferBelt::new(BufferBeltDescriptor {
memory: blade_graphics::Memory::Shared,
min_chunk_size: 0x1000,
alignment: 4,
alignment: blade_graphics::limits::STORAGE_BUFFER_ALIGNMENT,
});

Self {
Expand Down
2 changes: 1 addition & 1 deletion blade-graphics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub mod limits {
/// Max number of resources in a bind group.
pub const RESOURCES_IN_GROUP: u32 = 8;
/// Min storage buffer alignment.
pub const STORAGE_BUFFER_ALIGNMENT: u64 = 256;
pub const STORAGE_BUFFER_ALIGNMENT: u64 = 16;
/// Min acceleration structure scratch buffer alignment.
pub const ACCELERATION_STRUCTURE_SCRATCH_ALIGNMENT: u64 = 256;
}
Expand Down
9 changes: 7 additions & 2 deletions blade-render/src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,8 @@ impl blade_asset::Baker for Baker {
.iter()
.map(|geo| geo.indices.len())
.sum::<usize>();
let total_index_size = total_indices as u64 * 4;
let total_index_size = total_indices as u64 * 4
+ model.geometries.len() as u64 * blade_graphics::limits::STORAGE_BUFFER_ALIGNMENT;
let index_buffer = self.gpu_context.create_buffer(blade_graphics::BufferDesc {
name: "index",
size: total_index_size,
Expand Down Expand Up @@ -694,6 +695,10 @@ impl blade_asset::Baker for Baker {
let mut transform_offset = 0;
let mut geometries = Vec::with_capacity(model.geometries.len());
for geometry in model.geometries.iter() {
index_offset = crate::util::align_to(
index_offset,
blade_graphics::limits::STORAGE_BUFFER_ALIGNMENT,
);
let material = &model.materials[geometry.material_index as usize];
unsafe {
ptr::copy_nonoverlapping(
Expand Down Expand Up @@ -747,7 +752,7 @@ impl blade_asset::Baker for Baker {
transform_offset += mem::size_of::<blade_graphics::Transform>() as u64;
}
assert_eq!(start_vertex as usize, total_vertices);
assert_eq!(index_offset, total_index_size);
assert!(index_offset <= total_index_size);
assert_eq!(transform_offset, total_transform_size);

let sizes = self
Expand Down
9 changes: 9 additions & 0 deletions blade-render/src/util/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
mod frame_pacer;

pub use self::frame_pacer::*;

pub fn align_to(offset: u64, alignment: u64) -> u64 {
let rem = offset & (alignment - 1);
if rem == 0 {
offset
} else {
offset - rem + alignment
}
}
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ impl ops::Index<JointHandle> for Physics {
impl ops::IndexMut<JointHandle> for Physics {
fn index_mut(&mut self, handle: JointHandle) -> &mut Self::Output {
match handle {
JointHandle::Soft(h) => &mut self.impulse_joints.get_mut(h).unwrap().data,
JointHandle::Soft(h) => &mut self.impulse_joints.get_mut(h, true).unwrap().data,
JointHandle::Hard(h) => {
let (multibody, link_index) = self.multibody_joints.get_mut(h).unwrap();
&mut multibody.link_mut(link_index).unwrap().joint.data
Expand Down Expand Up @@ -1007,6 +1007,7 @@ impl Engine {
trimesh.triangles,
flags,
)
.unwrap()
}
}
};
Expand Down

0 comments on commit 7dffb3c

Please sign in to comment.