From 8c89728889c8597984a3be9df5b9ffd740a14fc3 Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Tue, 5 Jun 2018 22:26:42 +0200 Subject: [PATCH] mesa/st/tests: Add tests for array merge helper classes. v2: - Define tests also in the meson.build file. v4: - Check no-op mapping of all bits. - Convert tests to the new class layout used in the merge evaulation. - remove dependency on llvm in meson build (Thanks Dylan Baker for pointing out that this might not needed) Signed-off-by: Gert Wollny Acked-by: Dave Airlie --- src/mesa/state_tracker/tests/Makefile.am | 20 +- src/mesa/state_tracker/tests/meson.build | 16 +- .../state_tracker/tests/st_tests_common.h | 7 +- .../tests/test_glsl_to_tgsi_array_merge.cpp | 751 ++++++++++++++++++ 4 files changed, 787 insertions(+), 7 deletions(-) create mode 100644 src/mesa/state_tracker/tests/test_glsl_to_tgsi_array_merge.cpp diff --git a/src/mesa/state_tracker/tests/Makefile.am b/src/mesa/state_tracker/tests/Makefile.am index a49ad3ee106..0665a880844 100644 --- a/src/mesa/state_tracker/tests/Makefile.am +++ b/src/mesa/state_tracker/tests/Makefile.am @@ -17,8 +17,10 @@ AM_CPPFLAGS = \ if HAVE_STD_CXX11 if HAVE_SHARED_GLAPI -TESTS = st-renumerate-test -check_PROGRAMS = st-renumerate-test +TESTS = st-renumerate-test \ + st-array-merge-test +check_PROGRAMS = st-renumerate-test \ + st-array-merge-test check_LIBRARIES = libmesa-st-tests-common.a endif @@ -34,7 +36,13 @@ st_renumerate_test_SOURCES = \ st_renumerate_test_LDFLAGS = \ $(LLVM_LDFLAGS) -st_renumerate_test_LDADD = \ +st_array_merge_test_SOURCES = \ + test_glsl_to_tgsi_array_merge.cpp + +st_array_merge_test_LDFLAGS = \ + $(LLVM_LDFLAGS) + +st_common_LDADD = \ libmesa-st-tests-common.a \ $(top_builddir)/src/mesa/libmesagallium.la \ $(top_builddir)/src/mapi/shared-glapi/libglapi.la \ @@ -44,4 +52,10 @@ st_renumerate_test_LDADD = \ $(GALLIUM_COMMON_LIB_DEPS) \ $(LLVM_LIBS) +st_renumerate_test_LDADD = \ + $(st_common_LDADD) + +st_array_merge_test_LDADD = \ + $(st_common_LDADD) + EXTRA_DIST = meson.build diff --git a/src/mesa/state_tracker/tests/meson.build b/src/mesa/state_tracker/tests/meson.build index 0f845132091..5c472104d85 100644 --- a/src/mesa/state_tracker/tests/meson.build +++ b/src/mesa/state_tracker/tests/meson.build @@ -35,6 +35,20 @@ test( libmesa_st_test_common, libmesa_gallium, libglapi, libgallium, libmesa_util, ], - dependencies : [idep_gtest, dep_thread, dep_llvm] + dependencies : [idep_gtest, dep_thread] + ) +) + +test( + 'st-array-merge-test', + executable( + 'st_array_merge_test', + ['test_glsl_to_tgsi_array_merge.cpp', ir_expression_operation_h], + include_directories : inc_common, + link_with : [ + libmesa_st_test_common, libmesa_gallium, libglapi, libgallium, + libmesa_util, + ], + dependencies : [idep_gtest, dep_thread] ) ) diff --git a/src/mesa/state_tracker/tests/st_tests_common.h b/src/mesa/state_tracker/tests/st_tests_common.h index fe2a1d9888b..3046d20ceb3 100644 --- a/src/mesa/state_tracker/tests/st_tests_common.h +++ b/src/mesa/state_tracker/tests/st_tests_common.h @@ -24,14 +24,15 @@ #ifndef mesa_st_tests_h #define mesa_st_tests_h -#include -#include +#include "state_tracker/st_glsl_to_tgsi_temprename.h" +#include "state_tracker/st_glsl_to_tgsi_array_merge.h" +#include "gtest/gtest.h" + #include #define MP(X, W) std::make_pair(X, W) #define MT(X,Y,Z) std::make_tuple(X,Y,Z) - /* Use this to make the compiler pick the swizzle constructor below */ struct SWZ {}; diff --git a/src/mesa/state_tracker/tests/test_glsl_to_tgsi_array_merge.cpp b/src/mesa/state_tracker/tests/test_glsl_to_tgsi_array_merge.cpp new file mode 100644 index 00000000000..ca4b5d26a2c --- /dev/null +++ b/src/mesa/state_tracker/tests/test_glsl_to_tgsi_array_merge.cpp @@ -0,0 +1,751 @@ +/* + * Copyright © 2017 Gert Wollny + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + + +#include "st_tests_common.h" + +#include "tgsi/tgsi_ureg.h" +#include "tgsi/tgsi_info.h" +#include "mesa/program/prog_instruction.h" +#include "gtest/gtest.h" + +#include +#include +#include + +using std::vector; + +using namespace tgsi_array_merge; +using ArrayLiveRangeMerge=testing::Test; + +TEST_F(ArrayLiveRangeMerge, SimpleLiveRange) +{ + array_live_range a1(1, 10, 1, 5, WRITEMASK_X); + array_live_range a2(2, 5, 6, 10, WRITEMASK_X); + + array_live_range::merge(&a1, &a2); + + EXPECT_EQ(a1.array_id(), 1); + EXPECT_EQ(a1.begin(), 1); + EXPECT_EQ(a1.end(), 10); + EXPECT_EQ(a1.target_array_id(), 0); + EXPECT_EQ(a1.used_components(), 1); + EXPECT_EQ(a1.access_mask(), WRITEMASK_X); + + EXPECT_EQ(a1.remap_one_swizzle(0), 0); + EXPECT_EQ(a1.remap_one_swizzle(1), 1); + EXPECT_EQ(a1.remap_one_swizzle(2), 2); + EXPECT_EQ(a1.remap_one_swizzle(3), 3); + + EXPECT_EQ(a2.array_id(), 2); + EXPECT_EQ(a2.begin(), 6); + EXPECT_EQ(a2.end(), 10); + EXPECT_EQ(a2.target_array_id(), 1); + EXPECT_EQ(a2.used_components(), 1); + EXPECT_EQ(a2.access_mask(), WRITEMASK_X); + + EXPECT_EQ(a2.remap_one_swizzle(0), 0); + EXPECT_EQ(a2.remap_one_swizzle(1), 1); + EXPECT_EQ(a2.remap_one_swizzle(2), 2); + EXPECT_EQ(a2.remap_one_swizzle(3), 3); +} + +TEST_F(ArrayLiveRangeMerge, SimpleLiveRangeInverse) +{ + array_live_range a1(1, 5, 1, 5, WRITEMASK_X); + array_live_range a2(2, 10, 6, 10, WRITEMASK_X); + + array_live_range::merge(&a1, &a2); + + EXPECT_EQ(a1.array_id(), 1); + EXPECT_EQ(a1.begin(), 1); + EXPECT_EQ(a1.end(), 5); + EXPECT_EQ(a1.target_array_id(), 2); + EXPECT_EQ(a1.used_components(), 1); + EXPECT_EQ(a1.access_mask(), WRITEMASK_X); + + EXPECT_EQ(a1.remap_one_swizzle(0), 0); + EXPECT_EQ(a1.remap_one_swizzle(1), 1); + EXPECT_EQ(a1.remap_one_swizzle(2), 2); + EXPECT_EQ(a1.remap_one_swizzle(3), 3); + + EXPECT_EQ(a2.array_id(), 2); + EXPECT_EQ(a2.begin(), 1); + EXPECT_EQ(a2.end(), 10); + EXPECT_EQ(a2.target_array_id(), 0); + EXPECT_EQ(a2.used_components(), 1); + EXPECT_EQ(a2.access_mask(), WRITEMASK_X); + + EXPECT_EQ(a2.remap_one_swizzle(0), 0); + EXPECT_EQ(a2.remap_one_swizzle(1), 1); + EXPECT_EQ(a2.remap_one_swizzle(2), 2); + EXPECT_EQ(a2.remap_one_swizzle(3), 3); +} + + +TEST_F(ArrayLiveRangeMerge, Interleave_x_xyz) +{ + array_live_range a1(1, 10, 1, 10, WRITEMASK_X); + array_live_range a2(2, 9, 1, 10, WRITEMASK_XYZ); + + array_live_range::interleave(&a1, &a2); + + EXPECT_EQ(a1.array_id(), 1); + EXPECT_EQ(a1.begin(), 1); + EXPECT_EQ(a1.end(), 10); + EXPECT_EQ(a1.array_length(), 10u); + EXPECT_EQ(a1.target_array_id(), 0); + EXPECT_EQ(a1.used_components(), 4); + EXPECT_EQ(a1.access_mask(), WRITEMASK_XYZW); + + EXPECT_EQ(a1.remap_one_swizzle(0), 0); + EXPECT_EQ(a1.remap_one_swizzle(1), 1); + EXPECT_EQ(a1.remap_one_swizzle(2), 2); + EXPECT_EQ(a1.remap_one_swizzle(3), 3); + + EXPECT_EQ(a2.array_id(), 2); + EXPECT_EQ(a2.begin(), 1); + EXPECT_EQ(a2.end(), 10); + EXPECT_EQ(a2.target_array_id(), 1); + + EXPECT_EQ(a2.remap_one_swizzle(0), 1); + EXPECT_EQ(a2.remap_one_swizzle(1), 2); + EXPECT_EQ(a2.remap_one_swizzle(2), 3); + EXPECT_EQ(a2.remap_one_swizzle(3), -1); +} + +TEST_F(ArrayLiveRangeMerge, Interleave_xyz_x) +{ + array_live_range a1(1, 10, 1, 10, WRITEMASK_XYZ); + array_live_range a2(2, 9, 1, 10, WRITEMASK_X); + + array_live_range::interleave(&a1, &a2); + + EXPECT_EQ(a1.array_id(), 1); + EXPECT_EQ(a1.begin(), 1); + EXPECT_EQ(a1.end(), 10); + EXPECT_EQ(a1.array_length(), 10u); + EXPECT_EQ(a1.target_array_id(), 0); + EXPECT_EQ(a1.used_components(), 4); + EXPECT_EQ(a1.access_mask(), WRITEMASK_XYZW); + + EXPECT_EQ(a1.remap_one_swizzle(0), 0); + EXPECT_EQ(a1.remap_one_swizzle(1), 1); + EXPECT_EQ(a1.remap_one_swizzle(2), 2); + EXPECT_EQ(a1.remap_one_swizzle(3), 3); + + EXPECT_EQ(a2.array_id(), 2); + EXPECT_EQ(a2.begin(), 1); + EXPECT_EQ(a2.end(), 10); + EXPECT_EQ(a2.target_array_id(), 1); + + EXPECT_EQ(a2.remap_one_swizzle(0), 3); + EXPECT_EQ(a2.remap_one_swizzle(1), -1); + EXPECT_EQ(a2.remap_one_swizzle(2), -1); + EXPECT_EQ(a2.remap_one_swizzle(3), -1); +} + + +TEST_F(ArrayLiveRangeMerge, SimpleInterleave) +{ + array_live_range a1(1, 10, 1, 10, WRITEMASK_X); + array_live_range a2(2, 9, 1, 10, WRITEMASK_X); + + array_live_range::interleave(&a1, &a2); + + EXPECT_EQ(a1.array_id(), 1); + EXPECT_EQ(a1.begin(), 1); + EXPECT_EQ(a1.end(), 10); + EXPECT_EQ(a1.array_length(), 10u); + EXPECT_EQ(a1.target_array_id(), 0); + EXPECT_EQ(a1.used_components(), 2); + EXPECT_EQ(a1.access_mask(), WRITEMASK_XY); + + EXPECT_EQ(a1.remap_one_swizzle(0), 0); + EXPECT_EQ(a1.remap_one_swizzle(1), 1); + EXPECT_EQ(a1.remap_one_swizzle(2), 2); + EXPECT_EQ(a1.remap_one_swizzle(3), 3); + + EXPECT_EQ(a2.array_id(), 2); + EXPECT_EQ(a2.begin(), 1); + EXPECT_EQ(a2.end(), 10); + EXPECT_EQ(a2.target_array_id(), 1); + + EXPECT_EQ(a2.remap_one_swizzle(0), 1); + EXPECT_EQ(a2.remap_one_swizzle(1), -1); + EXPECT_EQ(a2.remap_one_swizzle(2), -1); + EXPECT_EQ(a2.remap_one_swizzle(3), -1); +} + + +TEST_F(ArrayLiveRangeMerge, SimpleInterleaveInverse) +{ + array_live_range a1(1, 8, 1, 10, WRITEMASK_X); + array_live_range a2(2, 9, 1, 10, WRITEMASK_X); + + array_live_range::interleave(&a1, &a2); + + EXPECT_EQ(a1.array_id(), 1); + EXPECT_EQ(a1.begin(), 1); + EXPECT_EQ(a1.end(), 10); + EXPECT_EQ(a1.target_array_id(), 2); + + EXPECT_EQ(a1.remap_one_swizzle(0), 1); + EXPECT_EQ(a1.remap_one_swizzle(1), -1); + EXPECT_EQ(a1.remap_one_swizzle(2), -1); + EXPECT_EQ(a1.remap_one_swizzle(3), -1); + + EXPECT_EQ(a2.array_id(), 2); + EXPECT_EQ(a2.target_array_id(), 0); + EXPECT_EQ(a2.begin(), 1); + EXPECT_EQ(a2.end(), 10); + EXPECT_EQ(a2.array_length(), 9u); + EXPECT_EQ(a2.used_components(), 2); + EXPECT_EQ(a2.access_mask(), WRITEMASK_XY); +} + + +TEST_F(ArrayLiveRangeMerge, InterleaveRiveRangeExtend) +{ + array_live_range a1(1, 10, 2, 9, WRITEMASK_X); + array_live_range a2(2, 9, 1, 10, WRITEMASK_X); + + array_live_range::interleave(&a1, &a2); + + EXPECT_EQ(a1.array_id(), 1); + EXPECT_EQ(a1.begin(), 1); + EXPECT_EQ(a1.end(), 10); + EXPECT_EQ(a1.array_length(), 10u); + EXPECT_EQ(a1.target_array_id(), 0); + EXPECT_EQ(a1.used_components(), 2); + EXPECT_EQ(a1.access_mask(), WRITEMASK_XY); + + EXPECT_EQ(a1.remap_one_swizzle(0), 0); + EXPECT_EQ(a1.remap_one_swizzle(1), 1); + EXPECT_EQ(a1.remap_one_swizzle(2), 2); + EXPECT_EQ(a1.remap_one_swizzle(3), 3); + + EXPECT_EQ(a2.array_id(), 2); + EXPECT_EQ(a2.begin(), 1); + EXPECT_EQ(a2.end(), 10); + EXPECT_EQ(a2.target_array_id(), 1); + + EXPECT_EQ(a2.remap_one_swizzle(0), 1); + EXPECT_EQ(a2.remap_one_swizzle(1), -1); + EXPECT_EQ(a2.remap_one_swizzle(2), -1); + EXPECT_EQ(a2.remap_one_swizzle(3), -1); +} + +TEST_F(ArrayLiveRangeMerge, InterleaveLiveRangeExtendInverse) +{ + array_live_range a1(1, 8, 2, 11, WRITEMASK_X); + array_live_range a2(2, 9, 1, 10, WRITEMASK_X); + + array_live_range::interleave(&a1, &a2); + + EXPECT_EQ(a1.array_id(), 1); + EXPECT_EQ(a1.begin(), 2); + EXPECT_EQ(a1.end(), 11); + EXPECT_EQ(a1.target_array_id(), 2); + EXPECT_EQ(a1.used_components(), 1); + EXPECT_EQ(a1.access_mask(), WRITEMASK_X); + + EXPECT_EQ(a1.remap_one_swizzle(0), 1); + EXPECT_EQ(a1.remap_one_swizzle(1), -1); + EXPECT_EQ(a1.remap_one_swizzle(2), -1); + EXPECT_EQ(a1.remap_one_swizzle(3), -1); + + EXPECT_EQ(a2.array_id(), 2); + EXPECT_EQ(a2.begin(), 1); + EXPECT_EQ(a2.end(), 11); + EXPECT_EQ(a2.target_array_id(), 0); + EXPECT_EQ(a2.used_components(), 2); + EXPECT_EQ(a2.access_mask(), WRITEMASK_XY); + + EXPECT_EQ(a2.remap_one_swizzle(0), 0); + EXPECT_EQ(a2.remap_one_swizzle(1), 1); + EXPECT_EQ(a2.remap_one_swizzle(2), 2); + EXPECT_EQ(a2.remap_one_swizzle(3), 3); +} + +TEST_F(ArrayLiveRangeMerge, InterleaveChained) +{ + array_live_range a1(1, 8, 2, 11, WRITEMASK_X); + array_live_range a2(2, 9, 1, 10, WRITEMASK_X); + array_live_range a3(3, 10, 1, 10, WRITEMASK_X); + + array_live_range::interleave(&a1, &a2); + array_live_range::interleave(&a2, &a3); + + EXPECT_EQ(a1.array_id(), 1); + EXPECT_EQ(a1.begin(), 2); + EXPECT_EQ(a1.end(), 11); + EXPECT_EQ(a1.target_array_id(), 2); + EXPECT_EQ(a1.used_components(), 1); + EXPECT_EQ(a1.access_mask(), WRITEMASK_X); + + EXPECT_EQ(a1.remap_one_swizzle(0), 2); + EXPECT_EQ(a1.remap_one_swizzle(1), -1); + EXPECT_EQ(a1.remap_one_swizzle(2), -1); + EXPECT_EQ(a1.remap_one_swizzle(3), -1); + + EXPECT_EQ(a2.array_id(), 2); + EXPECT_EQ(a2.begin(), 1); + EXPECT_EQ(a2.end(), 11); + EXPECT_EQ(a2.target_array_id(), 3); + EXPECT_EQ(a2.used_components(), 2); + EXPECT_EQ(a2.access_mask(), WRITEMASK_XY); + + EXPECT_EQ(a2.remap_one_swizzle(0), 1); + EXPECT_EQ(a2.remap_one_swizzle(1), 2); + EXPECT_EQ(a2.remap_one_swizzle(2), -1); + EXPECT_EQ(a2.remap_one_swizzle(3), -1); + + EXPECT_EQ(a3.array_id(), 3); + EXPECT_EQ(a3.begin(), 1); + EXPECT_EQ(a3.end(), 11); + EXPECT_EQ(a3.target_array_id(), 0); + EXPECT_EQ(a3.used_components(), 3); + EXPECT_EQ(a3.access_mask(), WRITEMASK_XYZ); + + EXPECT_EQ(a3.remap_one_swizzle(0), 0); + EXPECT_EQ(a3.remap_one_swizzle(1), 1); + EXPECT_EQ(a3.remap_one_swizzle(2), 2); + EXPECT_EQ(a3.remap_one_swizzle(3), 3); +} + +TEST_F(ArrayLiveRangeMerge, MergeInterleaveChained) +{ + array_live_range a1(1, 8, 1, 5, WRITEMASK_X); + array_live_range a2(2, 9, 6, 10, WRITEMASK_X); + array_live_range a3(3, 10, 1, 10, WRITEMASK_X); + + array_live_range::merge(&a1, &a2); + array_live_range::interleave(&a2, &a3); + + EXPECT_EQ(a1.array_id(), 1); + EXPECT_EQ(a1.begin(), 1); + EXPECT_EQ(a1.end(), 5); + EXPECT_EQ(a1.target_array_id(), 2); + EXPECT_EQ(a1.used_components(), 1); + EXPECT_EQ(a1.access_mask(), WRITEMASK_X); + + EXPECT_EQ(a1.remap_one_swizzle(0), 1); + EXPECT_EQ(a1.remap_one_swizzle(1), -1); + EXPECT_EQ(a1.remap_one_swizzle(2), -1); + EXPECT_EQ(a1.remap_one_swizzle(3), -1); + + EXPECT_EQ(a2.array_id(), 2); + EXPECT_EQ(a2.begin(), 1); + EXPECT_EQ(a2.end(), 10); + EXPECT_EQ(a2.target_array_id(), 3); + EXPECT_EQ(a2.used_components(), 1); + EXPECT_EQ(a2.access_mask(), WRITEMASK_X); + + EXPECT_EQ(a2.remap_one_swizzle(0), 1); + EXPECT_EQ(a2.remap_one_swizzle(1), -1); + EXPECT_EQ(a2.remap_one_swizzle(2), -1); + EXPECT_EQ(a2.remap_one_swizzle(3), -1); + + EXPECT_EQ(a3.array_id(), 3); + EXPECT_EQ(a3.begin(), 1); + EXPECT_EQ(a3.end(), 10); + EXPECT_EQ(a3.target_array_id(), 0); + EXPECT_EQ(a3.used_components(), 2); + EXPECT_EQ(a3.access_mask(), WRITEMASK_XY); + + EXPECT_EQ(a3.remap_one_swizzle(0), 0); + EXPECT_EQ(a3.remap_one_swizzle(1), 1); + EXPECT_EQ(a3.remap_one_swizzle(2), 2); + EXPECT_EQ(a3.remap_one_swizzle(3), 3); +} + +TEST_F(ArrayLiveRangeMerge, MergeMergeAndInterleave) +{ + array_live_range a1(1, 5, 1, 5, WRITEMASK_X); + array_live_range a2(2, 4, 6, 7, WRITEMASK_X); + array_live_range a3(3, 3, 1, 5, WRITEMASK_X); + array_live_range a4(4, 2, 6, 8, WRITEMASK_X); + + array_live_range::merge(&a1, &a2); + array_live_range::merge(&a3, &a4); + array_live_range::interleave(&a1, &a3); + + EXPECT_EQ(a1.array_id(), 1); + EXPECT_EQ(a1.begin(), 1); + EXPECT_EQ(a1.end(), 8); + EXPECT_EQ(a1.target_array_id(), 0); + EXPECT_EQ(a1.used_components(), 2); + EXPECT_EQ(a1.access_mask(), WRITEMASK_XY); + + EXPECT_EQ(a1.remap_one_swizzle(0), 0); + EXPECT_EQ(a1.remap_one_swizzle(1), 1); + EXPECT_EQ(a1.remap_one_swizzle(2), 2); + EXPECT_EQ(a1.remap_one_swizzle(3), 3); + + EXPECT_EQ(a2.array_id(), 2); + EXPECT_EQ(a2.begin(), 6); + EXPECT_EQ(a2.end(), 7); + EXPECT_EQ(a2.target_array_id(), 1); + EXPECT_EQ(a2.used_components(), 1); + EXPECT_EQ(a2.access_mask(), WRITEMASK_X); + + EXPECT_EQ(a2.remap_one_swizzle(0), 0); + EXPECT_EQ(a2.remap_one_swizzle(1), 1); + EXPECT_EQ(a2.remap_one_swizzle(2), 2); + EXPECT_EQ(a2.remap_one_swizzle(3), 3); + + EXPECT_EQ(a3.array_id(), 3); + EXPECT_EQ(a3.begin(), 1); + EXPECT_EQ(a3.end(), 8); + EXPECT_EQ(a3.target_array_id(), 1); + EXPECT_EQ(a3.used_components(), 1); + EXPECT_EQ(a3.access_mask(), WRITEMASK_X); + + EXPECT_EQ(a3.remap_one_swizzle(0), 1); + EXPECT_EQ(a3.remap_one_swizzle(1), -1); + EXPECT_EQ(a3.remap_one_swizzle(2), -1); + EXPECT_EQ(a3.remap_one_swizzle(3), -1); + + EXPECT_EQ(a4.array_id(), 4); + EXPECT_EQ(a4.begin(), 6); + EXPECT_EQ(a4.end(), 8); + EXPECT_EQ(a4.target_array_id(), 3); + EXPECT_EQ(a4.used_components(), 1); + EXPECT_EQ(a4.access_mask(), WRITEMASK_X); + + EXPECT_EQ(a4.remap_one_swizzle(0), 1); + EXPECT_EQ(a4.remap_one_swizzle(1), -1); + EXPECT_EQ(a4.remap_one_swizzle(2), -1); + EXPECT_EQ(a4.remap_one_swizzle(3), -1); + +} + + +TEST_F(ArrayLiveRangeMerge, MergeInterleaveMergeInterleaveChained) +{ + array_live_range a1(1, 8, 1, 5, WRITEMASK_X); + array_live_range a2(2, 9, 6, 10, WRITEMASK_X); + array_live_range a3(3, 10, 1, 10, WRITEMASK_X); + array_live_range a4(4, 11, 11, 20, WRITEMASK_XY); + array_live_range a5(5, 15, 5, 20, WRITEMASK_XY); + + array_live_range::merge(&a1, &a2); + array_live_range::interleave(&a2, &a3); // a2 -> a3 + array_live_range::merge(&a3, &a4); + array_live_range::interleave(&a4, &a5); // a4 -> a5 + + + EXPECT_EQ(a1.array_id(), 1); + EXPECT_EQ(a1.begin(), 1); + EXPECT_EQ(a1.end(), 5); + EXPECT_EQ(a1.target_array_id(), 2); + EXPECT_EQ(a1.used_components(), 1); + EXPECT_EQ(a1.access_mask(), WRITEMASK_X); + + EXPECT_EQ(a1.remap_one_swizzle(0), 3); + EXPECT_EQ(a1.remap_one_swizzle(1), -1); + EXPECT_EQ(a1.remap_one_swizzle(2), -1); + EXPECT_EQ(a1.remap_one_swizzle(3), -1); + + EXPECT_EQ(a2.array_id(), 2); + EXPECT_EQ(a2.begin(), 1); + EXPECT_EQ(a2.end(), 10); + EXPECT_EQ(a2.target_array_id(), 3); + EXPECT_EQ(a2.used_components(), 1); + EXPECT_EQ(a2.access_mask(), WRITEMASK_X); + + EXPECT_EQ(a2.remap_one_swizzle(0), 3); + EXPECT_EQ(a2.remap_one_swizzle(1), -1); + EXPECT_EQ(a2.remap_one_swizzle(2), -1); + EXPECT_EQ(a2.remap_one_swizzle(3), -1); + + EXPECT_EQ(a3.array_id(), 3); + EXPECT_EQ(a3.begin(), 1); + EXPECT_EQ(a3.end(), 10); + EXPECT_EQ(a3.target_array_id(), 4); + EXPECT_EQ(a3.used_components(), 2); + EXPECT_EQ(a3.access_mask(), WRITEMASK_XY); + + EXPECT_EQ(a3.remap_one_swizzle(0), 2); + EXPECT_EQ(a3.remap_one_swizzle(1), 3); + EXPECT_EQ(a3.remap_one_swizzle(2), -1); + EXPECT_EQ(a3.remap_one_swizzle(3), -1); + + EXPECT_EQ(a4.array_id(), 4); + EXPECT_EQ(a4.begin(), 1); + EXPECT_EQ(a4.end(), 20); + EXPECT_EQ(a4.target_array_id(), 5); + EXPECT_EQ(a4.used_components(), 2); + EXPECT_EQ(a4.access_mask(), WRITEMASK_XY); + + EXPECT_EQ(a4.remap_one_swizzle(0), 2); + EXPECT_EQ(a4.remap_one_swizzle(1), 3); + EXPECT_EQ(a4.remap_one_swizzle(2), -1); + EXPECT_EQ(a4.remap_one_swizzle(3), -1); + + EXPECT_EQ(a5.array_id(), 5); + EXPECT_EQ(a5.begin(), 1); + EXPECT_EQ(a5.end(), 20); + EXPECT_EQ(a5.target_array_id(), 0); + EXPECT_EQ(a5.used_components(), 4); + EXPECT_EQ(a5.access_mask(), WRITEMASK_XYZW); + + EXPECT_EQ(a5.remap_one_swizzle(0), 0); + EXPECT_EQ(a5.remap_one_swizzle(1), 1); + EXPECT_EQ(a5.remap_one_swizzle(2), 2); + EXPECT_EQ(a5.remap_one_swizzle(3), 3); +} + +using ArrayMergeTest=testing::Test; + +TEST_F(ArrayMergeTest, ArrayMergeTwoSwizzles) +{ + vector alt = { + {1, 4, 1, 5, WRITEMASK_X}, + {2, 4, 2, 5, WRITEMASK_X}, + }; + + int8_t expect_swizzle[] = {1, -1, -1, -1}; + vector expect = { + {}, + {1, expect_swizzle}, + }; + + vector result(alt.size() + 1); + + get_array_remapping(2, &alt[0], &result[0]); + + EXPECT_EQ(result[1], expect[0]); + EXPECT_EQ(result[2], expect[1]); + +} + +TEST_F(ArrayMergeTest, ArrayMergeFourSwizzles) +{ + vector alt = { + {1, 8, 1, 7, WRITEMASK_X}, + {2, 7, 2, 7, WRITEMASK_X}, + {3, 6, 3, 7, WRITEMASK_X}, + {4, 5, 4, 7, WRITEMASK_X}, + }; + int8_t expect_swizzle1[] = {1, -1, -1, -1}; + int8_t expect_swizzle2[] = {2, -1, -1, -1}; + int8_t expect_swizzle3[] = {3, -1, -1, -1}; + + vector expect = { + {}, + {1, expect_swizzle1}, + {1, expect_swizzle2}, + {1, expect_swizzle3}, + }; + + vector result(alt.size() + 1); + + get_array_remapping(4, &alt[0], &result[0]); + + EXPECT_EQ(result[1], expect[0]); + EXPECT_EQ(result[2], expect[1]); + EXPECT_EQ(result[3], expect[2]); + EXPECT_EQ(result[4], expect[3]); + +} + + +TEST_F(ArrayMergeTest, SimpleChainMerge) +{ + vector input = { + {1, 3, 1, 5, WRITEMASK_XYZW}, + {2, 2, 6, 7, WRITEMASK_XYZW}, + }; + + int8_t expect_swizzle[] = {0, 1, 2, 3}; + vector expect = { + {}, + {1, expect_swizzle}, + }; + + vector result(3); + get_array_remapping(2, &input[0], &result[0]); + + EXPECT_EQ(result[1], expect[0]); + EXPECT_EQ(result[2], expect[1]); +} + +TEST_F(ArrayMergeTest, MergeAndInterleave) +{ + vector input = { + {1, 5, 1, 5, WRITEMASK_X}, + {2, 4, 6, 7, WRITEMASK_X}, + {3, 3, 1, 5, WRITEMASK_X}, + {4, 2, 6, 7, WRITEMASK_X}, + }; + + int8_t expect_swizzle1[] = {0, 1, 2, 3}; + int8_t expect_swizzle2[] = {1, -1, -1, -1}; + int8_t expect_swizzle3[] = {1, -1, -1, -1}; + + vector expect = { + {}, + {1, expect_swizzle1}, + {1, expect_swizzle2}, + {1, expect_swizzle3} + }; + vector result(input.size() + 1); + get_array_remapping(input.size(), &input[0], &result[0]); + + EXPECT_EQ(result[1], expect[0]); + EXPECT_EQ(result[2], expect[1]); + EXPECT_EQ(result[3], expect[2]); + EXPECT_EQ(result[4], expect[3]); +} + +TEST_F(ArrayMergeTest, MergeAndInterleave2) +{ + vector input = { + {1, 5, 1, 5, WRITEMASK_X}, + {2, 4, 6, 7, WRITEMASK_X}, + {3, 3, 1, 8, WRITEMASK_XY}, + {4, 2, 6, 7, WRITEMASK_X}, + }; + + int8_t expect_swizzle1[] = {0, 1, 2, 3}; + int8_t expect_swizzle2[] = {1, 2, -1, -1}; + int8_t expect_swizzle3[] = {3, -1, -1, -1}; + + vector expect = { + {}, + {1, expect_swizzle1}, + {1, expect_swizzle2}, + {1, expect_swizzle3} + }; + vector result(input.size() + 1); + get_array_remapping(input.size(), &input[0], &result[0]); + + EXPECT_EQ(result[1], expect[0]); + EXPECT_EQ(result[2], expect[1]); + EXPECT_EQ(result[3], expect[2]); + EXPECT_EQ(result[4], expect[3]); +} + + +TEST_F(ArrayMergeTest, MergeAndInterleave3) +{ + vector input = { + {1, 5, 1, 5, WRITEMASK_X}, + {2, 4, 6, 7, WRITEMASK_XY}, + {3, 3, 1, 5, WRITEMASK_X} + }; + + int8_t expect_swizzle1[] = {0, 1, 2, 3}; + int8_t expect_swizzle2[] = {1, -1, -1, -1}; + + vector expect = { + {}, + {1, expect_swizzle1}, + {1, expect_swizzle2} + }; + vector result(input.size() + 1); + get_array_remapping(input.size(), &input[0], &result[0]); + + EXPECT_EQ(result[1], expect[0]); + EXPECT_EQ(result[2], expect[1]); + EXPECT_EQ(result[3], expect[2]); +} + +TEST_F(ArrayMergeTest, MergeAndInterleave4) +{ + vector input = { + {1, 7, 1, 5, WRITEMASK_X}, + {2, 6, 6, 7, WRITEMASK_XY}, + {3, 5, 1, 5, WRITEMASK_X}, + {4, 4, 8, 9, WRITEMASK_XYZ}, + {5, 3, 8, 9, WRITEMASK_W}, + {6, 2, 10, 11, WRITEMASK_XYZW}, + }; + + int8_t expect_swizzle1[] = {0, 1, 2, 3}; + int8_t expect_swizzle2[] = {1, -1, -1, -1}; + int8_t expect_swizzle3[] = {0, 1, 2, 3}; + int8_t expect_swizzle4[] = {-1, -1, -1, 3}; + int8_t expect_swizzle5[] = {0, 1, 2, 3}; + + vector expect = { + {}, + {1, expect_swizzle1}, + {1, expect_swizzle2}, + {1, expect_swizzle3}, /* W from below will be interleaved in */ + {1, expect_swizzle4}, + {1, expect_swizzle5} + }; + vector result(input.size() + 1); + get_array_remapping(input.size(), &input[0], &result[0]); + + EXPECT_EQ(result[1], expect[0]); + EXPECT_EQ(result[2], expect[1]); + EXPECT_EQ(result[3], expect[2]); + EXPECT_EQ(result[4], expect[3]); + EXPECT_EQ(result[5], expect[4]); + EXPECT_EQ(result[6], expect[5]); + +} + +TEST_F(ArrayMergeTest, MergeAndInterleave5) +{ + vector input = { + {1, 7, 1, 5, WRITEMASK_X}, + {2, 6, 1, 3, WRITEMASK_X}, + {3, 5, 4, 5, WRITEMASK_X}, + {4, 4, 6, 10, WRITEMASK_XY}, + {5, 8, 1, 10, WRITEMASK_XY} + }; + + /* 1. merge 3 into 2 + * 2. interleave 2 into 1 (x -> y) --- (y -> w) + * 3. merge 4 into 1 / + * 4. interleave 1 into 5 (x,y - z,w) + */ + + /* swizzle1 holds the summary mask */ + int8_t expect_swizzle1[] = {2, 3, -1, -1}; + int8_t expect_swizzle2[] = {3, -1, -1, -1}; + int8_t expect_swizzle3[] = {3, -1, -1, -1}; + int8_t expect_swizzle4[] = {2, 3, -1, -1}; + + vector expect = { + {5, expect_swizzle1}, + {5, expect_swizzle2}, + {5, expect_swizzle3}, + {5, expect_swizzle4}, + {} + }; + vector result(input.size() + 1); + get_array_remapping(input.size(), &input[0], &result[0]); + + EXPECT_EQ(result[1], expect[0]); + EXPECT_EQ(result[2], expect[1]); + EXPECT_EQ(result[3], expect[2]); + EXPECT_EQ(result[4], expect[3]); + EXPECT_EQ(result[5], expect[4]); + +} -- 2.30.2