From: Rhys Perry Date: Mon, 23 Jan 2023 19:54:12 +0000 (+0000) Subject: nir: add nir_lower_alu_width_test.fdot_order X-Git-Tag: upstream/23.3.3~11936 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=98cb7e010824e9458fea29f3a68f70e52c46ec0f;p=platform%2Fupstream%2Fmesa.git nir: add nir_lower_alu_width_test.fdot_order Signed-off-by: Rhys Perry Reviewed-by: Timur Kristóf Part-of: --- diff --git a/src/compiler/nir/meson.build b/src/compiler/nir/meson.build index 7427546..6ed71d4 100644 --- a/src/compiler/nir/meson.build +++ b/src/compiler/nir/meson.build @@ -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 index 0000000..5eb63c8 --- /dev/null +++ b/src/compiler/nir/tests/lower_alu_width_tests.cpp @@ -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 + +#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); +} + +}