-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[HLSL] add extra scalar vector overloads for clamp #129939
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
16 commits
Select commit
Hold shift + click to select a range
23debaf
extra scalar vector overloads for clamp
spall 44a41cc
make clang format happy
spall ac260e6
implement clamp overloads with templates instead of macros
spall 3311cbd
update semantic checking for __builtin_hlsl_elementwise_clamp; update…
spall fec28cf
make clang format happy
spall 101beb2
make clang format happy again
spall 69dab19
self review + respond to pr comments
spall 47c90c4
add vector size checks to clamp templates
spall dd0765a
make clang format happy
spall 819cae5
test for float5 error
spall 8e01d99
fix two tests
spall 4ed0507
change clamp templates so they call clamp instead of __builtin_hlsl_e…
spall 2807d0e
put test for each type in own file
spall 9636c1f
address pr comments
spall 65c4967
fix typo
spall eaa7cb9
fix return type in test
spall 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//===--- hlsl_compat_overloads.h - Extra HLSL overloads for 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_COMPAT_OVERLOADS_H_ | ||
#define _HLSl_COMPAT_OVERLOADS_H_ | ||
|
||
namespace hlsl { | ||
|
||
// Note: Functions in this file are sorted alphabetically, then grouped by base | ||
// element type, and the element types are sorted by size, then singed integer, | ||
// unsigned integer and floating point. Keeping this ordering consistent will | ||
// help keep this file manageable as it grows. | ||
|
||
//===----------------------------------------------------------------------===// | ||
// clamp builtins overloads | ||
//===----------------------------------------------------------------------===// | ||
|
||
template <typename T, typename R, typename U, uint N> | ||
constexpr __detail::enable_if_t< | ||
__detail::is_arithmetic<U>::Value && (N > 1 && N <= 4), vector<T, N>> | ||
clamp(vector<T, N> p0, vector<R, N> p1, U p2) { | ||
return clamp(p0, (vector<T, N>)p1, (vector<T, N>)p2); | ||
} | ||
template <typename T, typename R, typename U, uint N> | ||
constexpr __detail::enable_if_t< | ||
__detail::is_arithmetic<U>::Value && (N > 1 && N <= 4), vector<T, N>> | ||
clamp(vector<T, N> p0, U p1, vector<R, N> p2) { | ||
return clamp(p0, (vector<T, N>)p1, (vector<T, N>)p2); | ||
} | ||
template <typename T, typename U, typename V, uint N> | ||
constexpr __detail::enable_if_t<__detail::is_arithmetic<U>::Value && | ||
__detail::is_arithmetic<V>::Value && | ||
(N > 1 && N <= 4), | ||
vector<T, N>> | ||
clamp(vector<T, N> p0, U p1, V p2) { | ||
return clamp(p0, (vector<T, N>)p1, (vector<T, N>)p2); | ||
} | ||
template <typename T, typename R, typename S, uint N> | ||
constexpr __detail::enable_if_t<(N > 1 && N <= 4), vector<T, N>> | ||
clamp(vector<T, N> p0, vector<R, N> p1, vector<S, N> p2) { | ||
return clamp(p0, (vector<T, N>)p1, (vector<T, N>)p2); | ||
} | ||
template <typename U, typename V, typename W> | ||
constexpr __detail::enable_if_t<__detail::is_arithmetic<U>::Value && | ||
__detail::is_arithmetic<V>::Value && | ||
__detail::is_arithmetic<W>::Value, | ||
U> | ||
clamp(U p0, V p1, W p2) { | ||
return clamp(p0, (U)p1, (U)p2); | ||
} | ||
|
||
} // namespace hlsl | ||
#endif // _HLSL_COMPAT_OVERLOADS_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// RUN: not %clang_dxc -enable-16bit-types -T cs_6_0 -HV 202x %s 2>&1 | FileCheck %s -DTEST_TYPE=half | ||
// RUN: not %clang_dxc -enable-16bit-types -T cs_6_0 -HV 202x %s 2>&1 | FileCheck %s -DTEST_TYPE=half3 | ||
// RUN: not %clang_dxc -enable-16bit-types -T cs_6_0 -HV 202x %s 2>&1 | FileCheck %s -DTEST_TYPE=int16_t | ||
// RUN: not %clang_dxc -enable-16bit-types -T cs_6_0 -HV 202x %s 2>&1 | FileCheck %s -DTEST_TYPE=int16_t3 | ||
// RUN: not %clang_dxc -enable-16bit-types -T cs_6_0 -HV 202x %s 2>&1 | FileCheck %s -DTEST_TYPE=uint16_t | ||
// RUN: not %clang_dxc -enable-16bit-types -T cs_6_0 -HV 202x %s 2>&1 | FileCheck %s -DTEST_TYPE=uint16_t3 | ||
|
||
// check we error on 16 bit type if shader model is too old | ||
// CHECK: '-enable-16bit-types' option requires target HLSL Version >= 2018 and shader model >= 6.2, but HLSL Version is 'hlsl202x' and shader model is '6.0' | ||
TEST_TYPE test_half_error(TEST_TYPE p0, int p1) { | ||
return clamp(p0, p1, p1); | ||
} |
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
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.