Skip to content

Commit

Permalink
move other examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Vecvec committed Dec 12, 2023
1 parent 331625a commit 49b65e4
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 127 deletions.
22 changes: 0 additions & 22 deletions examples/ray-cube-fragment/Cargo.toml

This file was deleted.

23 changes: 0 additions & 23 deletions examples/ray-scene/Cargo.toml

This file was deleted.

2 changes: 2 additions & 0 deletions examples/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub mod timestamp_queries;
pub mod uniform_values;
pub mod water;
pub mod ray_cube_compute;
pub mod ray_cube_fragment;
pub mod ray_scene;

#[cfg(test)]
wgpu_test::gpu_test_main!();
12 changes: 12 additions & 0 deletions examples/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ const EXAMPLES: &[ExampleDesc] = &[
function: wgpu_examples::ray_cube_compute::main,
webgl: false, // No Ray-tracing extensions
webgpu: false, // No Ray-tracing extensions (yet)
},
ExampleDesc {
name: "ray_cube_fragment",
function: wgpu_examples::ray_cube_fragment::main,
webgl: false, // No Ray-tracing extensions
webgpu: false, // No Ray-tracing extensions (yet)
},
ExampleDesc {
name: "ray_scene",
function: wgpu_examples::ray_scene::main,
webgl: false, // No Ray-tracing extensions
webgpu: false, // No Ray-tracing extensions (yet)
}
];

Expand Down
35 changes: 17 additions & 18 deletions examples/src/ray_cube_compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl<F: Future<Output = Option<wgpu::Error>>> Future for ErrorFuture<F> {
let inner = unsafe { self.map_unchecked_mut(|me| &mut me.inner) };
inner.poll(cx).map(|error| {
if let Some(e) = error {
panic!("Rendering {e}");
panic!("Rendering {}", e);
}
})
}
Expand Down Expand Up @@ -613,20 +613,19 @@ pub fn main() {
crate::framework::run::<Example>("ray-cube");
}

#[test]
fn ray_cube_compute() {
crate::framework::test::<Example>(wgpu_example::framework::FrameworkRefTest {
image_path: "/examples/ray-cube-compute/screenshot.png",
width: 1024,
height: 768,
optional_features: wgpu::Features::default(),
base_test_parameters: wgpu_test::TestParameters {
required_features: <Example as wgpu_example::framework::Example>::required_features(),
required_downlevel_properties:
<Example as wgpu_example::framework::Example>::required_downlevel_capabilities(),
required_limits: <Example as wgpu_example::framework::Example>::required_limits(),
failures: Vec::new(),
},
comparisons: &[wgpu_test::ComparisonType::Mean(0.02)],
});
}
#[cfg(test)]
#[wgpu_test::gpu_test]
static TEST: crate::framework::ExampleTestParams = crate::framework::ExampleTestParams {
image_path: "/examples/ray_cube_compute/screenshot.png",
width: 1024,
height: 768,
optional_features: wgpu::Features::default(),
base_test_parameters: wgpu_test::TestParameters {
required_features: <Example as crate::framework::Example>::required_features(),
required_limits: <Example as crate::framework::Example>::required_limits(),
skips: vec![],
failures: Vec::new(),
required_downlevel_caps: <Example as crate::framework::Example>::required_downlevel_capabilities(),
},
comparisons: &[wgpu_test::ComparisonType::Mean(0.02)],
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ cargo run --example ray-cube-fragment

## Screenshots

![Cube example](./screenshot.png)
![Cube example](screenshot.png)
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl<F: Future<Output = Option<wgpu::Error>>> Future for ErrorFuture<F> {
let inner = unsafe { self.map_unchecked_mut(|me| &mut me.inner) };
inner.poll(cx).map(|error| {
if let Some(e) = error {
panic!("Rendering {e}");
panic!("Rendering {}", e);
}
})
}
Expand All @@ -110,7 +110,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::RAY_QUERY | wgpu::Features::RAY_TRACING_ACCELERATION_STRUCTURE
}
Expand Down Expand Up @@ -300,7 +300,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);

Expand Down Expand Up @@ -359,7 +358,7 @@ impl wgpu_example::framework::Example for Example {
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::GREEN),
store: true,
store: wgpu::StoreOp::Store,
},
})],
depth_stencil_attachment: None,
Expand All @@ -373,32 +372,26 @@ 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::<Example>("ray-cube");
pub fn main() {
crate::framework::run::<Example>("ray-cube");
}

#[test]
fn ray_cube_fragment() {
wgpu_example::framework::test::<Example>(wgpu_example::framework::FrameworkRefTest {
image_path: "/examples/ray-cube-fragment/screenshot.png",
width: 1024,
height: 768,
optional_features: wgpu::Features::default(),
base_test_parameters: wgpu_test::TestParameters {
required_features: <Example as wgpu_example::framework::Example>::required_features(),
required_downlevel_properties:
<Example as wgpu_example::framework::Example>::required_downlevel_capabilities(),
required_limits: <Example as wgpu_example::framework::Example>::required_limits(),
failures: Vec::new(),
},
comparisons: &[wgpu_test::ComparisonType::Mean(0.02)],
});
}
#[cfg(test)]
#[wgpu_test::gpu_test]
static TEST: crate::framework::ExampleTestParams = crate::framework::ExampleTestParams {
image_path: "/examples/ray_cube_fragment/screenshot.png",
width: 1024,
height: 768,
optional_features: wgpu::Features::default(),
base_test_parameters: wgpu_test::TestParameters {
required_features: <Example as crate::framework::Example>::required_features(),
required_limits: <Example as crate::framework::Example>::required_limits(),
skips: vec![],
failures: Vec::new(),
required_downlevel_caps: <Example as crate::framework::Example>::required_downlevel_capabilities(),
},
comparisons: &[wgpu_test::ComparisonType::Mean(0.02)],
};
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
60 changes: 26 additions & 34 deletions examples/ray-scene/src/main.rs → examples/src/ray_scene/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl<F: Future<Output = Option<wgpu::Error>>> Future for ErrorFuture<F> {
let inner = unsafe { self.map_unchecked_mut(|me| &mut me.inner) };
inner.poll(cx).map(|error| {
if let Some(e) = error {
panic!("Rendering {e}");
panic!("Rendering {}", e);
}
})
}
Expand Down Expand Up @@ -94,7 +94,8 @@ struct Material {
}

fn load_model(scene: &mut RawSceneComponents, path: &str) {
let path = env!("CARGO_MANIFEST_DIR").to_string() + "/../../" + path;
let path = env!("CARGO_MANIFEST_DIR").to_string() + "/src" + path;
println!("{}", path);
let mut object = obj::Obj::load(path).unwrap();
object.load_mtls().unwrap();

Expand Down Expand Up @@ -298,9 +299,8 @@ fn upload_scene_components(

fn load_scene(device: &wgpu::Device, queue: &wgpu::Queue) -> SceneComponents {
let mut scene = RawSceneComponents::default();
load_model(&mut scene, "/examples/skybox/models/teslacyberv3.0.obj");

load_model(&mut scene, "/examples/ray-scene/cube.obj");
load_model(&mut scene, "/ray_scene/cube.obj");

upload_scene_components(device, queue, &scene)
}
Expand All @@ -316,7 +316,7 @@ struct Example {
scene_components: SceneComponents,
}

impl wgpu_example::framework::Example for Example {
impl crate::framework::Example for Example {
fn required_features() -> wgpu::Features {
wgpu::Features::RAY_QUERY | wgpu::Features::RAY_TRACING_ACCELERATION_STRUCTURE
}
Expand Down Expand Up @@ -466,7 +466,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);

Expand All @@ -482,10 +481,10 @@ impl wgpu_example::framework::Example for Example {
for y in 0..side_count {
let instance = self
.tlas_package
.get_mut_single((x + y * side_count) as usize)
.get_mut_single(((x + y) * side_count) as usize)
.unwrap();

let blas_index = (x + y) % 2;
let blas_index = (x + y) % self.scene_components.bottom_level_acceleration_structures.len();

let x = x as f32 / (side_count - 1) as f32;
let y = y as f32 / (side_count - 1) as f32;
Expand All @@ -508,7 +507,6 @@ impl wgpu_example::framework::Example for Example {
let transform = transform.transpose().to_cols_array()[..12]
.try_into()
.unwrap();

*instance = Some(rt::TlasInstance::new(
&self.scene_components.bottom_level_acceleration_structures[blas_index],
transform,
Expand All @@ -532,7 +530,7 @@ impl wgpu_example::framework::Example for Example {
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::GREEN),
store: true,
store: wgpu::StoreOp::Store,
},
})],
depth_stencil_attachment: None,
Expand All @@ -546,32 +544,26 @@ 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::<Example>("ray-scene");
pub fn main() {
crate::framework::run::<Example>("ray_scene");
}

#[test]
fn ray_cube_fragment() {
wgpu_example::framework::test::<Example>(wgpu_example::framework::FrameworkRefTest {
image_path: "/examples/ray-cube-fragment/screenshot.png",
width: 1024,
height: 768,
optional_features: wgpu::Features::default(),
base_test_parameters: wgpu_test::TestParameters {
required_features: <Example as wgpu_example::framework::Example>::required_features(),
required_downlevel_properties:
<Example as wgpu_example::framework::Example>::required_downlevel_capabilities(),
required_limits: <Example as wgpu_example::framework::Example>::required_limits(),
failures: Vec::new(),
},
comparisons: &[wgpu_test::ComparisonType::Mean(0.02)],
});
}
#[cfg(test)]
#[wgpu_test::gpu_test]
static TEST: crate::framework::ExampleTestParams = crate::framework::ExampleTestParams {
image_path: "/examples/ray_cube_fragment/screenshot.png",
width: 1024,
height: 768,
optional_features: wgpu::Features::default(),
base_test_parameters: wgpu_test::TestParameters {
required_features: <Example as crate::framework::Example>::required_features(),
required_limits: <Example as crate::framework::Example>::required_limits(),
skips: vec![],
failures: Vec::new(),
required_downlevel_caps: <Example as crate::framework::Example>::required_downlevel_capabilities(),
},
comparisons: &[wgpu_test::ComparisonType::Mean(0.02)],
};
File renamed without changes.
2 changes: 1 addition & 1 deletion wgpu-core/src/device/ray_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
raw: Mutex::new(Some(e)),
device: device.clone(),
size,
info: ResourceInfo::new("Ratracing scratch buffer"),
info: ResourceInfo::new("Raytracing scratch buffer"),
is_coherent: mapping.is_coherent,
})))
}
Expand Down

0 comments on commit 49b65e4

Please sign in to comment.