Skip to content

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

@farzonl

Description

@farzonl

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.

Activity

added theissue type on Feb 27, 2025
self-assigned this
on Mar 4, 2025
added a commit that references this issue on Mar 4, 2025
4f04569
removed their assignment
on Mar 4, 2025
added a commit that references this issue on Mar 11, 2025
17386ba
added a commit that references this issue on Mar 11, 2025
1cb1407
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    HLSLHLSL Language Supportclang:headersHeaders provided by Clang, e.g. for intrinsics

    Type

    Projects

    Status

    Closed

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @farzonl@EugeneZelenko

      Issue actions

        [HLSL] reflect, distance, and length intrinsics are not restricting vector size · Issue #129003 · llvm/llvm-project