Skip to content

Commit

Permalink
[glsl-in]: Document some fields of `naga::front::glsl::context::Conte…
Browse files Browse the repository at this point in the history
…xt`. (#2244)
  • Loading branch information
jimblandy committed Feb 16, 2023
1 parent cc3a8ac commit dce689c
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 41 deletions.
58 changes: 29 additions & 29 deletions src/front/glsl/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ fn inject_standard_builtins(
| "floatBitsToInt" | "floatBitsToUint" | "dFdx" | "dFdxFine" | "dFdxCoarse" | "dFdy"
| "dFdyFine" | "dFdyCoarse" | "fwidth" | "fwidthFine" | "fwidthCoarse" => {
// bits layout
// bit 0 trough 1 - dims
// bit 0 through 1 - dims
for bits in 0..0b100 {
let size = match bits {
0b00 => None,
Expand Down Expand Up @@ -587,7 +587,7 @@ fn inject_standard_builtins(
}
"intBitsToFloat" | "uintBitsToFloat" => {
// bits layout
// bit 0 trough 1 - dims
// bit 0 through 1 - dims
for bits in 0..0b100 {
let size = match bits {
0b00 => None,
Expand All @@ -611,7 +611,7 @@ fn inject_standard_builtins(
}
"pow" => {
// bits layout
// bit 0 trough 1 - dims
// bit 0 through 1 - dims
for bits in 0..0b100 {
let size = match bits {
0b00 => None,
Expand All @@ -633,7 +633,7 @@ fn inject_standard_builtins(
}
"abs" | "sign" => {
// bits layout
// bit 0 trough 1 - dims
// bit 0 through 1 - dims
// bit 2 - float/sint
for bits in 0..0b1000 {
let size = match bits & 0b11 {
Expand Down Expand Up @@ -682,7 +682,7 @@ fn inject_standard_builtins(

// bits layout
// bit 0 - int/uint
// bit 1 trough 2 - dims
// bit 1 through 2 - dims
for bits in 0..0b1000 {
let kind = match bits & 0b1 {
0b0 => Sk::Sint,
Expand Down Expand Up @@ -796,7 +796,7 @@ fn inject_standard_builtins(
"atan" => {
// bits layout
// bit 0 - atan/atan2
// bit 1 trough 2 - dims
// bit 1 through 2 - dims
for bits in 0..0b1000 {
let fun = match bits & 0b1 {
0b0 => MathFunction::Atan,
Expand Down Expand Up @@ -827,7 +827,7 @@ fn inject_standard_builtins(
}
"all" | "any" | "not" => {
// bits layout
// bit 0 trough 1 - dims
// bit 0 through 1 - dims
for bits in 0..0b11 {
let size = match bits {
0b00 => VectorSize::Bi,
Expand Down Expand Up @@ -916,8 +916,8 @@ fn inject_standard_builtins(
}
"min" | "max" => {
// bits layout
// bit 0 trough 1 - scalar kind
// bit 2 trough 4 - dims
// bit 0 through 1 - scalar kind
// bit 2 through 4 - dims
for bits in 0..0b11100 {
let kind = match bits & 0b11 {
0b00 => Sk::Float,
Expand Down Expand Up @@ -957,8 +957,8 @@ fn inject_standard_builtins(
}
"mix" => {
// bits layout
// bit 0 trough 1 - dims
// bit 2 trough 4 - types
// bit 0 through 1 - dims
// bit 2 through 4 - types
//
// 0b10011 is the last element since splatted single elements
// were already added
Expand Down Expand Up @@ -1002,8 +1002,8 @@ fn inject_standard_builtins(
}
"clamp" => {
// bits layout
// bit 0 trough 1 - float/int/uint
// bit 2 trough 3 - dims
// bit 0 through 1 - float/int/uint
// bit 2 through 3 - dims
// bit 4 - splatted
//
// 0b11010 is the last element since splatted single elements
Expand Down Expand Up @@ -1053,7 +1053,7 @@ fn inject_double_builtin(declaration: &mut FunctionDeclaration, module: &mut Mod
match name {
"abs" | "sign" => {
// bits layout
// bit 0 trough 1 - dims
// bit 0 through 1 - dims
for bits in 0..0b100 {
let size = match bits {
0b00 => None,
Expand All @@ -1080,7 +1080,7 @@ fn inject_double_builtin(declaration: &mut FunctionDeclaration, module: &mut Mod
}
"min" | "max" => {
// bits layout
// bit 0 trough 2 - dims
// bit 0 through 2 - dims
for bits in 0..0b111 {
let (size, second_size) = match bits {
0b000 => (None, None),
Expand Down Expand Up @@ -1115,8 +1115,8 @@ fn inject_double_builtin(declaration: &mut FunctionDeclaration, module: &mut Mod
}
"mix" => {
// bits layout
// bit 0 trough 1 - dims
// bit 2 trough 3 - splatted/boolean
// bit 0 through 1 - dims
// bit 2 through 3 - splatted/boolean
//
// 0b1010 is the last element since splatted with single elements
// is equal to normal single elements
Expand Down Expand Up @@ -1159,7 +1159,7 @@ fn inject_double_builtin(declaration: &mut FunctionDeclaration, module: &mut Mod
}
"clamp" => {
// bits layout
// bit 0 trough 1 - dims
// bit 0 through 1 - dims
// bit 2 - splatted
//
// 0b110 is the last element since splatted with single elements
Expand Down Expand Up @@ -1231,7 +1231,7 @@ fn inject_common_builtin(
"ceil" | "round" | "roundEven" | "floor" | "fract" | "trunc" | "sqrt" | "inversesqrt"
| "normalize" | "length" | "isinf" | "isnan" => {
// bits layout
// bit 0 trough 1 - dims
// bit 0 through 1 - dims
for bits in 0..0b100 {
let size = match bits {
0b00 => None,
Expand Down Expand Up @@ -1272,7 +1272,7 @@ fn inject_common_builtin(
}
"dot" | "reflect" | "distance" | "ldexp" => {
// bits layout
// bit 0 trough 1 - dims
// bit 0 through 1 - dims
for bits in 0..0b100 {
let size = match bits {
0b00 => None,
Expand Down Expand Up @@ -1307,7 +1307,7 @@ fn inject_common_builtin(
}
"transpose" => {
// bits layout
// bit 0 trough 3 - dims
// bit 0 through 3 - dims
for bits in 0..0b1001 {
let (rows, columns) = match bits {
0b0000 => (VectorSize::Bi, VectorSize::Bi),
Expand All @@ -1333,7 +1333,7 @@ fn inject_common_builtin(
}
"inverse" | "determinant" => {
// bits layout
// bit 0 trough 1 - dims
// bit 0 through 1 - dims
for bits in 0..0b11 {
let (rows, columns) = match bits {
0b00 => (VectorSize::Bi, VectorSize::Bi),
Expand All @@ -1359,7 +1359,7 @@ fn inject_common_builtin(
}
"mod" | "step" => {
// bits layout
// bit 0 trough 2 - dims
// bit 0 through 2 - dims
for bits in 0..0b111 {
let (size, second_size) = match bits {
0b000 => (None, None),
Expand Down Expand Up @@ -1404,7 +1404,7 @@ fn inject_common_builtin(
}
"modf" | "frexp" => {
// bits layout
// bit 0 trough 1 - dims
// bit 0 through 1 - dims
for bits in 0..0b100 {
let size = match bits {
0b00 => None,
Expand Down Expand Up @@ -1478,7 +1478,7 @@ fn inject_common_builtin(
}
"outerProduct" => {
// bits layout
// bit 0 trough 3 - dims
// bit 0 through 3 - dims
for bits in 0..0b1001 {
let (size1, size2) = match bits {
0b0000 => (VectorSize::Bi, VectorSize::Bi),
Expand Down Expand Up @@ -1512,7 +1512,7 @@ fn inject_common_builtin(
}
"faceforward" | "fma" => {
// bits layout
// bit 0 trough 1 - dims
// bit 0 through 1 - dims
for bits in 0..0b100 {
let size = match bits {
0b00 => None,
Expand Down Expand Up @@ -1545,7 +1545,7 @@ fn inject_common_builtin(
}
"refract" => {
// bits layout
// bit 0 trough 1 - dims
// bit 0 through 1 - dims
for bits in 0..0b100 {
let size = match bits {
0b00 => None,
Expand Down Expand Up @@ -1580,7 +1580,7 @@ fn inject_common_builtin(
}
"smoothstep" => {
// bit 0 - splatted
// bit 1 trough 2 - dims
// bit 1 through 2 - dims
for bits in 0..0b1000 {
let splatted = bits & 0b1 == 0b1;
let size = match bits >> 1 {
Expand Down Expand Up @@ -2391,7 +2391,7 @@ pub fn sampled_to_depth(
// Copy the handle to allow borrowing the `ctx` again
let ty = *ty;

// If the image was passed trough a function argument we also need to change
// If the image was passed through a function argument we also need to change
// the corresponding parameter
if let Expression::FunctionArgument(i) = ctx[image] {
ctx.parameters[i as usize] = ty;
Expand Down
22 changes: 19 additions & 3 deletions src/front/glsl/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,24 @@ impl ExprPos {
pub struct Context {
pub expressions: Arena<Expression>,
pub locals: Arena<LocalVariable>,

/// The [`FunctionArgument`]s for the final [`crate::Function`].
///
/// Parameters with the `out` and `inout` qualifiers have [`Pointer`] types
/// here. For example, an `inout vec2 a` argument would be a [`Pointer`] to
/// a [`Vector`].
///
/// [`Pointer`]: crate::TypeInner::Pointer
/// [`Vector`]: crate::TypeInner::Vector
pub arguments: Vec<FunctionArgument>,

/// The parameter types given in the source code.
///
/// The `out` and `inout` qualifiers don't affect the types that appear
/// here. For example, an `inout vec2 a` argument would simply be a
/// [`Vector`], not a pointer to one.
///
/// [`Vector`]: crate::TypeInner::Vector
pub parameters: Vec<Handle<Type>>,
pub parameters_info: Vec<ParameterInfo>,

Expand Down Expand Up @@ -1019,7 +1035,7 @@ impl Context {
}
ExprPos::AccessBase { constant_index } => {
// If the index isn't constant all accesses backed by a constant base need
// to be done trough a proxy local variable, since constants have a non
// to be done through a proxy local variable, since constants have a non
// pointer type which is required for dynamic indexing
if !constant_index {
if let Some((constant, ty)) = var.constant {
Expand Down Expand Up @@ -1575,11 +1591,11 @@ impl Index<Handle<Expression>> for Context {

/// Helper struct passed when parsing expressions
///
/// This struct should only be obtained trough [`stmt_ctx`](Context::stmt_ctx)
/// This struct should only be obtained through [`stmt_ctx`](Context::stmt_ctx)
/// and only one of these may be active at any time per context.
#[derive(Debug)]
pub struct StmtContext {
/// A arena of high level expressions which can be lowered trough a
/// A arena of high level expressions which can be lowered through a
/// [`Context`](Context) to naga's [`Expression`](crate::Expression)s
pub hir_exprs: Arena<HirExpr>,
}
Expand Down
4 changes: 2 additions & 2 deletions src/front/glsl/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ impl Frontend {
// conversions used for querying the best overload
let mut new_conversions = vec![Conversion::None; args.len()];

// Loop trough the overload parameters and check if the current overload is better
// Loop through the overload parameters and check if the current overload is better
// compared to the previous best overload.
for (i, overload_parameter) in overload.parameters.iter().enumerate() {
let call_argument = &args[i];
Expand Down Expand Up @@ -875,7 +875,7 @@ impl Frontend {
let mut arguments = Vec::with_capacity(args.len());
let mut proxy_writes = Vec::new();

// Iterate trough the function call arguments applying transformations as needed
// Iterate through the function call arguments applying transformations as needed
for (((parameter_info, call_argument), expr), parameter) in parameters_info
.iter()
.zip(&args)
Expand Down
4 changes: 2 additions & 2 deletions src/front/glsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ impl From<ShaderStage> for Options {
/// stored in the shader [`Module`](Module).
#[derive(Debug)]
pub struct ShaderMetadata {
/// The GLSL version specified in the shader trough the use of the
/// The GLSL version specified in the shader through the use of the
/// `#version` preprocessor directive.
pub version: u16,
/// The GLSL profile specified in the shader trough the use of the
/// The GLSL profile specified in the shader through the use of the
/// `#version` preprocessor directive.
pub profile: Profile,
/// The shader stage in the pipeline, passed to the [`parse`](Frontend::parse)
Expand Down
2 changes: 1 addition & 1 deletion src/front/glsl/parser/declarations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ impl<'source> ParsingContext<'source> {

// If program execution has reached here then this will be a
// init_declarator_list
// token_falltrough will have a token that was already bumped
// token_fallthrough will have a token that was already bumped
if let Some(ty) = ty {
let mut ctx = DeclarationContext {
qualifiers,
Expand Down
8 changes: 4 additions & 4 deletions src/front/glsl/parser/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ impl<'source> ParsingContext<'source> {
// to have any cases.
if let Some(case) = cases.last_mut() {
// GLSL requires that the last case not be empty, so we check
// that here and produce an error otherwise (fall_trough must
// that here and produce an error otherwise (fall_through must
// also be checked because `break`s count as statements but
// they aren't added to the body)
if case.body.is_empty() && case.fall_through {
Expand All @@ -299,9 +299,9 @@ impl<'source> ParsingContext<'source> {
}

// GLSL allows the last case to not have any `break` statement,
// this would mark it as fall trough but naga's IR requires that
// the last case must not be fall trough, so we mark need to mark
// the last case as not fall trough always.
// this would mark it as fall through but naga's IR requires that
// the last case must not be fall through, so we mark need to mark
// the last case as not fall through always.
case.fall_through = false;
}

Expand Down

0 comments on commit dce689c

Please sign in to comment.