@@ -62,7 +62,14 @@ fn create_vertices() -> (Vec<Vertex>, Vec<u16>) {
6262 20 , 21 , 22 , 22 , 23 , 20 , // back
6363 ] ;
6464
65- ( vertex_data. to_vec ( ) , index_data. to_vec ( ) )
65+ (
66+ vertex_data. to_vec ( ) ,
67+ std:: iter:: repeat ( index_data)
68+ . flatten ( )
69+ . take ( 153 * 3 )
70+ . cloned ( )
71+ . collect ( ) ,
72+ )
6673}
6774
6875#[ repr( C ) ]
@@ -98,6 +105,7 @@ struct Example {
98105 uniforms : Uniforms ,
99106 uniform_buf : wgpu:: Buffer ,
100107 blas : wgpu:: Blas ,
108+ blas_with_one_too_much_triangles : wgpu:: Blas ,
101109 tlas_package : wgpu:: TlasPackage ,
102110 pipeline : wgpu:: RenderPipeline ,
103111 bind_group : wgpu:: BindGroup ,
@@ -168,7 +176,7 @@ impl crate::framework::Example for Example {
168176 vertex_format : wgpu:: VertexFormat :: Float32x3 ,
169177 vertex_count : vertex_data. len ( ) as u32 ,
170178 index_format : Some ( wgpu:: IndexFormat :: Uint16 ) ,
171- index_count : Some ( index_data. len ( ) as u32 ) ,
179+ index_count : Some ( index_data. len ( ) as u32 - 3 ) ,
172180 flags : wgpu:: AccelerationStructureGeometryFlags :: OPAQUE ,
173181 } ;
174182
@@ -183,6 +191,26 @@ impl crate::framework::Example for Example {
183191 } ,
184192 ) ;
185193
194+ let blas_with_one_too_much_triangles_geo_size_desc =
195+ wgpu:: BlasTriangleGeometrySizeDescriptor {
196+ vertex_format : wgpu:: VertexFormat :: Float32x3 ,
197+ vertex_count : vertex_data. len ( ) as u32 ,
198+ index_format : Some ( wgpu:: IndexFormat :: Uint16 ) ,
199+ index_count : Some ( index_data. len ( ) as u32 ) ,
200+ flags : wgpu:: AccelerationStructureGeometryFlags :: OPAQUE ,
201+ } ;
202+
203+ let blas_with_one_too_much_triangles = device. create_blas (
204+ & wgpu:: CreateBlasDescriptor {
205+ label : None ,
206+ flags : wgpu:: AccelerationStructureFlags :: PREFER_FAST_TRACE ,
207+ update_mode : wgpu:: AccelerationStructureUpdateMode :: Build ,
208+ } ,
209+ wgpu:: BlasGeometrySizeDescriptors :: Triangles {
210+ descriptors : vec ! [ blas_with_one_too_much_triangles_geo_size_desc. clone( ) ] ,
211+ } ,
212+ ) ;
213+
186214 let tlas = device. create_tlas ( & wgpu:: CreateTlasDescriptor {
187215 label : None ,
188216 flags : wgpu:: AccelerationStructureFlags :: PREFER_FAST_TRACE ,
@@ -243,22 +271,38 @@ impl crate::framework::Example for Example {
243271 device. create_command_encoder ( & wgpu:: CommandEncoderDescriptor { label : None } ) ;
244272
245273 encoder. build_acceleration_structures (
246- iter:: once ( & wgpu:: BlasBuildEntry {
247- blas : & blas,
248- geometry : wgpu:: BlasGeometries :: TriangleGeometries ( vec ! [
249- wgpu:: BlasTriangleGeometry {
250- size: & blas_geo_size_desc,
251- vertex_buffer: & vertex_buf,
252- first_vertex: 0 ,
253- vertex_stride: mem:: size_of:: <Vertex >( ) as u64 ,
254- index_buffer: Some ( & index_buf) ,
255- first_index: Some ( 0 ) ,
256- transform_buffer: None ,
257- transform_buffer_offset: None ,
258- } ,
259- ] ) ,
260- } ) ,
261- // iter::empty(),
274+ vec ! [
275+ & wgpu:: BlasBuildEntry {
276+ blas: & blas,
277+ geometry: wgpu:: BlasGeometries :: TriangleGeometries ( vec![
278+ wgpu:: BlasTriangleGeometry {
279+ size: & blas_geo_size_desc,
280+ vertex_buffer: & vertex_buf,
281+ first_vertex: 0 ,
282+ vertex_stride: mem:: size_of:: <Vertex >( ) as u64 ,
283+ index_buffer: Some ( & index_buf) ,
284+ first_index: Some ( 0 ) ,
285+ transform_buffer: None ,
286+ transform_buffer_offset: None ,
287+ } ,
288+ ] ) ,
289+ } ,
290+ & wgpu:: BlasBuildEntry {
291+ blas: & blas_with_one_too_much_triangles,
292+ geometry: wgpu:: BlasGeometries :: TriangleGeometries ( vec![
293+ wgpu:: BlasTriangleGeometry {
294+ size: & blas_with_one_too_much_triangles_geo_size_desc,
295+ vertex_buffer: & vertex_buf,
296+ first_vertex: 0 ,
297+ vertex_stride: mem:: size_of:: <Vertex >( ) as u64 ,
298+ index_buffer: Some ( & index_buf) ,
299+ first_index: Some ( 0 ) ,
300+ transform_buffer: None ,
301+ transform_buffer_offset: None ,
302+ } ,
303+ ] ) ,
304+ } ,
305+ ] ,
262306 iter:: once ( & tlas_package) ,
263307 ) ;
264308
@@ -270,6 +314,7 @@ impl crate::framework::Example for Example {
270314 uniforms,
271315 uniform_buf,
272316 blas,
317+ blas_with_one_too_much_triangles,
273318 tlas_package,
274319 pipeline,
275320 bind_group,
@@ -311,6 +356,7 @@ impl crate::framework::Example for Example {
311356 for x in 0 ..side_count {
312357 for y in 0 ..side_count {
313358 let instance = self . tlas_package . index_mut ( ( x + y * side_count) as usize ) ;
359+ let checker = ( x ^ y) & 1 == 0 ;
314360
315361 let x = x as f32 / ( side_count - 1 ) as f32 ;
316362 let y = y as f32 / ( side_count - 1 ) as f32 ;
@@ -334,7 +380,16 @@ impl crate::framework::Example for Example {
334380 . try_into ( )
335381 . unwrap ( ) ;
336382
337- * instance = Some ( wgpu:: TlasInstance :: new ( & self . blas , transform, 0 , 0xff ) ) ;
383+ * instance = Some ( wgpu:: TlasInstance :: new (
384+ if checker {
385+ & self . blas
386+ } else {
387+ & self . blas_with_one_too_much_triangles
388+ } ,
389+ transform,
390+ 0 ,
391+ 0xff ,
392+ ) ) ;
338393 }
339394 }
340395 }
0 commit comments