diff --git a/include/hlsl++_vector_float8.h b/include/hlsl++_vector_float8.h index 6bfa614..fc000af 100644 --- a/include/hlsl++_vector_float8.h +++ b/include/hlsl++_vector_float8.h @@ -503,6 +503,18 @@ namespace hlslpp hlslpp_inline float8(float8&& f) hlslpp_noexcept : vec(f.vec) {} hlslpp_inline float8& operator = (float8&& f) hlslpp_noexcept { vec = f.vec; return *this; } + float& operator[](int N) + { + hlslpp_assert(N >= 0 && N <= 7); + return f32[N]; + } + + const float& operator[](int N) const + { + hlslpp_assert(N >= 0 && N <= 7); + return f32[N]; + } + union { n256 vec; diff --git a/include/hlsl++_vector_int.h b/include/hlsl++_vector_int.h index c99c7e3..6bbfb61 100644 --- a/include/hlsl++_vector_int.h +++ b/include/hlsl++_vector_int.h @@ -337,10 +337,22 @@ namespace hlslpp hlslpp_inline operator int32_t() const { return i32[0]; } + int32_t& operator[](int N) + { + hlslpp_assert(N == 0); + return i32[N]; + } + + const int32_t& operator[](int N) const + { + hlslpp_assert(N == 0); + return i32[N]; + } + union { n128i vec; - int32_t i32[4]; + int32_t i32[1]; #include "swizzle/hlsl++_vector_int_x.h" }; }; @@ -371,10 +383,22 @@ namespace hlslpp hlslpp_inline int2(int2&& i) hlslpp_noexcept : vec(i.vec) {} hlslpp_inline int2& operator = (int2&& i) hlslpp_noexcept { vec = i.vec; return *this; } + int32_t& operator[](int N) + { + hlslpp_assert(N >= 0 && N <= 1); + return i32[N]; + } + + const int32_t& operator[](int N) const + { + hlslpp_assert(N >= 0 && N <= 1); + return i32[N]; + } + union { n128i vec; - int32_t i32[4]; + int32_t i32[2]; #include "swizzle/hlsl++_vector_int_x.h" #include "swizzle/hlsl++_vector_int_y.h" }; @@ -410,10 +434,22 @@ namespace hlslpp hlslpp_inline int3(int3&& i) hlslpp_noexcept : vec(i.vec) {} hlslpp_inline int3& operator = (int3&& i) hlslpp_noexcept { vec = i.vec; return *this; } + int32_t& operator[](int N) + { + hlslpp_assert(N >= 0 && N <= 2); + return i32[N]; + } + + const int32_t& operator[](int N) const + { + hlslpp_assert(N >= 0 && N <= 2); + return i32[N]; + } + union { n128i vec; - int32_t i32[4]; + int32_t i32[3]; #include "swizzle/hlsl++_vector_int_x.h" #include "swizzle/hlsl++_vector_int_y.h" #include "swizzle/hlsl++_vector_int_z.h" @@ -460,6 +496,18 @@ namespace hlslpp hlslpp_inline int4(int4&& i) hlslpp_noexcept : vec(i.vec) {} hlslpp_inline int4& operator = (int4&& i) hlslpp_noexcept { vec = i.vec; return *this; } + int32_t& operator[](int N) + { + hlslpp_assert(N >= 0 && N <= 3); + return i32[N]; + } + + const int32_t& operator[](int N) const + { + hlslpp_assert(N >= 0 && N <= 3); + return i32[N]; + } + union { n128i vec; diff --git a/include/hlsl++_vector_uint.h b/include/hlsl++_vector_uint.h index f29ee35..7e37729 100644 --- a/include/hlsl++_vector_uint.h +++ b/include/hlsl++_vector_uint.h @@ -343,10 +343,22 @@ namespace hlslpp hlslpp_inline operator uint32_t() const { return u32[0]; } + uint32_t& operator[](int N) + { + hlslpp_assert(N == 0); + return u32[N]; + } + + const uint32_t& operator[](int N) const + { + hlslpp_assert(N == 0); + return u32[N]; + } + union { n128u vec; - uint32_t u32[4]; + uint32_t u32[1]; #include "swizzle/hlsl++_vector_uint_x.h" }; }; @@ -376,10 +388,22 @@ namespace hlslpp hlslpp_inline uint2(uint2&& i) hlslpp_noexcept : vec(i.vec) {} hlslpp_inline uint2& operator = (uint2&& i) hlslpp_noexcept { vec = i.vec; return *this; } + uint32_t& operator[](int N) + { + hlslpp_assert(N >= 0 && N <= 1); + return u32[N]; + } + + const uint32_t& operator[](int N) const + { + hlslpp_assert(N >= 0 && N <= 1); + return u32[N]; + } + union { n128u vec; - uint32_t u32[4]; + uint32_t u32[2]; #include "swizzle/hlsl++_vector_uint_x.h" #include "swizzle/hlsl++_vector_uint_y.h" }; @@ -416,10 +440,22 @@ namespace hlslpp hlslpp_inline uint3(uint3&& i) hlslpp_noexcept : vec(i.vec) {} hlslpp_inline uint3& operator = (uint3&& i) hlslpp_noexcept { vec = i.vec; return *this; } + uint32_t& operator[](int N) + { + hlslpp_assert(N >= 0 && N <= 2); + return u32[N]; + } + + const uint32_t& operator[](int N) const + { + hlslpp_assert(N >= 0 && N <= 2); + return u32[N]; + } + union { n128u vec; - uint32_t u32[4]; + uint32_t u32[3]; #include "swizzle/hlsl++_vector_uint_x.h" #include "swizzle/hlsl++_vector_uint_y.h" #include "swizzle/hlsl++_vector_uint_z.h" @@ -466,6 +502,18 @@ namespace hlslpp hlslpp_inline uint4(uint4&& i) hlslpp_noexcept : vec(i.vec) {} hlslpp_inline uint4& operator = (uint4&& i) hlslpp_noexcept { vec = i.vec; return *this; } + uint32_t& operator[](int N) + { + hlslpp_assert(N >= 0 && N <= 3); + return u32[N]; + } + + const uint32_t& operator[](int N) const + { + hlslpp_assert(N >= 0 && N <= 3); + return u32[N]; + } + union { n128u vec;