Skip to content

[HLSL] reflect, distance, and length intrinsics are not restricting vector size #129003

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

Closed
farzonl opened this issue Feb 27, 2025 · 0 comments · Fixed by #130724
Closed

[HLSL] reflect, distance, and length intrinsics are not restricting vector size #129003

farzonl opened this issue Feb 27, 2025 · 0 comments · Fixed by #130724
Labels
clang:headers Headers provided by Clang, e.g. for intrinsics HLSL HLSL Language Support

Comments

@farzonl
Copy link
Member

farzonl commented Feb 27, 2025

template <int L>
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
const inline vector<half, L> reflect(vector<half, L> I, vector<half, L> N) {
return __detail::reflect_vec_impl(I, N);
}
template <int L>
const inline vector<float, L> reflect(vector<float, L> I, vector<float, L> N) {
return __detail::reflect_vec_impl(I, N);
}

template <int N>
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
const inline half length(vector<half, N> X) {
return __detail::length_vec_impl(X);
}
template <int N> const inline float length(vector<float, N> X) {
return __detail::length_vec_impl(X);
}

template <int N>
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
const inline half distance(vector<half, N> X, vector<half, N> Y) {
return __detail::distance_vec_impl(X, Y);
}
template <int N>
const inline float distance(vector<float, N> X, vector<float, N> Y) {
return __detail::distance_vec_impl(X, Y);
}

The fix:
we need to exclude vec1s and limit to vec4. the apis need something similar to c++

 std::enable_if_t<(N > 1 && N <=4)

Long term we will want to support long vectors we may want to do those like so

_HLSL_AVAILABILITY(shadermodel, 6.9)
template <int N, typename = std::enable_if_t<(N >4)>>

For this ticket though we will only restrict the vector range.

Obviously std can't work maybe we can do something like:

template <int N>
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
const inline __detail::enable_if_t<(N > 1 && N <= 4),half>
distance(vector<half, N> X, vector<half, N> Y) {
  return __detail::distance_vec_impl(X, Y);
}

template <int N>
const inline __detail::enable_if_t<(N > 1 && N <= 4),float>
distance(vector<float, N> X, vector<float, N> Y) {
  return __detail::distance_vec_impl(X, Y);
}

template <int N>
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
const inline __detail::enable_if_t<(N > 1 && N <= 4),half>
length(vector<half, N> X) {
  return __detail::length_vec_impl(X);
}

template <int N>
const inline __detail::enable_if_t<(N > 1 && N <= 4),float>
length(vector<float, N> X) {
  return __detail::length_vec_impl(X);
}

template <int L>
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
const inline __detail::enable_if_t<(L > 1 && L <= 4),vector<half, L>>
reflect(vector<half, L> I, vector<half, L> N) {
  return __detail::reflect_vec_impl(I, N);
}

template <int L>
const inline __detail::enable_if_t<(L > 1 && L <= 4),vector<float, L>>
reflect(vector<float, L> I, vector<float, L> N) {
  return __detail::reflect_vec_impl(I, N);
}

Will likely need to see what other options are to restrict vector ranges.

@farzonl farzonl added the HLSL HLSL Language Support label Feb 27, 2025
@farzonl farzonl self-assigned this Mar 4, 2025
farzonl added a commit to farzonl/llvm-project that referenced this issue Mar 4, 2025
- fixes llvm#129616
- fixes llvm#129003 by adding enable_if_t vector ranges.
- alphabetize the or intrinsic
@farzonl farzonl removed their assignment Mar 4, 2025
farzonl added a commit to farzonl/llvm-project that referenced this issue Mar 11, 2025
fixes llvm#129003
- fix up sema tests
- fix up templates for scalar and vector HLSL intrinsic overloads
farzonl added a commit to farzonl/llvm-project that referenced this issue Mar 11, 2025
fixes llvm#129003
- fix up sema tests
- fix up templates for scalar and vector HLSL intrinsic overloads
farzonl added a commit that referenced this issue Mar 11, 2025
…es (#130724)

fixes #129003
- fix up sema tests
- fix up templates for scalar and vector HLSL intrinsic overloads
@EugeneZelenko EugeneZelenko added the clang:headers Headers provided by Clang, e.g. for intrinsics label Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:headers Headers provided by Clang, e.g. for intrinsics HLSL HLSL Language Support
Projects
Status: Closed
Development

Successfully merging a pull request may close this issue.

2 participants