i965: Fix a "discards 'const' qualifier" warning.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_blorp_blit_eu.cpp
1 /*
2 * Copyright © 2013 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 */
23
24 #include "glsl/ralloc.h"
25 #include "brw_blorp_blit_eu.h"
26 #include "brw_blorp.h"
27
28 brw_blorp_eu_emitter::brw_blorp_eu_emitter(struct brw_context *brw)
29 : mem_ctx(ralloc_context(NULL)),
30 generator(brw, mem_ctx,
31 rzalloc(mem_ctx, struct brw_wm_prog_key),
32 rzalloc(mem_ctx, struct brw_wm_prog_data),
33 NULL, NULL, false)
34 {
35 }
36
37 brw_blorp_eu_emitter::~brw_blorp_eu_emitter()
38 {
39 ralloc_free(mem_ctx);
40 }
41
42 const unsigned *
43 brw_blorp_eu_emitter::get_program(unsigned *program_size, FILE *dump_file)
44 {
45 const unsigned *res;
46
47 if (unlikely(INTEL_DEBUG & DEBUG_BLORP)) {
48 fprintf(stderr, "Native code for BLORP blit:\n");
49 res = generator.generate_assembly(NULL, &insts, program_size, dump_file);
50 fprintf(stderr, "\n");
51 } else {
52 res = generator.generate_assembly(NULL, &insts, program_size);
53 }
54
55 return res;
56 }
57
58 /**
59 * Emit code that kills pixels whose X and Y coordinates are outside the
60 * boundary of the rectangle defined by the push constants (dst_x0, dst_y0,
61 * dst_x1, dst_y1).
62 */
63 void
64 brw_blorp_eu_emitter::emit_kill_if_outside_rect(const struct brw_reg &x,
65 const struct brw_reg &y,
66 const struct brw_reg &dst_x0,
67 const struct brw_reg &dst_x1,
68 const struct brw_reg &dst_y0,
69 const struct brw_reg &dst_y1)
70 {
71 struct brw_reg f0 = brw_flag_reg(0, 0);
72 struct brw_reg g1 = retype(brw_vec1_grf(1, 7), BRW_REGISTER_TYPE_UW);
73
74 emit_cmp(BRW_CONDITIONAL_GE, x, dst_x0);
75 emit_cmp(BRW_CONDITIONAL_GE, y, dst_y0)->predicate = BRW_PREDICATE_NORMAL;
76 emit_cmp(BRW_CONDITIONAL_L, x, dst_x1)->predicate = BRW_PREDICATE_NORMAL;
77 emit_cmp(BRW_CONDITIONAL_L, y, dst_y1)->predicate = BRW_PREDICATE_NORMAL;
78
79 fs_inst *inst = new (mem_ctx) fs_inst(BRW_OPCODE_AND, g1, f0, g1);
80 inst->force_writemask_all = true;
81 insts.push_tail(inst);
82 }
83
84 void
85 brw_blorp_eu_emitter::emit_texture_lookup(const struct brw_reg &dst,
86 enum opcode op,
87 unsigned base_mrf,
88 unsigned msg_length)
89 {
90 fs_inst *inst = new (mem_ctx) fs_inst(op, dst, brw_message_reg(base_mrf));
91
92 inst->base_mrf = base_mrf;
93 inst->mlen = msg_length;
94 inst->sampler = 0;
95 inst->header_present = false;
96
97 insts.push_tail(inst);
98 }
99
100 void
101 brw_blorp_eu_emitter::emit_render_target_write(const struct brw_reg &src0,
102 unsigned msg_reg_nr,
103 unsigned msg_length,
104 bool use_header)
105 {
106 fs_inst *inst = new (mem_ctx) fs_inst(FS_OPCODE_BLORP_FB_WRITE);
107
108 inst->src[0] = src0;
109 inst->base_mrf = msg_reg_nr;
110 inst->mlen = msg_length;
111 inst->header_present = use_header;
112 inst->target = BRW_BLORP_RENDERBUFFER_BINDING_TABLE_INDEX;
113
114 insts.push_tail(inst);
115 }
116
117 void
118 brw_blorp_eu_emitter::emit_combine(enum opcode combine_opcode,
119 const struct brw_reg &dst,
120 const struct brw_reg &src_1,
121 const struct brw_reg &src_2)
122 {
123 assert(combine_opcode == BRW_OPCODE_ADD || combine_opcode == BRW_OPCODE_AVG);
124
125 insts.push_tail(new (mem_ctx) fs_inst(combine_opcode, dst, src_1, src_2));
126 }
127
128 fs_inst *
129 brw_blorp_eu_emitter::emit_cmp(int op,
130 const struct brw_reg &x,
131 const struct brw_reg &y)
132 {
133 fs_inst *cmp = new (mem_ctx) fs_inst(BRW_OPCODE_CMP,
134 vec16(brw_null_reg()), x, y);
135 cmp->conditional_mod = op;
136 insts.push_tail(cmp);
137 return cmp;
138 }
139