-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Implement the fmod
HLSL Function
#99118
Comments
I'll work on this task. |
This change implements the frontend for llvm#99118 Builtins.td - add the fmod builtin CGBuiltin.cpp - add the builtin to DirectX intrinsic mapping hlsl_intrinsics.h - add the fmod api SemaHLSL.cpp - add type checks for builtin IntrinsicsDirectX.td - add the fmod DirectX intrinsic
This change implements the frontend for llvm#99118 Builtins.td - add the fmod builtin CGBuiltin.cpp - lower the builtin to llvm FRem instruction hlsl_intrinsics.h - add the fmod api SemaHLSL.cpp - add type checks for builtin clang/docs/LanguageExtensions.rst - add the builtin in *Elementwise Builtins*
This change implements the frontend for llvm#99118 Builtins.td - add the fmod builtin CGBuiltin.cpp - lower the builtin to llvm FRem instruction hlsl_intrinsics.h - add the fmod api SemaHLSL.cpp - add type checks for builtin clang/docs/LanguageExtensions.rst - add the builtin in *Elementwise Builtins*
This change implements the frontend for llvm#99118 Builtins.td - add the fmod builtin CGBuiltin.cpp - lower the builtin to llvm FRem instruction hlsl_intrinsics.h - add the fmod api SemaHLSL.cpp - add type checks for builtin clang/docs/LanguageExtensions.rst - add the builtin in *Elementwise Builtins* clang/docs/ReleaseNotes.rst - announce the builtin
This change add the elementwise fmod builtin to support HLSL function 'fmod' in clang for llvm#99118 Builtins.td - add the fmod builtin CGBuiltin.cpp - lower the builtin to llvm FRem instruction hlsl_intrinsics.h - add the fmod api SemaChecking.cpp - add type checks for builtin SemaHLSL.cpp - add HLSL type checks for builtin clang/docs/LanguageExtensions.rst - add the builtin in *Elementwise Builtins* clang/docs/ReleaseNotes.rst - announce the builtin
This change add the elementwise fmod builtin to support HLSL function 'fmod' in clang for llvm#99118 Builtins.td - add the fmod builtin CGBuiltin.cpp - lower the builtin to llvm FRem instruction hlsl_intrinsics.h - add the fmod api SemaChecking.cpp - add type checks for builtin SemaHLSL.cpp - add HLSL type checks for builtin clang/docs/LanguageExtensions.rst - add the builtin in *Elementwise Builtins* clang/docs/ReleaseNotes.rst - announce the builtin
This change add the elementwise fmod builtin to support HLSL function 'fmod' in clang for llvm#99118 Builtins.td - add the fmod builtin CGBuiltin.cpp - lower the builtin to llvm FRem instruction hlsl_intrinsics.h - add the fmod api SemaChecking.cpp - add type checks for builtin SemaHLSL.cpp - add HLSL type checks for builtin clang/docs/LanguageExtensions.rst - add the builtin in *Elementwise Builtins* clang/docs/ReleaseNotes.rst - announce the builtin
This change add the elementwise fmod builtin to support HLSL function 'fmod' in clang for llvm#99118 Builtins.td - add the fmod builtin CGBuiltin.cpp - lower the builtin to llvm FRem instruction hlsl_intrinsics.h - add the fmod api SemaChecking.cpp - add type checks for builtin SemaHLSL.cpp - add HLSL type checks for builtin clang/docs/LanguageExtensions.rst - add the builtin in *Elementwise Builtins* clang/docs/ReleaseNotes.rst - announce the builtin
This change add the elementwise fmod builtin to support HLSL function 'fmod' in clang for #99118 Builtins.td - add the fmod builtin CGBuiltin.cpp - lower the builtin to llvm FRem instruction hlsl_intrinsics.h - add the fmod api SemaChecking.cpp - add type checks for builtin SemaHLSL.cpp - add HLSL type checks for builtin clang/docs/LanguageExtensions.rst - add the builtin in *Elementwise Builtins* clang/docs/ReleaseNotes.rst - announce the builtin
We want to decide llvm/wg-hlsl#86 before we continue with this. |
I'll be taking on this task. |
@kmpeng @V-FEXrt had some concerns about vec1s. I noticed we aren't restricing vector sizes and we probably should. My idea for thst is the following: template <int N, typename = std::enable_if_t<(N > 1 && N <=4)>>
const inline vector<float, N> fmod(vector<float, N> X, vector<float, N> Y) {
return __detail::fmod_vec_impl(X, Y);
}
_HLSL_AVAILABILITY(shadermodel, 6.9)
template <int N, typename = std::enable_if_t<(N >4)>>
const inline vector<float, N> fmod(vector<float, N> X, vector<float, N> Y) {
return __detail::fmod_vec_impl(X, Y);
} I filed a bug to fix up the other intrinsics here: #129003 |
@farzonl yeah we were talking about that yesterday. The expectation is that a vec1 would get cast/scalarized right? |
@V-FEXrt not via this ticket. We haven’t supported vec1s for any of the non templatized intrinsics. We shouldn’t be adding it as an overload for fmod or any of the ones mentioned in the above mentioned bug. If they would get cast/scalarized/whatever that would be via overload resolution rules. We are probably screwing up those resolutions by having intrinsics that can take in vec1s |
Got it, makes sense |
fmod is currently defined as
replace it with a templatized version
This should call a version in
clang/lib/Headers/hlsl/hlsl_detail.h
that will do the target switching for us.
DirectX
For reference the algorithm you are expected to implement in HLSL source shold match the DXC implementation.
Please find the reference implmentation linked here: https://github.com/microsoft/DirectXShaderCompiler/blob/c2ed9ad4ee775f3de903ce757c994aecc59a5306/lib/HLSL/HLOperationLower.cpp#L2253C1-L2271C2
SPIR-V
OpFRem:
Description:
The floating-point remainder whose sign matches the sign
of Operand 1.
Result Type must be a scalar or vector of floating-point
type.
The types of Operand 1 and Operand 2 both must be the same as
Result Type.
Results are computed per component. The resulting value is undefined if
Operand 2 is 0. Otherwise, the result is the remainder
r of Operand 1 divided by Operand 2 where if r ≠ 0, the sign of
r is the same as the sign of Operand 1.
5
140
<id>
Result Type
Result <id>
<id>
Operand 1
<id>
Operand 2
Test Case(s)
Example 1
HLSL:
Returns the floating-point remainder of x/y.
Parameters
Return Value
The floating-point remainder of the x parameter divided by the y parameter.
Remarks
The floating-point remainder is calculated such that x = i * y + f, where i is an integer, f has the same sign as x, and the absolute value of f is less than the absolute value of y.
Type Description
Minimum Shader Model
This function is supported in the following shader models.
Requirements
See also
Intrinsic Functions (DirectX HLSL)
The text was updated successfully, but these errors were encountered: