Skip to content

Commit

Permalink
Merge branch 'master' into 84-mip-levels
Browse files Browse the repository at this point in the history
  • Loading branch information
attackgoat committed Dec 21, 2024
2 parents dca9116 + d1d8bff commit a989812
Show file tree
Hide file tree
Showing 18 changed files with 1,321 additions and 731 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ash-window = "0.13"
derive_builder = "0.20"
gpu-allocator = "0.27"
log = "0.4"
ordered-float = "4.1"
ordered-float = "4.2"
parking_lot = { version = "0.12", optional = true }
paste = "1.0"
profiling = "1.0"
Expand All @@ -39,10 +39,10 @@ ash-molten = "0.19"
[dev-dependencies]
anyhow = "1.0"
bmfont = { version = "0.3", default-features = false }
bytemuck = "1.14"
bytemuck = "1.16"
clap = { version = "4.5", features = ["derive"] }
glam = { version = "0.27", features = ["bytemuck"] }
half = { version = "2.3", features = ["bytemuck"] }
glam = { version = "0.28", features = ["bytemuck"] }
half = { version = "2.4", features = ["bytemuck"] }
hassle-rs = "0.11"
image = "0.25"
inline-spirv = "0.2"
Expand Down
8 changes: 2 additions & 6 deletions contrib/screen-13-fx/src/image_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ use {
#[cfg(debug_assertions)]
use log::warn;

fn align_up_u32(val: u32, atom: u32) -> u32 {
(val + atom - 1) & !(atom - 1)
}

/// Describes the channels and pixel stride of an image format
#[derive(Clone, Copy, Debug)]
pub enum ImageFormat {
Expand Down Expand Up @@ -133,7 +129,7 @@ impl ImageLoader {
);

#[cfg(debug_assertions)]
if pixels.len() > align_up_u32(format.stride() as u32 * width * height, 4) as usize {
if pixels.len() > (format.stride() as u32 * width * height).next_multiple_of(4) as usize {
warn!("unused data");
}

Expand All @@ -156,7 +152,7 @@ impl ImageLoader {

//trace!("{bitmap_width}x{bitmap_height} Stride={bitmap_stride}");

let pixel_buf_stride = align_up_u32(stride, 12);
let pixel_buf_stride = stride.next_multiple_of(12);
let pixel_buf_len = (pixel_buf_stride * height) as vk::DeviceSize;

//trace!("pixel_buf_len={pixel_buf_len} pixel_buf_stride={pixel_buf_stride}");
Expand Down
4 changes: 3 additions & 1 deletion examples/cpu_readback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,7 @@ fn main() -> Result<(), DriverError> {
println!("Waited {}μs", (Instant::now() - started).as_micros());

// It is now safe to read back what we did!
Ok(println!("{:?}", Buffer::mapped_slice(&dst_buf)))
println!("{:?}", Buffer::mapped_slice(&dst_buf));

Ok(())
}
6 changes: 1 addition & 5 deletions examples/font_bmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,7 @@ fn main() -> anyhow::Result<()> {
.record_compute(move |compute, _| {
compute
.push_constants(&elapsed_time.as_secs_f32().to_ne_bytes())
.dispatch(
(frame.width + subgroup_size - 1) / subgroup_size,
frame.height,
1,
);
.dispatch(frame.width.div_ceil(subgroup_size), frame.height, 1);
});

// Print some text onto the image
Expand Down
90 changes: 35 additions & 55 deletions examples/ray_omni.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,30 +148,31 @@ fn create_blas(
device: &Arc<Device>,
models: &[&Model],
) -> Result<Arc<AccelerationStructure>, DriverError> {
let info = AccelerationStructureGeometryInfo {
ty: vk::AccelerationStructureTypeKHR::BOTTOM_LEVEL,
flags: vk::BuildAccelerationStructureFlagsKHR::PREFER_FAST_TRACE,
geometries: models
let info = AccelerationStructureGeometryInfo::blas(
models
.iter()
.map(|model| AccelerationStructureGeometry {
max_primitive_count: model.index_count / 3,
flags: vk::GeometryFlagsKHR::OPAQUE,
geometry: AccelerationStructureGeometryData::Triangles {
index_data: DeviceOrHostAddress::DeviceAddress(Buffer::device_address(
&model.index_buf,
)),
index_type: vk::IndexType::UINT32,
max_vertex: model.vertex_count,
transform_data: None,
vertex_data: DeviceOrHostAddress::DeviceAddress(Buffer::device_address(
&model.vertex_buf,
)),
vertex_format: vk::Format::R32G32B32_SFLOAT,
vertex_stride: 24,
},
.map(|model| {
(
AccelerationStructureGeometry {
max_primitive_count: model.index_count / 3,
flags: vk::GeometryFlagsKHR::OPAQUE,
geometry: AccelerationStructureGeometryData::triangles(
Buffer::device_address(&model.index_buf),
vk::IndexType::UINT32,
model.vertex_count,
None,
Buffer::device_address(&model.vertex_buf),
vk::Format::R32G32B32_SFLOAT,
24,
),
},
vk::AccelerationStructureBuildRangeInfoKHR::default()
.primitive_count(model.index_count / 3),
)
})
.collect(),
};
.collect::<Box<_>>(),
)
.flags(vk::BuildAccelerationStructureFlagsKHR::PREFER_FAST_TRACE);
let size = AccelerationStructure::size_of(device, &info);

let mut render_graph = RenderGraph::new();
Expand All @@ -196,15 +197,7 @@ fn create_blas(
.to_builder()
.alignment(accel_struct_scratch_offset_alignment),
)?);
let build_ranges = models
.iter()
.map(|model| vk::AccelerationStructureBuildRangeInfoKHR {
primitive_count: model.index_count / 3,
primitive_offset: 0,
first_vertex: 0,
transform_offset: 0,
})
.collect::<Box<_>>();
let scratch_data = render_graph.node_device_address(scratch_buf);

let mut pass = render_graph.begin_pass("Build BLAS");

Expand All @@ -219,7 +212,7 @@ fn create_blas(
pass.access_node(blas, AccessType::AccelerationStructureBuildWrite)
.access_node(scratch_buf, AccessType::AccelerationStructureBufferWrite)
.record_acceleration(move |accel, _| {
accel.build_structure(blas, scratch_buf, &info, &build_ranges);
accel.build_structure(&info, blas, scratch_data);
});

let blas = render_graph.unbind_node(blas);
Expand Down Expand Up @@ -358,18 +351,14 @@ fn create_tlas(
buffer
});

let info = AccelerationStructureGeometryInfo {
ty: vk::AccelerationStructureTypeKHR::TOP_LEVEL,
flags: vk::BuildAccelerationStructureFlagsKHR::PREFER_FAST_TRACE,
geometries: vec![AccelerationStructureGeometry {
max_primitive_count: 2,
flags: vk::GeometryFlagsKHR::OPAQUE,
geometry: AccelerationStructureGeometryData::Instances {
array_of_pointers: false,
data: DeviceOrHostAddress::DeviceAddress(Buffer::device_address(&instance_buf)),
},
}],
};
let info = AccelerationStructureGeometryInfo::tlas([(
AccelerationStructureGeometry::opaque(
2,
AccelerationStructureGeometryData::instances(Buffer::device_address(&instance_buf)),
),
vk::AccelerationStructureBuildRangeInfoKHR::default().primitive_count(1),
)])
.flags(vk::BuildAccelerationStructureFlagsKHR::PREFER_FAST_TRACE);
let size = AccelerationStructure::size_of(device, &info);
let tlas =
render_graph.bind_node(pool.lease(AccelerationStructureInfo::tlas(size.create_size))?);
Expand All @@ -391,6 +380,7 @@ fn create_tlas(
.alignment(accel_struct_scratch_offset_alignment),
)?,
);
let scratch_data = render_graph.node_device_address(scratch_buf);
let blas = render_graph.bind_node(blas);
let instance_buf = render_graph.bind_node(instance_buf);

Expand All @@ -401,17 +391,7 @@ fn create_tlas(
.access_node(scratch_buf, AccessType::AccelerationStructureBufferWrite)
.access_node(tlas, AccessType::AccelerationStructureBuildWrite)
.record_acceleration(move |accel, _| {
accel.build_structure(
tlas,
scratch_buf,
&info,
&[vk::AccelerationStructureBuildRangeInfoKHR {
first_vertex: 0,
primitive_count: 1,
primitive_offset: 0,
transform_offset: 0,
}],
)
accel.build_structure(&info, tlas, scratch_data);
});

Ok(tlas)
Expand Down
Loading

0 comments on commit a989812

Please sign in to comment.