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] Implement MathFunction::Clamp #1502

Merged
merged 4 commits into from
Apr 11, 2022

Conversation

sjinno
Copy link
Contributor

@sjinno sjinno commented Nov 1, 2021

As the title says, added the implementation of MathFunction::Clamp. Feedback is very much appreciated! :)

@cwfitzgerald cwfitzgerald added area: front-end Input formats for conversion lang: GLSL OpenGL Shading Language and removed area: front-end Input formats for conversion lang: GLSL OpenGL Shading Language labels Nov 1, 2021
@cwfitzgerald cwfitzgerald changed the title Implement MathFunction::Clamp [glsl-in] Implement MathFunction::Clamp Nov 1, 2021
},
width,
),
_ => return Err(ConstantSolvingError::InvalidMathArg),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, Naga IR follows the WGSL spec, and that says that the clamp function operates "component-wise when [the argument type] is a vector". It's fine not to bother handling vector arguments for now, but this should be a NotImplemented error, not an InvalidMathArg error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, though I haven't handled vector arguments yet.

src/front/glsl/constants.rs Outdated Show resolved Hide resolved
@sjinno sjinno marked this pull request as draft November 3, 2021 14:49
@sjinno sjinno marked this pull request as ready for review November 3, 2021 19:01
Copy link
Collaborator

@JCapucho JCapucho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some concerns related to NaNs handling, that I would like addressed

src/front/glsl/constants.rs Outdated Show resolved Hide resolved
src/front/glsl/constants.rs Outdated Show resolved Hide resolved
@JCapucho JCapucho linked an issue Nov 7, 2021 that may be closed by this pull request
Change `ConstantSolvingError::InvalidMathArg` to `ConstantSolvingError::NotImplemented`
for the clamp function with the input of unimplemented types.

Unimplemented types:
    - vec2
    - vec3
    - vec4
@sjinno sjinno force-pushed the 1498-implement-clamp branch 3 times, most recently from b32c826 to 40ce0b9 Compare March 17, 2022 21:52
…ions.

Co-authored-by: JCapucho <jcapucho7@gmail.com>
Copy link
Collaborator

@JCapucho JCapucho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just need to wait on @jimblandy approval

Copy link
Member

@jimblandy jimblandy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor comments - other than that, this looks good.

Comment on lines 562 to 564
/// While rust does provide a `f64::max` method it has a different behavior than the
/// glsl `max` for `NaN`s, in rust if any of the arguments is a `NaN` then the other
/// is returned.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalize "Rust", and write "GLSL" in all caps. Also, this is a run-on sentence; please change ", in rust if" to ". In Rust, if"

/// std::f64::NAN.max(1.0);
/// ```
///
/// Rust will return 1.0 while glsl should return NaN
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing period at end of sentence.

}
}

/// Helper function to implement the glsl `min` function for floats
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments for glsl_float_min as glsl_float_max.

Copy link
Member

@jimblandy jimblandy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - thank you!

@jimblandy jimblandy merged commit b21634a into gfx-rs:master Apr 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[glsl-in] naga rejects use of clamp in constant initializer
4 participants