Skip to content

Commit 81aaf8a

Browse files
committed
Add convience functions for creating TlasInstances
1 parent 2c3e503 commit 81aaf8a

11 files changed

Lines changed: 53 additions & 63 deletions

File tree

‎examples/features/src/ray_aabb_compute/mod.rs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,14 +284,12 @@ impl crate::framework::Example for Example {
284284
],
285285
});
286286

287-
tlas[0] = Some(wgpu::TlasInstance::new(
287+
tlas[0] = Some(wgpu::TlasInstance::from_blas_transformed(
288288
&blas,
289289
affine_to_rows(&Affine3A::from_rotation_translation(
290290
Quat::IDENTITY,
291291
Vec3::new(0.0, 0.0, 0.0),
292292
)),
293-
0,
294-
0xff,
295293
));
296294

297295
let mut encoder =

‎examples/features/src/ray_cube_compute/mod.rs‎

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -331,19 +331,18 @@ impl crate::framework::Example for Example {
331331

332332
for x in 0..side_count {
333333
for y in 0..side_count {
334-
tlas[(x + y * side_count) as usize] = Some(wgpu::TlasInstance::new(
335-
&blas,
336-
affine_to_rows(&Affine3A::from_rotation_translation(
337-
Quat::from_rotation_y(45.9_f32.to_radians()),
338-
Vec3 {
339-
x: x as f32 * dist,
340-
y: y as f32 * dist,
341-
z: -30.0,
342-
},
343-
)),
344-
0,
345-
0xff,
346-
));
334+
tlas[(x + y * side_count) as usize] =
335+
Some(wgpu::TlasInstance::from_blas_transformed(
336+
&blas,
337+
affine_to_rows(&Affine3A::from_rotation_translation(
338+
Quat::from_rotation_y(45.9_f32.to_radians()),
339+
Vec3 {
340+
x: x as f32 * dist,
341+
y: y as f32 * dist,
342+
z: -30.0,
343+
},
344+
)),
345+
));
347346
}
348347
}
349348

‎examples/features/src/ray_cube_fragment/mod.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,9 @@ impl crate::framework::Example for Example {
307307
.try_into()
308308
.unwrap();
309309

310-
*instance = Some(wgpu::TlasInstance::new(&self.blas, transform, 0, 0xff));
310+
*instance = Some(wgpu::TlasInstance::from_blas_transformed(
311+
&self.blas, transform,
312+
));
311313
}
312314
}
313315
}

‎examples/features/src/ray_cube_normals/mod.rs‎

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -322,19 +322,18 @@ impl crate::framework::Example for Example {
322322

323323
for x in 0..side_count {
324324
for y in 0..side_count {
325-
tlas[(x + y * side_count) as usize] = Some(wgpu::TlasInstance::new(
326-
&blas,
327-
affine_to_rows(&Affine3A::from_rotation_translation(
328-
Quat::from_rotation_y(45.9_f32.to_radians()),
329-
Vec3 {
330-
x: x as f32 * dist,
331-
y: y as f32 * dist,
332-
z: -30.0,
333-
},
334-
)),
335-
0,
336-
0xff,
337-
));
325+
tlas[(x + y * side_count) as usize] =
326+
Some(wgpu::TlasInstance::from_blas_transformed(
327+
&blas,
328+
affine_to_rows(&Affine3A::from_rotation_translation(
329+
Quat::from_rotation_y(45.9_f32.to_radians()),
330+
Vec3 {
331+
x: x as f32 * dist,
332+
y: y as f32 * dist,
333+
z: -30.0,
334+
},
335+
)),
336+
));
338337
}
339338
}
340339

‎examples/features/src/ray_shadows/mod.rs‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,7 @@ impl crate::framework::Example for Example {
218218
cache: None,
219219
});
220220

221-
tlas[0] = Some(wgpu::TlasInstance::new(
222-
&blas,
223-
[1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0],
224-
0,
225-
0xFF,
226-
));
221+
tlas[0] = Some(wgpu::TlasInstance::from_blas_untransformed(&blas));
227222

228223
let mut encoder =
229224
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });

‎tests/tests/wgpu-gpu/ray_tracing/as_aabb.rs‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,7 @@ fn aabb_blas_build_and_trace(ctx: TestingContext) {
8181
flags: AccelerationStructureFlags::PREFER_FAST_TRACE,
8282
update_mode: AccelerationStructureUpdateMode::Build,
8383
});
84-
tlas[0] = Some(TlasInstance::new(
85-
&blas,
86-
[1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0],
87-
0,
88-
0xFF,
89-
));
84+
tlas[0] = Some(TlasInstance::from_blas_untransformed(&blas));
9085

9186
let mut encoder = ctx
9287
.device

‎tests/tests/wgpu-gpu/ray_tracing/as_build.rs‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -551,12 +551,7 @@ fn build_with_transform(ctx: TestingContext) {
551551
flags: AccelerationStructureFlags::PREFER_FAST_TRACE,
552552
update_mode: AccelerationStructureUpdateMode::Build,
553553
});
554-
tlas[0] = Some(TlasInstance::new(
555-
&blas,
556-
[1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0],
557-
0,
558-
0xFF,
559-
));
554+
tlas[0] = Some(TlasInstance::from_blas_untransformed(&blas));
560555

561556
let mut encoder_build = ctx
562557
.device

‎tests/tests/wgpu-gpu/ray_tracing/as_use_after_free.rs‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,7 @@ fn acceleration_structure_use_after_free(ctx: TestingContext) {
5959
update_mode: AccelerationStructureUpdateMode::Build,
6060
});
6161

62-
tlas[0] = Some(TlasInstance::new(
63-
&blas,
64-
[1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0],
65-
0,
66-
0xFF,
67-
));
62+
tlas[0] = Some(TlasInstance::from_blas_untransformed(&blas));
6863

6964
// Actually build the BLAS.
7065
let mut encoder = ctx

‎tests/tests/wgpu-gpu/ray_tracing/mod.rs‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,7 @@ impl AsBuildContext {
7979
update_mode: AccelerationStructureUpdateMode::Build,
8080
});
8181

82-
tlas[0] = Some(TlasInstance::new(
83-
&blas,
84-
[1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0],
85-
0,
86-
0xFF,
87-
));
82+
tlas[0] = Some(TlasInstance::from_blas_untransformed(&blas));
8883

8984
Self {
9085
vertices,

‎tests/tests/wgpu-gpu/ray_tracing/scene/mod.rs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fn acceleration_structure_build(ctx: &TestingContext, use_index_buffer: bool) {
6464
});
6565

6666
for j in 0..max_instances {
67-
tlas[j as usize] = Some(wgpu::TlasInstance::new(
67+
tlas[j as usize] = Some(wgpu::TlasInstance::from_blas_transformed(
6868
&blas,
6969
mesh_gen::affine_to_rows(&Affine3A::from_rotation_translation(
7070
Quat::from_rotation_y(45.9_f32.to_radians()),
@@ -74,8 +74,6 @@ fn acceleration_structure_build(ctx: &TestingContext, use_index_buffer: bool) {
7474
z: 0.0,
7575
},
7676
)),
77-
0,
78-
0xff,
7977
));
8078
}
8179

0 commit comments

Comments
 (0)