shaders: shader compilation setup

This commit is contained in:
firestar99 2025-08-04 20:45:10 +02:00
parent 98a85d2069
commit 4085c3a603
6 changed files with 472 additions and 9 deletions

View file

@ -6,10 +6,14 @@ description = "graphene raster data format"
authors = ["Graphite Authors <contact@graphite.rs>"]
license = "MIT OR Apache-2.0"
[lib]
crate-type = ["rlib", "dylib"]
[features]
default = ["std"]
std = [
"dep:graphene-core",
"dep:graphene-raster-nodes-shaders",
"dep:dyn-any",
"dep:image",
"dep:ndarray",
@ -31,11 +35,13 @@ node-macro = { workspace = true }
# Local std dependencies
dyn-any = { workspace = true, optional = true }
graphene-core = { workspace = true, optional = true }
graphene-raster-nodes-shaders = { path = "./shaders", optional = true }
# Workspace dependencies
bytemuck = { workspace = true }
glam = { version = "0.29", default-features = false, features = ["nostd-libm", "scalar-math"] }
spirv-std = { workspace = true }
num-traits = { workspace = true }
glam = { version = "0.29", default-features = false, features = ["nostd-libm", "scalar-math"] }
# Workspace std dependencies
specta = { workspace = true, optional = true }

View file

@ -0,0 +1,13 @@
[package]
name = "graphene-raster-nodes-shaders"
version = "0.1.0"
edition = "2024"
description = "graphene raster data format"
authors = ["Graphite Authors <contact@graphite.rs>"]
license = "MIT OR Apache-2.0"
[dependencies]
[build-dependencies]
cargo-gpu = { workspace = true }
env_logger = { workspace = true }

View file

@ -0,0 +1,25 @@
use cargo_gpu::spirv_builder::{MetadataPrintout, SpirvMetadata};
use std::path::PathBuf;
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::builder().init();
let shader_crate = PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"), "/.."));
// install the toolchain and build the `rustc_codegen_spirv` codegen backend with it
let backend = cargo_gpu::Install::from_shader_crate(shader_crate.clone()).run()?;
// build the shader crate
let mut builder = backend.to_spirv_builder(shader_crate, "spirv-unknown-naga-wgsl");
builder.print_metadata = MetadataPrintout::DependencyOnly;
builder.spirv_metadata = SpirvMetadata::Full;
builder.shader_crate_features.default_features = false;
let wgsl_result = builder.build()?;
let path_to_spv = wgsl_result.module.unwrap_single();
// needs to be fixed upstream
let path_to_wgsl = path_to_spv.with_extension("wgsl");
println!("cargo::rustc-env=WGSL_SHADER_PATH={}", path_to_wgsl.display());
Ok(())
}

View file

@ -0,0 +1 @@
pub const WGSL_SHADER: &str = include_str!(env!("WGSL_SHADER_PATH"));