mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[glsl-new] store int constants in module (#111)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use crate::{Arena, FastHashMap, Function, Handle, Type};
|
||||
use crate::{Arena, Constant, FastHashMap, Function, Handle, Type};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Program {
|
||||
@@ -9,6 +9,7 @@ pub struct Program {
|
||||
pub functions: Arena<Function>,
|
||||
pub lookup_type: FastHashMap<String, Handle<Type>>,
|
||||
pub types: Arena<Type>,
|
||||
pub constants: Arena<Constant>,
|
||||
}
|
||||
|
||||
impl Program {
|
||||
@@ -21,6 +22,7 @@ impl Program {
|
||||
functions: Arena::<Function>::new(),
|
||||
lookup_type: FastHashMap::default(),
|
||||
types: Arena::<Type>::new(),
|
||||
constants: Arena::<Constant>::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ pub fn parse_str(source: &str, entry: String, stage: ShaderStage) -> Result<Modu
|
||||
let mut module = Module::generate_empty();
|
||||
module.functions = program.functions;
|
||||
module.types = program.types;
|
||||
module.constants = program.constants;
|
||||
|
||||
// find entry point
|
||||
if let Some(entry_handle) = program.lookup_function.get(&entry) {
|
||||
|
||||
@@ -6,8 +6,8 @@ pomelo! {
|
||||
//%verbose;
|
||||
%include {
|
||||
use super::super::{error::ErrorKind, token::*, ast::*};
|
||||
use crate::{Arena, Expression, Function, Handle, LocalVariable, ScalarKind,
|
||||
Type, TypeInner, VectorSize};
|
||||
use crate::{Arena, Constant, ConstantInner, Expression, Function, Handle,
|
||||
LocalVariable, ScalarKind, Type, TypeInner, VectorSize};
|
||||
}
|
||||
%token #[derive(Debug)] pub enum Token {};
|
||||
%parser pub struct Parser<'a> {};
|
||||
@@ -75,7 +75,21 @@ pomelo! {
|
||||
variable_identifier ::= Identifier;
|
||||
|
||||
primary_expression ::= variable_identifier;
|
||||
primary_expression ::= IntConstant;
|
||||
primary_expression ::= IntConstant(i) {
|
||||
let ty = extra.types.fetch_or_append(Type {
|
||||
name: None,
|
||||
inner: TypeInner::Scalar {
|
||||
kind: ScalarKind::Sint,
|
||||
width: 4,
|
||||
}
|
||||
});
|
||||
let ch = extra.constants.fetch_or_append(Constant {
|
||||
name: None,
|
||||
specialization: None,
|
||||
ty,
|
||||
inner: ConstantInner::Sint(i.1)
|
||||
});
|
||||
}
|
||||
primary_expression ::= UintConstant;
|
||||
primary_expression ::= FloatConstant;
|
||||
primary_expression ::= BoolConstant;
|
||||
|
||||
Reference in New Issue
Block a user