From 8cdcb17e5e58ad2089bbdab5fe046da4e3e316e8 Mon Sep 17 00:00:00 2001 From: Michael Tang Date: Mon, 4 Jan 2021 23:45:10 -0800 Subject: [PATCH] Fix ray-tracing example build and change `wavefront_obj` -> `obj` --- examples/Cargo.toml | 2 +- examples/ray-tracing/main.rs | 53 +++++++++++++------------------ src/backend/vulkan/Cargo.toml | 2 +- src/backend/vulkan/src/command.rs | 2 -- 4 files changed, 24 insertions(+), 35 deletions(-) diff --git a/examples/Cargo.toml b/examples/Cargo.toml index a2a27548f01..f016d3f78e2 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -41,7 +41,7 @@ hal = { path = "../src/hal", version = "0.6", package = "gfx-hal" } auxil = { path = "../src/auxil/auxil", version = "0.5", package = "gfx-auxil" } gfx-backend-empty = { path = "../src/backend/empty", version = "0.6" } winit = { version = "0.23", features = ["web-sys"] } -wavefront_obj = "9.0" +obj = "0.10" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] env_logger = "0.7" diff --git a/examples/ray-tracing/main.rs b/examples/ray-tracing/main.rs index 9eb6d3207b5..75cd75eae9c 100644 --- a/examples/ray-tracing/main.rs +++ b/examples/ray-tracing/main.rs @@ -88,31 +88,22 @@ fn main() { "You are running the example with the empty backend, no graphical output is to be expected" ); - let teapot = wavefront_obj::obj::parse(include_str!("./data/teapot.obj")).unwrap(); - assert_eq!(teapot.objects.len(), 1); - let teapot_vertices = teapot.objects[0] - .vertices - .iter() - .map(|vertex| Vertex { - a_Pos: [vertex.x as f32, vertex.y as f32, vertex.z as f32], - }) - .collect::>(); + let teapot = obj::Obj::load(concat!( + env!("CARGO_MANIFEST_DIR"), + "/ray-tracing/data/teapot.obj" + )) + .unwrap(); + assert_eq!(teapot.data.objects.len(), 1); + let teapot_vertices = &teapot.data.position; let teapot_indices = { - let object = &teapot.objects[0]; - assert_eq!(object.geometry.len(), 1); - object.geometry[0] - .shapes + let object = &teapot.data.objects[0]; + assert_eq!(object.groups.len(), 1); + object.groups[0] + .polys .iter() - .flat_map(|shape| match shape.primitive { - wavefront_obj::obj::Primitive::Point(_) => { - unimplemented!() - } - wavefront_obj::obj::Primitive::Line(_, _) => { - unimplemented!() - } - wavefront_obj::obj::Primitive::Triangle(a, b, c) => std::iter::once(a.0 as u16) - .chain(std::iter::once(b.0 as u16)) - .chain(std::iter::once(c.0 as u16)), + .flat_map(|poly| { + assert_eq!(poly.0.len(), 3, "this isn't a triangle!?!"); + poly.0.iter().map(|index_tuple| index_tuple.0 as u16) }) .collect::>() }; @@ -198,7 +189,7 @@ fn main() { &memory_types, buffer::Usage::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY | buffer::Usage::SHADER_DEVICE_ADDRESS, - &teapot_vertices, + teapot_vertices, ); let index_buffer = upload_to_buffer::( @@ -623,14 +614,14 @@ fn main() { &[], ) .unwrap(); - let descriptor_set = descriptor_pool.allocate_set(&layout).unwrap(); + let mut descriptor_set = descriptor_pool.allocate_set(&layout).unwrap(); - device.write_descriptor_sets(iter::once(pso::DescriptorSetWrite { - set: &descriptor_set, + device.write_descriptor_set(pso::DescriptorSetWrite { + set: &mut descriptor_set, binding: 0, array_offset: 0, descriptors: vec![pso::Descriptor::AccelerationStructure(&tlas.accel_struct)], - })); + }); } } } @@ -694,7 +685,7 @@ fn upload_to_buffer( let buffer_stride = mem::size_of::() as u64; let buffer_len = data.len() as u64 * buffer_stride; - let (buffer, buffer_memory) = create_empty_buffer::( + let (buffer, mut buffer_memory) = create_empty_buffer::( device, non_coherent_alignment, memory_types, @@ -704,13 +695,13 @@ fn upload_to_buffer( unsafe { let mapping = device - .map_memory(&buffer_memory, memory::Segment::ALL) + .map_memory(&mut buffer_memory, memory::Segment::ALL) .unwrap(); ptr::copy_nonoverlapping(data.as_ptr() as *const u8, mapping, buffer_len as usize); device .flush_mapped_memory_ranges(iter::once((&buffer_memory, memory::Segment::ALL))) .unwrap(); - device.unmap_memory(&buffer_memory); + device.unmap_memory(&mut buffer_memory); } (buffer, buffer_memory) diff --git a/src/backend/vulkan/Cargo.toml b/src/backend/vulkan/Cargo.toml index 7d9d48655db..0bce5e7a5dc 100644 --- a/src/backend/vulkan/Cargo.toml +++ b/src/backend/vulkan/Cargo.toml @@ -25,7 +25,7 @@ byteorder = "1" log = { version = "0.4" } lazy_static = "1" shared_library = { version = "0.1.9", optional = true } -ash = "0.31" +ash = { git = "https://github.com/MaikKlein/ash", rev = "3703e73d304e840f0ee36d1ed369473c8d7c252a" } hal = { path = "../../hal", version = "0.6", package = "gfx-hal" } smallvec = "1.0" raw-window-handle = "0.3" diff --git a/src/backend/vulkan/src/command.rs b/src/backend/vulkan/src/command.rs index 071f8cf0858..5616c5b1118 100644 --- a/src/backend/vulkan/src/command.rs +++ b/src/backend/vulkan/src/command.rs @@ -1178,7 +1178,6 @@ impl com::CommandBuffer for CommandBuffer { unsafe fn copy_acceleration_structure_to_memory( &self, src: &n::AccelerationStructure, - // TODO(cpu-repr) dst_buffer: &n::Buffer, dst_offset: buffer::Offset, mode: hal::acceleration_structure::CopyMode, @@ -1188,7 +1187,6 @@ impl com::CommandBuffer for CommandBuffer { unsafe fn copy_memory_to_acceleration_structure( &self, - // TODO(cpu-repr) src_buffer: &n::Buffer, src_offset: buffer::Offset, dst: &n::AccelerationStructure,