Skip to content

Commit

Permalink
Bug 1684384 - Update glsl to 6.0. r=gfx-reviewers,lsalzman
Browse files Browse the repository at this point in the history
  • Loading branch information
glandium committed Jun 7, 2022
1 parent 45b3dcb commit 9ded937
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 37 deletions.
48 changes: 43 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion glsl-to-cxx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
glsl = "4.0"
glsl = "6.0"
43 changes: 24 additions & 19 deletions glsl-to-cxx/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */

use glsl::syntax;
use glsl::syntax::{ArrayedIdentifier, ArraySpecifier, AssignmentOp, BinaryOp, Identifier};
use glsl::syntax::{ArrayedIdentifier, ArraySpecifier, ArraySpecifierDimension, AssignmentOp, BinaryOp, Identifier};
use glsl::syntax::{NonEmpty, PrecisionQualifier, StructFieldSpecifier, StructSpecifier};
use glsl::syntax::{TypeSpecifier, TypeSpecifierNonArray, UnaryOp};
use std::cell::{Cell, Ref, RefCell};
Expand Down Expand Up @@ -112,10 +112,10 @@ pub struct ArraySizes {
impl LiftFrom<&ArraySpecifier> for ArraySizes {
fn lift(state: &mut State, a: &ArraySpecifier) -> Self {
ArraySizes {
sizes: vec![match a {
ArraySpecifier::Unsized => panic!(),
ArraySpecifier::ExplicitlySized(expr) => translate_expression(state, expr),
}],
sizes: a.dimensions.0.iter().map(|a| match a {
ArraySpecifierDimension::Unsized => panic!(),
ArraySpecifierDimension::ExplicitlySized(expr) => translate_expression(state, expr),
}).collect(),
}
}
}
Expand Down Expand Up @@ -1385,7 +1385,7 @@ pub enum ExprKind {
/// assignment operator and the value to associate with.
Assignment(Box<Expr>, AssignmentOp, Box<Expr>),
/// Add an array specifier to an expression.
Bracket(Box<Expr>, Box<Expr>),
Bracket(Box<Expr>, Vec<Expr>),
/// A functional call. It has a function identifier and a list of expressions (arguments).
FunCall(FunIdentifier, Vec<Expr>),
/// An expression associated with a field selection (struct).
Expand Down Expand Up @@ -2239,13 +2239,15 @@ fn translate_expression(state: &mut State, e: &syntax::Expr) -> Expr {
if global == state.clip_dist_sym {
if let ExprKind::Bracket(_, idx) = &lhs.kind {
// Get the constant array index used for gl_ClipDistance and add it to the used mask.
let idx = match idx.kind {
ExprKind::IntConst(idx) => idx,
ExprKind::UIntConst(idx) => idx as i32,
_ => panic!("bad index for gl_ClipDistance"),
};
assert!(idx >= 0 && idx < 4);
state.used_clip_dist |= 1 << idx;
for dimension in idx {
let idx = match dimension.kind {
ExprKind::IntConst(idx) => idx,
ExprKind::UIntConst(idx) => idx as i32,
_ => panic!("bad index for gl_ClipDistance"),
};
assert!(idx >= 0 && idx < 4);
state.used_clip_dist |= 1 << idx;
}
}
}
}
Expand Down Expand Up @@ -2595,12 +2597,12 @@ fn translate_expression(state: &mut State, e: &syntax::Expr) -> Expr {
array_sizes: a,
}
};
let indx = match specifier {
ArraySpecifier::Unsized => panic!("need expression"),
ArraySpecifier::ExplicitlySized(e) => translate_expression(state, e),
};
let indx = specifier.dimensions.0.iter().map(|a| match a {
ArraySpecifierDimension::Unsized => panic!("need expression"),
ArraySpecifierDimension::ExplicitlySized(e) => translate_expression(state, e),
}).collect();
Expr {
kind: ExprKind::Bracket(e, Box::new(indx)),
kind: ExprKind::Bracket(e, indx),
ty,
}
}
Expand Down Expand Up @@ -4255,7 +4257,10 @@ fn infer_expr_inner(state: &mut State, expr: &Expr, assign: &mut SymRef) -> RunC
state.merge_run_class(sym, run_class)
}
ExprKind::Bracket(ref e, ref indx) => {
infer_expr_inner(state, e, assign).merge(infer_expr(state, indx))
indx.iter().fold(
infer_expr_inner(state, e, assign),
|run_class, indx| run_class.merge(infer_expr(state, indx)),
)
}
ExprKind::FunCall(ref fun, ref args) => {
let arg_classes: Vec<(RunClass, SymRef)> = args
Expand Down
27 changes: 17 additions & 10 deletions glsl-to-cxx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1219,14 +1219,16 @@ pub fn show_struct_field(state: &OutputState, field: &hir::StructField) {
}

pub fn show_array_spec(state: &OutputState, a: &syntax::ArraySpecifier) {
match *a {
syntax::ArraySpecifier::Unsized => {
state.write("[]");
}
syntax::ArraySpecifier::ExplicitlySized(ref e) => {
state.write("[");
show_expr(state, &e);
state.write("]");
for dimension in &a.dimensions {
match dimension {
syntax::ArraySpecifierDimension::Unsized => {
state.write("[]");
}
syntax::ArraySpecifierDimension::ExplicitlySized(ref e) => {
state.write("[");
show_expr(state, &e);
state.write("]");
}
}
}
}
Expand Down Expand Up @@ -1494,7 +1496,10 @@ fn expr_run_class(state: &OutputState, expr: &hir::Expr) -> hir::RunClass {
expr_run_class(state, v).merge(expr_run_class(state, e))
}
hir::ExprKind::Bracket(ref e, ref indx) => {
expr_run_class(state, e).merge(expr_run_class(state, indx))
indx.iter().fold(
expr_run_class(state, e),
|run_class, indx| run_class.merge(expr_run_class(state, indx)),
)
}
hir::ExprKind::FunCall(ref fun, ref args) => {
let arg_mask: u32 = args.iter().enumerate().fold(0, |mask, (idx, e)| {
Expand Down Expand Up @@ -1804,7 +1809,9 @@ pub fn show_hir_expr_inner(state: &OutputState, expr: &hir::Expr, top_level: boo
hir::ExprKind::Bracket(ref e, ref indx) => {
show_hir_expr(state, &e);
state.write("[");
show_hir_expr(state, indx);
for dimension in indx {
show_hir_expr(state, dimension);
}
state.write("]");
}
hir::ExprKind::FunCall(ref fun, ref args) => {
Expand Down
2 changes: 1 addition & 1 deletion wrench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ env_logger = { version = "0.5", optional = true }
gleam = "0.13"
glutin = "0.28"
clap = { version = "2", features = ["yaml"] }
glsl = "4.0"
glsl = "6.0"
log = "0.4"
yaml-rust = "0.4"
serde_json = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion wrench/src/test_shaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn test_no_flat_scalar_varyings(name: &str, shader: &mut ShaderStage) {
}

impl Visitor for FlatScalarVaryingsVisitor {
fn visit_single_declaration(&mut self, declaration: &mut SingleDeclaration) -> Visit {
fn visit_single_declaration(&mut self, declaration: &SingleDeclaration) -> Visit {
let is_scalar = matches!(declaration.ty.ty.ty,
TypeSpecifierNonArray::Bool
| TypeSpecifierNonArray::Int
Expand Down

0 comments on commit 9ded937

Please sign in to comment.