Remove unsafe acceleration structure build (#7513)

This commit is contained in:
Vecvec authored and GitHub committed 2025-06-12 00:43:03 -04:00
1 parent 645354a528
commit aa427de4ea
23 files changed
+102 -602

No files matched your search

@@ -132,7 +132,7 @@ struct Example {
vertex_buf: wgpu::Buffer,
#[expect(dead_code)]
index_buf: wgpu::Buffer,
tlas_package: wgpu::TlasPackage,
tlas: wgpu::Tlas,
compute_pipeline: wgpu::ComputePipeline,
compute_bind_group: wgpu::BindGroup,
blit_pipeline: wgpu::RenderPipeline,
@@ -259,7 +259,7 @@ impl crate::framework::Example for Example {
},
);
let tlas = device.create_tlas(&wgpu::CreateTlasDescriptor {
let mut tlas = device.create_tlas(&wgpu::CreateTlasDescriptor {
label: None,
flags: wgpu::AccelerationStructureFlags::PREFER_FAST_TRACE,
update_mode: wgpu::AccelerationStructureUpdateMode::Build,
@@ -348,13 +348,11 @@ impl crate::framework::Example for Example {
],
});
let mut tlas_package = wgpu::TlasPackage::new(tlas);
let dist = 3.0;
for x in 0..side_count {
for y in 0..side_count {
tlas_package[(x + y * side_count) as usize] = Some(wgpu::TlasInstance::new(
tlas[(x + y * side_count) as usize] = Some(wgpu::TlasInstance::new(
&blas,
affine_to_rows(&Affine3A::from_rotation_translation(
Quat::from_rotation_y(45.9_f32.to_radians()),
@@ -389,7 +387,7 @@ impl crate::framework::Example for Example {
},
]),
}),
iter::once(&tlas_package),
iter::once(&tlas),
);
queue.submit(Some(encoder.finish()));
@@ -401,7 +399,7 @@ impl crate::framework::Example for Example {
uniform_buf,
vertex_buf,
index_buf,
tlas_package,
tlas,
compute_pipeline,
compute_bind_group,
blit_pipeline,
@@ -427,7 +425,7 @@ impl crate::framework::Example for Example {
let anim_time = self.animation_timer.time();
self.tlas_package[0].as_mut().unwrap().transform =
self.tlas[0].as_mut().unwrap().transform =
affine_to_rows(&Affine3A::from_rotation_translation(
Quat::from_euler(
glam::EulerRot::XYZ,
@@ -445,7 +443,7 @@ impl crate::framework::Example for Example {
let mut encoder =
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
encoder.build_acceleration_structures(iter::empty(), iter::once(&self.tlas_package));
encoder.build_acceleration_structures(iter::empty(), iter::once(&self.tlas));
{
let mut cpass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor {
@@ -99,7 +99,7 @@ struct Example {
uniforms: Uniforms,
uniform_buf: wgpu::Buffer,
blas: wgpu::Blas,
tlas_package: wgpu::TlasPackage,
tlas: wgpu::Tlas,
pipeline: wgpu::RenderPipeline,
bind_group: wgpu::BindGroup,
animation_timer: utils::AnimationTimer,
@@ -238,8 +238,6 @@ impl crate::framework::Example for Example {
],
});
let tlas_package = wgpu::TlasPackage::new(tlas);
let mut encoder =
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
@@ -260,7 +258,7 @@ impl crate::framework::Example for Example {
]),
}),
// iter::empty(),
iter::once(&tlas_package),
iter::once(&tlas),
);
queue.submit(Some(encoder.finish()));
@@ -269,7 +267,7 @@ impl crate::framework::Example for Example {
uniforms,
uniform_buf,
blas,
tlas_package,
tlas,
pipeline,
bind_group,
animation_timer: utils::AnimationTimer::default(),
@@ -309,7 +307,7 @@ impl crate::framework::Example for Example {
for x in 0..side_count {
for y in 0..side_count {
let instance = self.tlas_package.index_mut((x + y * side_count) as usize);
let instance = self.tlas.index_mut((x + y * side_count) as usize);
let x = x as f32 / (side_count - 1) as f32;
let y = y as f32 / (side_count - 1) as f32;
@@ -341,7 +339,7 @@ impl crate::framework::Example for Example {
let mut encoder =
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
encoder.build_acceleration_structures(iter::empty(), iter::once(&self.tlas_package));
encoder.build_acceleration_structures(iter::empty(), iter::once(&self.tlas));
{
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
@@ -121,7 +121,7 @@ impl<F: Future<Output = Option<wgpu::Error>>> Future for ErrorFuture<F> {
struct Example {
rt_target: wgpu::Texture,
tlas_package: wgpu::TlasPackage,
tlas: wgpu::Tlas,
compute_pipeline: wgpu::ComputePipeline,
compute_bind_group: wgpu::BindGroup,
blit_pipeline: wgpu::RenderPipeline,
@@ -250,7 +250,7 @@ impl crate::framework::Example for Example {
},
);
let tlas = device.create_tlas(&wgpu::CreateTlasDescriptor {
let mut tlas = device.create_tlas(&wgpu::CreateTlasDescriptor {
label: None,
flags: wgpu::AccelerationStructureFlags::PREFER_FAST_TRACE
| wgpu::AccelerationStructureFlags::ALLOW_RAY_HIT_VERTEX_RETURN,
@@ -340,13 +340,11 @@ impl crate::framework::Example for Example {
],
});
let mut tlas_package = wgpu::TlasPackage::new(tlas);
let dist = 3.0;
for x in 0..side_count {
for y in 0..side_count {
tlas_package[(x + y * side_count) as usize] = Some(wgpu::TlasInstance::new(
tlas[(x + y * side_count) as usize] = Some(wgpu::TlasInstance::new(
&blas,
affine_to_rows(&Affine3A::from_rotation_translation(
Quat::from_rotation_y(45.9_f32.to_radians()),
@@ -381,14 +379,14 @@ impl crate::framework::Example for Example {
},
]),
}),
iter::once(&tlas_package),
iter::once(&tlas),
);
queue.submit(Some(encoder.finish()));
Example {
rt_target,
tlas_package,
tlas,
compute_pipeline,
compute_bind_group,
blit_pipeline,
@@ -414,7 +412,7 @@ impl crate::framework::Example for Example {
let anim_time = self.animation_timer.time();
self.tlas_package[0].as_mut().unwrap().transform =
self.tlas[0].as_mut().unwrap().transform =
affine_to_rows(&Affine3A::from_rotation_translation(
Quat::from_euler(
glam::EulerRot::XYZ,
@@ -432,7 +430,7 @@ impl crate::framework::Example for Example {
let mut encoder =
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
encoder.build_acceleration_structures(iter::empty(), iter::once(&self.tlas_package));
encoder.build_acceleration_structures(iter::empty(), iter::once(&self.tlas));
{
let mut cpass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor {
+5 -7
View File
@@ -308,7 +308,7 @@ fn load_scene(device: &wgpu::Device, queue: &wgpu::Queue) -> SceneComponents {
struct Example {
uniforms: Uniforms,
uniform_buf: wgpu::Buffer,
tlas_package: wgpu::TlasPackage,
tlas: wgpu::Tlas,
pipeline: wgpu::RenderPipeline,
bind_group: wgpu::BindGroup,
scene_components: SceneComponents,
@@ -370,8 +370,6 @@ impl crate::framework::Example for Example {
max_instances: side_count * side_count,
});
let tlas_package = wgpu::TlasPackage::new(tlas);
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))),
@@ -414,7 +412,7 @@ impl crate::framework::Example for Example {
},
wgpu::BindGroupEntry {
binding: 5,
resource: tlas_package.as_binding(),
resource: tlas.as_binding(),
},
wgpu::BindGroupEntry {
binding: 1,
@@ -438,7 +436,7 @@ impl crate::framework::Example for Example {
Example {
uniforms,
uniform_buf,
tlas_package,
tlas,
pipeline,
bind_group,
scene_components,
@@ -479,7 +477,7 @@ impl crate::framework::Example for Example {
for x in 0..side_count {
for y in 0..side_count {
let instance = self.tlas_package.index_mut(x + y * side_count);
let instance = self.tlas.index_mut(x + y * side_count);
let blas_index = (x + y)
% self
@@ -521,7 +519,7 @@ impl crate::framework::Example for Example {
let mut encoder =
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
encoder.build_acceleration_structures(iter::empty(), iter::once(&self.tlas_package));
encoder.build_acceleration_structures(iter::empty(), iter::once(&self.tlas));
{
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
+4 -6
View File
@@ -170,7 +170,7 @@ impl crate::framework::Example for Example {
},
);
let tlas = device.create_tlas(&wgpu::CreateTlasDescriptor {
let mut tlas = device.create_tlas(&wgpu::CreateTlasDescriptor {
label: None,
flags: wgpu::AccelerationStructureFlags::PREFER_FAST_TRACE,
update_mode: wgpu::AccelerationStructureUpdateMode::Build,
@@ -244,9 +244,7 @@ impl crate::framework::Example for Example {
cache: None,
});
let mut tlas_package = wgpu::TlasPackage::new(tlas);
tlas_package[0] = Some(wgpu::TlasInstance::new(
tlas[0] = Some(wgpu::TlasInstance::new(
&blas,
[1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0],
0,
@@ -272,7 +270,7 @@ impl crate::framework::Example for Example {
},
]),
}),
iter::once(&tlas_package),
iter::once(&tlas),
);
queue.submit(Some(encoder.finish()));
@@ -287,7 +285,7 @@ impl crate::framework::Example for Example {
},
wgpu::BindGroupEntry {
binding: 1,
resource: tlas_package.as_binding(),
resource: tlas.as_binding(),
},
],
});
@@ -5,13 +5,13 @@ use wgpu::{include_wgsl, BufferUsages, IndexFormat, SamplerDescriptor};
use wgpu::{
AccelerationStructureFlags, AccelerationStructureUpdateMode, BlasBuildEntry, BlasGeometries,
BlasGeometrySizeDescriptors, BlasTriangleGeometry, BlasTriangleGeometrySizeDescriptor,
CreateBlasDescriptor, CreateTlasDescriptor, TlasInstance, TlasPackage,
CreateBlasDescriptor, CreateTlasDescriptor, Tlas, TlasInstance,
};
use crate::utils;
struct Example {
tlas_package: TlasPackage,
tlas: Tlas,
compute_pipeline: wgpu::ComputePipeline,
blit_pipeline: wgpu::RenderPipeline,
bind_group: wgpu::BindGroup,
@@ -146,16 +146,14 @@ impl crate::framework::Example for Example {
},
);
let tlas = device.create_tlas(&CreateTlasDescriptor {
let mut tlas = device.create_tlas(&CreateTlasDescriptor {
label: None,
max_instances: 3,
flags: AccelerationStructureFlags::PREFER_FAST_TRACE,
update_mode: AccelerationStructureUpdateMode::Build,
});
let mut tlas_package = TlasPackage::new(tlas);
tlas_package[0] = Some(TlasInstance::new(
tlas[0] = Some(TlasInstance::new(
&blas,
Mat4::from_translation(Vec3 {
x: 0.0,
@@ -170,7 +168,7 @@ impl crate::framework::Example for Example {
0xff,
));
tlas_package[1] = Some(TlasInstance::new(
tlas[1] = Some(TlasInstance::new(
&blas,
Mat4::from_translation(Vec3 {
x: -1.0,
@@ -185,7 +183,7 @@ impl crate::framework::Example for Example {
0xff,
));
tlas_package[2] = Some(TlasInstance::new(
tlas[2] = Some(TlasInstance::new(
&blas,
Mat4::from_translation(Vec3 {
x: 1.0,
@@ -233,7 +231,7 @@ impl crate::framework::Example for Example {
transform_buffer_offset: None,
}]),
}),
Some(&tlas_package),
Some(&tlas),
);
queue.submit(Some(encoder.finish()));
@@ -332,7 +330,7 @@ impl crate::framework::Example for Example {
},
wgpu::BindGroupEntry {
binding: 2,
resource: wgpu::BindingResource::AccelerationStructure(tlas_package.tlas()),
resource: wgpu::BindingResource::AccelerationStructure(&tlas),
},
],
});
@@ -355,7 +353,7 @@ impl crate::framework::Example for Example {
});
Self {
tlas_package,
tlas,
compute_pipeline,
blit_pipeline,
bind_group,
@@ -376,7 +374,7 @@ impl crate::framework::Example for Example {
fn update(&mut self, _event: winit::event::WindowEvent) {}
fn render(&mut self, view: &wgpu::TextureView, device: &wgpu::Device, queue: &wgpu::Queue) {
self.tlas_package[0].as_mut().unwrap().transform =
self.tlas[0].as_mut().unwrap().transform =
Mat4::from_rotation_y(self.animation_timer.time())
.transpose()
.to_cols_array()[..12]
@@ -386,7 +384,7 @@ impl crate::framework::Example for Example {
let mut encoder =
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
encoder.build_acceleration_structures(None, Some(&self.tlas_package));
encoder.build_acceleration_structures(None, Some(&self.tlas));
{
let mut cpass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor {