Skip to content

Commit 8cdcb17

Browse files
committed
Fix ray-tracing example build and change wavefront_obj -> obj
1 parent 3f8074e commit 8cdcb17

File tree

4 files changed

+24
-35
lines changed

4 files changed

+24
-35
lines changed

examples/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ hal = { path = "../src/hal", version = "0.6", package = "gfx-hal" }
4141
auxil = { path = "../src/auxil/auxil", version = "0.5", package = "gfx-auxil" }
4242
gfx-backend-empty = { path = "../src/backend/empty", version = "0.6" }
4343
winit = { version = "0.23", features = ["web-sys"] }
44-
wavefront_obj = "9.0"
44+
obj = "0.10"
4545

4646
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
4747
env_logger = "0.7"

examples/ray-tracing/main.rs

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -88,31 +88,22 @@ fn main() {
8888
"You are running the example with the empty backend, no graphical output is to be expected"
8989
);
9090

91-
let teapot = wavefront_obj::obj::parse(include_str!("./data/teapot.obj")).unwrap();
92-
assert_eq!(teapot.objects.len(), 1);
93-
let teapot_vertices = teapot.objects[0]
94-
.vertices
95-
.iter()
96-
.map(|vertex| Vertex {
97-
a_Pos: [vertex.x as f32, vertex.y as f32, vertex.z as f32],
98-
})
99-
.collect::<Vec<_>>();
91+
let teapot = obj::Obj::load(concat!(
92+
env!("CARGO_MANIFEST_DIR"),
93+
"/ray-tracing/data/teapot.obj"
94+
))
95+
.unwrap();
96+
assert_eq!(teapot.data.objects.len(), 1);
97+
let teapot_vertices = &teapot.data.position;
10098
let teapot_indices = {
101-
let object = &teapot.objects[0];
102-
assert_eq!(object.geometry.len(), 1);
103-
object.geometry[0]
104-
.shapes
99+
let object = &teapot.data.objects[0];
100+
assert_eq!(object.groups.len(), 1);
101+
object.groups[0]
102+
.polys
105103
.iter()
106-
.flat_map(|shape| match shape.primitive {
107-
wavefront_obj::obj::Primitive::Point(_) => {
108-
unimplemented!()
109-
}
110-
wavefront_obj::obj::Primitive::Line(_, _) => {
111-
unimplemented!()
112-
}
113-
wavefront_obj::obj::Primitive::Triangle(a, b, c) => std::iter::once(a.0 as u16)
114-
.chain(std::iter::once(b.0 as u16))
115-
.chain(std::iter::once(c.0 as u16)),
104+
.flat_map(|poly| {
105+
assert_eq!(poly.0.len(), 3, "this isn't a triangle!?!");
106+
poly.0.iter().map(|index_tuple| index_tuple.0 as u16)
116107
})
117108
.collect::<Vec<_>>()
118109
};
@@ -198,7 +189,7 @@ fn main() {
198189
&memory_types,
199190
buffer::Usage::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY
200191
| buffer::Usage::SHADER_DEVICE_ADDRESS,
201-
&teapot_vertices,
192+
teapot_vertices,
202193
);
203194

204195
let index_buffer = upload_to_buffer::<back::Backend, _>(
@@ -623,14 +614,14 @@ fn main() {
623614
&[],
624615
)
625616
.unwrap();
626-
let descriptor_set = descriptor_pool.allocate_set(&layout).unwrap();
617+
let mut descriptor_set = descriptor_pool.allocate_set(&layout).unwrap();
627618

628-
device.write_descriptor_sets(iter::once(pso::DescriptorSetWrite {
629-
set: &descriptor_set,
619+
device.write_descriptor_set(pso::DescriptorSetWrite {
620+
set: &mut descriptor_set,
630621
binding: 0,
631622
array_offset: 0,
632623
descriptors: vec![pso::Descriptor::AccelerationStructure(&tlas.accel_struct)],
633-
}));
624+
});
634625
}
635626
}
636627
}
@@ -694,7 +685,7 @@ fn upload_to_buffer<B: hal::Backend, T>(
694685
let buffer_stride = mem::size_of::<T>() as u64;
695686
let buffer_len = data.len() as u64 * buffer_stride;
696687

697-
let (buffer, buffer_memory) = create_empty_buffer::<B>(
688+
let (buffer, mut buffer_memory) = create_empty_buffer::<B>(
698689
device,
699690
non_coherent_alignment,
700691
memory_types,
@@ -704,13 +695,13 @@ fn upload_to_buffer<B: hal::Backend, T>(
704695

705696
unsafe {
706697
let mapping = device
707-
.map_memory(&buffer_memory, memory::Segment::ALL)
698+
.map_memory(&mut buffer_memory, memory::Segment::ALL)
708699
.unwrap();
709700
ptr::copy_nonoverlapping(data.as_ptr() as *const u8, mapping, buffer_len as usize);
710701
device
711702
.flush_mapped_memory_ranges(iter::once((&buffer_memory, memory::Segment::ALL)))
712703
.unwrap();
713-
device.unmap_memory(&buffer_memory);
704+
device.unmap_memory(&mut buffer_memory);
714705
}
715706

716707
(buffer, buffer_memory)

src/backend/vulkan/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ byteorder = "1"
2525
log = { version = "0.4" }
2626
lazy_static = "1"
2727
shared_library = { version = "0.1.9", optional = true }
28-
ash = "0.31"
28+
ash = { git = "https://github.com/MaikKlein/ash", rev = "3703e73d304e840f0ee36d1ed369473c8d7c252a" }
2929
hal = { path = "../../hal", version = "0.6", package = "gfx-hal" }
3030
smallvec = "1.0"
3131
raw-window-handle = "0.3"

src/backend/vulkan/src/command.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,6 @@ impl com::CommandBuffer<Backend> for CommandBuffer {
11781178
unsafe fn copy_acceleration_structure_to_memory(
11791179
&self,
11801180
src: &n::AccelerationStructure,
1181-
// TODO(cpu-repr)
11821181
dst_buffer: &n::Buffer,
11831182
dst_offset: buffer::Offset,
11841183
mode: hal::acceleration_structure::CopyMode,
@@ -1188,7 +1187,6 @@ impl com::CommandBuffer<Backend> for CommandBuffer {
11881187

11891188
unsafe fn copy_memory_to_acceleration_structure(
11901189
&self,
1191-
// TODO(cpu-repr)
11921190
src_buffer: &n::Buffer,
11931191
src_offset: buffer::Offset,
11941192
dst: &n::AccelerationStructure,

0 commit comments

Comments
 (0)