@@ -62,7 +62,14 @@ fn create_vertices() -> (Vec<Vertex>, Vec<u16>) {
62
62
20 , 21 , 22 , 22 , 23 , 20 , // back
63
63
] ;
64
64
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
+ )
66
73
}
67
74
68
75
#[ repr( C ) ]
@@ -98,6 +105,7 @@ struct Example {
98
105
uniforms : Uniforms ,
99
106
uniform_buf : wgpu:: Buffer ,
100
107
blas : wgpu:: Blas ,
108
+ blas_with_one_too_many_triangles : wgpu:: Blas ,
101
109
tlas_package : wgpu:: TlasPackage ,
102
110
pipeline : wgpu:: RenderPipeline ,
103
111
bind_group : wgpu:: BindGroup ,
@@ -168,7 +176,7 @@ impl crate::framework::Example for Example {
168
176
vertex_format : wgpu:: VertexFormat :: Float32x3 ,
169
177
vertex_count : vertex_data. len ( ) as u32 ,
170
178
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 ) ,
172
180
flags : wgpu:: AccelerationStructureGeometryFlags :: OPAQUE ,
173
181
} ;
174
182
@@ -183,6 +191,26 @@ impl crate::framework::Example for Example {
183
191
} ,
184
192
) ;
185
193
194
+ let blas_with_one_too_many_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_many_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_many_triangles_geo_size_desc. clone( ) ] ,
211
+ } ,
212
+ ) ;
213
+
186
214
let tlas = device. create_tlas ( & wgpu:: CreateTlasDescriptor {
187
215
label : None ,
188
216
flags : wgpu:: AccelerationStructureFlags :: PREFER_FAST_TRACE ,
@@ -243,22 +271,38 @@ impl crate::framework::Example for Example {
243
271
device. create_command_encoder ( & wgpu:: CommandEncoderDescriptor { label : None } ) ;
244
272
245
273
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_many_triangles,
292
+ geometry: wgpu:: BlasGeometries :: TriangleGeometries ( vec![
293
+ wgpu:: BlasTriangleGeometry {
294
+ size: & blas_with_one_too_many_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
+ ] ,
262
306
iter:: once ( & tlas_package) ,
263
307
) ;
264
308
@@ -270,6 +314,7 @@ impl crate::framework::Example for Example {
270
314
uniforms,
271
315
uniform_buf,
272
316
blas,
317
+ blas_with_one_too_many_triangles,
273
318
tlas_package,
274
319
pipeline,
275
320
bind_group,
@@ -311,6 +356,7 @@ impl crate::framework::Example for Example {
311
356
for x in 0 ..side_count {
312
357
for y in 0 ..side_count {
313
358
let instance = self . tlas_package . index_mut ( ( x + y * side_count) as usize ) ;
359
+ let checker = ( x ^ y) & 1 == 0 ;
314
360
315
361
let x = x as f32 / ( side_count - 1 ) as f32 ;
316
362
let y = y as f32 / ( side_count - 1 ) as f32 ;
@@ -334,7 +380,16 @@ impl crate::framework::Example for Example {
334
380
. try_into ( )
335
381
. unwrap ( ) ;
336
382
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_many_triangles
388
+ } ,
389
+ transform,
390
+ 0 ,
391
+ 0xff ,
392
+ ) ) ;
338
393
}
339
394
}
340
395
}
0 commit comments