Skip to content

Commit

Permalink
Fix compound assignment operators for single-component integer swizzl…
Browse files Browse the repository at this point in the history
…es (#50)

-Fixed compound assignment operators not working for single-component swizzle of int and uint vectors. Only components other than the first one were affected (y/z/w).
-Added some relevant test cases
  • Loading branch information
denys-liubushkin authored Mar 11, 2021
1 parent 2eb2727 commit d48145a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/hlsl++_vector_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ namespace hlslpp
template<int X>
iswizzle1<X>& iswizzle1<X>::operator = (const int1& i)
{
vec = _hlslpp_blend_epi32(vec, i.vec, HLSLPP_COMPONENT_X(X)); return *this;
vec = _hlslpp_blend_epi32(vec, (swizzle<0, X>(i.vec)), HLSLPP_COMPONENT_X(X)); return *this;
}

template<int X, int Y>
Expand Down
2 changes: 1 addition & 1 deletion include/hlsl++_vector_uint.h
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ namespace hlslpp
template<int X>
uswizzle1<X>& uswizzle1<X>::operator = (const uint1& i)
{
vec = _hlslpp_blend_epi32(vec, i.vec, HLSLPP_COMPONENT_X(X)); return *this;
vec = _hlslpp_blend_epi32(vec, (swizzle<0, X>(i.vec)), HLSLPP_COMPONENT_X(X)); return *this;
}

template<int X, int Y>
Expand Down
12 changes: 12 additions & 0 deletions src/hlsl++_unit_tests_vector_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ void RunUnitTestsVectorInt()
ivadd_f_3 += 3; eq(ivadd_f_3, (int32_t)ivfoo3.x + 3 + 3, (int32_t)ivfoo3.y + 3 + 3, (int32_t)ivfoo3.z + 3 + 3);
ivadd_f_4 += 4; eq(ivadd_f_4, (int32_t)ivfoo4.x + 4 + 4, (int32_t)ivfoo4.y + 4 + 4, (int32_t)ivfoo4.z + 4 + 4, (int32_t)ivfoo4.w + 4 + 4);

ivadd_f_2.y += 2; eq(ivadd_f_2, (int32_t)ivfoo2.x + 2 + 2, (int32_t)ivfoo2.y + 2 + 2 + 2);
ivadd_f_3.z += 3; eq(ivadd_f_3, (int32_t)ivfoo3.x + 3 + 3, (int32_t)ivfoo3.y + 3 + 3, (int32_t)ivfoo3.z + 3 + 3 + 3);
ivadd_f_4.w += 4; eq(ivadd_f_4, (int32_t)ivfoo4.x + 4 + 4, (int32_t)ivfoo4.y + 4 + 4, (int32_t)ivfoo4.z + 4 + 4, (int32_t)ivfoo4.w + 4 + 4 + 4);

int1 ivadd_swiz_a_1 = ivfoo1 + ivbar1.x; eq(ivadd_swiz_a_1, (int32_t)ivfoo1 + (int32_t)ivbar1.x);
int1 ivadd_swiz_b_1 = ivfoo1.r + ivbar1.x; eq(ivadd_swiz_b_1, (int32_t)ivfoo1.r + (int32_t)ivbar1.x);
int1 ivadd_swiz_c_1 = ivfoo1.r + ivbar1; eq(ivadd_swiz_c_1, (int32_t)ivfoo1.r + (int32_t)ivbar1);
Expand Down Expand Up @@ -204,6 +208,10 @@ void RunUnitTestsVectorInt()
ivsub_f_3 -= 3; eq(ivsub_f_3, (int32_t)ivfoo3.x - 3 - 3, (int32_t)ivfoo3.y - 3 - 3, (int32_t)ivfoo3.z - 3 - 3);
ivsub_f_4 -= 4; eq(ivsub_f_4, (int32_t)ivfoo4.x - 4 - 4, (int32_t)ivfoo4.y - 4 - 4, (int32_t)ivfoo4.z - 4 - 4, (int32_t)ivfoo4.w - 4 - 4);

ivsub_f_2.y -= 2; eq(ivsub_f_2, (int32_t)ivfoo2.x - 2 - 2, (int32_t)ivfoo2.y - 2 - 2 - 2);
ivsub_f_3.z -= 3; eq(ivsub_f_3, (int32_t)ivfoo3.x - 3 - 3, (int32_t)ivfoo3.y - 3 - 3, (int32_t)ivfoo3.z - 3 - 3 - 3);
ivsub_f_4.w -= 4; eq(ivsub_f_4, (int32_t)ivfoo4.x - 4 - 4, (int32_t)ivfoo4.y - 4 - 4, (int32_t)ivfoo4.z - 4 - 4, (int32_t)ivfoo4.w - 4 - 4 - 4);

int1 ivsub_swiz_a_1 = ivfoo1 - ivbar1.x; eq(ivsub_swiz_a_1, (int32_t)ivfoo1 - (int32_t)ivbar1.x);
int1 ivsub_swiz_b_1 = ivfoo1.r - ivbar1.x; eq(ivsub_swiz_b_1, (int32_t)ivfoo1.r - (int32_t)ivbar1.x);
int1 ivsub_swiz_c_1 = ivfoo1.r - ivbar1; eq(ivsub_swiz_c_1, (int32_t)ivfoo1.r - (int32_t)ivbar1);
Expand Down Expand Up @@ -251,6 +259,10 @@ void RunUnitTestsVectorInt()
ivmul_f_3 *= 3; eq(ivmul_f_3, (int32_t)ivfoo3.x * 3 * 3, (int32_t)ivfoo3.y * 3 * 3, (int32_t)ivfoo3.z * 3 * 3);
ivmul_f_4 *= 4; eq(ivmul_f_4, (int32_t)ivfoo4.x * 4 * 4, (int32_t)ivfoo4.y * 4 * 4, (int32_t)ivfoo4.z * 4 * 4, (int32_t)ivfoo4.w * 4 * 4);

ivmul_f_2.y *= 2; eq(ivmul_f_2, (int32_t)ivfoo2.x * 2 * 2, (int32_t)ivfoo2.y * 2 * 2 * 2);
ivmul_f_3.z *= 3; eq(ivmul_f_3, (int32_t)ivfoo3.x * 3 * 3, (int32_t)ivfoo3.y * 3 * 3, (int32_t)ivfoo3.z * 3 * 3 * 3);
ivmul_f_4.w *= 4; eq(ivmul_f_4, (int32_t)ivfoo4.x * 4 * 4, (int32_t)ivfoo4.y * 4 * 4, (int32_t)ivfoo4.z * 4 * 4, (int32_t)ivfoo4.w * 4 * 4 * 4);

int1 ivmul_swiz_a_1 = ivfoo1 * ivbar1.x;
int1 ivmul_swiz_b_1 = ivfoo1.r * ivbar1.x;
int1 ivmul_swiz_c_1 = ivfoo1.r * ivbar1;
Expand Down

0 comments on commit d48145a

Please sign in to comment.