Skip to content

Commit

Permalink
Add formating checks to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
JCapucho authored and kvark committed Sep 19, 2021
1 parent d7ca7d4 commit 9b34d50
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 45 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,17 @@ jobs:
with:
command: doc
args: -p naga --all-features --document-private-items
fmt:
name: Format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt
- name: run rustfmt
run: |
cargo fmt -- --check
7 changes: 0 additions & 7 deletions .monocodus

This file was deleted.

177 changes: 139 additions & 38 deletions src/front/glsl/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ fn make_coords_arg(number_of_components: usize, kind: Sk) -> TypeInner {
let width = 4;

match number_of_components {
1 => TypeInner::Scalar {
kind,
width,
},
1 => TypeInner::Scalar { kind, width },
_ => TypeInner::Vector {
size: match number_of_components {
2 => VectorSize::Bi,
Expand Down Expand Up @@ -138,9 +135,18 @@ pub fn inject_builtin(declaration: &mut FunctionDeclaration, module: &mut Module
))
}
}
"texture" | "textureGrad" | "textureGradOffset" | "textureLod" | "textureLodOffset" | "textureOffset"
| "textureProj" | "textureProjGrad" | "textureProjGradOffset" | "textureProjLod"
| "textureProjLodOffset" | "textureProjOffset" => {
"texture"
| "textureGrad"
| "textureGradOffset"
| "textureLod"
| "textureLodOffset"
| "textureOffset"
| "textureProj"
| "textureProjGrad"
| "textureProjGradOffset"
| "textureProjLod"
| "textureProjLodOffset"
| "textureProjOffset" => {
// bits layout
// bits 0 through 1 - dims
// bit 2 - shadow
Expand All @@ -157,44 +163,122 @@ pub fn inject_builtin(declaration: &mut FunctionDeclaration, module: &mut Module

let builtin = match name {
// texture(gsampler, gvec P, [float bias]);
"texture" => MacroCall::Texture { proj: false, offset: false, shadow, level_type: TextureLevelType::None, },
"texture" => MacroCall::Texture {
proj: false,
offset: false,
shadow,
level_type: TextureLevelType::None,
},
// textureGrad(gsampler, gvec P, gvec dPdx, gvec dPdy);
"textureGrad" => MacroCall::Texture { proj: false, offset: false, shadow, level_type: TextureLevelType::Grad, },
"textureGrad" => MacroCall::Texture {
proj: false,
offset: false,
shadow,
level_type: TextureLevelType::Grad,
},
// textureGradOffset(gsampler, gvec P, gvec dPdx, gvec dPdy, ivec offset);
"textureGradOffset" => MacroCall::Texture { proj: false, offset: true, shadow, level_type: TextureLevelType::Grad, },
"textureGradOffset" => MacroCall::Texture {
proj: false,
offset: true,
shadow,
level_type: TextureLevelType::Grad,
},
// textureLod(gsampler, gvec P, float lod);
"textureLod" => MacroCall::Texture { proj: false, offset: false, shadow, level_type: TextureLevelType::Lod, },
"textureLod" => MacroCall::Texture {
proj: false,
offset: false,
shadow,
level_type: TextureLevelType::Lod,
},
// textureLodOffset(gsampler, gvec P, float lod, ivec offset);
"textureLodOffset" => MacroCall::Texture { proj: false, offset: true, shadow, level_type: TextureLevelType::Lod, },
"textureLodOffset" => MacroCall::Texture {
proj: false,
offset: true,
shadow,
level_type: TextureLevelType::Lod,
},
// textureOffset(gsampler, gvec+1 P, ivec offset, [float bias]);
"textureOffset" => MacroCall::Texture { proj: false, offset: true, shadow, level_type: TextureLevelType::None, },
"textureOffset" => MacroCall::Texture {
proj: false,
offset: true,
shadow,
level_type: TextureLevelType::None,
},
// textureProj(gsampler, gvec+1 P, [float bias]);
"textureProj" => MacroCall::Texture { proj: true, offset: false, shadow, level_type: TextureLevelType::None, },
"textureProj" => MacroCall::Texture {
proj: true,
offset: false,
shadow,
level_type: TextureLevelType::None,
},
// textureProjGrad(gsampler, gvec+1 P, gvec dPdx, gvec dPdy);
"textureProjGrad" => MacroCall::Texture { proj: true, offset: false, shadow, level_type: TextureLevelType::Grad, },
"textureProjGrad" => MacroCall::Texture {
proj: true,
offset: false,
shadow,
level_type: TextureLevelType::Grad,
},
// textureProjGradOffset(gsampler, gvec+1 P, gvec dPdx, gvec dPdy, ivec offset);
"textureProjGradOffset" => MacroCall::Texture { proj: true, offset: true, shadow, level_type: TextureLevelType::Grad, },
"textureProjGradOffset" => MacroCall::Texture {
proj: true,
offset: true,
shadow,
level_type: TextureLevelType::Grad,
},
// textureProjLod(gsampler, gvec+1 P, float lod);
"textureProjLod" => MacroCall::Texture { proj: true, offset: false, shadow, level_type: TextureLevelType::Lod, },
"textureProjLod" => MacroCall::Texture {
proj: true,
offset: false,
shadow,
level_type: TextureLevelType::Lod,
},
// textureProjLodOffset(gsampler, gvec+1 P, gvec dPdx, gvec dPdy, ivec offset);
"textureProjLodOffset" => MacroCall::Texture { proj: true, offset: true, shadow, level_type: TextureLevelType::Lod, },
"textureProjLodOffset" => MacroCall::Texture {
proj: true,
offset: true,
shadow,
level_type: TextureLevelType::Lod,
},
// textureProjOffset(gsampler, gvec+1 P, ivec offset, [float bias]);
"textureProjOffset" => MacroCall::Texture { proj: true, offset: true, shadow, level_type: TextureLevelType::None, },
"textureProjOffset" => MacroCall::Texture {
proj: true,
offset: true,
shadow,
level_type: TextureLevelType::None,
},
_ => unreachable!(),
};

// Parse out the variant settings.
let proj = matches!(builtin, MacroCall::Texture { proj: true, .. });
let grad = matches!(builtin, MacroCall::Texture { level_type: TextureLevelType::Grad, .. });
let lod = matches!(builtin, MacroCall::Texture { level_type: TextureLevelType::Lod, .. });
let grad = matches!(
builtin,
MacroCall::Texture {
level_type: TextureLevelType::Grad,
..
}
);
let lod = matches!(
builtin,
MacroCall::Texture {
level_type: TextureLevelType::Lod,
..
}
);
let offset = matches!(builtin, MacroCall::Texture { offset: true, .. });

let supports_variant = proj && !shadow;
if variant && !supports_variant {
continue;
}

let supports_bias = matches!(builtin, MacroCall::Texture { level_type: TextureLevelType::None, .. }) && !shadow;
let supports_bias = matches!(
builtin,
MacroCall::Texture {
level_type: TextureLevelType::None,
..
}
) && !shadow;
if bias && !supports_bias {
continue;
}
Expand Down Expand Up @@ -275,17 +359,23 @@ pub fn inject_builtin(declaration: &mut FunctionDeclaration, module: &mut Module
}

match builtin {
MacroCall::Texture { level_type: TextureLevelType::Lod, .. } => {
MacroCall::Texture {
level_type: TextureLevelType::Lod,
..
} => {
args.push(TypeInner::Scalar {
kind: Sk::Float,
width,
});
},
MacroCall::Texture { level_type: TextureLevelType::Grad, .. } => {
}
MacroCall::Texture {
level_type: TextureLevelType::Grad,
..
} => {
args.push(make_coords_arg(num_coords_from_dim, Sk::Float));
args.push(make_coords_arg(num_coords_from_dim, Sk::Float));
},
_ => {},
}
_ => {}
};

if offset {
Expand Down Expand Up @@ -1344,7 +1434,11 @@ fn inject_common_builtin(
}

#[derive(Clone, Copy, PartialEq, Debug)]
pub enum TextureLevelType { None, Lod, Grad }
pub enum TextureLevelType {
None,
Lod,
Grad,
}

/// A compiler defined builtin function
#[derive(Clone, Copy, PartialEq, Debug)]
Expand Down Expand Up @@ -1393,7 +1487,12 @@ impl MacroCall {
ctx.samplers.insert(args[0], args[1]);
Ok(args[0])
}
MacroCall::Texture { proj, offset, shadow, level_type } => {
MacroCall::Texture {
proj,
offset,
shadow,
level_type,
} => {
let mut coords = args[1];

if proj {
Expand All @@ -1411,7 +1510,10 @@ impl MacroCall {
);
let left = if let VectorSize::Bi = size {
ctx.add_expression(
Expression::AccessIndex { base: coords, index: 0 },
Expression::AccessIndex {
base: coords,
index: 0,
},
SourceMetadata::none(),
body,
)
Expand Down Expand Up @@ -1439,7 +1541,8 @@ impl MacroCall {
}

let extra = args.get(2).copied();
let comps = parser.coordinate_components(ctx, args[0], coords, extra, meta, body)?;
let comps =
parser.coordinate_components(ctx, args[0], coords, extra, meta, body)?;

let mut num_args = 2;

Expand All @@ -1455,10 +1558,7 @@ impl MacroCall {
num_args += 1;

if shadow {
log::warn!(
"Assuming LOD {:?} is zero",
args[2],
);
log::warn!("Assuming LOD {:?} is zero", args[2],);

SampleLevel::Zero
} else {
Expand Down Expand Up @@ -1494,10 +1594,10 @@ impl MacroCall {
Err(e) => {
parser.errors.push(e);
None
},
}
}
}
false => None
false => None,
};

// Now go back and look for optional bias arg (if available)
Expand All @@ -1521,7 +1621,8 @@ impl MacroCall {
body,
)),
MacroCall::TexelFetch => {
let comps = parser.coordinate_components(ctx, args[0], args[1], None, meta, body)?;
let comps =
parser.coordinate_components(ctx, args[0], args[1], None, meta, body)?;
Ok(ctx.add_expression(
Expression::ImageLoad {
image: args[0],
Expand Down

0 comments on commit 9b34d50

Please sign in to comment.