mirror of
https://github.com/italicsjenga/vello.git
synced 2025-01-09 12:21:31 +11:00
Merge pull request #320 from armansito/revise-backend-src-access
[shaders] Revise access to backend-agnostic metadata
This commit is contained in:
commit
b0303ccf98
|
@ -21,18 +21,7 @@ fn main() {
|
||||||
shaders.sort_by(|x, y| x.0.cmp(&y.0));
|
shaders.sort_by(|x, y| x.0.cmp(&y.0));
|
||||||
let mut buf = String::default();
|
let mut buf = String::default();
|
||||||
write_types(&mut buf, &shaders).unwrap();
|
write_types(&mut buf, &shaders).unwrap();
|
||||||
if cfg!(feature = "wgsl") {
|
write_shaders(&mut buf, &shaders).unwrap();
|
||||||
write_shaders(&mut buf, "wgsl", &shaders, |info| {
|
|
||||||
info.source.as_bytes().to_owned()
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
if cfg!(feature = "msl") {
|
|
||||||
write_shaders(&mut buf, "msl", &shaders, |info| {
|
|
||||||
compile::msl::translate(info).unwrap().as_bytes().to_owned()
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
std::fs::write(&dest_path, &buf).unwrap();
|
std::fs::write(&dest_path, &buf).unwrap();
|
||||||
println!("cargo:rerun-if-changed=../shader");
|
println!("cargo:rerun-if-changed=../shader");
|
||||||
}
|
}
|
||||||
|
@ -65,11 +54,9 @@ fn write_types(buf: &mut String, shaders: &[(String, ShaderInfo)]) -> Result<(),
|
||||||
|
|
||||||
fn write_shaders(
|
fn write_shaders(
|
||||||
buf: &mut String,
|
buf: &mut String,
|
||||||
mod_name: &str,
|
|
||||||
shaders: &[(String, ShaderInfo)],
|
shaders: &[(String, ShaderInfo)],
|
||||||
translate: impl Fn(&ShaderInfo) -> Vec<u8>,
|
|
||||||
) -> Result<(), std::fmt::Error> {
|
) -> Result<(), std::fmt::Error> {
|
||||||
writeln!(buf, "pub mod {mod_name} {{")?;
|
writeln!(buf, "mod gen {{")?;
|
||||||
writeln!(buf, " use super::*;")?;
|
writeln!(buf, " use super::*;")?;
|
||||||
writeln!(buf, " use BindType::*;")?;
|
writeln!(buf, " use BindType::*;")?;
|
||||||
writeln!(buf, " pub const SHADERS: Shaders<'static> = Shaders {{")?;
|
writeln!(buf, " pub const SHADERS: Shaders<'static> = Shaders {{")?;
|
||||||
|
@ -80,14 +67,8 @@ fn write_shaders(
|
||||||
.map(|binding| binding.ty)
|
.map(|binding| binding.ty)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let wg_bufs = &info.workgroup_buffers;
|
let wg_bufs = &info.workgroup_buffers;
|
||||||
let source = translate(info);
|
|
||||||
writeln!(buf, " {name}: ComputeShader {{")?;
|
writeln!(buf, " {name}: ComputeShader {{")?;
|
||||||
writeln!(buf, " name: Cow::Borrowed({:?}),", name)?;
|
writeln!(buf, " name: Cow::Borrowed({:?}),", name)?;
|
||||||
writeln!(
|
|
||||||
buf,
|
|
||||||
" code: Cow::Borrowed(&{:?}),",
|
|
||||||
source.as_slice()
|
|
||||||
)?;
|
|
||||||
writeln!(
|
writeln!(
|
||||||
buf,
|
buf,
|
||||||
" workgroup_size: {:?},",
|
" workgroup_size: {:?},",
|
||||||
|
@ -99,6 +80,16 @@ fn write_shaders(
|
||||||
" workgroup_buffers: Cow::Borrowed(&{:?}),",
|
" workgroup_buffers: Cow::Borrowed(&{:?}),",
|
||||||
wg_bufs
|
wg_bufs
|
||||||
)?;
|
)?;
|
||||||
|
if cfg!(feature = "wgsl") {
|
||||||
|
writeln!(buf, " wgsl: Cow::Borrowed(&{:?}),", info.source)?;
|
||||||
|
}
|
||||||
|
if cfg!(feature = "msl") {
|
||||||
|
writeln!(
|
||||||
|
buf,
|
||||||
|
" msl: Cow::Borrowed(&{:?}),",
|
||||||
|
compile::msl::translate(info).unwrap()
|
||||||
|
)?;
|
||||||
|
}
|
||||||
writeln!(buf, " }},")?;
|
writeln!(buf, " }},")?;
|
||||||
}
|
}
|
||||||
writeln!(buf, " }};")?;
|
writeln!(buf, " }};")?;
|
||||||
|
|
|
@ -13,10 +13,15 @@ use std::borrow::Cow;
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct ComputeShader<'a> {
|
pub struct ComputeShader<'a> {
|
||||||
pub name: Cow<'a, str>,
|
pub name: Cow<'a, str>,
|
||||||
pub code: Cow<'a, [u8]>,
|
|
||||||
pub workgroup_size: [u32; 3],
|
pub workgroup_size: [u32; 3],
|
||||||
pub bindings: Cow<'a, [BindType]>,
|
pub bindings: Cow<'a, [BindType]>,
|
||||||
pub workgroup_buffers: Cow<'a, [WorkgroupBufferInfo]>,
|
pub workgroup_buffers: Cow<'a, [WorkgroupBufferInfo]>,
|
||||||
|
|
||||||
|
#[cfg(feature = "wgsl")]
|
||||||
|
pub wgsl: Cow<'a, str>,
|
||||||
|
|
||||||
|
#[cfg(feature = "msl")]
|
||||||
|
pub msl: Cow<'a, str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait PipelineHost {
|
pub trait PipelineHost {
|
||||||
|
@ -32,3 +37,5 @@ pub trait PipelineHost {
|
||||||
}
|
}
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/shaders.rs"));
|
include!(concat!(env!("OUT_DIR"), "/shaders.rs"));
|
||||||
|
|
||||||
|
pub use gen::SHADERS;
|
||||||
|
|
Loading…
Reference in a new issue