Files
wgpu/examples/features/src/main.rs
T
JerandJim Blandy efbfa36ded Dealing with data too large for a single buffer (#6138)
* init files, dir structure

* wip: it's working need to suss out the readme and some of the consts...

* ok that's probably good enough for a first pass...

* chore: spelling

* chore: readme tweaks

* chore: clippy and fmt

* chore: add self and changes to changelog.md

* fix: typo and remove env_logger via cfg flag for wasm builds (which this doesn't supprot anyway)

* refactor: bring inline with newer wgpu

* refactor: bring inline with newer wgpu

* chore: work on the readme a bit...

* refactor: remove a bunch of everything, be simple

* wip: get a test going

* wip: remove unrequired pub(s)...

* refactor: remove a bunch of everything, be simple

wip: get a test going

* wip: remove unrequired pub(s)...

wip: remove unrequired pub(s)...

* chore: cleanups, typos, simplifying

* chore: reconcile changelog diffs

* fix: re-add our change to the changelog

* wip: finess the docs a bit per request...

* chore: trying to get the woring right...

* chore: trying to get the woring right...

* fix: typos

* fix: spelling

* Update mod.rs

swap all loops over to 'for' by request.

Flume's sender is already Send/Sync

chunks will already split for us

.unwraps() unwraps everywhere!

* Update CHANGELOG.md

Co-authored-by: Jim Blandy <jimb@red-bean.com>

* 1GB as the example says we'll do

- 1GB as the example says we'll do
- update readme for windows users.

* init files, dir structure

* wip: it's working need to suss out the readme and some of the consts...

* ok that's probably good enough for a first pass...

* chore: spelling

* chore: readme tweaks

* chore: clippy and fmt

* chore: add self and changes to changelog.md

* fix: typo and remove env_logger via cfg flag for wasm builds (which this doesn't supprot anyway)

* refactor: bring inline with newer wgpu

* refactor: bring inline with newer wgpu

* chore: work on the readme a bit...

* refactor: remove a bunch of everything, be simple

* wip: get a test going

* wip: remove unrequired pub(s)...

* wip: remove unrequired pub(s)...

wip: remove unrequired pub(s)...

* chore: cleanups, typos, simplifying

* fix: re-add our change to the changelog

* wip: finess the docs a bit per request...

* chore: trying to get the woring right...

* chore: trying to get the woring right...

* fix: typos

* fix: spelling

* Update mod.rs

swap all loops over to 'for' by request.

Flume's sender is already Send/Sync

chunks will already split for us

.unwraps() unwraps everywhere!

* Update CHANGELOG.md

Co-authored-by: Jim Blandy <jimb@red-bean.com>

* 1GB as the example says we'll do

- 1GB as the example says we'll do
- update readme for windows users.

* bring up to date with trunk

sync with trunk.
make more of Jim's changes

* some of the consts have changed name.

* small tweaks

* what is the flag called now?

what is the flag called now?

* Update shader.wgsl

naming things betterer

* Update README.md

reword readme

* Update README.md

simplify readme

* Update mod.rs

remove unused

* well at least it compiles again

* BUG: ... it seems to run forever and never complete.

* nicer shader module creation

* ... add logging to track down infinite hangtime...

* use 2 buffers in the test

* test and example pass (now they do the same number of buffers..

* that's better...

* fix: remove duplicate entries

* fix: whitespace

* move changelog entry to #unreleased per request

* fix: target_arch != wasm to satiate pipeline

* fix: target_arch != wasm to satiate pipeline

* pipeline want's us to allow allows...

* savage hacks to make the wasm build ignore our test

* fix: allow the allowing of allows that allow the dead_code.

* Fix: no tests on wasm

---------

Co-authored-by: Jim Blandy <jimb@red-bean.com>
2025-03-28 02:24:29 +00:00

267 lines
7.5 KiB
Rust

struct ExampleDesc {
name: &'static str,
function: fn(),
#[cfg_attr(not(target_arch = "wasm32"), expect(dead_code))]
webgl: bool,
#[cfg_attr(not(target_arch = "wasm32"), expect(dead_code))]
webgpu: bool,
}
const EXAMPLES: &[ExampleDesc] = &[
ExampleDesc {
name: "big_compute_buffers",
function: wgpu_examples::big_compute_buffers::main,
webgl: false, // Native only example
webgpu: false, // Native only example
},
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_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: "multiple_render_targets",
function: wgpu_examples::multiple_render_targets::main,
webgl: false,
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,
},
ExampleDesc {
name: "ray_cube_normals",
function: wgpu_examples::ray_cube_normals::main,
webgl: false, // No Ray-tracing extensions
webgpu: false, // No Ray-tracing extensions (yet)
},
];
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)();
}