[Mesa-dev] [PATCH v3 08/13] mesa/st/tests: Add tests for array merge helper classes.
Dylan Baker
dylan at pnwbakers.com
Mon May 7 16:31:25 UTC 2018
Quoting Gert Wollny (2018-04-28 12:30:08)
> v2: Define tests also in the meson.build file.
> Signed-off-by: Gert Wollny <gw.fossdev at gmail.com>
> ---
> src/mesa/state_tracker/tests/Makefile.am | 20 +-
> src/mesa/state_tracker/tests/meson.build | 14 +
> src/mesa/state_tracker/tests/st_tests_common.h | 7 +-
> .../tests/test_glsl_to_tgsi_array_merge.cpp | 296 +++++++++++++++++++++
> 4 files changed, 331 insertions(+), 6 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 a49ad3ee10..0665a88084 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 0f84513209..71da5dc520 100644
> --- a/src/mesa/state_tracker/tests/meson.build
> +++ b/src/mesa/state_tracker/tests/meson.build
> @@ -38,3 +38,17 @@ test(
> dependencies : [idep_gtest, dep_thread, dep_llvm]
> )
> )
> +
> +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, dep_llvm]
Does your new test actually depend on llvm?
> + )
> +)
> diff --git a/src/mesa/state_tracker/tests/st_tests_common.h b/src/mesa/state_tracker/tests/st_tests_common.h
> index 03baf50753..a4fe65947e 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 <state_tracker/st_glsl_to_tgsi_temprename.h>
> -#include <gtest/gtest.h>
> +#include "state_tracker/st_glsl_to_tgsi_temprename.h"
> +#include "state_tracker/st_glsl_to_tgsi_array_merge.h"
> +#include "gtest/gtest.h"
> +
> #include <utility>
>
> #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 0000000000..d8a5e7fbd1
> --- /dev/null
> +++ b/src/mesa/state_tracker/tests/test_glsl_to_tgsi_array_merge.cpp
> @@ -0,0 +1,296 @@
> +/*
> + * 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 <utility>
> +#include <algorithm>
> +#include <iostream>
> +
> +using std::vector;
> +
> +using namespace tgsi_array_merge;
> +using SwizzleRemapTest=testing::Test;
> +
> +TEST_F(SwizzleRemapTest, ArrayRemappingBase_x_x)
> +{
> + array_remapping map1(10, 1, 1);
> + ASSERT_EQ(map1.target_array_id(), 10u);
> + ASSERT_EQ(map1.map_writemask(1), 2);
> + ASSERT_EQ(map1.map_one_swizzle(0), 1);
> + ASSERT_EQ(map1.combined_access_mask(), 3);
> +}
> +
> +TEST_F(SwizzleRemapTest, ArrayRemappingBase_xy_x)
> +{
> + array_remapping map1(5, 3, 1);
> + ASSERT_EQ(map1.target_array_id(), 5u);
> + ASSERT_EQ(map1.map_writemask(1), 4);
> + ASSERT_EQ(map1.map_one_swizzle(0), 2);
> + ASSERT_EQ(map1.combined_access_mask(), 0x7);
> +}
> +
> +TEST_F(SwizzleRemapTest, ArrayRemappingBase_no_reswizzle)
> +{
> + array_remapping map1(5, 3);
> + ASSERT_EQ(map1.target_array_id(), 5u);
> + for (int i = 1; i < 16; ++i)
> + ASSERT_EQ(map1.map_writemask(i), i);
> +
> + for (int i = 0; i < 4; ++i)
> + ASSERT_EQ(map1.map_one_swizzle(i), i);
> +}
> +
> +TEST_F(SwizzleRemapTest, ArrayRemappingBase_xyz_x)
> +{
> + array_remapping map1(5, 7, 1);
> + ASSERT_EQ(map1.target_array_id(), 5u);
> + ASSERT_EQ(map1.map_writemask(1), 8);
> + ASSERT_EQ(map1.map_one_swizzle(0), 3);
> + ASSERT_EQ(map1.combined_access_mask(), 0xF);
> +}
> +
> +TEST_F(SwizzleRemapTest, ArrayRemappingBase_xy_xy)
> +{
> + array_remapping map1(5, 3, 3);
> + ASSERT_EQ(map1.target_array_id(), 5u);
> + ASSERT_EQ(map1.map_writemask(1), 4);
> + ASSERT_EQ(map1.map_writemask(2), 8);
> + ASSERT_EQ(map1.map_writemask(3), 0xC);
> + ASSERT_EQ(map1.map_one_swizzle(0), 2);
> + ASSERT_EQ(map1.map_one_swizzle(1), 3);
> + ASSERT_EQ(map1.combined_access_mask(), 0xF);
> +}
> +
> +TEST_F(SwizzleRemapTest, ArrayRemappingBase_xz_xw)
> +{
> + array_remapping map1(5, 5, 9);
> + std::cerr << map1 << "\n";
> + ASSERT_EQ(map1.target_array_id(), 5u);
> + ASSERT_EQ(map1.map_writemask(1), 2);
> + ASSERT_EQ(map1.map_writemask(8), 8);
> + ASSERT_EQ(map1.map_writemask(9), 0xA);
> + ASSERT_EQ(map1.map_one_swizzle(0), 1);
> + ASSERT_EQ(map1.map_one_swizzle(3), 3);
> + ASSERT_EQ(map1.combined_access_mask(), 0xF);
> +}
> +
> +using ArrayMergeTest=testing::Test;
> +
> +TEST_F(ArrayMergeTest, ArrayMergeTwoSwizzles)
> +{
> + vector<array_live_range> alt = {
> + {1, 4, 1, 5, WRITEMASK_X},
> + {2, 4, 2, 5, WRITEMASK_X},
> + };
> +
> + vector<array_remapping> expect = {
> + {},
> + {1, WRITEMASK_X, WRITEMASK_X},
> + };
> +
> + vector<array_remapping> 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<array_live_range> 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},
> + };
> +
> + vector<array_remapping> expect = {
> + {},
> + {1, WRITEMASK_X, WRITEMASK_X},
> + {1, WRITEMASK_XY, WRITEMASK_X},
> + {1, WRITEMASK_XYZ, WRITEMASK_X},
> + };
> +
> + vector<array_remapping> 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<array_live_range> input = {
> + {1, 3, 1, 5, WRITEMASK_XYZW},
> + {2, 2, 6, 7, WRITEMASK_XYZW},
> + };
> +
> + vector<array_remapping> expect = {
> + {},
> + {1, WRITEMASK_XYZW},
> + };
> +
> + vector<array_remapping> result(3);
> + get_array_remapping(2, &input[0], &result[0]);
> +
> + for (unsigned i = 0; i < expect.size(); ++i)
> + EXPECT_EQ(result[i + 1], expect[i]);
> +}
> +
> +TEST_F(ArrayMergeTest, MergeAndInterleave)
> +{
> + vector<array_live_range> 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},
> + };
> +
> + vector<array_remapping> expect = {
> + {},
> + {1, WRITEMASK_X},
> + {1, WRITEMASK_X, WRITEMASK_X},
> + {1, WRITEMASK_X, WRITEMASK_X}
> + };
> + vector<array_remapping> result(input.size() + 1);
> + get_array_remapping(input.size(), &input[0], &result[0]);
> +
> + for (unsigned i = 0; i < expect.size(); ++i)
> + EXPECT_EQ(result[i + 1], expect[i]);
> +}
> +
> +TEST_F(ArrayMergeTest, MergeAndInterleave2)
> +{
> + vector<array_live_range> 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},
> + };
> +
> + vector<array_remapping> expect = {
> + {},
> + {1, WRITEMASK_X},
> + {1, WRITEMASK_X, WRITEMASK_XY},
> + {1, WRITEMASK_XYZ, WRITEMASK_X}
> + };
> + vector<array_remapping> result(input.size() + 1);
> + get_array_remapping(input.size(), &input[0], &result[0]);
> +
> + for (unsigned i = 0; i < expect.size(); ++i)
> + EXPECT_EQ(result[i + 1], expect[i]);
> +}
> +
> +
> +TEST_F(ArrayMergeTest, MergeAndInterleave3)
> +{
> + vector<array_live_range> input = {
> + {1, 5, 1, 5, WRITEMASK_X},
> + {2, 4, 6, 7, WRITEMASK_XY},
> + {3, 3, 1, 5, WRITEMASK_X}
> + };
> +
> + vector<array_remapping> expect = {
> + {},
> + {1, WRITEMASK_X},
> + {1, WRITEMASK_X, WRITEMASK_X}
> + };
> + vector<array_remapping> result(input.size() + 1);
> + get_array_remapping(input.size(), &input[0], &result[0]);
> +
> + for (unsigned i = 0; i < expect.size(); ++i)
> + EXPECT_EQ(result[i + 1], expect[i]);
> +}
> +
> +TEST_F(ArrayMergeTest, MergeAndInterleave4)
> +{
> + vector<array_live_range> 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},
> + };
> +
> + vector<array_remapping> expect = {
> + {},
> + {1, WRITEMASK_XY},
> + {1, WRITEMASK_X, WRITEMASK_X},
> + {1, WRITEMASK_XYZ},
> + {1, WRITEMASK_XYZ, WRITEMASK_W},
> + {1, WRITEMASK_XYZW}
> + };
> + vector<array_remapping> 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<array_live_range> 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}
> + };
> +
> + vector<array_remapping> expect = {
> + {5, WRITEMASK_XY, WRITEMASK_XY}, /* expect xy because of interleaving */
> + {5, WRITEMASK_XYZ, WRITEMASK_X},
> + {5, WRITEMASK_XYZ, WRITEMASK_X},
> + {5, WRITEMASK_XY, WRITEMASK_XY},
> + {}
> + };
> + vector<array_remapping> 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.16.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: signature
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20180507/2c41efac/attachment-0001.sig>
More information about the mesa-dev
mailing list