-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[HLSL] select scalar overloads for vector conditions #129396
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7620f9f
[HLSL] select scalar overloads for vector conditions
llvm-beanz c93ecf3
Added comments to address @spall's feedback and clang-format
llvm-beanz 135b1cd
Alother slight suffling of hlsl includes
llvm-beanz e69bf7e
NFC. Clang-format
llvm-beanz a33f73b
Make clang-format happy and don't break the include order
llvm-beanz e5fb51b
Adding some comments
llvm-beanz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
//===----- hlsl_intrinsic_helpers.h - HLSL helpers intrinsics -------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef _HLSL_HLSL_INTRINSIC_HELPERS_H_ | ||
#define _HLSL_HLSL_INTRINSIC_HELPERS_H_ | ||
|
||
namespace hlsl { | ||
namespace __detail { | ||
|
||
constexpr vector<uint, 4> d3d_color_to_ubyte4_impl(vector<float, 4> V) { | ||
// Use the same scaling factor used by FXC, and DXC for DXIL | ||
// (i.e., 255.001953) | ||
// https://github.com/microsoft/DirectXShaderCompiler/blob/070d0d5a2beacef9eeb51037a9b04665716fd6f3/lib/HLSL/HLOperationLower.cpp#L666C1-L697C2 | ||
// The DXC implementation refers to a comment on the following stackoverflow | ||
// discussion to justify the scaling factor: "Built-in rounding, necessary | ||
// because of truncation. 0.001953 * 256 = 0.5" | ||
// https://stackoverflow.com/questions/52103720/why-does-d3dcolortoubyte4-multiplies-components-by-255-001953f | ||
return V.zyxw * 255.001953f; | ||
} | ||
|
||
template <typename T> | ||
constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T> | ||
length_impl(T X) { | ||
return abs(X); | ||
} | ||
|
||
template <typename T, int N> | ||
constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T> | ||
length_vec_impl(vector<T, N> X) { | ||
#if (__has_builtin(__builtin_spirv_length)) | ||
return __builtin_spirv_length(X); | ||
#else | ||
return sqrt(dot(X, X)); | ||
#endif | ||
} | ||
|
||
template <typename T> | ||
constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T> | ||
distance_impl(T X, T Y) { | ||
return length_impl(X - Y); | ||
} | ||
|
||
template <typename T, int N> | ||
constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T> | ||
distance_vec_impl(vector<T, N> X, vector<T, N> Y) { | ||
return length_vec_impl(X - Y); | ||
} | ||
|
||
template <typename T> | ||
constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T> | ||
reflect_impl(T I, T N) { | ||
return I - 2 * N * I * N; | ||
} | ||
|
||
template <typename T, int L> | ||
constexpr vector<T, L> reflect_vec_impl(vector<T, L> I, vector<T, L> N) { | ||
#if (__has_builtin(__builtin_spirv_reflect)) | ||
return __builtin_spirv_reflect(I, N); | ||
#else | ||
return I - 2 * N * dot(I, N); | ||
#endif | ||
} | ||
} // namespace __detail | ||
} // namespace hlsl | ||
|
||
#endif // _HLSL_HLSL_INTRINSIC_HELPERS_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does the
enable_if_t
template inhlsl_detail.h
get exposed here? Does order inclang/lib/Headers/hlsl.h
matter I see you havehlsl_detail.h
beforehlsl_alias_intrinsics.h
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hlsl_detail.h is included first in hlsl.h, which makes it included before the other headers. These headers are all implementation details, and aren't expected to be exposed to user code since hlsl.h is implicitly included in all HLSL source files.