2 * Copyright © 2014 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 #include <gtest/gtest.h>
32 class copy_propagation_test
: public ::testing::Test
{
36 struct brw_context
*brw
;
37 struct gl_context
*ctx
;
38 struct gl_shader_program
*shader_prog
;
39 struct brw_vertex_program
*vp
;
43 class copy_propagation_vec4_visitor
: public vec4_visitor
46 copy_propagation_vec4_visitor(struct brw_context
*brw
,
47 struct gl_shader_program
*shader_prog
)
48 : vec4_visitor(brw
, NULL
, NULL
, NULL
, NULL
, shader_prog
,
49 MESA_SHADER_VERTEX
, NULL
,
50 false, false /* no_spills */,
51 ST_NONE
, ST_NONE
, ST_NONE
)
56 virtual dst_reg
*make_reg_for_system_value(ir_variable
*ir
)
58 assert(!"Not reached");
62 virtual void setup_payload()
64 assert(!"Not reached");
67 virtual void emit_prolog()
69 assert(!"Not reached");
72 virtual void emit_program_code()
74 assert(!"Not reached");
77 virtual void emit_thread_end()
79 assert(!"Not reached");
82 virtual void emit_urb_write_header(int mrf
)
84 assert(!"Not reached");
87 virtual vec4_instruction
*emit_urb_write_opcode(bool complete
)
89 assert(!"Not reached");
95 void copy_propagation_test::SetUp()
97 brw
= (struct brw_context
*)calloc(1, sizeof(*brw
));
100 vp
= ralloc(NULL
, struct brw_vertex_program
);
102 shader_prog
= ralloc(NULL
, struct gl_shader_program
);
104 v
= new copy_propagation_vec4_visitor(brw
, shader_prog
);
106 _mesa_init_vertex_program(ctx
, &vp
->program
, GL_VERTEX_SHADER
, 0);
112 copy_propagation(vec4_visitor
*v
)
117 fprintf(stderr
, "instructions before:\n");
118 v
->dump_instructions();
121 v
->opt_copy_propagation();
124 fprintf(stderr
, "instructions after:\n");
125 v
->dump_instructions();
129 TEST_F(copy_propagation_test
, test_swizzle_swizzle
)
131 dst_reg a
= dst_reg(v
, glsl_type::vec4_type
);
132 dst_reg b
= dst_reg(v
, glsl_type::vec4_type
);
133 dst_reg c
= dst_reg(v
, glsl_type::vec4_type
);
135 v
->emit(v
->ADD(a
, src_reg(a
), src_reg(a
)));
137 v
->emit(v
->MOV(b
, swizzle(src_reg(a
), BRW_SWIZZLE4(SWIZZLE_Y
,
142 vec4_instruction
*test_mov
=
143 v
->MOV(c
, swizzle(src_reg(b
), BRW_SWIZZLE4(SWIZZLE_Y
,
151 EXPECT_EQ(test_mov
->src
[0].reg
, a
.reg
);
152 EXPECT_EQ(test_mov
->src
[0].swizzle
, BRW_SWIZZLE4(SWIZZLE_Z
,