Mesa (main): pan/bi: Add fclamp unit tests
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Wed Aug 11 19:20:00 UTC 2021
Module: Mesa
Branch: main
Commit: 4f347e96b82d2c149f2edcbb0bf5c6badabb520f
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=4f347e96b82d2c149f2edcbb0bf5c6badabb520f
Author: Alyssa Rosenzweig <alyssa at collabora.com>
Date: Wed Aug 4 12:12:31 2021 -0400
pan/bi: Add fclamp unit tests
The negative cases here did not pass before this series, showing the bug
in the clamp optimization. By introducing the FCLAMP pseudo op, the bug
is fixed. Let's ensure we don't regress.
Signed-off-by: Alyssa Rosenzweig <alyssa at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12205>
---
src/panfrost/bifrost/test/test-optimizer.c | 101 +++++++++++++++++++++++++++++
1 file changed, 101 insertions(+)
diff --git a/src/panfrost/bifrost/test/test-optimizer.c b/src/panfrost/bifrost/test/test-optimizer.c
index 43dc01574f5..6fc94609df3 100644
--- a/src/panfrost/bifrost/test/test-optimizer.c
+++ b/src/panfrost/bifrost/test/test-optimizer.c
@@ -136,6 +136,107 @@ main(int argc, const char **argv)
NEGCASE(bi_fadd_f32_to(b, reg, bi_fadd_f32(b, bi_neg(bi_abs(x)), zero, BI_ROUND_NONE), y, BI_ROUND_NONE));
NEGCASE(bi_fadd_f32_to(b, reg, bi_fadd_f32(b, x, zero, BI_ROUND_NONE), y, BI_ROUND_NONE));
+ /* Check clamps are propagated */
+ CASE({
+ bi_instr *I = bi_fclamp_f32_to(b, reg, bi_fadd_f32(b, x, y, BI_ROUND_NONE));
+ I->clamp = BI_CLAMP_CLAMP_0_INF;
+ }, {
+ bi_instr *I = bi_fadd_f32_to(b, reg, x, y, BI_ROUND_NONE);
+ I->clamp = BI_CLAMP_CLAMP_0_INF;
+ });
+
+ CASE({
+ bi_instr *I = bi_fclamp_v2f16_to(b, reg, bi_fadd_v2f16(b, x, y, BI_ROUND_NONE));
+ I->clamp = BI_CLAMP_CLAMP_0_1;
+ }, {
+ bi_instr *I = bi_fadd_v2f16_to(b, reg, x, y, BI_ROUND_NONE);
+ I->clamp = BI_CLAMP_CLAMP_0_1;
+ });
+
+ /* Check clamps are composed */
+ CASE({
+ bi_instr *I = bi_fadd_f32_to(b, bi_temp(b->shader), x, y, BI_ROUND_NONE);
+ bi_instr *J = bi_fclamp_f32_to(b, reg, I->dest[0]);
+ I->clamp = BI_CLAMP_CLAMP_M1_1;
+ J->clamp = BI_CLAMP_CLAMP_0_INF;
+ }, {
+ bi_instr *I = bi_fadd_f32_to(b, reg, x, y, BI_ROUND_NONE);
+ I->clamp = BI_CLAMP_CLAMP_0_1;
+ });
+
+ CASE({
+ bi_instr *I = bi_fadd_f32_to(b, bi_temp(b->shader), x, y, BI_ROUND_NONE);
+ bi_instr *J = bi_fclamp_f32_to(b, reg, I->dest[0]);
+ I->clamp = BI_CLAMP_CLAMP_0_1;
+ J->clamp = BI_CLAMP_CLAMP_0_INF;
+ }, {
+ bi_instr *I = bi_fadd_f32_to(b, reg, x, y, BI_ROUND_NONE);
+ I->clamp = BI_CLAMP_CLAMP_0_1;
+ });
+
+ CASE({
+ bi_instr *I = bi_fadd_f32_to(b, bi_temp(b->shader), x, y, BI_ROUND_NONE);
+ bi_instr *J = bi_fclamp_f32_to(b, reg, I->dest[0]);
+ I->clamp = BI_CLAMP_CLAMP_0_INF;
+ J->clamp = BI_CLAMP_CLAMP_0_INF;
+ }, {
+ bi_instr *I = bi_fadd_f32_to(b, reg, x, y, BI_ROUND_NONE);
+ I->clamp = BI_CLAMP_CLAMP_0_INF;
+ });
+
+ CASE({
+ bi_instr *I = bi_fadd_v2f16_to(b, bi_temp(b->shader), x, y, BI_ROUND_NONE);
+ bi_instr *J = bi_fclamp_v2f16_to(b, reg, I->dest[0]);
+ I->clamp = BI_CLAMP_CLAMP_M1_1;
+ J->clamp = BI_CLAMP_CLAMP_0_INF;
+ }, {
+ bi_instr *I = bi_fadd_v2f16_to(b, reg, x, y, BI_ROUND_NONE);
+ I->clamp = BI_CLAMP_CLAMP_0_1;
+ });
+
+ CASE({
+ bi_instr *I = bi_fadd_v2f16_to(b, bi_temp(b->shader), x, y, BI_ROUND_NONE);
+ bi_instr *J = bi_fclamp_v2f16_to(b, reg, I->dest[0]);
+ I->clamp = BI_CLAMP_CLAMP_0_1;
+ J->clamp = BI_CLAMP_CLAMP_0_INF;
+ }, {
+ bi_instr *I = bi_fadd_v2f16_to(b, reg, x, y, BI_ROUND_NONE);
+ I->clamp = BI_CLAMP_CLAMP_0_1;
+ });
+
+ CASE({
+ bi_instr *I = bi_fadd_v2f16_to(b, bi_temp(b->shader), x, y, BI_ROUND_NONE);
+ bi_instr *J = bi_fclamp_v2f16_to(b, reg, I->dest[0]);
+ I->clamp = BI_CLAMP_CLAMP_0_INF;
+ J->clamp = BI_CLAMP_CLAMP_0_INF;
+ }, {
+ bi_instr *I = bi_fadd_v2f16_to(b, reg, x, y, BI_ROUND_NONE);
+ I->clamp = BI_CLAMP_CLAMP_0_INF;
+ });
+
+ /* We can't mix sizes */
+
+ NEGCASE({
+ bi_instr *I = bi_fclamp_f32_to(b, reg, bi_fadd_v2f16(b, x, y, BI_ROUND_NONE));
+ I->clamp = BI_CLAMP_CLAMP_0_1;
+ });
+
+ NEGCASE({
+ bi_instr *I = bi_fclamp_v2f16_to(b, reg, bi_fadd_f32(b, x, y, BI_ROUND_NONE));
+ I->clamp = BI_CLAMP_CLAMP_0_1;
+ });
+
+ /* We can't use addition by 0.0 for clamps due to signed zeros. */
+ NEGCASE({
+ bi_instr *I = bi_fadd_f32_to(b, reg, bi_fadd_f32(b, x, y, BI_ROUND_NONE), zero, BI_ROUND_NONE);
+ I->clamp = BI_CLAMP_CLAMP_M1_1;
+ });
+
+ NEGCASE({
+ bi_instr *I = bi_fadd_v2f16_to(b, reg, bi_fadd_v2f16(b, x, y, BI_ROUND_NONE), zero, BI_ROUND_NONE);
+ I->clamp = BI_CLAMP_CLAMP_0_1;
+ });
+
ralloc_free(ralloc_ctx);
TEST_END(nr_pass, nr_fail);
}
More information about the mesa-commit
mailing list