X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=shader-compiler%2Fsrc%2Flib.rs;h=de1288c2c69da2228f7380d83d0dec0af2ec7e2b;hb=0ec240fce4f11332788b1d673df7932313e66795;hp=dd4c4408b52f54ba376112107dde6e96cbabe2c2;hpb=ccce0423365359b39fd8a92145d5911724d2510f;p=kazan.git diff --git a/shader-compiler/src/lib.rs b/shader-compiler/src/lib.rs index dd4c440..de1288c 100644 --- a/shader-compiler/src/lib.rs +++ b/shader-compiler/src/lib.rs @@ -38,19 +38,19 @@ impl Default for Context { } mod pointer_type { - use super::{Context, Type}; + use super::{Context, FrontendType}; use std::cell::RefCell; use std::fmt; use std::hash::{Hash, Hasher}; use std::rc::{Rc, Weak}; #[derive(Default)] - pub struct ContextTypes(Vec>); + pub struct ContextTypes(Vec>); #[derive(Clone, Debug)] enum PointerTypeState { Void, - Normal(Weak), + Normal(Weak), Unresolved, } @@ -72,7 +72,7 @@ mod pointer_type { } impl PointerType { - pub fn new(context: &mut Context, pointee: Option>) -> Self { + pub fn new(context: &mut Context, pointee: Option>) -> Self { Self { pointee: RefCell::new(match pointee { Some(pointee) => { @@ -94,7 +94,7 @@ mod pointer_type { pointee: RefCell::new(PointerTypeState::Unresolved), } } - pub fn resolve(&self, context: &mut Context, new_pointee: Option>) { + pub fn resolve(&self, context: &mut Context, new_pointee: Option>) { let mut pointee = self.pointee.borrow_mut(); match &*pointee { PointerTypeState::Unresolved => {} @@ -102,7 +102,7 @@ mod pointer_type { } *pointee = Self::new(context, new_pointee).pointee.into_inner(); } - pub fn pointee(&self) -> Option> { + pub fn pointee(&self) -> Option> { match *self.pointee.borrow() { PointerTypeState::Normal(ref pointee) => Some( pointee @@ -160,7 +160,7 @@ pub struct VectorType { #[derive(Clone, Eq, PartialEq, Hash, Debug)] pub struct StructMember { pub decorations: Vec, - pub member_type: Rc, + pub member_type: Rc, } #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] @@ -234,59 +234,59 @@ impl fmt::Debug for StructType { #[derive(Clone, Eq, PartialEq, Hash, Debug)] pub struct ArrayType { pub decorations: Vec, - pub element: Rc, + pub element: Rc, pub element_count: Option, } #[derive(Clone, Eq, PartialEq, Hash, Debug)] -pub enum Type { +pub enum FrontendType { Scalar(ScalarType), Vector(VectorType), Struct(StructType), Array(ArrayType), } -impl Type { +impl FrontendType { pub fn is_pointer(&self) -> bool { - if let Type::Scalar(ScalarType::Pointer(_)) = self { + if let FrontendType::Scalar(ScalarType::Pointer(_)) = self { true } else { false } } pub fn is_scalar(&self) -> bool { - if let Type::Scalar(_) = self { + if let FrontendType::Scalar(_) = self { true } else { false } } pub fn is_vector(&self) -> bool { - if let Type::Vector(_) = self { + if let FrontendType::Vector(_) = self { true } else { false } } - pub fn get_pointee(&self) -> Option> { - if let Type::Scalar(ScalarType::Pointer(pointer)) = self { + pub fn get_pointee(&self) -> Option> { + if let FrontendType::Scalar(ScalarType::Pointer(pointer)) = self { pointer.pointee() } else { unreachable!("not a pointer") } } - pub fn get_nonvoid_pointee(&self) -> Rc { + pub fn get_nonvoid_pointee(&self) -> Rc { self.get_pointee().expect("void is not allowed here") } pub fn get_scalar(&self) -> &ScalarType { - if let Type::Scalar(scalar) = self { + if let FrontendType::Scalar(scalar) = self { scalar } else { unreachable!("not a scalar type") } } pub fn get_vector(&self) -> &VectorType { - if let Type::Vector(vector) = self { + if let FrontendType::Vector(vector) = self { vector } else { unreachable!("not a vector type") @@ -387,8 +387,8 @@ define_scalar_vector_constant_impl!(f64, F64, get_f64); define_scalar_vector_constant_impl!(bool, Bool, get_bool); impl ScalarConstant { - pub fn get_type(self) -> Type { - Type::Scalar(self.get_scalar_type()) + pub fn get_type(self) -> FrontendType { + FrontendType::Scalar(self.get_scalar_type()) } pub fn get_scalar_type(self) -> ScalarType { match self { @@ -457,8 +457,8 @@ impl VectorConstant { VectorConstant::Bool(v) => v.len(), } } - pub fn get_type(&self) -> Type { - Type::Vector(VectorType { + pub fn get_type(&self) -> FrontendType { + FrontendType::Vector(VectorType { element: self.get_element_type(), element_count: self.get_element_count(), }) @@ -472,7 +472,7 @@ pub enum Constant { } impl Constant { - pub fn get_type(&self) -> Type { + pub fn get_type(&self) -> FrontendType { match self { Constant::Scalar(v) => v.get_type(), Constant::Vector(v) => v.get_type(), @@ -498,9 +498,9 @@ struct BuiltInVariable { } impl BuiltInVariable { - fn get_type(&self, _context: &mut Context) -> Rc { + fn get_type(&self, _context: &mut Context) -> Rc { match self.built_in { - BuiltIn::GlobalInvocationId => Rc::new(Type::Vector(VectorType { + BuiltIn::GlobalInvocationId => Rc::new(FrontendType::Vector(VectorType { element: ScalarType::U32, element_count: 3, })), @@ -513,20 +513,33 @@ impl BuiltInVariable { struct UniformVariable { binding: u32, descriptor_set: u32, - variable_type: Rc, + variable_type: Rc, +} + +#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] +enum CrossLaneBehavior { + Uniform, + Nonuniform, +} + +#[derive(Debug)] +struct FrontendValue<'a, C: shader_compiler_backend::Context<'a>> { + frontend_type: Rc, + backend_value: Option, + cross_lane_behavior: CrossLaneBehavior, } #[derive(Debug)] enum IdKind<'a, C: shader_compiler_backend::Context<'a>> { Undefined, DecorationGroup, - Type(Rc), + Type(Rc), VoidType, FunctionType { - return_type: Option>, - arguments: Vec>, + return_type: Option>, + arguments: Vec>, }, - ForwardPointer(Rc), + ForwardPointer(Rc), BuiltInVariable(BuiltInVariable), Constant(Rc), UniformVariable(UniformVariable), @@ -535,6 +548,7 @@ enum IdKind<'a, C: shader_compiler_backend::Context<'a>> { basic_block: C::BasicBlock, buildable_basic_block: Option, }, + Value(FrontendValue<'a, C>), } #[derive(Debug)] @@ -559,14 +573,14 @@ impl<'a, C: shader_compiler_backend::Context<'a>> IdProperties<'a, C> { } self.kind = kind; } - fn get_type(&self) -> Option<&Rc> { + fn get_type(&self) -> Option<&Rc> { match &self.kind { IdKind::Type(t) => Some(t), IdKind::VoidType => None, _ => unreachable!("id is not type"), } } - fn get_nonvoid_type(&self) -> &Rc { + fn get_nonvoid_type(&self) -> &Rc { self.get_type().expect("void is not allowed here") } fn get_constant(&self) -> &Rc { @@ -575,6 +589,18 @@ impl<'a, C: shader_compiler_backend::Context<'a>> IdProperties<'a, C> { _ => unreachable!("id is not a constant"), } } + fn get_value(&self) -> &FrontendValue<'a, C> { + match &self.kind { + IdKind::Value(retval) => retval, + _ => unreachable!("id is not a value"), + } + } + fn get_value_mut(&mut self) -> &mut FrontendValue<'a, C> { + match &mut self.kind { + IdKind::Value(retval) => retval, + _ => unreachable!("id is not a value"), + } + } fn assert_no_member_decorations(&self, id: IdRef) { for member_decoration in &self.member_decorations { unreachable!(