#[derive(Debug, Clone, PartialEq)]
pub struct ShaderModule {
pub structs: Vec<StructDecl>,
pub bindings: Vec<Binding>,
pub private_vars: Vec<PrivateVar>,
pub const_decls: Vec<ConstDecl>,
pub functions: Vec<Function>,
pub entry_points: Vec<EntryPoint>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ConstDecl {
pub name: String,
pub ty: Option<Type>,
pub initializer: String,
}
#[derive(Debug, Clone, PartialEq)]
pub enum AddressSpace {
Private,
Workgroup,
}
#[derive(Debug, Clone, PartialEq)]
pub struct PrivateVar {
pub name: String,
pub ty: Type,
pub address_space: AddressSpace,
}
#[derive(Debug, Clone, PartialEq)]
pub struct StructDecl {
pub name: String,
pub fields: Vec<StructField>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct StructField {
pub name: String,
pub ty: Type,
pub align: Option<u32>,
pub size: Option<u32>,
pub location: Option<u32>,
pub builtin: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Binding {
pub group: u32,
pub binding: u32,
pub name: String,
pub kind: BindingKind,
}
#[derive(Debug, Clone, PartialEq)]
pub enum BindingKind {
Uniform(Type),
Storage {
access_mode: StorageAccess,
ty: Type,
},
Texture {
texture_type: TextureType,
},
Sampler,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum StorageAccess {
Read,
Write,
ReadWrite,
}
#[derive(Debug, Clone, PartialEq)]
pub enum TextureType {
Texture2D(ScalarType),
TextureCube(ScalarType),
Texture3D(ScalarType),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ShaderStage {
Vertex,
Fragment,
Compute,
}
#[derive(Debug, Clone, PartialEq)]
pub struct EntryPoint {
pub stage: ShaderStage,
pub workgroup_size: Option<(u32, u32, u32)>,
pub name: String,
pub params: Vec<Param>,
pub return_type: Option<ReturnType>,
pub body: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Function {
pub name: String,
pub params: Vec<Param>,
pub return_type: Option<Type>, pub body: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Param {
pub name: String,
pub ty: Type,
pub location: Option<u32>,
pub builtin: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ReturnType {
pub ty: Type,
pub location: Option<u32>,
pub builtin: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Type {
Scalar(ScalarType),
Vec2(Option<ScalarType>), Vec3(Option<ScalarType>),
Vec4(Option<ScalarType>),
Mat2x2(Option<ScalarType>),
Mat3x3(Option<ScalarType>),
Mat4x4(Option<ScalarType>),
Array(Box<Type>, Option<u32>), Atomic(ScalarType),
Struct(String),
Texture2D(ScalarType),
TextureCube(ScalarType),
Texture3D(ScalarType),
Sampler,
SamplerComparison,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ScalarType {
F32,
F64,
U32,
I32,
Bool,
}