[Mesa-dev] [PATCH v5 5/6] mesa/st: glsl_to_tgsi: Add test set for evaluation of rename mapping
Gert Wollny
gw.fossdev at gmail.com
Sun Jun 25 07:22:14 UTC 2017
The patch adds tests for the register rename mapping evaluation.
---
.../tests/test_glsl_to_tgsi_lifetime.cpp | 94 ++++++++++++++++++++++
1 file changed, 94 insertions(+)
diff --git a/src/mesa/state_tracker/tests/test_glsl_to_tgsi_lifetime.cpp b/src/mesa/state_tracker/tests/test_glsl_to_tgsi_lifetime.cpp
index 5f3378637a..f53b5c23a1 100644
--- a/src/mesa/state_tracker/tests/test_glsl_to_tgsi_lifetime.cpp
+++ b/src/mesa/state_tracker/tests/test_glsl_to_tgsi_lifetime.cpp
@@ -89,6 +89,13 @@ protected:
void check(const vector<lifetime>& result, const expectation& e);
};
+/* With this test class the renaming mepping estimation is tested */
+class RegisterRemapping : public MesaTestWithMemCtx {
+protected:
+ void run(const vector<lifetime>& lt, const vector<int>& expect);
+};
+
+
/* This test class checks that the life time covers at least
* in the expected range. It is used for cases where we know that
* a the implementation could be improved on estimating the minimal
@@ -466,6 +473,29 @@ TEST_F(LifetimeEvaluatorExactTest, LoopWithReadWriteInSwitchDifferentCase)
run (code, expectation({{-1,-1},{0, 9}}));
}
+/* Here we read and write to the same temp, but it is conditional,
+ * so the lifetime must start with the first read */
+TEST_F(LifetimeEvaluatorExactTest, WriteConditionallyFromSelf)
+{
+ const vector<MockCodeline> code = {
+ {TGSI_OPCODE_USEQ, {0}, {in0, in1}, {}},
+ {TGSI_OPCODE_UCMP, {1}, {0, in1, 1}, {}},
+ {TGSI_OPCODE_UCMP, {1}, {0, in1, 1}, {}},
+ {TGSI_OPCODE_UCMP, {1}, {0, in1, 1}, {}},
+ {TGSI_OPCODE_UCMP, {1}, {0, in1, 1}, {}},
+ {TGSI_OPCODE_FSLT, {2}, {1, in1}, {}},
+ {TGSI_OPCODE_UIF, {2}, {}, {}},
+ {TGSI_OPCODE_MOV, {3}, {in1}, {}},
+ {TGSI_OPCODE_ELSE},
+ {TGSI_OPCODE_MOV, {4}, {in1}, {}},
+ {TGSI_OPCODE_MOV, {4}, {4}, {}},
+ {TGSI_OPCODE_MOV, {3}, {4}, {}},
+ {TGSI_OPCODE_ENDIF},
+ {TGSI_OPCODE_MOV,{out1}, {3}, {}},
+ {TGSI_OPCODE_END}
+ };
+ run (code, expectation({{-1,-1},{1, 5}, {5, 6}, {7, 13}, {9, 11}}));
+}
TEST_F(LifetimeEvaluatorExactTest, LoopRWInSwitchCaseLastCaseWithoutBreak)
{
@@ -831,6 +861,47 @@ TEST_F(LifetimeEvaluatorExactTest, NestedLoopWithWriteAfterBreak)
run (code, expectation({{-1,-1},{0, 8}}));
}
+TEST_F(RegisterRemapping, RegisterRemapping1)
+{
+ vector<lifetime> lt({{-1,-1},
+ {0, 1},
+ {0, 2},
+ {1, 2},
+ {2, 10},
+ {3, 5},
+ {5, 10}
+ });
+
+ vector<int> expect({0, 1, 2, 1, 1, 2, 2});
+ run(lt, expect);
+}
+
+
+TEST_F(RegisterRemapping, RegisterRemapping2)
+{
+ vector<lifetime> lt({{-1,-1},
+ {0, 1},
+ {0, 2},
+ {3, 3},
+ {4, 4},
+ });
+ vector<int> expect({0, 1, 2, 1, 1});
+ run(lt, expect);
+}
+
+TEST_F(RegisterRemapping, RegisterRemappingMergeAll)
+{
+ vector<lifetime> lt({{-1,-1},
+ {0, 1},
+ {1, 2},
+ {2, 3},
+ {3, 4},
+ });
+ vector<int> expect({0, 1, 1, 1, 1});
+ run(lt, expect);
+}
+
+
/* Implementation of helper and test classes */
MockShader::~MockShader()
@@ -974,3 +1045,26 @@ void LifetimeEvaluatorAtLeastTest::check( const vector<lifetime>& lifetimes,
EXPECT_GE(lifetimes[i].end, e[i][1]);
}
}
+
+void RegisterRemapping::run(const vector<lifetime>& lt,
+ const vector<int>& expect)
+{
+ rename_reg_pair proto{false, 0};
+ vector<rename_reg_pair> result(lt.size(), proto);
+
+ get_temp_registers_remapping(mem_ctx, lt.size(), <[0], &result[0]);
+
+ vector<int> remap(lt.size());
+ for (unsigned i = 0; i < lt.size(); ++i) {
+ remap[i] = result[i].valid ? result[i].new_reg : i;
+ }
+
+ std::transform(remap.begin(), remap.end(), result.begin(), remap.begin(),
+ [](int x, const rename_reg_pair& rn) {
+ return rn.valid ? rn.new_reg : x;
+ });
+
+ for(unsigned i = 1; i < remap.size(); ++i) {
+ EXPECT_EQ(remap[i], expect[i]);
+ }
+}
--
2.13.0
More information about the mesa-dev
mailing list