diff --git a/examples/ray-cube-compute/Cargo.toml b/examples/ray-cube-compute/Cargo.toml deleted file mode 100644 index adeffa765b..0000000000 --- a/examples/ray-cube-compute/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "ray-cube-compute" -version.workspace = true -license.workspace = true -edition.workspace = true -description = "todo" -publish = false - -[[bin]] -name = "ray-cube-compute" -path = "src/main.rs" - -[dependencies] -bytemuck.workspace = true -glam.workspace = true -wasm-bindgen-test.workspace = true -wgpu-example.workspace = true -wgpu.workspace = true -winit.workspace = true - -[dev-dependencies] -wgpu-test.workspace = true diff --git a/examples/src/lib.rs b/examples/src/lib.rs index 1a55631097..f69430afb7 100644 --- a/examples/src/lib.rs +++ b/examples/src/lib.rs @@ -24,6 +24,7 @@ pub mod texture_arrays; pub mod timestamp_queries; pub mod uniform_values; pub mod water; +pub mod ray_cube_compute; #[cfg(test)] wgpu_test::gpu_test_main!(); diff --git a/examples/src/main.rs b/examples/src/main.rs index 948cfd4944..4a19a4d7fb 100644 --- a/examples/src/main.rs +++ b/examples/src/main.rs @@ -146,6 +146,12 @@ const EXAMPLES: &[ExampleDesc] = &[ webgl: false, // No RODS webgpu: true, }, + ExampleDesc { + name: "ray_cube_compute", + function: wgpu_examples::ray_cube_compute::main, + webgl: false, // No Ray-tracing extensions + webgpu: false, // No Ray-tracing extensions (yet) + } ]; fn get_example_name() -> Option { diff --git a/examples/ray-cube-compute/README.md b/examples/src/ray_cube_compute/README.md similarity index 86% rename from examples/ray-cube-compute/README.md rename to examples/src/ray_cube_compute/README.md index 7020f6a37c..9110787e38 100644 --- a/examples/ray-cube-compute/README.md +++ b/examples/src/ray_cube_compute/README.md @@ -11,4 +11,4 @@ cargo run --example ray-cube-compute ## Screenshots -![Cube example](./screenshot.png) +![Cube example](screenshot.png) diff --git a/examples/ray-cube-compute/src/blit.wgsl b/examples/src/ray_cube_compute/blit.wgsl similarity index 100% rename from examples/ray-cube-compute/src/blit.wgsl rename to examples/src/ray_cube_compute/blit.wgsl diff --git a/examples/ray-cube-compute/src/main.rs b/examples/src/ray_cube_compute/mod.rs similarity index 97% rename from examples/ray-cube-compute/src/main.rs rename to examples/src/ray_cube_compute/mod.rs index 44289df80c..5730f44bc9 100644 --- a/examples/ray-cube-compute/src/main.rs +++ b/examples/src/ray_cube_compute/mod.rs @@ -5,7 +5,7 @@ use glam::{Affine3A, Mat4, Quat, Vec3}; use wgpu::util::DeviceExt; use rt::traits::*; -use wgpu::ray_tracing as rt; +use wgpu::{ray_tracing as rt, StoreOp}; // from cube #[repr(C)] @@ -259,7 +259,7 @@ struct Example { start_inst: Instant, } -impl wgpu_example::framework::Example for Example { +impl crate::framework::Example for Example { fn required_features() -> wgpu::Features { wgpu::Features::TEXTURE_BINDING_ARRAY | wgpu::Features::STORAGE_RESOURCE_BINDING_ARRAY @@ -543,7 +543,6 @@ impl wgpu_example::framework::Example for Example { view: &wgpu::TextureView, device: &wgpu::Device, queue: &wgpu::Queue, - spawner: &wgpu_example::framework::Spawner, ) { device.push_error_scope(wgpu::ErrorFilter::Validation); @@ -592,7 +591,7 @@ impl wgpu_example::framework::Example for Example { resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color::GREEN), - store: true, + store: StoreOp::Store, }, })], depth_stencil_attachment: None, @@ -607,20 +606,16 @@ impl wgpu_example::framework::Example for Example { queue.submit(Some(encoder.finish())); - // If an error occurs, report it and panic. - spawner.spawn_local(ErrorFuture { - inner: device.pop_error_scope(), - }); } } -fn main() { - wgpu_example::framework::run::("ray-cube"); +pub fn main() { + crate::framework::run::("ray-cube"); } #[test] fn ray_cube_compute() { - wgpu_example::framework::test::(wgpu_example::framework::FrameworkRefTest { + crate::framework::test::(wgpu_example::framework::FrameworkRefTest { image_path: "/examples/ray-cube-compute/screenshot.png", width: 1024, height: 768, diff --git a/examples/ray-cube-compute/screenshot.png b/examples/src/ray_cube_compute/screenshot.png similarity index 100% rename from examples/ray-cube-compute/screenshot.png rename to examples/src/ray_cube_compute/screenshot.png diff --git a/examples/ray-cube-compute/src/shader.wgsl b/examples/src/ray_cube_compute/shader.wgsl similarity index 100% rename from examples/ray-cube-compute/src/shader.wgsl rename to examples/src/ray_cube_compute/shader.wgsl diff --git a/wgpu-core/src/command/ray_tracing.rs b/wgpu-core/src/command/ray_tracing.rs index aa597f39f2..6297570d6a 100644 --- a/wgpu-core/src/command/ray_tracing.rs +++ b/wgpu-core/src/command/ray_tracing.rs @@ -698,7 +698,7 @@ impl Global { raw: Mutex::new(Some(scratch_buffer)), device: device.clone(), size: max(scratch_buffer_blas_size, scratch_buffer_tlas_size), - info: ResourceInfo::new("Ratracing scratch buffer"), + info: ResourceInfo::new("Raytracing scratch buffer"), is_coherent: scratch_mapping.is_coherent, }))); @@ -1300,12 +1300,11 @@ impl Global { .create_buffer(&hal::BufferDescriptor { label: Some("(wgpu) scratch buffer"), size: max(scratch_buffer_blas_size, scratch_buffer_tlas_size), - usage: hal::BufferUses::ACCELERATION_STRUCTURE_SCRATCH, + usage: hal::BufferUses::ACCELERATION_STRUCTURE_SCRATCH | BufferUses::MAP_WRITE, memory_flags: hal::MemoryFlags::empty(), }) .map_err(crate::device::DeviceError::from)? }; - let staging_buffer = if !instance_buffer_staging_source.is_empty() { unsafe { let staging_buffer = device @@ -1324,7 +1323,6 @@ impl Global { 0..instance_buffer_staging_source.len() as u64, ) .map_err(crate::device::DeviceError::from)?; - ptr::copy_nonoverlapping( instance_buffer_staging_source.as_ptr(), mapping.ptr.as_ptr(), @@ -1335,14 +1333,16 @@ impl Global { .unmap_buffer(&staging_buffer) .map_err(crate::device::DeviceError::from)?; assert!(mapping.is_coherent); - - Some(StagingBuffer { + let buf = StagingBuffer { raw: Mutex::new(Some(staging_buffer)), device: device.clone(), size: instance_buffer_staging_source.len() as u64, info: ResourceInfo::new("Raytracing staging buffer"), is_coherent: mapping.is_coherent, - }) + }; + let staging_fid = hub.staging_buffers.request(); + let stage_buf = staging_fid.init(buf); + Some(stage_buf) } } else { None @@ -1508,7 +1508,7 @@ impl Global { .as_mut() .unwrap() .temp_resources - .push(TempResource::StagingBuffer(Arc::new(staging_buffer))); + .push(TempResource::StagingBuffer(staging_buffer)); } } let scratch_mapping = unsafe { @@ -1516,23 +1516,28 @@ impl Global { .raw() .map_buffer( &scratch_buffer, - 0..instance_buffer_staging_source.len() as u64, + 0..max(scratch_buffer_blas_size, scratch_buffer_tlas_size), ) .map_err(crate::device::DeviceError::from)? }; + + let buf = StagingBuffer { + raw: Mutex::new(Some(scratch_buffer)), + device: device.clone(), + size: max(scratch_buffer_blas_size, scratch_buffer_tlas_size), + info: ResourceInfo::new("Ratracing scratch buffer"), + is_coherent: scratch_mapping.is_coherent, + }; + let staging_fid = hub.staging_buffers.request(); + let stage_buf = staging_fid.init(buf); + device .pending_writes .lock() .as_mut() .unwrap() .temp_resources - .push(TempResource::StagingBuffer(Arc::new(StagingBuffer { - raw: Mutex::new(Some(scratch_buffer)), - device: device.clone(), - size: max(scratch_buffer_blas_size, scratch_buffer_tlas_size), - info: ResourceInfo::new("Ratracing scratch buffer"), - is_coherent: scratch_mapping.is_coherent, - }))); + .push(TempResource::StagingBuffer(stage_buf)); Ok(()) }