Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glsl-in: Splat inputs for smoothstep if needed #1976

Merged
merged 1 commit into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/front/glsl/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,7 @@ fn inject_common_builtin(
};
declaration.overloads.push(module.add_builtin(
vec![ty(), ty(), base_ty()],
MacroCall::MathFunction(MathFunction::SmoothStep),
MacroCall::SmoothStep { splatted: size },
))
}
}
Expand Down Expand Up @@ -1604,6 +1604,12 @@ pub enum MacroCall {
BitCast(Sk),
Derivate(DerivativeAxis),
Barrier,
/// SmoothStep needs a separate variant because it might need it's inputs
/// to be splatted depending on the overload
SmoothStep {
/// The size of the splat operation if some
splatted: Option<VectorSize>,
},
}

impl MacroCall {
Expand Down Expand Up @@ -2072,6 +2078,22 @@ impl MacroCall {
body.push(crate::Statement::Barrier(crate::Barrier::all()), meta);
return Ok(None);
}
MacroCall::SmoothStep { splatted } => {
ctx.implicit_splat(parser, &mut args[0], meta, splatted)?;
ctx.implicit_splat(parser, &mut args[1], meta, splatted)?;

ctx.add_expression(
Expression::Math {
fun: MathFunction::SmoothStep,
arg: args[0],
arg1: args.get(1).copied(),
arg2: args.get(2).copied(),
arg3: None,
},
Span::default(),
body,
)
}
}))
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/in/glsl/math-functions.vert
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,7 @@ void main() {
// float ldexpOut = ldexp(a.x, i);
vec4 rad = radians(a);
float deg = degrees(a.x);
float smoothStepScalar = smoothstep(0.0, 1.0, 0.5);
vec4 smoothStepVector = smoothstep(vec4(0.0), vec4(1.0), vec4(0.5));
vec4 smoothStepMixed = smoothstep(0.0, 1.0, vec4(0.5));
}
10 changes: 10 additions & 0 deletions tests/out/wgsl/math-functions-vert.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ fn main_1() {
var stepOut: vec4<f32>;
var rad: vec4<f32>;
var deg: f32;
var smoothStepScalar: f32;
var smoothStepVector: vec4<f32>;
var smoothStepMixed: vec4<f32>;

_ = vec4<f32>(1.0);
_ = vec4<f32>(2.0);
Expand Down Expand Up @@ -205,6 +208,13 @@ fn main_1() {
_ = _e233.x;
let _e235 = a;
deg = degrees(_e235.x);
smoothStepScalar = smoothstep(0.0, 1.0, 0.5);
_ = vec4<f32>(0.0);
_ = vec4<f32>(1.0);
_ = vec4<f32>(0.5);
smoothStepVector = smoothstep(vec4<f32>(0.0), vec4<f32>(1.0), vec4<f32>(0.5));
_ = vec4<f32>(0.5);
smoothStepMixed = smoothstep(vec4<f32>(0.0), vec4<f32>(1.0), vec4<f32>(0.5));
return;
}

Expand Down