2014-04-07 19:40:39 +01:00
|
|
|
/*
|
|
|
|
* Copyright © 2014 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-23 02:27:42 +00:00
|
|
|
#include "program/program.h"
|
2014-04-07 19:40:39 +01:00
|
|
|
|
|
|
|
using namespace brw;
|
|
|
|
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
class copy_propagation_test : public ::testing::Test {
|
|
|
|
virtual void SetUp();
|
|
|
|
|
|
|
|
public:
|
2015-06-23 01:17:56 +01:00
|
|
|
struct brw_compiler *compiler;
|
2016-08-22 23:01:08 +01:00
|
|
|
struct gen_device_info *devinfo;
|
2014-04-07 19:40:39 +01:00
|
|
|
struct gl_context *ctx;
|
|
|
|
struct gl_shader_program *shader_prog;
|
2016-02-08 23:32:12 +00:00
|
|
|
struct brw_vue_prog_data *prog_data;
|
2014-04-07 19:40:39 +01:00
|
|
|
vec4_visitor *v;
|
|
|
|
};
|
|
|
|
|
|
|
|
class copy_propagation_vec4_visitor : public vec4_visitor
|
|
|
|
{
|
|
|
|
public:
|
2015-06-23 01:17:56 +01:00
|
|
|
copy_propagation_vec4_visitor(struct brw_compiler *compiler,
|
2016-02-08 23:32:12 +00:00
|
|
|
nir_shader *shader,
|
|
|
|
struct brw_vue_prog_data *prog_data)
|
|
|
|
: vec4_visitor(compiler, NULL, NULL, prog_data, shader, NULL,
|
2015-06-19 23:40:09 +01:00
|
|
|
false /* no_spills */, -1)
|
2014-04-07 19:40:39 +01:00
|
|
|
{
|
2016-02-08 23:32:12 +00:00
|
|
|
prog_data->dispatch_mode = DISPATCH_MODE_4X2_DUAL_OBJECT;
|
2014-04-07 19:40:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2016-05-13 01:44:46 +01:00
|
|
|
virtual dst_reg *make_reg_for_system_value(int location)
|
2014-04-07 19:40:39 +01:00
|
|
|
{
|
2014-06-29 22:54:01 +01:00
|
|
|
unreachable("Not reached");
|
2014-04-07 19:40:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void setup_payload()
|
|
|
|
{
|
2014-06-29 22:54:01 +01:00
|
|
|
unreachable("Not reached");
|
2014-04-07 19:40:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void emit_prolog()
|
|
|
|
{
|
2014-06-29 22:54:01 +01:00
|
|
|
unreachable("Not reached");
|
2014-04-07 19:40:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void emit_thread_end()
|
|
|
|
{
|
2014-06-29 22:54:01 +01:00
|
|
|
unreachable("Not reached");
|
2014-04-07 19:40:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void emit_urb_write_header(int mrf)
|
|
|
|
{
|
2014-06-29 22:54:01 +01:00
|
|
|
unreachable("Not reached");
|
2014-04-07 19:40:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual vec4_instruction *emit_urb_write_opcode(bool complete)
|
|
|
|
{
|
2014-06-30 03:12:04 +01:00
|
|
|
unreachable("Not reached");
|
2014-04-07 19:40:39 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void copy_propagation_test::SetUp()
|
|
|
|
{
|
2015-06-23 01:17:56 +01:00
|
|
|
ctx = (struct gl_context *)calloc(1, sizeof(*ctx));
|
|
|
|
compiler = (struct brw_compiler *)calloc(1, sizeof(*compiler));
|
2016-08-22 23:01:08 +01:00
|
|
|
devinfo = (struct gen_device_info *)calloc(1, sizeof(*devinfo));
|
2016-02-08 23:32:12 +00:00
|
|
|
prog_data = (struct brw_vue_prog_data *)calloc(1, sizeof(*prog_data));
|
2015-06-23 01:17:56 +01:00
|
|
|
compiler->devinfo = devinfo;
|
2014-04-07 19:40:39 +01:00
|
|
|
|
2016-10-13 01:41:23 +01:00
|
|
|
nir_shader *shader =
|
|
|
|
nir_shader_create(NULL, MESA_SHADER_VERTEX, NULL, NULL);
|
2014-04-07 19:40:39 +01:00
|
|
|
|
2016-02-08 23:32:12 +00:00
|
|
|
v = new copy_propagation_vec4_visitor(compiler, shader, prog_data);
|
2014-04-07 19:40:39 +01:00
|
|
|
|
2015-06-23 01:17:56 +01:00
|
|
|
devinfo->gen = 4;
|
2014-04-07 19:40:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
copy_propagation(vec4_visitor *v)
|
|
|
|
{
|
|
|
|
bool print = false;
|
|
|
|
|
|
|
|
if (print) {
|
|
|
|
fprintf(stderr, "instructions before:\n");
|
|
|
|
v->dump_instructions();
|
|
|
|
}
|
|
|
|
|
2014-09-25 00:05:50 +01:00
|
|
|
v->calculate_cfg();
|
2014-04-07 19:40:39 +01:00
|
|
|
v->opt_copy_propagation();
|
|
|
|
|
|
|
|
if (print) {
|
|
|
|
fprintf(stderr, "instructions after:\n");
|
|
|
|
v->dump_instructions();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(copy_propagation_test, test_swizzle_swizzle)
|
|
|
|
{
|
|
|
|
dst_reg a = dst_reg(v, glsl_type::vec4_type);
|
|
|
|
dst_reg b = dst_reg(v, glsl_type::vec4_type);
|
|
|
|
dst_reg c = dst_reg(v, glsl_type::vec4_type);
|
|
|
|
|
|
|
|
v->emit(v->ADD(a, src_reg(a), src_reg(a)));
|
|
|
|
|
|
|
|
v->emit(v->MOV(b, swizzle(src_reg(a), BRW_SWIZZLE4(SWIZZLE_Y,
|
|
|
|
SWIZZLE_Z,
|
|
|
|
SWIZZLE_W,
|
|
|
|
SWIZZLE_X))));
|
|
|
|
|
|
|
|
vec4_instruction *test_mov =
|
|
|
|
v->MOV(c, swizzle(src_reg(b), BRW_SWIZZLE4(SWIZZLE_Y,
|
|
|
|
SWIZZLE_Z,
|
|
|
|
SWIZZLE_W,
|
|
|
|
SWIZZLE_X)));
|
|
|
|
v->emit(test_mov);
|
|
|
|
|
|
|
|
copy_propagation(v);
|
|
|
|
|
2015-10-26 11:35:14 +00:00
|
|
|
EXPECT_EQ(test_mov->src[0].nr, a.nr);
|
2014-04-07 19:40:39 +01:00
|
|
|
EXPECT_EQ(test_mov->src[0].swizzle, BRW_SWIZZLE4(SWIZZLE_Z,
|
|
|
|
SWIZZLE_W,
|
|
|
|
SWIZZLE_X,
|
|
|
|
SWIZZLE_Y));
|
|
|
|
}
|
2014-04-14 14:52:34 +01:00
|
|
|
|
|
|
|
TEST_F(copy_propagation_test, test_swizzle_writemask)
|
|
|
|
{
|
|
|
|
dst_reg a = dst_reg(v, glsl_type::vec4_type);
|
|
|
|
dst_reg b = dst_reg(v, glsl_type::vec4_type);
|
|
|
|
dst_reg c = dst_reg(v, glsl_type::vec4_type);
|
|
|
|
|
|
|
|
v->emit(v->MOV(b, swizzle(src_reg(a), BRW_SWIZZLE4(SWIZZLE_X,
|
|
|
|
SWIZZLE_Y,
|
|
|
|
SWIZZLE_X,
|
|
|
|
SWIZZLE_Z))));
|
|
|
|
|
2015-11-02 20:12:44 +00:00
|
|
|
v->emit(v->MOV(writemask(a, WRITEMASK_XYZ), brw_imm_f(1.0f)));
|
2014-04-14 14:52:34 +01:00
|
|
|
|
|
|
|
vec4_instruction *test_mov =
|
|
|
|
v->MOV(c, swizzle(src_reg(b), BRW_SWIZZLE4(SWIZZLE_W,
|
|
|
|
SWIZZLE_W,
|
|
|
|
SWIZZLE_W,
|
|
|
|
SWIZZLE_W)));
|
|
|
|
v->emit(test_mov);
|
|
|
|
|
|
|
|
copy_propagation(v);
|
|
|
|
|
|
|
|
/* should not copy propagate */
|
2015-10-26 11:35:14 +00:00
|
|
|
EXPECT_EQ(test_mov->src[0].nr, b.nr);
|
2014-04-14 14:52:34 +01:00
|
|
|
EXPECT_EQ(test_mov->src[0].swizzle, BRW_SWIZZLE4(SWIZZLE_W,
|
|
|
|
SWIZZLE_W,
|
|
|
|
SWIZZLE_W,
|
|
|
|
SWIZZLE_W));
|
|
|
|
}
|