nir: add nir_lower_alu_width_test.fdot_order
authorRhys Perry <pendingchaos02@gmail.com>
Mon, 23 Jan 2023 19:54:12 +0000 (19:54 +0000)
committerMarge Bot <emma+marge@anholt.net>
Wed, 8 Mar 2023 14:38:26 +0000 (14:38 +0000)
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20812>

src/compiler/nir/meson.build
src/compiler/nir/tests/lower_alu_width_tests.cpp [new file with mode: 0644]

index 7427546..6ed71d4 100644 (file)
@@ -411,6 +411,7 @@ if with_tests
         'tests/control_flow_tests.cpp',
         'tests/core_tests.cpp',
         'tests/loop_analyze_tests.cpp',
+        'tests/lower_alu_width_tests.cpp',
         'tests/lower_returns_tests.cpp',
         'tests/mod_analysis_tests.cpp',
         'tests/negative_equal_tests.cpp',
diff --git a/src/compiler/nir/tests/lower_alu_width_tests.cpp b/src/compiler/nir/tests/lower_alu_width_tests.cpp
new file mode 100644 (file)
index 0000000..5eb63c8
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright © 2023 Valve Corporation
+ *
+ * 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 <gtest/gtest.h>
+
+#include "nir.h"
+#include "nir_builder.h"
+
+namespace {
+
+class nir_lower_alu_width_test : public ::testing::Test {
+protected:
+   nir_lower_alu_width_test();
+   ~nir_lower_alu_width_test();
+
+   nir_builder b;
+};
+
+nir_lower_alu_width_test::nir_lower_alu_width_test()
+{
+   glsl_type_singleton_init_or_ref();
+
+   static const nir_shader_compiler_options options = { };
+   b = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, &options, "nir_lower_alu_width test");
+}
+
+nir_lower_alu_width_test::~nir_lower_alu_width_test()
+{
+   ralloc_free(b.shader);
+   glsl_type_singleton_decref();
+}
+
+TEST_F(nir_lower_alu_width_test, fdot_order)
+{
+   nir_variable *res_var = nir_local_variable_create(b.impl, glsl_float_type(), "res");
+
+   b.exact = true;
+
+   /* If this isn't done in xyz order, it evaluates to infinity. */
+   nir_ssa_def *val = nir_fdot(
+      &b, nir_imm_vec3(&b, 1.7014118346046923e+38, 1.7014118346046923e+38, 8.507059173023462e+37),
+      nir_imm_vec3(&b, -0.5, 1.5, 1.0));
+   nir_intrinsic_instr *store =
+      nir_build_store_deref(&b, &nir_build_deref_var(&b, res_var)->dest.ssa, val);
+
+   nir_lower_alu_width(b.shader, NULL, NULL);
+   nir_opt_constant_folding(b.shader);
+
+   ASSERT_TRUE(nir_src_is_const(store->src[1]));
+   EXPECT_EQ(nir_src_as_float(store->src[1]), 2.5521177519070385e+38);
+}
+
+}