Skip to content

Commit 767e58e

Browse files
committed
wgpu: add api choice wgpu, generated
1 parent 9b7a399 commit 767e58e

File tree

23 files changed

+469
-8
lines changed

23 files changed

+469
-8
lines changed

generated/graphics/ash/cargo-gpu/mygraphics-shaders/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use bytemuck::{Pod, Zeroable};
44
use core::f32::consts::PI;
5-
use glam::{vec2, vec3, Vec3, Vec4};
5+
use glam::{Vec3, Vec4, vec2, vec3};
66
#[cfg(target_arch = "spirv")]
77
use spirv_std::num_traits::Float;
88
use spirv_std::spirv;

generated/graphics/ash/cargo-gpu/mygraphics/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use cargo_gpu::spirv_builder::{MetadataPrintout, ShaderPanicStrategy};
21
use cargo_gpu::Install;
2+
use cargo_gpu::spirv_builder::{MetadataPrintout, ShaderPanicStrategy};
33
use std::path::PathBuf;
44

55
pub fn main() -> anyhow::Result<()> {

generated/graphics/ash/spirv-builder/mygraphics-shaders/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use bytemuck::{Pod, Zeroable};
44
use core::f32::consts::PI;
5-
use glam::{vec2, vec3, Vec3, Vec4};
5+
use glam::{Vec3, Vec4, vec2, vec3};
66
#[cfg(target_arch = "spirv")]
77
use spirv_std::num_traits::Float;
88
use spirv_std::spirv;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[workspace]
2+
members = [
3+
"mygraphics",
4+
"mygraphics-shaders"
5+
]
6+
resolver = "3"
7+
8+
[workspace.package]
9+
version = "0.1.0"
10+
authors = ["generated <generated>"]
11+
edition = "2024"
12+
license = "MIT"
13+
repository = ""
14+
15+
[workspace.lints.rust]
16+
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(target_arch, values("spirv"))'] }
17+
18+
[workspace.dependencies]
19+
cargo-gpu = { git = "https://github.com/Rust-GPU/cargo-gpu", rev = "bf24eb6060e0c7b0013eceddd23b5d7cee68f4cc" }
20+
spirv-std = { git = "https://github.com/Rust-GPU/rust-gpu", rev = "6fb875068d0d35b1a81ae89b73cf7a464f8c60f7" }
21+
22+
glam = { version = "0.30.9", default-features = false }
23+
bytemuck = { version = "1.24.0", features = ["derive"] }
24+
ash = "0.38"
25+
ash-window = "0.13"
26+
raw-window-handle = "0.6.2"
27+
winit = "0.30.0"
28+
cfg-if = "1.0.0"
29+
anyhow = "1.0.98"
30+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "mygraphics-shaders"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[lints]
7+
workspace = true
8+
9+
[lib]
10+
crate-type = ["lib", "dylib"]
11+
12+
[dependencies]
13+
spirv-std.workspace = true
14+
glam.workspace = true
15+
bytemuck.workspace = true
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#![no_std]
2+
3+
use bytemuck::{Pod, Zeroable};
4+
use core::f32::consts::PI;
5+
use glam::{Vec3, Vec4, vec2, vec3};
6+
#[cfg(target_arch = "spirv")]
7+
use spirv_std::num_traits::Float;
8+
use spirv_std::spirv;
9+
10+
#[derive(Copy, Clone, Pod, Zeroable)]
11+
#[repr(C)]
12+
pub struct ShaderConstants {
13+
pub width: u32,
14+
pub height: u32,
15+
pub time: f32,
16+
}
17+
18+
#[spirv(fragment)]
19+
pub fn main_fs(vtx_color: Vec3, output: &mut Vec4) {
20+
*output = Vec4::from((vtx_color, 1.));
21+
}
22+
23+
#[spirv(vertex)]
24+
pub fn main_vs(
25+
#[spirv(vertex_index)] vert_id: i32,
26+
#[spirv(push_constant)] constants: &ShaderConstants,
27+
#[spirv(position)] vtx_pos: &mut Vec4,
28+
vtx_color: &mut Vec3,
29+
) {
30+
let speed = 0.4;
31+
let time = constants.time * speed + vert_id as f32 * (2. * PI * 120. / 360.);
32+
let position = vec2(f32::sin(time), f32::cos(time));
33+
*vtx_pos = Vec4::from((position, 0.0, 1.0));
34+
35+
*vtx_color = [vec3(1., 0., 0.), vec3(0., 1., 0.), vec3(0., 0., 1.)][vert_id as usize % 3];
36+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[package]
2+
name = "mygraphics"
3+
publish = false
4+
version.workspace = true
5+
authors.workspace = true
6+
edition.workspace = true
7+
license.workspace = true
8+
repository.workspace = true
9+
10+
[lints]
11+
workspace = true
12+
13+
[dependencies]
14+
mygraphics-shaders = { path = "../mygraphics-shaders" }
15+
16+
ash.workspace = true
17+
ash-window.workspace = true
18+
raw-window-handle.workspace = true
19+
winit.workspace = true
20+
anyhow.workspace = true
21+
bytemuck.workspace = true
22+
23+
[build-dependencies]
24+
cargo-gpu.workspace = true
25+
anyhow.workspace = true
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use cargo_gpu::Install;
2+
use cargo_gpu::spirv_builder::{MetadataPrintout, ShaderPanicStrategy};
3+
use std::path::PathBuf;
4+
5+
pub fn main() -> anyhow::Result<()> {
6+
let manifest_dir = env!("CARGO_MANIFEST_DIR");
7+
let crate_path = [manifest_dir, "..", "mygraphics-shaders"]
8+
.iter()
9+
.copied()
10+
.collect::<PathBuf>();
11+
12+
let install = Install::from_shader_crate(crate_path.clone()).run()?;
13+
let mut builder = install.to_spirv_builder(crate_path, "spirv-unknown-vulkan1.3");
14+
builder.print_metadata = MetadataPrintout::DependencyOnly;
15+
builder.shader_panic_strategy = ShaderPanicStrategy::DebugPrintfThenExit {
16+
print_inputs: true,
17+
print_backtrace: true,
18+
};
19+
20+
let compile_result = builder.build()?;
21+
let spv_path = compile_result.module.unwrap_single();
22+
println!("cargo::rustc-env=SHADER_SPV_PATH={}", spv_path.display());
23+
Ok(())
24+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// FIXME(eddyb) update/review these lints.
2+
//
3+
// BEGIN - Embark standard lints v0.4
4+
// do not change or add/remove here, but one can add exceptions after this section
5+
// for more info see: <https://github.com/EmbarkStudios/rust-ecosystem/issues/59>
6+
//#![deny(unsafe_code)] // impractical in this crate dealing with unsafe `ash`
7+
#![warn(
8+
clippy::all,
9+
clippy::await_holding_lock,
10+
clippy::char_lit_as_u8,
11+
clippy::checked_conversions,
12+
clippy::dbg_macro,
13+
clippy::debug_assert_with_mut_call,
14+
clippy::doc_markdown,
15+
clippy::empty_enum,
16+
clippy::enum_glob_use,
17+
clippy::exit,
18+
clippy::expl_impl_clone_on_copy,
19+
clippy::explicit_deref_methods,
20+
clippy::explicit_into_iter_loop,
21+
clippy::fallible_impl_from,
22+
clippy::filter_map_next,
23+
clippy::float_cmp_const,
24+
clippy::fn_params_excessive_bools,
25+
clippy::if_let_mutex,
26+
clippy::implicit_clone,
27+
clippy::imprecise_flops,
28+
clippy::inefficient_to_string,
29+
clippy::invalid_upcast_comparisons,
30+
clippy::large_types_passed_by_value,
31+
clippy::let_unit_value,
32+
clippy::linkedlist,
33+
clippy::lossy_float_literal,
34+
clippy::macro_use_imports,
35+
clippy::manual_ok_or,
36+
clippy::map_err_ignore,
37+
clippy::map_flatten,
38+
clippy::map_unwrap_or,
39+
clippy::match_same_arms,
40+
clippy::match_wildcard_for_single_variants,
41+
clippy::mem_forget,
42+
clippy::mut_mut,
43+
clippy::mutex_integer,
44+
clippy::needless_borrow,
45+
clippy::needless_continue,
46+
clippy::option_option,
47+
clippy::path_buf_push_overwrite,
48+
clippy::ptr_as_ptr,
49+
clippy::ref_option_ref,
50+
clippy::rest_pat_in_fully_bound_structs,
51+
clippy::same_functions_in_if_condition,
52+
clippy::semicolon_if_nothing_returned,
53+
clippy::string_add_assign,
54+
clippy::string_add,
55+
clippy::string_lit_as_bytes,
56+
clippy::string_to_string,
57+
clippy::todo,
58+
clippy::trait_duplication_in_bounds,
59+
clippy::unimplemented,
60+
clippy::unnested_or_patterns,
61+
clippy::unused_self,
62+
clippy::useless_transmute,
63+
clippy::verbose_file_reads,
64+
clippy::zero_sized_map_values,
65+
future_incompatible,
66+
nonstandard_style,
67+
rust_2018_idioms
68+
)]
69+
// END - Embark standard lints v0.4
70+
// crate-specific exceptions:
71+
// #![allow()]
72+
73+
pub mod util;
74+
pub mod wgpu_renderer;

graphics/mygraphics/src/main.rs renamed to generated/graphics/wgpu/cargo-gpu/mygraphics/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pub fn main() -> anyhow::Result<()> {
2-
mygraphics::ash_renderer::main()
2+
mygraphics::wgpu_renderer::main()
33
}

0 commit comments

Comments
 (0)