Improve the examples' directory structure (#2375)

* Make each example its own workspace member

* Fix runtime-shader example

* Fix shader-include example

* Fix teapot example

* Fix `run_all.sh`

* Fix output files getting saved in cwd

* Fix spelling for examples readme filename

* Remove wrong leftover dependencies for gl-interop

* Fix pipeline-cache example

* Clearer .gitignore

* Help cargo be less useless
This commit is contained in:
marc0246 2023-10-29 18:46:14 +01:00 committed by GitHub
parent 1e0a4d5300
commit 4c515a81cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
110 changed files with 564 additions and 62 deletions

10
.gitignore vendored
View File

@ -1,10 +1,10 @@
target
/Cargo.lock
.cargo
examples/**/triangle.png
examples/**/mandelbrot.png
examples/**/multiview1.png
examples/**/multiview2.png
examples/**/pipeline_cache.bin
examples/dynamic-local-size/mandelbrot.png
examples/msaa-renderpass/triangle.png
examples/multiview/multiview1.png
examples/multiview/multiview2.png
examples/pipeline-caching/pipeline_cache.bin
.idea
*.swp

View File

@ -1,3 +1,10 @@
[workspace]
members = ["examples", "vulkano", "vulkano-macros", "vulkano-shaders", "vulkano-util", "vulkano-win"]
members = [
"examples/*",
"vulkano",
"vulkano-macros",
"vulkano-shaders",
"vulkano-util",
"vulkano-win",
]
resolver = "2"

View File

@ -1,29 +0,0 @@
[package]
name = "examples"
version = "0.1.0"
edition = "2021"
authors = [
"Pierre Krieger <pierre.krieger1708@gmail.com>",
"The vulkano contributors",
]
publish = false
[dependencies]
# The `vulkano` crate is the main crate that you must use to use Vulkan.
vulkano = { path = "../vulkano", features = ["serde"] }
# Provides the `shader!` macro that is used to generate code for using shaders.
vulkano-shaders = { path = "../vulkano-shaders" }
# The Vulkan library doesn't provide any functionality to create and handle windows, as
# this would be out of scope. In order to open a window, we are going to use the `winit` crate.
winit = "0.28"
vulkano-util = { path = "../vulkano-util" }
cgmath = "0.18"
glium = "0.32.1"
png = "0.17"
rand = "0.8.4"
ron = "0.8"
serde = { version = "1.0", features = ["derive"] }
# Glium has still not been updated to the latest winit version
winit_glium = { package = "winit", version = "0.27.1" }

View File

@ -0,0 +1,16 @@
[package]
name = "async-update"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "async-update"
path = "main.rs"
[dependencies]
cgmath = "0.18"
rand = "0.8"
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }
winit = "0.28"

View File

@ -0,0 +1,13 @@
[package]
name = "basic-compute-shader"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "basic-compute-shader"
path = "main.rs"
[dependencies]
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }

View File

@ -0,0 +1,14 @@
[package]
name = "buffer-allocator"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "buffer-allocator"
path = "main.rs"
[dependencies]
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }
winit = "0.28"

View File

@ -0,0 +1,13 @@
[package]
name = "clear-attachments"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "clear-attachments"
path = "main.rs"
[dependencies]
vulkano = { path = "../../vulkano" }
winit = "0.28"

12
examples/debug/Cargo.toml Normal file
View File

@ -0,0 +1,12 @@
[package]
name = "debug"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "debug"
path = "main.rs"
[dependencies]
vulkano = { path = "../../vulkano" }

View File

@ -0,0 +1,15 @@
[package]
name = "deferred"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "deferred"
path = "main.rs"
[dependencies]
cgmath = "0.18"
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }
winit = "0.28"

View File

@ -0,0 +1,13 @@
[package]
name = "dynamic-buffers"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "dynamic-buffers"
path = "main.rs"
[dependencies]
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }

View File

@ -0,0 +1,14 @@
[package]
name = "dynamic-local-size"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "dynamic-local-size"
path = "main.rs"
[dependencies]
png = "0.17"
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }

View File

@ -288,12 +288,16 @@ fn main() {
println!("Success");
let buffer_content = buf.read().unwrap();
let path = Path::new("mandelbrot.png");
let file = File::create(path).unwrap();
let path = Path::new(env!("CARGO_MANIFEST_DIR")).join("mandelbrot.png");
let file = File::create(&path).unwrap();
let w = &mut BufWriter::new(file);
let mut encoder = png::Encoder::new(w, 1024, 1024);
encoder.set_color(png::ColorType::Rgba);
encoder.set_depth(png::BitDepth::Eight);
let mut writer = encoder.write_header().unwrap();
writer.write_image_data(&buffer_content).unwrap();
if let Ok(path) = path.canonicalize() {
println!("Saved to {}", path.display());
}
}

View File

@ -0,0 +1,17 @@
[package]
name = "gl-interop"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "gl-interop"
path = "main.rs"
[dependencies]
glium = "0.32.1"
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }
winit = "0.28"
# Glium has still not been updated to the latest winit version
winit_glium = { package = "winit", version = "0.27.1" }

View File

@ -0,0 +1,15 @@
[package]
name = "image-self-copy-blit"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "image-self-copy-blit"
path = "main.rs"
[dependencies]
png = "0.17"
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }
winit = "0.28"

View File

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

15
examples/image/Cargo.toml Normal file
View File

@ -0,0 +1,15 @@
[package]
name = "image"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "image"
path = "main.rs"
[dependencies]
png = "0.17"
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }
winit = "0.28"

View File

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

@ -0,0 +1,15 @@
[package]
name = "immutable-sampler"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "immutable-sampler"
path = "main.rs"
[dependencies]
png = "0.17"
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }
winit = "0.28"

View File

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

@ -0,0 +1,14 @@
[package]
name = "indirect"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "indirect"
path = "main.rs"
[dependencies]
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }
winit = "0.28"

View File

@ -0,0 +1,14 @@
[package]
name = "instancing"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "instancing"
path = "main.rs"
[dependencies]
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }
winit = "0.28"

View File

@ -0,0 +1,17 @@
[package]
name = "interactive-fractal"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "interactive-fractal"
path = "main.rs"
[dependencies]
cgmath = "0.18"
rand = "0.8"
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }
vulkano-util = { path = "../../vulkano-util" }
winit = "0.28"

View File

@ -0,0 +1,14 @@
[package]
name = "msaa-renderpass"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "msaa-renderpass"
path = "main.rs"
[dependencies]
png = "0.17"
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }

View File

@ -423,8 +423,8 @@ fn main() {
.unwrap();
let buffer_content = buf.read().unwrap();
let path = Path::new("triangle.png");
let file = File::create(path).unwrap();
let path = Path::new(env!("CARGO_MANIFEST_DIR")).join("triangle.png");
let file = File::create(&path).unwrap();
let w = &mut BufWriter::new(file);
let mut encoder = png::Encoder::new(w, 1024, 1024); // Width is 2 pixels and height is 1.
encoder.set_color(png::ColorType::Rgba);

View File

@ -0,0 +1,17 @@
[package]
name = "multi-window-game-of-life"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "multi-window-game-of-life"
path = "main.rs"
[dependencies]
cgmath = "0.18"
rand = "0.8"
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }
vulkano-util = { path = "../../vulkano-util" }
winit = "0.28"

View File

@ -0,0 +1,14 @@
[package]
name = "multi-window"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "multi-window"
path = "main.rs"
[dependencies]
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }
winit = "0.28"

View File

@ -0,0 +1,14 @@
[package]
name = "multiview"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "multiview"
path = "main.rs"
[dependencies]
png = "0.17"
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }

View File

@ -420,8 +420,8 @@ fn main() {
fn write_image_buffer_to_file(buffer: Subbuffer<[u8]>, path: &str, width: u32, height: u32) {
let buffer_content = buffer.read().unwrap();
let path = Path::new(path);
let file = File::create(path).unwrap();
let path = Path::new(env!("CARGO_MANIFEST_DIR")).join(path);
let file = File::create(&path).unwrap();
let w = &mut BufWriter::new(file);
let mut encoder = png::Encoder::new(w, width, height);
encoder.set_color(png::ColorType::Rgba);

View File

@ -0,0 +1,14 @@
[package]
name = "occlusion-query"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "occlusion-query"
path = "main.rs"
[dependencies]
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }
winit = "0.28"

View File

@ -0,0 +1,13 @@
[package]
name = "pipeline-caching"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "pipeline-caching"
path = "main.rs"
[dependencies]
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }

View File

@ -27,6 +27,7 @@
use std::{
fs::{remove_file, rename, File},
io::{Read, Write},
path::{Path, PathBuf},
};
use vulkano::{
device::{
@ -160,11 +161,13 @@ fn main() {
// disk.
if let Ok(data) = pipeline_cache.get_data() {
if let Ok(mut file) = File::create("pipeline_cache.bin.tmp") {
let tmp_path = relpath("pipeline_cache.bin.tmp");
if let Ok(mut file) = File::create(&tmp_path) {
if file.write_all(&data).is_ok() {
let _ = rename("pipeline_cache.bin.tmp", "pipeline_cache.bin");
let _ = rename(&tmp_path, relpath("pipeline_cache.bin"));
} else {
let _ = remove_file("pipeline_cache.bin.tmp");
let _ = remove_file(&tmp_path);
}
}
}
@ -177,7 +180,7 @@ fn main() {
// `PipelineCache` from that. Note that this function is currently unsafe as there are no
// checks, as it was mentioned at the start of this example.
let initial_data = {
if let Ok(mut file) = File::open("pipeline_cache.bin") {
if let Ok(mut file) = File::open(relpath("pipeline_cache.bin")) {
let mut data = Vec::new();
if file.read_to_end(&mut data).is_ok() {
data
@ -211,3 +214,7 @@ fn main() {
);
println!("Success");
}
fn relpath(path: &str) -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).join(path)
}

View File

@ -0,0 +1,13 @@
[package]
name = "push-constants"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "push-constants"
path = "main.rs"
[dependencies]
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }

View File

@ -0,0 +1,15 @@
[package]
name = "push-descriptors"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "push-descriptors"
path = "main.rs"
[dependencies]
png = "0.17"
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }
winit = "0.28"

View File

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

@ -6,6 +6,6 @@ set -e
# Human input is required to close all the windows
# Human monitoring is also required to check for errors in stdout
cargo build
exa -F src/bin | rg '(\.rs|/)$' | sd '(\.rs|/)' '' | rargs cargo run --bin {}
rm -f pipeline_cache.bin
cargo build --bins
exa -F . | rg '/$' | sd '/' '' | rargs cargo run --bin {}
rm -f pipeline-caching/pipeline_cache.bin

View File

@ -0,0 +1,15 @@
[package]
name = "runtime-array"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "runtime-array"
path = "main.rs"
[dependencies]
png = "0.17"
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }
winit = "0.28"

View File

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -0,0 +1,13 @@
[package]
name = "runtime-shader"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "runtime-shader"
path = "main.rs"
[dependencies]
vulkano = { path = "../../vulkano" }
winit = "0.28"

View File

@ -177,7 +177,7 @@ fn main() {
let graphics_pipeline = {
let vs = {
let code = read_spirv_words_from_file("src/bin/runtime-shader/vert.spv");
let code = read_spirv_words_from_file("vert.spv");
// Create a ShaderModule on a device the same Shader::load does it.
// NOTE: You will have to verify correctness of the data by yourself!
@ -188,7 +188,7 @@ fn main() {
};
let fs = {
let code = read_spirv_words_from_file("src/bin/runtime-shader/frag.spv");
let code = read_spirv_words_from_file("frag.spv");
let module = unsafe {
ShaderModule::new(device.clone(), ShaderModuleCreateInfo::new(&code)).unwrap()
@ -434,14 +434,8 @@ fn read_spirv_words_from_file(path: impl AsRef<Path>) -> Vec<u32> {
// Read the file.
let path = path.as_ref();
let mut bytes = vec![];
let mut file = File::open(path).unwrap_or_else(|err| {
panic!(
"can't open file `{}`: {}.\n\
Note: this example needs to be run from the root of the example crate",
path.display(),
err,
)
});
let path = Path::new(env!("CARGO_MANIFEST_DIR")).join(path);
let mut file = File::open(&path).unwrap();
file.read_to_end(&mut bytes).unwrap();
vulkano::shader::spirv::bytes_to_words(&bytes)

View File

@ -0,0 +1,13 @@
[package]
name = "self-copy-buffer"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "self-copy-buffer"
path = "main.rs"
[dependencies]
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }

View File

@ -0,0 +1,13 @@
[package]
name = "shader-include"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "shader-include"
path = "main.rs"
[dependencies]
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }

View File

@ -96,7 +96,7 @@ fn main() {
ty: "compute",
// We declare what directories to search for when using the `#include <...>`
// syntax. Specified directories have descending priorities based on their order.
include: ["src/bin/shader-include/standard-shaders"],
include: ["standard-shaders"],
src: r#"
#version 450

View File

@ -0,0 +1,16 @@
[package]
name = "shader-types-derive"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "shader-types-derive"
path = "main.rs"
[dependencies]
ron = "0.8"
serde = { version = "1.0", features = ["derive"] }
vulkano = { path = "../../vulkano", features = ["serde"] }
vulkano-shaders = { path = "../../vulkano-shaders" }
winit = "0.28"

View File

@ -0,0 +1,13 @@
[package]
name = "shader-types-sharing"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "shader-types-sharing"
path = "main.rs"
[dependencies]
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }

View File

@ -0,0 +1,14 @@
[package]
name = "simple-particles"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "simple-particles"
path = "main.rs"
[dependencies]
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }
winit = "0.28"

View File

@ -0,0 +1,13 @@
[package]
name = "specialization-constants"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "specialization-constants"
path = "main.rs"
[dependencies]
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }

View File

@ -0,0 +1,15 @@
[package]
name = "teapot"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "teapot"
path = "main.rs"
[dependencies]
cgmath = "0.18"
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }
winit = "0.28"

View File

@ -7,8 +7,8 @@
// notice may not be copied, modified, or distributed except
// according to those terms.
use self::model::{Normal, Position, INDICES, NORMALS, POSITIONS};
use cgmath::{Matrix3, Matrix4, Point3, Rad, Vector3};
use examples::{Normal, Position, INDICES, NORMALS, POSITIONS};
use std::{sync::Arc, time::Instant};
use vulkano::{
buffer::{
@ -59,6 +59,8 @@ use winit::{
window::WindowBuilder,
};
mod model;
fn main() {
// The start of this example is exactly the same as `triangle`. You should read the `triangle`
// example if you haven't done so yet.
@ -538,13 +540,13 @@ fn window_size_dependent_setup(
mod vs {
vulkano_shaders::shader! {
ty: "vertex",
path: "src/bin/teapot/vert.glsl",
path: "vert.glsl",
}
}
mod fs {
vulkano_shaders::shader! {
ty: "fragment",
path: "src/bin/teapot/frag.glsl",
path: "frag.glsl",
}
}

View File

@ -0,0 +1,14 @@
[package]
name = "tessellation"
version = "0.0.0"
edition = "2021"
publish = false
[[bin]]
name = "tessellation"
path = "main.rs"
[dependencies]
vulkano = { path = "../../vulkano" }
vulkano-shaders = { path = "../../vulkano-shaders" }
winit = "0.28"

Some files were not shown because too many files have changed in this diff Show More