2 * Copyright © 2010 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
21 * DEALINGS IN THE SOFTWARE.
25 * \file brw_cubemap_normalize.cpp
27 * IR lower pass to perform the normalization of the cubemap coordinates to
28 * have the largest magnitude component be -1.0 or 1.0.
30 * \author Eric Anholt <eric@anholt.net>
33 #include "../glsl/glsl_types.h"
34 #include "../glsl/ir.h"
36 class brw_cubemap_normalize_visitor
: public ir_hierarchical_visitor
{
38 brw_cubemap_normalize_visitor()
43 ir_visitor_status
visit_leave(ir_texture
*ir
);
49 brw_cubemap_normalize_visitor::visit_leave(ir_texture
*ir
)
51 if (ir
->sampler
->type
->sampler_dimensionality
!= GLSL_SAMPLER_DIM_CUBE
)
52 return visit_continue
;
54 void *mem_ctx
= talloc_parent(ir
);
56 ir_variable
*var
= new(mem_ctx
) ir_variable(ir
->coordinate
->type
,
57 "coordinate", ir_var_auto
);
58 base_ir
->insert_before(var
);
59 ir_dereference
*deref
= new(mem_ctx
) ir_dereference_variable(var
);
60 ir_assignment
*assign
= new(mem_ctx
) ir_assignment(deref
, ir
->coordinate
,
62 base_ir
->insert_before(assign
);
64 deref
= new(mem_ctx
) ir_dereference_variable(var
);
65 ir_rvalue
*swiz0
= new(mem_ctx
) ir_swizzle(deref
, 0, 0, 0, 0, 1);
66 deref
= new(mem_ctx
) ir_dereference_variable(var
);
67 ir_rvalue
*swiz1
= new(mem_ctx
) ir_swizzle(deref
, 1, 0, 0, 0, 1);
68 deref
= new(mem_ctx
) ir_dereference_variable(var
);
69 ir_rvalue
*swiz2
= new(mem_ctx
) ir_swizzle(deref
, 2, 0, 0, 0, 1);
71 swiz0
= new(mem_ctx
) ir_expression(ir_unop_abs
, swiz0
->type
, swiz0
, NULL
);
72 swiz1
= new(mem_ctx
) ir_expression(ir_unop_abs
, swiz1
->type
, swiz1
, NULL
);
73 swiz2
= new(mem_ctx
) ir_expression(ir_unop_abs
, swiz2
->type
, swiz2
, NULL
);
76 expr
= new(mem_ctx
) ir_expression(ir_binop_max
,
77 glsl_type::float_type
,
80 expr
= new(mem_ctx
) ir_expression(ir_binop_max
,
81 glsl_type::float_type
,
84 expr
= new(mem_ctx
) ir_expression(ir_unop_rcp
,
85 glsl_type::float_type
,
88 deref
= new(mem_ctx
) ir_dereference_variable(var
);
89 ir
->coordinate
= new(mem_ctx
) ir_expression(ir_binop_mul
,
95 return visit_continue
;
101 brw_do_cubemap_normalize(exec_list
*instructions
)
103 brw_cubemap_normalize_visitor v
;
105 visit_list_elements(&v
, instructions
);