2012-11-30 23:52:38 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2012 Intel 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 "brw_vec4.h"
|
2015-11-22 18:27:42 -08:00
|
|
|
#include "program/program.h"
|
2012-11-30 23:52:38 -08:00
|
|
|
|
|
|
|
|
using namespace brw;
|
|
|
|
|
|
|
|
|
|
int ret = 0;
|
|
|
|
|
|
2015-04-07 22:05:28 +03:00
|
|
|
#define register_coalesce(v) _register_coalesce(v, __func__)
|
2012-11-30 23:52:38 -08:00
|
|
|
|
|
|
|
|
class register_coalesce_test : public ::testing::Test {
|
|
|
|
|
virtual void SetUp();
|
2021-02-10 16:43:08 +01:00
|
|
|
virtual void TearDown();
|
2012-11-30 23:52:38 -08:00
|
|
|
|
|
|
|
|
public:
|
2015-06-22 17:17:56 -07:00
|
|
|
struct brw_compiler *compiler;
|
2016-08-22 15:01:08 -07:00
|
|
|
struct gen_device_info *devinfo;
|
2021-02-10 16:43:08 +01:00
|
|
|
void *ctx;
|
2012-11-30 23:52:38 -08:00
|
|
|
struct gl_shader_program *shader_prog;
|
2016-02-08 15:32:12 -08:00
|
|
|
struct brw_vue_prog_data *prog_data;
|
2012-11-30 23:52:38 -08:00
|
|
|
vec4_visitor *v;
|
|
|
|
|
};
|
|
|
|
|
|
2013-02-15 20:12:13 -08:00
|
|
|
|
|
|
|
|
class register_coalesce_vec4_visitor : public vec4_visitor
|
|
|
|
|
{
|
|
|
|
|
public:
|
2015-06-22 17:17:56 -07:00
|
|
|
register_coalesce_vec4_visitor(struct brw_compiler *compiler,
|
2021-02-10 16:43:08 +01:00
|
|
|
void *mem_ctx,
|
2016-02-08 15:32:12 -08:00
|
|
|
nir_shader *shader,
|
|
|
|
|
struct brw_vue_prog_data *prog_data)
|
2021-02-10 16:43:08 +01:00
|
|
|
: vec4_visitor(compiler, NULL, NULL, prog_data, shader, mem_ctx,
|
2021-03-23 11:31:51 -07:00
|
|
|
false /* no_spills */, -1, false)
|
2013-02-15 20:12:13 -08:00
|
|
|
{
|
2016-02-08 15:32:12 -08:00
|
|
|
prog_data->dispatch_mode = DISPATCH_MODE_4X2_DUAL_OBJECT;
|
2013-02-15 20:12:13 -08:00
|
|
|
}
|
2013-02-17 08:05:52 -08:00
|
|
|
|
|
|
|
|
protected:
|
2018-06-21 14:22:02 -07:00
|
|
|
virtual dst_reg *make_reg_for_system_value(int /* location */)
|
2013-02-17 08:05:52 -08:00
|
|
|
{
|
2014-06-29 14:54:01 -07:00
|
|
|
unreachable("Not reached");
|
2013-02-17 08:05:52 -08:00
|
|
|
}
|
|
|
|
|
|
2013-07-13 09:03:18 -07:00
|
|
|
virtual void setup_payload()
|
2013-02-17 08:05:52 -08:00
|
|
|
{
|
2014-06-29 14:54:01 -07:00
|
|
|
unreachable("Not reached");
|
2013-02-17 08:05:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void emit_prolog()
|
|
|
|
|
{
|
2014-06-29 14:54:01 -07:00
|
|
|
unreachable("Not reached");
|
2013-02-17 08:05:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void emit_thread_end()
|
|
|
|
|
{
|
2014-06-29 14:54:01 -07:00
|
|
|
unreachable("Not reached");
|
2013-03-22 06:59:52 -07:00
|
|
|
}
|
|
|
|
|
|
2018-06-21 14:22:02 -07:00
|
|
|
virtual void emit_urb_write_header(int /* mrf */)
|
2013-03-22 06:59:52 -07:00
|
|
|
{
|
2014-06-29 14:54:01 -07:00
|
|
|
unreachable("Not reached");
|
2013-03-22 06:59:52 -07:00
|
|
|
}
|
|
|
|
|
|
2018-06-21 14:22:02 -07:00
|
|
|
virtual vec4_instruction *emit_urb_write_opcode(bool /* complete */)
|
2013-03-22 06:59:52 -07:00
|
|
|
{
|
2014-06-29 19:12:04 -07:00
|
|
|
unreachable("Not reached");
|
2013-02-17 08:05:52 -08:00
|
|
|
}
|
2013-02-15 20:12:13 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2012-11-30 23:52:38 -08:00
|
|
|
void register_coalesce_test::SetUp()
|
|
|
|
|
{
|
2021-02-10 16:43:08 +01:00
|
|
|
ctx = ralloc_context(NULL);
|
|
|
|
|
compiler = rzalloc(ctx, struct brw_compiler);
|
|
|
|
|
devinfo = rzalloc(ctx, struct gen_device_info);
|
2015-06-22 17:17:56 -07:00
|
|
|
compiler->devinfo = devinfo;
|
2012-11-30 23:52:38 -08:00
|
|
|
|
2021-02-10 16:43:08 +01:00
|
|
|
prog_data = ralloc(ctx, struct brw_vue_prog_data);
|
|
|
|
|
|
2016-10-13 11:41:23 +11:00
|
|
|
nir_shader *shader =
|
2021-02-10 16:43:08 +01:00
|
|
|
nir_shader_create(ctx, MESA_SHADER_VERTEX, NULL, NULL);
|
2012-11-30 23:52:38 -08:00
|
|
|
|
2021-02-10 16:43:08 +01:00
|
|
|
v = new register_coalesce_vec4_visitor(compiler, ctx, shader, prog_data);
|
2012-11-30 23:52:38 -08:00
|
|
|
|
2021-03-29 14:41:58 -07:00
|
|
|
devinfo->ver = 4;
|
|
|
|
|
devinfo->verx10 = devinfo->ver * 10;
|
2012-11-30 23:52:38 -08:00
|
|
|
}
|
|
|
|
|
|
2021-02-10 16:43:08 +01:00
|
|
|
void register_coalesce_test::TearDown()
|
|
|
|
|
{
|
|
|
|
|
delete v;
|
|
|
|
|
v = NULL;
|
|
|
|
|
|
|
|
|
|
ralloc_free(ctx);
|
|
|
|
|
ctx = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-30 23:52:38 -08:00
|
|
|
static void
|
|
|
|
|
_register_coalesce(vec4_visitor *v, const char *func)
|
|
|
|
|
{
|
2020-07-30 16:18:37 +02:00
|
|
|
const bool print = getenv("TEST_DEBUG");
|
2012-11-30 23:52:38 -08:00
|
|
|
|
|
|
|
|
if (print) {
|
|
|
|
|
printf("%s: instructions before:\n", func);
|
|
|
|
|
v->dump_instructions();
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-24 16:05:50 -07:00
|
|
|
v->calculate_cfg();
|
2012-08-01 19:35:18 -07:00
|
|
|
v->opt_register_coalesce();
|
2012-11-30 23:52:38 -08:00
|
|
|
|
|
|
|
|
if (print) {
|
|
|
|
|
printf("%s: instructions after:\n", func);
|
|
|
|
|
v->dump_instructions();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-01 19:35:18 -07:00
|
|
|
TEST_F(register_coalesce_test, test_compute_to_mrf)
|
2012-11-30 23:52:38 -08:00
|
|
|
{
|
|
|
|
|
src_reg something = src_reg(v, glsl_type::float_type);
|
|
|
|
|
dst_reg temp = dst_reg(v, glsl_type::float_type);
|
|
|
|
|
dst_reg init;
|
|
|
|
|
|
|
|
|
|
dst_reg m0 = dst_reg(MRF, 0);
|
|
|
|
|
m0.writemask = WRITEMASK_X;
|
|
|
|
|
m0.type = BRW_REGISTER_TYPE_F;
|
|
|
|
|
|
2015-11-02 12:12:44 -08:00
|
|
|
vec4_instruction *mul = v->emit(v->MUL(temp, something, brw_imm_f(1.0f)));
|
2012-11-30 23:52:38 -08:00
|
|
|
v->emit(v->MOV(m0, src_reg(temp)));
|
|
|
|
|
|
|
|
|
|
register_coalesce(v);
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(mul->dst.file, MRF);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(register_coalesce_test, test_multiple_use)
|
|
|
|
|
{
|
|
|
|
|
src_reg something = src_reg(v, glsl_type::float_type);
|
|
|
|
|
dst_reg temp = dst_reg(v, glsl_type::vec4_type);
|
|
|
|
|
dst_reg init;
|
|
|
|
|
|
|
|
|
|
dst_reg m0 = dst_reg(MRF, 0);
|
|
|
|
|
m0.writemask = WRITEMASK_X;
|
|
|
|
|
m0.type = BRW_REGISTER_TYPE_F;
|
|
|
|
|
|
|
|
|
|
dst_reg m1 = dst_reg(MRF, 1);
|
|
|
|
|
m1.writemask = WRITEMASK_XYZW;
|
|
|
|
|
m1.type = BRW_REGISTER_TYPE_F;
|
|
|
|
|
|
|
|
|
|
src_reg src = src_reg(temp);
|
2015-11-02 12:12:44 -08:00
|
|
|
vec4_instruction *mul = v->emit(v->MUL(temp, something, brw_imm_f(1.0f)));
|
2012-11-30 23:52:38 -08:00
|
|
|
src.swizzle = BRW_SWIZZLE_XXXX;
|
|
|
|
|
v->emit(v->MOV(m0, src));
|
|
|
|
|
src.swizzle = BRW_SWIZZLE_XYZW;
|
|
|
|
|
v->emit(v->MOV(m1, src));
|
|
|
|
|
|
|
|
|
|
register_coalesce(v);
|
|
|
|
|
|
|
|
|
|
EXPECT_NE(mul->dst.file, MRF);
|
|
|
|
|
}
|
2012-11-30 22:29:26 -08:00
|
|
|
|
|
|
|
|
TEST_F(register_coalesce_test, test_dp4_mrf)
|
|
|
|
|
{
|
|
|
|
|
src_reg some_src_1 = src_reg(v, glsl_type::vec4_type);
|
|
|
|
|
src_reg some_src_2 = src_reg(v, glsl_type::vec4_type);
|
|
|
|
|
dst_reg init;
|
|
|
|
|
|
|
|
|
|
dst_reg m0 = dst_reg(MRF, 0);
|
|
|
|
|
m0.writemask = WRITEMASK_Y;
|
|
|
|
|
m0.type = BRW_REGISTER_TYPE_F;
|
|
|
|
|
|
|
|
|
|
dst_reg temp = dst_reg(v, glsl_type::float_type);
|
|
|
|
|
|
|
|
|
|
vec4_instruction *dp4 = v->emit(v->DP4(temp, some_src_1, some_src_2));
|
|
|
|
|
v->emit(v->MOV(m0, src_reg(temp)));
|
|
|
|
|
|
|
|
|
|
register_coalesce(v);
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(dp4->dst.file, MRF);
|
|
|
|
|
EXPECT_EQ(dp4->dst.writemask, WRITEMASK_Y);
|
|
|
|
|
}
|
2012-08-01 19:35:18 -07:00
|
|
|
|
|
|
|
|
TEST_F(register_coalesce_test, test_dp4_grf)
|
|
|
|
|
{
|
|
|
|
|
src_reg some_src_1 = src_reg(v, glsl_type::vec4_type);
|
|
|
|
|
src_reg some_src_2 = src_reg(v, glsl_type::vec4_type);
|
|
|
|
|
dst_reg init;
|
|
|
|
|
|
|
|
|
|
dst_reg to = dst_reg(v, glsl_type::vec4_type);
|
|
|
|
|
dst_reg temp = dst_reg(v, glsl_type::float_type);
|
|
|
|
|
|
|
|
|
|
vec4_instruction *dp4 = v->emit(v->DP4(temp, some_src_1, some_src_2));
|
|
|
|
|
to.writemask = WRITEMASK_Y;
|
|
|
|
|
v->emit(v->MOV(to, src_reg(temp)));
|
|
|
|
|
|
|
|
|
|
/* if we don't do something with the result, the automatic dead code
|
|
|
|
|
* elimination will remove all our instructions.
|
|
|
|
|
*/
|
|
|
|
|
src_reg src = src_reg(to);
|
|
|
|
|
src.negate = true;
|
|
|
|
|
v->emit(v->MOV(dst_reg(MRF, 0), src));
|
|
|
|
|
|
|
|
|
|
register_coalesce(v);
|
|
|
|
|
|
2015-10-26 04:35:14 -07:00
|
|
|
EXPECT_EQ(dp4->dst.nr, to.nr);
|
2012-08-01 19:35:18 -07:00
|
|
|
EXPECT_EQ(dp4->dst.writemask, WRITEMASK_Y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(register_coalesce_test, test_channel_mul_grf)
|
|
|
|
|
{
|
|
|
|
|
src_reg some_src_1 = src_reg(v, glsl_type::vec4_type);
|
|
|
|
|
src_reg some_src_2 = src_reg(v, glsl_type::vec4_type);
|
|
|
|
|
dst_reg init;
|
|
|
|
|
|
|
|
|
|
dst_reg to = dst_reg(v, glsl_type::vec4_type);
|
|
|
|
|
dst_reg temp = dst_reg(v, glsl_type::float_type);
|
|
|
|
|
|
|
|
|
|
vec4_instruction *mul = v->emit(v->MUL(temp, some_src_1, some_src_2));
|
|
|
|
|
to.writemask = WRITEMASK_Y;
|
|
|
|
|
v->emit(v->MOV(to, src_reg(temp)));
|
|
|
|
|
|
|
|
|
|
/* if we don't do something with the result, the automatic dead code
|
|
|
|
|
* elimination will remove all our instructions.
|
|
|
|
|
*/
|
|
|
|
|
src_reg src = src_reg(to);
|
|
|
|
|
src.negate = true;
|
|
|
|
|
v->emit(v->MOV(dst_reg(MRF, 0), src));
|
|
|
|
|
|
|
|
|
|
register_coalesce(v);
|
|
|
|
|
|
2015-10-26 04:35:14 -07:00
|
|
|
EXPECT_EQ(mul->dst.nr, to.nr);
|
2012-08-01 19:35:18 -07:00
|
|
|
}
|