Files
wgpu/examples/src/main.rs
Vecvec 79a6f2cd31 Ray Queries (#6291)
* fix more compile errors

* fix err

* fix all compile errors

* fix clippy errors

* fix issues in ray-traced-triangle example

* fix clippy warnings

* fix wasm not compiling

* fix test

* fix clippy (again)

* fix some rustfmt issues

* fix more rustfmt issues

* fix even more rustfmt issues

* fix yet more rustfmt issues

* add #[allow(dead_code)] to some structs to fix clippy on web assembly

* more format fixes

* even more format fixes

* close to final format fixes

* final format fixes (hopefully)

* actual final format fixes (hopefully)

* move ray_cube_cube example and fix bugs

* move other examples

* fix crash when dropping

* fix test

* apply clippy and rustfmt changes

* fix some memory leaks

* fix incompatibility with new wgpu trunk changes

* fix clippy & fmt

* fix clippy errors on github

* update to trunk

* remove a line that printed log "Created blas ..." in device create tlas

* fix merge issues

* fix merge

* fix fmt

* restored example ray scene functionality

* WIP fix rebase

* Fix compile issues

* More fixes

* Fix rebase

* Add wgls backend write_value_type AccelerationStructure

* Add back xtask Cargo.lock

* Revert serde path

* Doc typos

* Add -diff

* Revert more serde

* Revert serde again?

* Fix doc typo

* add test

* clippy & fmt

* fix error "blas does not exist"

* fix various things

* fix unused acceleration structures causing invalid SPIR-V

* fix merge

* fix use after free in a different way (now moved tlas instances to wgpu_core)

* refactor & fmt

* remove accidentally created file

* remove accidentally created file (actually)

* merge & fix

* Fix problems

* fix validation error

* fix validation

* fix merge

* fmt

* fix merge

* use staging buffer trackers in creating the ray-tracing staging buffers (not the tlas_s)

* change one missed staging buffer's tracker

* wip: example

* finished shadow!

* fix merge

* clippy

* remove some uses of blas ids

* fmt

* fix merge

* deduplicate code shared between command_encoder_build_acceleration_structures and command_encoder_build_acceleration_structures_unsafe_tlas

* clippy

* fix merge

* fix warnings

* clippy & fmt

* re-add matching to get_raw_tlas_instance_size and tlas_instance_into_bytes

* fmt

* fix command

* wip: fix merge

* fix merge

* fmt & docs

* fix wasm clippy

* fix issues with tests

* fix issues with tests

* fmt & clippy (wasm)

* wip ray-traced-triangle (non hal)

* unify camera location in ray_shadows

* fix tests

* add readme to ray_traced_triangle

* note that vertex format must be f32x3 (not yet validated)

* changelog

* require VertexFormat::Float32x3

* fix compile error

* when creating and building acceleration structures require Features::RAY_TRACING_ACCELERATION_STRUCTURE is enabled

* remove duplicate workaround

* fix most feedback

* remove all changes from .gitattributes

* fix compile error in test

* more changes along same lines

* format

* apply feedback to more places

* fix `cargo clippy` not just `cargo clippy --all-features`

* cache max instances from tlas creation

* fix clippy

* fix examples

* fix tests

* remove now useless docs

* add more docs

* yet more docs

* still more docs

* Documentation.

* Running out of unique commit messages to say writing docs.

* Add more references to docs.

* Get BindGroup in scope

* Remove unintentional changes

* Remove #[allow(dead_code)]

* Remove old comments

* Add device.poll

* make ray_scene start right way up

* fmt

* move scratch buffer to its own module

* actually remove intentional changes (turns out wgt is inconsistent)

* use better names in ray_scene/shader.wgsl

* fmt

* remove more unintentional changes.

* work on ray_tracing use after free

* spelling

Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>

* grammar

Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>

* move things into struct (should be all vectors with 3 item types or more)

* remove long-standing locks.

* fmt

* move not using index buffer to test

* impl index & index mut for tlas package

* impl index & index mut for tlas package

* fix errors

* fix test errors

* move everything out of ray_tracing.rs

* more index_mut

* fmt

* fix docs links

* move to separate impl block

* fix older request review

* fmt

* remove missed deref

* fix wasm clippy

* change to suggestions

* fmt

* add a note as to why `command_encoder_build_acceleration_structures_unsafe_tlas` and `command_encoder_build_acceleration_structures` are currently separate

* add a todo to reconsider soon `command_encoder_build_acceleration_structures_unsafe_tlas`

* switch to mat4 in ray-tracing examples

* Combine RT Tests Under Single Submodule

* Add More Raytracing Tests and Re-Organize

* Documentation and Formatting Fixes

* Remove Forced Alignment in wgpu-hal

* work on out_of_order_as_build and add out_of_order_as_build_use

* fmt

* update test label naming

* fix one validation error

* fix clippy & fmt

* add acceleration structure creation tests

* make mis-matched index test use the correct function

* move validation into validate_command_buffer

* fix tests

* add blas and tlas to pending writes to remove (now unneeded) `device.poll()`s

* remove commented out code from examples and properly use the constants in ray_shadow

* add examples to examples\README.md

* rename ray tracing to ray queries in readme

* remove unneeded usage from scratch buffer creation

* use snatchables for raw acceleration structures

* format

* add EXPERIMENTAL_ to features

* fix missed comment

---------

Co-authored-by: Daniel Keitel <daniel.mg.keitel@fau.de>
Co-authored-by: JMS55 <47158642+JMS55@users.noreply.github.com>
Co-authored-by: atlas dostal <rodol@rivalrebels.com>
Co-authored-by: vero <email@atlasdostal.com>
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
2024-11-09 17:59:48 +00:00

261 lines
7.2 KiB
Rust

struct ExampleDesc {
name: &'static str,
function: fn(),
#[allow(dead_code)] // isn't used on native
webgl: bool,
#[allow(dead_code)] // isn't used on native
webgpu: bool,
}
const EXAMPLES: &[ExampleDesc] = &[
ExampleDesc {
name: "boids",
function: wgpu_examples::boids::main,
webgl: false, // No compute
webgpu: true,
},
ExampleDesc {
name: "bunnymark",
function: wgpu_examples::bunnymark::main,
webgl: true,
webgpu: true,
},
ExampleDesc {
name: "conservative_raster",
function: wgpu_examples::conservative_raster::main,
webgl: false, // No conservative raster
webgpu: false, // No conservative raster
},
ExampleDesc {
name: "cube",
function: wgpu_examples::cube::main,
webgl: true,
webgpu: true,
},
ExampleDesc {
name: "hello",
function: wgpu_examples::hello::main,
webgl: false, // No canvas for WebGL
webgpu: true,
},
ExampleDesc {
name: "hello_compute",
function: wgpu_examples::hello_compute::main,
webgl: false, // No compute
webgpu: true,
},
ExampleDesc {
name: "hello_synchronization",
function: wgpu_examples::hello_synchronization::main,
webgl: false, // No canvas for WebGL
webgpu: true,
},
ExampleDesc {
name: "hello_triangle",
function: wgpu_examples::hello_triangle::main,
webgl: true,
webgpu: true,
},
ExampleDesc {
name: "hello_windows",
function: wgpu_examples::hello_windows::main,
webgl: false, // Native only example
webgpu: false, // Native only example
},
ExampleDesc {
name: "hello_workgroups",
function: wgpu_examples::hello_workgroups::main,
webgl: false,
webgpu: true,
},
ExampleDesc {
name: "mipmap",
function: wgpu_examples::mipmap::main,
webgl: true,
webgpu: true,
},
ExampleDesc {
name: "msaa_line",
function: wgpu_examples::msaa_line::main,
webgl: true,
webgpu: true,
},
ExampleDesc {
name: "render_to_texture",
function: wgpu_examples::render_to_texture::main,
webgl: false, // No canvas for WebGL
webgpu: true,
},
ExampleDesc {
name: "repeated_compute",
function: wgpu_examples::repeated_compute::main,
webgl: false, // No compute
webgpu: true,
},
ExampleDesc {
name: "shadow",
function: wgpu_examples::shadow::main,
webgl: true,
webgpu: true,
},
ExampleDesc {
name: "skybox",
function: wgpu_examples::skybox::main,
webgl: true,
webgpu: true,
},
ExampleDesc {
name: "srgb_blend",
function: wgpu_examples::srgb_blend::main,
webgl: true,
webgpu: true,
},
ExampleDesc {
name: "stencil_triangles",
function: wgpu_examples::stencil_triangles::main,
webgl: true,
webgpu: true,
},
ExampleDesc {
name: "storage_texture",
function: wgpu_examples::storage_texture::main,
webgl: false, // No storage textures
webgpu: true,
},
ExampleDesc {
name: "texture_arrays",
function: wgpu_examples::texture_arrays::main,
webgl: false, // No texture arrays
webgpu: false, // No texture arrays
},
ExampleDesc {
name: "timestamp_queries",
function: wgpu_examples::timestamp_queries::main,
webgl: false, // No canvas for WebGL
webgpu: false, // No timestamp queries
},
ExampleDesc {
name: "uniform_values",
function: wgpu_examples::uniform_values::main,
webgl: false, // No compute
webgpu: true,
},
ExampleDesc {
name: "water",
function: wgpu_examples::water::main,
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)
},
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)
},
ExampleDesc {
name: "ray_shadows",
function: wgpu_examples::ray_shadows::main,
webgl: false, // No Ray-tracing extensions
webgpu: false, // No Ray-tracing extensions (yet)
},
ExampleDesc {
name: "ray_traced_triangle",
function: wgpu_examples::ray_traced_triangle::main,
webgl: false,
webgpu: false,
},
];
fn get_example_name() -> Option<String> {
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
let query_string = web_sys::window()?.location().search().ok()?;
wgpu_examples::framework::parse_url_query_string(&query_string, "example").map(String::from)
} else {
std::env::args().nth(1)
}
}
}
#[cfg(target_arch = "wasm32")]
fn print_examples() {
// Get the document, header, and body elements.
let document = web_sys::window().unwrap().document().unwrap();
for backend in ["webgl2", "webgpu"] {
let ul = document
.get_element_by_id(&format!("{backend}-list"))
.unwrap();
for example in EXAMPLES {
if backend == "webgl2" && !example.webgl {
continue;
}
if backend == "webgpu" && !example.webgpu {
continue;
}
let link = document.create_element("a").unwrap();
link.set_text_content(Some(example.name));
link.set_attribute(
"href",
&format!("?backend={backend}&example={}", example.name),
)
.unwrap();
link.set_class_name("example-link");
let item = document.create_element("div").unwrap();
item.append_child(&link).unwrap();
item.set_class_name("example-item");
ul.append_child(&item).unwrap();
}
}
}
#[cfg(target_arch = "wasm32")]
fn print_unknown_example(_result: Option<String>) {}
#[cfg(not(target_arch = "wasm32"))]
fn print_unknown_example(result: Option<String>) {
if let Some(example) = result {
println!("Unknown example: {example}");
} else {
println!("Please specify an example as the first argument!");
}
println!("\nAvailable Examples:");
for examples in EXAMPLES {
println!("\t{}", examples.name);
}
}
fn main() {
#[cfg(target_arch = "wasm32")]
print_examples();
let Some(example) = get_example_name() else {
print_unknown_example(None);
return;
};
let Some(found) = EXAMPLES.iter().find(|e| e.name == example) else {
print_unknown_example(Some(example));
return;
};
(found.function)();
}