Skip to content

Commit f80c026

Browse files
committed
web linkage on wasm32 only
1 parent 2fbc4c5 commit f80c026

28 files changed

+264
-405
lines changed

Cargo.lock

+8-45
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ glam = { version = "0.24.2", default-features = false }
2626
gltf = { version = "1.4,1", features = ["KHR_lights_punctual", "KHR_materials_unlit", "KHR_materials_emissive_strength", "extras", "extensions"] }
2727
image = "0.24"
2828
log = "0.4"
29-
naga = { version = "0.19", features = ["spv-in", "wgsl-out", "wgsl-in", "msl-out"] }
29+
naga = { version = "22.1.0", features = ["spv-in", "wgsl-out", "wgsl-in", "msl-out"] }
3030
pretty_assertions = "1.4.0"
3131
proc-macro2 = { version = "1.0", features = ["span-locations"] }
3232
rustc-hash = "1.1"
@@ -40,6 +40,7 @@ web-sys = "0.3"
4040
winit = { version = "0.30" }
4141
wgpu = "22.1.0"
4242

43+
4344
[profile.dev]
4445
opt-level = 1
4546

crates/renderling/Cargo.toml

+1-4
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,8 @@ tutorial_slabbed_renderlet = []
8888

8989
wasm = ["wgpu/fragile-send-sync-non-atomic-wasm"]
9090

91-
[patch.crates-io]
92-
spirv-std = { git = "https://github.com/Rust-GPU/rust-gpu" }
93-
9491
[build-dependencies]
95-
naga = { version = "22.1", features = ["spv-in", "wgsl-out", "wgsl-in", "msl-out"] }
92+
naga = {workspace = true}
9693
pathdiff = "0.2.2"
9794
quote = "1.0"
9895
serde = {version = "1.0", features = ["derive"]}

crates/renderling/src/build.rs

+10-17
Original file line numberDiff line numberDiff line change
@@ -25,53 +25,46 @@ impl core::fmt::Display for Linkage {
2525
wgsl_entry_point,
2626
} = self;
2727

28+
let fn_name = self.fn_name();
29+
2830
let quote = quote! {
2931
use crate::linkage::ShaderLinkage;
3032

31-
mod native {
33+
#[cfg(not(target_arch = "wasm32"))]
34+
mod target {
3235
pub const ENTRY_POINT: &str = #entry_point;
3336

3437
pub fn descriptor() -> wgpu::ShaderModuleDescriptor<'static> {
3538
wgpu::include_spirv!(#spv_include_source_path)
3639
}
3740

3841
pub fn linkage(device: &wgpu::Device) -> super::ShaderLinkage {
42+
log::info!("creating native linkage for {}", #fn_name);
3943
super::ShaderLinkage {
4044
entry_point: ENTRY_POINT,
4145
module: device.create_shader_module(descriptor()).into()
4246
}
4347
}
4448
}
45-
46-
mod web {
49+
#[cfg(target_arch = "wasm32")]
50+
mod target {
4751
pub const ENTRY_POINT: &str = #wgsl_entry_point;
4852

4953
pub fn descriptor() -> wgpu::ShaderModuleDescriptor<'static> {
50-
wgpu::include_spirv!(#wgsl_include_source_path)
54+
wgpu::include_wgsl!(#wgsl_include_source_path)
5155
}
5256

5357
pub fn linkage(device: &wgpu::Device) -> super::ShaderLinkage {
58+
log::info!("creating web linkage for {}", #fn_name);
5459
super::ShaderLinkage {
5560
entry_point: ENTRY_POINT,
5661
module: device.create_shader_module(descriptor()).into()
5762
}
5863
}
5964
}
6065

61-
pub fn linkage_native(device: &wgpu::Device) -> ShaderLinkage {
62-
native::linkage(device)
63-
}
64-
65-
pub fn linkage_web(device: &wgpu::Device) -> ShaderLinkage {
66-
web::linkage(device)
67-
}
68-
6966
pub fn linkage(device: &wgpu::Device) -> ShaderLinkage {
70-
if cfg!(feature = "wasm") {
71-
web::linkage(device)
72-
} else {
73-
native::linkage(device)
74-
}
67+
target::linkage(device)
7568
}
7669
};
7770

Original file line numberDiff line numberDiff line change
@@ -1,40 +1,37 @@
11
#![allow(dead_code)]
22
//! Automatically generated by Renderling's `build.rs`.
33
use crate::linkage::ShaderLinkage;
4-
mod native {
4+
#[cfg(not(target_arch = "wasm32"))]
5+
mod target {
56
pub const ENTRY_POINT: &str = "bloom::bloom_downsample_fragment";
67
pub fn descriptor() -> wgpu::ShaderModuleDescriptor<'static> {
78
wgpu::include_spirv!("../../shaders/bloom-bloom_downsample_fragment.spv")
89
}
910
pub fn linkage(device: &wgpu::Device) -> super::ShaderLinkage {
11+
log::info!(
12+
"creating native linkage for {}",
13+
"bloom_downsample_fragment"
14+
);
1015
super::ShaderLinkage {
1116
entry_point: ENTRY_POINT,
1217
module: device.create_shader_module(descriptor()).into(),
1318
}
1419
}
1520
}
16-
mod web {
21+
#[cfg(target_arch = "wasm32")]
22+
mod target {
1723
pub const ENTRY_POINT: &str = "bloombloom_downsample_fragment";
1824
pub fn descriptor() -> wgpu::ShaderModuleDescriptor<'static> {
19-
wgpu::include_spirv!("../../shaders/bloom-bloom_downsample_fragment.wgsl")
25+
wgpu::include_wgsl!("../../shaders/bloom-bloom_downsample_fragment.wgsl")
2026
}
2127
pub fn linkage(device: &wgpu::Device) -> super::ShaderLinkage {
28+
log::info!("creating web linkage for {}", "bloom_downsample_fragment");
2229
super::ShaderLinkage {
2330
entry_point: ENTRY_POINT,
2431
module: device.create_shader_module(descriptor()).into(),
2532
}
2633
}
2734
}
28-
pub fn linkage_native(device: &wgpu::Device) -> ShaderLinkage {
29-
native::linkage(device)
30-
}
31-
pub fn linkage_web(device: &wgpu::Device) -> ShaderLinkage {
32-
web::linkage(device)
33-
}
3435
pub fn linkage(device: &wgpu::Device) -> ShaderLinkage {
35-
if cfg!(feature = "wasm") {
36-
web::linkage(device)
37-
} else {
38-
native::linkage(device)
39-
}
36+
target::linkage(device)
4037
}
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,34 @@
11
#![allow(dead_code)]
22
//! Automatically generated by Renderling's `build.rs`.
33
use crate::linkage::ShaderLinkage;
4-
mod native {
4+
#[cfg(not(target_arch = "wasm32"))]
5+
mod target {
56
pub const ENTRY_POINT: &str = "bloom::bloom_mix_fragment";
67
pub fn descriptor() -> wgpu::ShaderModuleDescriptor<'static> {
78
wgpu::include_spirv!("../../shaders/bloom-bloom_mix_fragment.spv")
89
}
910
pub fn linkage(device: &wgpu::Device) -> super::ShaderLinkage {
11+
log::info!("creating native linkage for {}", "bloom_mix_fragment");
1012
super::ShaderLinkage {
1113
entry_point: ENTRY_POINT,
1214
module: device.create_shader_module(descriptor()).into(),
1315
}
1416
}
1517
}
16-
mod web {
18+
#[cfg(target_arch = "wasm32")]
19+
mod target {
1720
pub const ENTRY_POINT: &str = "bloombloom_mix_fragment";
1821
pub fn descriptor() -> wgpu::ShaderModuleDescriptor<'static> {
19-
wgpu::include_spirv!("../../shaders/bloom-bloom_mix_fragment.wgsl")
22+
wgpu::include_wgsl!("../../shaders/bloom-bloom_mix_fragment.wgsl")
2023
}
2124
pub fn linkage(device: &wgpu::Device) -> super::ShaderLinkage {
25+
log::info!("creating web linkage for {}", "bloom_mix_fragment");
2226
super::ShaderLinkage {
2327
entry_point: ENTRY_POINT,
2428
module: device.create_shader_module(descriptor()).into(),
2529
}
2630
}
2731
}
28-
pub fn linkage_native(device: &wgpu::Device) -> ShaderLinkage {
29-
native::linkage(device)
30-
}
31-
pub fn linkage_web(device: &wgpu::Device) -> ShaderLinkage {
32-
web::linkage(device)
33-
}
3432
pub fn linkage(device: &wgpu::Device) -> ShaderLinkage {
35-
if cfg!(feature = "wasm") {
36-
web::linkage(device)
37-
} else {
38-
native::linkage(device)
39-
}
33+
target::linkage(device)
4034
}
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,34 @@
11
#![allow(dead_code)]
22
//! Automatically generated by Renderling's `build.rs`.
33
use crate::linkage::ShaderLinkage;
4-
mod native {
4+
#[cfg(not(target_arch = "wasm32"))]
5+
mod target {
56
pub const ENTRY_POINT: &str = "bloom::bloom_upsample_fragment";
67
pub fn descriptor() -> wgpu::ShaderModuleDescriptor<'static> {
78
wgpu::include_spirv!("../../shaders/bloom-bloom_upsample_fragment.spv")
89
}
910
pub fn linkage(device: &wgpu::Device) -> super::ShaderLinkage {
11+
log::info!("creating native linkage for {}", "bloom_upsample_fragment");
1012
super::ShaderLinkage {
1113
entry_point: ENTRY_POINT,
1214
module: device.create_shader_module(descriptor()).into(),
1315
}
1416
}
1517
}
16-
mod web {
18+
#[cfg(target_arch = "wasm32")]
19+
mod target {
1720
pub const ENTRY_POINT: &str = "bloombloom_upsample_fragment";
1821
pub fn descriptor() -> wgpu::ShaderModuleDescriptor<'static> {
19-
wgpu::include_spirv!("../../shaders/bloom-bloom_upsample_fragment.wgsl")
22+
wgpu::include_wgsl!("../../shaders/bloom-bloom_upsample_fragment.wgsl")
2023
}
2124
pub fn linkage(device: &wgpu::Device) -> super::ShaderLinkage {
25+
log::info!("creating web linkage for {}", "bloom_upsample_fragment");
2226
super::ShaderLinkage {
2327
entry_point: ENTRY_POINT,
2428
module: device.create_shader_module(descriptor()).into(),
2529
}
2630
}
2731
}
28-
pub fn linkage_native(device: &wgpu::Device) -> ShaderLinkage {
29-
native::linkage(device)
30-
}
31-
pub fn linkage_web(device: &wgpu::Device) -> ShaderLinkage {
32-
web::linkage(device)
33-
}
3432
pub fn linkage(device: &wgpu::Device) -> ShaderLinkage {
35-
if cfg!(feature = "wasm") {
36-
web::linkage(device)
37-
} else {
38-
native::linkage(device)
39-
}
33+
target::linkage(device)
4034
}

0 commit comments

Comments
 (0)