1584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt/* Copyright © 2011 Intel Corporation
2af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt *
3af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt * Permission is hereby granted, free of charge, to any person obtaining a
4af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt * copy of this software and associated documentation files (the "Software"),
5af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt * to deal in the Software without restriction, including without limitation
6af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt * and/or sell copies of the Software, and to permit persons to whom the
8af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt * Software is furnished to do so, subject to the following conditions:
9af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt *
10af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt * The above copyright notice and this permission notice (including the next
11af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt * paragraph) shall be included in all copies or substantial portions of the
12af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt * Software.
13af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt *
14af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt * IN THE SOFTWARE.
21af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt */
22af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
23af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt#include "brw_vec4.h"
242f0edc60f4bd2ae5999a6afa656e3bb3f181bf0fChad Versace#include "glsl/ir_print_visitor.h"
25af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
26af3c9803d818fd33139f1247a387d64b967b8992Eric Anholtextern "C" {
27af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt#include "brw_eu.h"
282e712e41db0c0676e9f30fc73172c0e8de8d84d4Kenneth Graunke#include "main/macros.h"
29af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt};
30af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
31af3c9803d818fd33139f1247a387d64b967b8992Eric Anholtusing namespace brw;
32af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
33af3c9803d818fd33139f1247a387d64b967b8992Eric Anholtnamespace brw {
34af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
35af3c9803d818fd33139f1247a387d64b967b8992Eric Anholtint
36af3c9803d818fd33139f1247a387d64b967b8992Eric Anholtvec4_visitor::setup_attributes(int payload_reg)
37af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt{
38af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   int nr_attributes;
391c65abb211e6a3df8c46180ae3242486ee97dc8dEric Anholt   int attribute_map[VERT_ATTRIB_MAX + 1];
40af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
41af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   nr_attributes = 0;
42af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   for (int i = 0; i < VERT_ATTRIB_MAX; i++) {
43af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      if (prog_data->inputs_read & BITFIELD64_BIT(i)) {
44af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 attribute_map[i] = payload_reg + nr_attributes;
45af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 nr_attributes++;
46af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      }
47af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   }
48af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
491c65abb211e6a3df8c46180ae3242486ee97dc8dEric Anholt   /* VertexID is stored by the VF as the last vertex element, but we
501c65abb211e6a3df8c46180ae3242486ee97dc8dEric Anholt    * don't represent it with a flag in inputs_read, so we call it
511c65abb211e6a3df8c46180ae3242486ee97dc8dEric Anholt    * VERT_ATTRIB_MAX.
521c65abb211e6a3df8c46180ae3242486ee97dc8dEric Anholt    */
531c65abb211e6a3df8c46180ae3242486ee97dc8dEric Anholt   if (prog_data->uses_vertexid) {
541c65abb211e6a3df8c46180ae3242486ee97dc8dEric Anholt      attribute_map[VERT_ATTRIB_MAX] = payload_reg + nr_attributes;
551c65abb211e6a3df8c46180ae3242486ee97dc8dEric Anholt      nr_attributes++;
561c65abb211e6a3df8c46180ae3242486ee97dc8dEric Anholt   }
571c65abb211e6a3df8c46180ae3242486ee97dc8dEric Anholt
58905f3d03090c7b86e410959c5640054f5f6894efEric Anholt   foreach_list(node, &this->instructions) {
59905f3d03090c7b86e410959c5640054f5f6894efEric Anholt      vec4_instruction *inst = (vec4_instruction *)node;
60af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
6181a0b2166991a3015f8336e184c34cf6a92adfe0Eric Anholt      /* We have to support ATTR as a destination for GL_FIXED fixup. */
6281a0b2166991a3015f8336e184c34cf6a92adfe0Eric Anholt      if (inst->dst.file == ATTR) {
6381a0b2166991a3015f8336e184c34cf6a92adfe0Eric Anholt	 int grf = attribute_map[inst->dst.reg + inst->dst.reg_offset];
6481a0b2166991a3015f8336e184c34cf6a92adfe0Eric Anholt
6581a0b2166991a3015f8336e184c34cf6a92adfe0Eric Anholt	 struct brw_reg reg = brw_vec8_grf(grf, 0);
6681a0b2166991a3015f8336e184c34cf6a92adfe0Eric Anholt	 reg.dw1.bits.writemask = inst->dst.writemask;
6781a0b2166991a3015f8336e184c34cf6a92adfe0Eric Anholt
6881a0b2166991a3015f8336e184c34cf6a92adfe0Eric Anholt	 inst->dst.file = HW_REG;
6981a0b2166991a3015f8336e184c34cf6a92adfe0Eric Anholt	 inst->dst.fixed_hw_reg = reg;
7081a0b2166991a3015f8336e184c34cf6a92adfe0Eric Anholt      }
7181a0b2166991a3015f8336e184c34cf6a92adfe0Eric Anholt
72af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      for (int i = 0; i < 3; i++) {
73af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 if (inst->src[i].file != ATTR)
74af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	    continue;
75af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
76a55fbbc1a2b579aed1e80036367b521ef6928f66Eric Anholt	 int grf = attribute_map[inst->src[i].reg + inst->src[i].reg_offset];
7754e66a0a6327b55f15a7c641ec68da505ff19a35Eric Anholt
7854e66a0a6327b55f15a7c641ec68da505ff19a35Eric Anholt	 struct brw_reg reg = brw_vec8_grf(grf, 0);
7954e66a0a6327b55f15a7c641ec68da505ff19a35Eric Anholt	 reg.dw1.bits.swizzle = inst->src[i].swizzle;
8029e2bc8b13be0f7ec48f8514e47322353e041365Paul Berry         reg.type = inst->src[i].type;
8154e66a0a6327b55f15a7c641ec68da505ff19a35Eric Anholt	 if (inst->src[i].abs)
8254e66a0a6327b55f15a7c641ec68da505ff19a35Eric Anholt	    reg = brw_abs(reg);
8354e66a0a6327b55f15a7c641ec68da505ff19a35Eric Anholt	 if (inst->src[i].negate)
8454e66a0a6327b55f15a7c641ec68da505ff19a35Eric Anholt	    reg = negate(reg);
8554e66a0a6327b55f15a7c641ec68da505ff19a35Eric Anholt
86af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 inst->src[i].file = HW_REG;
8754e66a0a6327b55f15a7c641ec68da505ff19a35Eric Anholt	 inst->src[i].fixed_hw_reg = reg;
88af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      }
89af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   }
90af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
91af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   /* The BSpec says we always have to read at least one thing from
92af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt    * the VF, and it appears that the hardware wedges otherwise.
93af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt    */
94af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   if (nr_attributes == 0)
95af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      nr_attributes = 1;
96af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
97af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   prog_data->urb_read_length = (nr_attributes + 1) / 2;
98af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
99f0cecd43d6b6d3f5def3fd43b9c95baaf3be9b16Eric Anholt   unsigned vue_entries = MAX2(nr_attributes, c->prog_data.vue_map.num_slots);
1002e712e41db0c0676e9f30fc73172c0e8de8d84d4Kenneth Graunke
1012e712e41db0c0676e9f30fc73172c0e8de8d84d4Kenneth Graunke   if (intel->gen == 6)
1022e712e41db0c0676e9f30fc73172c0e8de8d84d4Kenneth Graunke      c->prog_data.urb_entry_size = ALIGN(vue_entries, 8) / 8;
1032e712e41db0c0676e9f30fc73172c0e8de8d84d4Kenneth Graunke   else
1042e712e41db0c0676e9f30fc73172c0e8de8d84d4Kenneth Graunke      c->prog_data.urb_entry_size = ALIGN(vue_entries, 4) / 4;
1052e712e41db0c0676e9f30fc73172c0e8de8d84d4Kenneth Graunke
106a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt   return payload_reg + nr_attributes;
107af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt}
108af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
109a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholtint
110a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholtvec4_visitor::setup_uniforms(int reg)
111af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt{
112a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt   /* The pre-gen6 VS requires that some push constants get loaded no
113a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt    * matter what, or the GPU would hang.
114a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt    */
115eca762d831e099b549dafa0be896eac82b3fceb9Eric Anholt   if (intel->gen < 6 && this->uniforms == 0) {
116483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt      this->uniform_vector_size[this->uniforms] = 1;
117a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt
118a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt      for (unsigned int i = 0; i < 4; i++) {
119a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt	 unsigned int slot = this->uniforms * 4 + i;
120ee41383ab31f6ef5f1d18961de78371d4f52065bKenneth Graunke	 static float zero = 0.0;
121ee41383ab31f6ef5f1d18961de78371d4f52065bKenneth Graunke	 c->prog_data.param[slot] = &zero;
122a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt      }
123a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt
124a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt      this->uniforms++;
125eca762d831e099b549dafa0be896eac82b3fceb9Eric Anholt      reg++;
126a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt   } else {
127a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt      reg += ALIGN(uniforms, 2) / 2;
128a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt   }
129a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt
130a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt   c->prog_data.nr_params = this->uniforms * 4;
131a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt
132af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   c->prog_data.curb_read_length = reg - 1;
133a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt   c->prog_data.uses_new_param_layout = true;
134a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt
135a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt   return reg;
136a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt}
137a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt
138a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholtvoid
139a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholtvec4_visitor::setup_payload(void)
140a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt{
141a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt   int reg = 0;
142a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt
143a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt   /* The payload always contains important data in g0, which contains
144a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt    * the URB handles that are passed on to the URB write at the end
145a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt    * of the thread.  So, we always start push constants at g1.
146a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt    */
147a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt   reg++;
148af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
149a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt   reg = setup_uniforms(reg);
150a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt
151a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt   reg = setup_attributes(reg);
152af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
153af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   this->first_non_payload_grf = reg;
154af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt}
155af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
156af3c9803d818fd33139f1247a387d64b967b8992Eric Anholtstruct brw_reg
157af3c9803d818fd33139f1247a387d64b967b8992Eric Anholtvec4_instruction::get_dst(void)
158af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt{
159af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   struct brw_reg brw_reg;
160af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
161af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   switch (dst.file) {
162af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   case GRF:
163af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      brw_reg = brw_vec8_grf(dst.reg + dst.reg_offset, 0);
164af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      brw_reg = retype(brw_reg, dst.type);
165af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      brw_reg.dw1.bits.writemask = dst.writemask;
166af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      break;
167af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
16865d46c96c2540f8181293c318b412446a953faefEric Anholt   case MRF:
16965d46c96c2540f8181293c318b412446a953faefEric Anholt      brw_reg = brw_message_reg(dst.reg + dst.reg_offset);
17065d46c96c2540f8181293c318b412446a953faefEric Anholt      brw_reg = retype(brw_reg, dst.type);
17165d46c96c2540f8181293c318b412446a953faefEric Anholt      brw_reg.dw1.bits.writemask = dst.writemask;
17265d46c96c2540f8181293c318b412446a953faefEric Anholt      break;
17365d46c96c2540f8181293c318b412446a953faefEric Anholt
174af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   case HW_REG:
175af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      brw_reg = dst.fixed_hw_reg;
176af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      break;
177af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
178af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   case BAD_FILE:
179af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      brw_reg = brw_null_reg();
180af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      break;
181af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
182af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   default:
183af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      assert(!"not reached");
184af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      brw_reg = brw_null_reg();
185af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      break;
186af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   }
187af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   return brw_reg;
188af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt}
189af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
190af3c9803d818fd33139f1247a387d64b967b8992Eric Anholtstruct brw_reg
191af3c9803d818fd33139f1247a387d64b967b8992Eric Anholtvec4_instruction::get_src(int i)
192af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt{
193af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   struct brw_reg brw_reg;
194af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
195af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   switch (src[i].file) {
196af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   case GRF:
197af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      brw_reg = brw_vec8_grf(src[i].reg + src[i].reg_offset, 0);
198af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      brw_reg = retype(brw_reg, src[i].type);
199af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      brw_reg.dw1.bits.swizzle = src[i].swizzle;
200af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      if (src[i].abs)
201af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 brw_reg = brw_abs(brw_reg);
202af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      if (src[i].negate)
203af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 brw_reg = negate(brw_reg);
204af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      break;
205af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
206af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   case IMM:
207af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      switch (src[i].type) {
208af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      case BRW_REGISTER_TYPE_F:
209af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 brw_reg = brw_imm_f(src[i].imm.f);
210af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 break;
211af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      case BRW_REGISTER_TYPE_D:
212af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 brw_reg = brw_imm_d(src[i].imm.i);
213af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 break;
214af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      case BRW_REGISTER_TYPE_UD:
215af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 brw_reg = brw_imm_ud(src[i].imm.u);
216af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 break;
217af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      default:
218af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 assert(!"not reached");
219af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 brw_reg = brw_null_reg();
220af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 break;
221af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      }
222af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      break;
223af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
224a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt   case UNIFORM:
225a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt      brw_reg = stride(brw_vec4_grf(1 + (src[i].reg + src[i].reg_offset) / 2,
226a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt				    ((src[i].reg + src[i].reg_offset) % 2) * 4),
227a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt		       0, 4, 1);
228a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt      brw_reg = retype(brw_reg, src[i].type);
229a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt      brw_reg.dw1.bits.swizzle = src[i].swizzle;
230a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt      if (src[i].abs)
231a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt	 brw_reg = brw_abs(brw_reg);
232a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt      if (src[i].negate)
233a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt	 brw_reg = negate(brw_reg);
234483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt
235483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt      /* This should have been moved to pull constants. */
236483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt      assert(!src[i].reladdr);
237a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt      break;
238a070d5f363e99b0f846d555e9ca3a74ec807fdc0Eric Anholt
239af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   case HW_REG:
240af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      brw_reg = src[i].fixed_hw_reg;
241af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      break;
242af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
243af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   case BAD_FILE:
244af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      /* Probably unused. */
245af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      brw_reg = brw_null_reg();
246af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      break;
247af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   case ATTR:
248af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   default:
249af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      assert(!"not reached");
250af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      brw_reg = brw_null_reg();
251af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      break;
252af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   }
253af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
254af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   return brw_reg;
255af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt}
256af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
257af3c9803d818fd33139f1247a387d64b967b8992Eric Anholtvoid
258af3c9803d818fd33139f1247a387d64b967b8992Eric Anholtvec4_visitor::generate_math1_gen4(vec4_instruction *inst,
259af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt				  struct brw_reg dst,
260af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt				  struct brw_reg src)
261af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt{
262af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   brw_math(p,
263af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	    dst,
264af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	    brw_math_function(inst->opcode),
265af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	    inst->base_mrf,
266af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	    src,
2679f842886077258ddda5d5a32b1f5d9fe2e5818bcEric Anholt	    BRW_MATH_DATA_VECTOR,
268af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	    BRW_MATH_PRECISION_FULL);
269af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt}
270af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
271abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholtstatic void
272abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholtcheck_gen6_math_src_arg(struct brw_reg src)
273abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt{
274abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt   /* Source swizzles are ignored. */
275abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt   assert(!src.abs);
276abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt   assert(!src.negate);
2778ccbcda5c64a8bea47f6b41d46bf015ba8e515fcChris Wilson   assert(src.dw1.bits.swizzle == BRW_SWIZZLE_XYZW);
278abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt}
279abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt
280af3c9803d818fd33139f1247a387d64b967b8992Eric Anholtvoid
281af3c9803d818fd33139f1247a387d64b967b8992Eric Anholtvec4_visitor::generate_math1_gen6(vec4_instruction *inst,
282af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt				  struct brw_reg dst,
283af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt				  struct brw_reg src)
284af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt{
285250770b74d33bb8625c780a74a89477af033d13aEric Anholt   /* Can't do writemask because math can't be align16. */
286250770b74d33bb8625c780a74a89477af033d13aEric Anholt   assert(dst.dw1.bits.writemask == WRITEMASK_XYZW);
287abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt   check_gen6_math_src_arg(src);
288250770b74d33bb8625c780a74a89477af033d13aEric Anholt
289250770b74d33bb8625c780a74a89477af033d13aEric Anholt   brw_set_access_mode(p, BRW_ALIGN_1);
290af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   brw_math(p,
291af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	    dst,
292af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	    brw_math_function(inst->opcode),
293af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	    inst->base_mrf,
294af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	    src,
295af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	    BRW_MATH_DATA_SCALAR,
296af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	    BRW_MATH_PRECISION_FULL);
297250770b74d33bb8625c780a74a89477af033d13aEric Anholt   brw_set_access_mode(p, BRW_ALIGN_16);
298af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt}
299af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
300af3c9803d818fd33139f1247a387d64b967b8992Eric Anholtvoid
301a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunkevec4_visitor::generate_math2_gen7(vec4_instruction *inst,
302a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke				  struct brw_reg dst,
303a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke				  struct brw_reg src0,
304a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke				  struct brw_reg src1)
305a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke{
306a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke   brw_math2(p,
307a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke	     dst,
308a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke	     brw_math_function(inst->opcode),
309a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke	     src0, src1);
310a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke}
311a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke
312a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunkevoid
313abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholtvec4_visitor::generate_math2_gen6(vec4_instruction *inst,
314abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt				  struct brw_reg dst,
315abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt				  struct brw_reg src0,
316abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt				  struct brw_reg src1)
317abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt{
318abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt   /* Can't do writemask because math can't be align16. */
319abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt   assert(dst.dw1.bits.writemask == WRITEMASK_XYZW);
320abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt   /* Source swizzles are ignored. */
321abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt   check_gen6_math_src_arg(src0);
322abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt   check_gen6_math_src_arg(src1);
323abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt
324abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt   brw_set_access_mode(p, BRW_ALIGN_1);
325abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt   brw_math2(p,
326abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt	     dst,
327abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt	     brw_math_function(inst->opcode),
328abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt	     src0, src1);
329abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt   brw_set_access_mode(p, BRW_ALIGN_16);
330abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt}
331abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt
332abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholtvoid
333abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholtvec4_visitor::generate_math2_gen4(vec4_instruction *inst,
334abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt				  struct brw_reg dst,
335abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt				  struct brw_reg src0,
336abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt				  struct brw_reg src1)
337abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt{
338b9af592dfa8f8d0fe9f29c2d48bf6846cbd5c50fKenneth Graunke   /* From the Ironlake PRM, Volume 4, Part 1, Section 6.1.13
339b9af592dfa8f8d0fe9f29c2d48bf6846cbd5c50fKenneth Graunke    * "Message Payload":
340b9af592dfa8f8d0fe9f29c2d48bf6846cbd5c50fKenneth Graunke    *
341b9af592dfa8f8d0fe9f29c2d48bf6846cbd5c50fKenneth Graunke    * "Operand0[7].  For the INT DIV functions, this operand is the
342b9af592dfa8f8d0fe9f29c2d48bf6846cbd5c50fKenneth Graunke    *  denominator."
343b9af592dfa8f8d0fe9f29c2d48bf6846cbd5c50fKenneth Graunke    *  ...
344b9af592dfa8f8d0fe9f29c2d48bf6846cbd5c50fKenneth Graunke    * "Operand1[7].  For the INT DIV functions, this operand is the
345b9af592dfa8f8d0fe9f29c2d48bf6846cbd5c50fKenneth Graunke    *  numerator."
346b9af592dfa8f8d0fe9f29c2d48bf6846cbd5c50fKenneth Graunke    */
347b9af592dfa8f8d0fe9f29c2d48bf6846cbd5c50fKenneth Graunke   bool is_int_div = inst->opcode != SHADER_OPCODE_POW;
348b9af592dfa8f8d0fe9f29c2d48bf6846cbd5c50fKenneth Graunke   struct brw_reg &op0 = is_int_div ? src1 : src0;
349b9af592dfa8f8d0fe9f29c2d48bf6846cbd5c50fKenneth Graunke   struct brw_reg &op1 = is_int_div ? src0 : src1;
350b9af592dfa8f8d0fe9f29c2d48bf6846cbd5c50fKenneth Graunke
351b0adbda75a092a92211bb519a395494532ddb17eEric Anholt   brw_push_insn_state(p);
352b0adbda75a092a92211bb519a395494532ddb17eEric Anholt   brw_set_saturate(p, false);
353b0adbda75a092a92211bb519a395494532ddb17eEric Anholt   brw_set_predicate_control(p, BRW_PREDICATE_NONE);
354b9af592dfa8f8d0fe9f29c2d48bf6846cbd5c50fKenneth Graunke   brw_MOV(p, retype(brw_message_reg(inst->base_mrf + 1), op1.type), op1);
355b0adbda75a092a92211bb519a395494532ddb17eEric Anholt   brw_pop_insn_state(p);
356abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt
357abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt   brw_math(p,
358abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt	    dst,
359abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt	    brw_math_function(inst->opcode),
360abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt	    inst->base_mrf,
361b9af592dfa8f8d0fe9f29c2d48bf6846cbd5c50fKenneth Graunke	    op0,
362abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt	    BRW_MATH_DATA_VECTOR,
363abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt	    BRW_MATH_PRECISION_FULL);
364abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt}
365abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt
366abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholtvoid
367ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunkevec4_visitor::generate_tex(vec4_instruction *inst,
368ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke			   struct brw_reg dst,
369ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke			   struct brw_reg src)
370ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke{
371ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke   int msg_type = -1;
372ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke
373ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke   if (intel->gen >= 5) {
374ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke      switch (inst->opcode) {
375ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke      case SHADER_OPCODE_TEX:
376ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke      case SHADER_OPCODE_TXL:
377ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	 if (inst->shadow_compare) {
378ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	    msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_LOD_COMPARE;
379ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	 } else {
380ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	    msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_LOD;
381ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	 }
382ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	 break;
383ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke      case SHADER_OPCODE_TXD:
384d02343e5016a5795451af3e0315b658b39463a30Kenneth Graunke         if (inst->shadow_compare) {
385d02343e5016a5795451af3e0315b658b39463a30Kenneth Graunke            /* Gen7.5+.  Otherwise, lowered by brw_lower_texture_gradients(). */
386d02343e5016a5795451af3e0315b658b39463a30Kenneth Graunke            assert(intel->is_haswell);
387d02343e5016a5795451af3e0315b658b39463a30Kenneth Graunke            msg_type = HSW_SAMPLER_MESSAGE_SAMPLE_DERIV_COMPARE;
388d02343e5016a5795451af3e0315b658b39463a30Kenneth Graunke         } else {
389d02343e5016a5795451af3e0315b658b39463a30Kenneth Graunke            msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_DERIVS;
390d02343e5016a5795451af3e0315b658b39463a30Kenneth Graunke         }
391ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	 break;
392ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke      case SHADER_OPCODE_TXF:
393ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	 msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_LD;
394ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	 break;
395ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke      case SHADER_OPCODE_TXS:
396ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	 msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_RESINFO;
397ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	 break;
398ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke      default:
399ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	 assert(!"should not get here: invalid VS texture opcode");
400ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	 break;
401ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke      }
402ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke   } else {
403ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke      switch (inst->opcode) {
404ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke      case SHADER_OPCODE_TEX:
405ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke      case SHADER_OPCODE_TXL:
406ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	 if (inst->shadow_compare) {
407ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	    msg_type = BRW_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_LOD_COMPARE;
408ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	    assert(inst->mlen == 3);
409ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	 } else {
410ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	    msg_type = BRW_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_LOD;
411ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	    assert(inst->mlen == 2);
412ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	 }
413ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	 break;
414ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke      case SHADER_OPCODE_TXD:
415ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	 /* There is no sample_d_c message; comparisons are done manually. */
416ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	 msg_type = BRW_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_GRADIENTS;
417ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	 assert(inst->mlen == 4);
418ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	 break;
419ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke      case SHADER_OPCODE_TXF:
420ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	 msg_type = BRW_SAMPLER_MESSAGE_SIMD4X2_LD;
421ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	 assert(inst->mlen == 2);
422ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	 break;
423ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke      case SHADER_OPCODE_TXS:
424ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	 msg_type = BRW_SAMPLER_MESSAGE_SIMD4X2_RESINFO;
425ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	 assert(inst->mlen == 2);
426ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	 break;
427ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke      default:
428ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	 assert(!"should not get here: invalid VS texture opcode");
429ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	 break;
430ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke      }
431ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke   }
432ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke
433ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke   assert(msg_type != -1);
434ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke
435328b693a199a67ce3a17d258f34d7bfd26790871Kenneth Graunke   /* Load the message header if present.  If there's a texture offset, we need
436328b693a199a67ce3a17d258f34d7bfd26790871Kenneth Graunke    * to set it up explicitly and load the offset bitfield.  Otherwise, we can
437328b693a199a67ce3a17d258f34d7bfd26790871Kenneth Graunke    * use an implied move from g0 to the first message register.
438328b693a199a67ce3a17d258f34d7bfd26790871Kenneth Graunke    */
439328b693a199a67ce3a17d258f34d7bfd26790871Kenneth Graunke   if (inst->texture_offset) {
440328b693a199a67ce3a17d258f34d7bfd26790871Kenneth Graunke      /* Explicitly set up the message header by copying g0 to the MRF. */
441328b693a199a67ce3a17d258f34d7bfd26790871Kenneth Graunke      brw_MOV(p, retype(brw_message_reg(inst->base_mrf), BRW_REGISTER_TYPE_UD),
442328b693a199a67ce3a17d258f34d7bfd26790871Kenneth Graunke	         retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD));
443328b693a199a67ce3a17d258f34d7bfd26790871Kenneth Graunke
444328b693a199a67ce3a17d258f34d7bfd26790871Kenneth Graunke      /* Then set the offset bits in DWord 2. */
445328b693a199a67ce3a17d258f34d7bfd26790871Kenneth Graunke      brw_set_access_mode(p, BRW_ALIGN_1);
446328b693a199a67ce3a17d258f34d7bfd26790871Kenneth Graunke      brw_MOV(p,
447328b693a199a67ce3a17d258f34d7bfd26790871Kenneth Graunke	      retype(brw_vec1_reg(BRW_MESSAGE_REGISTER_FILE, inst->base_mrf, 2),
448328b693a199a67ce3a17d258f34d7bfd26790871Kenneth Graunke		     BRW_REGISTER_TYPE_UD),
449328b693a199a67ce3a17d258f34d7bfd26790871Kenneth Graunke	      brw_imm_uw(inst->texture_offset));
450328b693a199a67ce3a17d258f34d7bfd26790871Kenneth Graunke      brw_set_access_mode(p, BRW_ALIGN_16);
451328b693a199a67ce3a17d258f34d7bfd26790871Kenneth Graunke   } else if (inst->header_present) {
452ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke      /* Set up an implied move from g0 to the MRF. */
453ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke      src = brw_vec8_grf(0, 0);
454ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke   }
455ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke
456ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke   uint32_t return_format;
457ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke
458ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke   switch (dst.type) {
459ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke   case BRW_REGISTER_TYPE_D:
460ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke      return_format = BRW_SAMPLER_RETURN_FORMAT_SINT32;
461ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke      break;
462ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke   case BRW_REGISTER_TYPE_UD:
463ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke      return_format = BRW_SAMPLER_RETURN_FORMAT_UINT32;
464ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke      break;
465ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke   default:
466ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke      return_format = BRW_SAMPLER_RETURN_FORMAT_FLOAT32;
467ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke      break;
468ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke   }
469ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke
470ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke   brw_SAMPLE(p,
471ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	      dst,
472ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	      inst->base_mrf,
473ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	      src,
47407e00b3040d6da381595c65db5afe597f20d99fcEric Anholt	      SURF_INDEX_VS_TEXTURE(inst->sampler),
475ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	      inst->sampler,
476ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	      WRITEMASK_XYZW,
477ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	      msg_type,
478ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	      1, /* response length */
479ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	      inst->mlen,
480ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	      inst->header_present,
481ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	      BRW_SAMPLER_SIMD_MODE_SIMD4X2,
482ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke	      return_format);
483ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke}
484ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke
485ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunkevoid
486af3c9803d818fd33139f1247a387d64b967b8992Eric Anholtvec4_visitor::generate_urb_write(vec4_instruction *inst)
487af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt{
488af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   brw_urb_WRITE(p,
489af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt		 brw_null_reg(), /* dest */
490af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt		 inst->base_mrf, /* starting mrf reg nr */
491af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt		 brw_vec8_grf(0, 0), /* src */
492af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt		 false,		/* allocate */
493af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt		 true,		/* used */
494af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt		 inst->mlen,
495af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt		 0,		/* response len */
496af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt		 inst->eot,	/* eot */
497af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt		 inst->eot,	/* writes complete */
498af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt		 inst->offset,	/* urb destination offset */
499af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt		 BRW_URB_SWIZZLE_INTERLEAVE);
500af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt}
501af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
502af3c9803d818fd33139f1247a387d64b967b8992Eric Anholtvoid
503584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholtvec4_visitor::generate_oword_dual_block_offsets(struct brw_reg m1,
504584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt						struct brw_reg index)
505584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt{
506584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   int second_vertex_offset;
507584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt
508584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   if (intel->gen >= 6)
509584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt      second_vertex_offset = 1;
510584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   else
511584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt      second_vertex_offset = 16;
512584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt
513584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   m1 = retype(m1, BRW_REGISTER_TYPE_D);
514584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt
515584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   /* Set up M1 (message payload).  Only the block offsets in M1.0 and
516584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt    * M1.4 are used, and the rest are ignored.
517584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt    */
518584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   struct brw_reg m1_0 = suboffset(vec1(m1), 0);
519584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   struct brw_reg m1_4 = suboffset(vec1(m1), 4);
520584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   struct brw_reg index_0 = suboffset(vec1(index), 0);
521584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   struct brw_reg index_4 = suboffset(vec1(index), 4);
522584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt
523584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   brw_push_insn_state(p);
524584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   brw_set_mask_control(p, BRW_MASK_DISABLE);
525584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   brw_set_access_mode(p, BRW_ALIGN_1);
526584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt
527584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   brw_MOV(p, m1_0, index_0);
528584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt
529584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   brw_set_predicate_inverse(p, true);
530584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   if (index.file == BRW_IMMEDIATE_VALUE) {
53188612e2c1b1580b92d229ec6d2236fe07b32e060Eric Anholt      index_4.dw1.ud += second_vertex_offset;
532584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt      brw_MOV(p, m1_4, index_4);
533584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   } else {
534584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt      brw_ADD(p, m1_4, index_4, brw_imm_d(second_vertex_offset));
535584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   }
536584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt
537584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   brw_pop_insn_state(p);
538584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt}
539584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt
540584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholtvoid
541584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholtvec4_visitor::generate_scratch_read(vec4_instruction *inst,
542584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt				    struct brw_reg dst,
543584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt				    struct brw_reg index)
544584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt{
545ddf8e602a774ecfd1b660e398dd9bf763d86a074Eric Anholt   struct brw_reg header = brw_vec8_grf(0, 0);
546ddf8e602a774ecfd1b660e398dd9bf763d86a074Eric Anholt
547ddf8e602a774ecfd1b660e398dd9bf763d86a074Eric Anholt   gen6_resolve_implied_move(p, &header, inst->base_mrf);
548584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt
549584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   generate_oword_dual_block_offsets(brw_message_reg(inst->base_mrf + 1),
550584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt				     index);
551584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt
552584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   uint32_t msg_type;
553584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt
554584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   if (intel->gen >= 6)
555584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt      msg_type = GEN6_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ;
556584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   else if (intel->gen == 5 || intel->is_g4x)
557584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt      msg_type = G45_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ;
558584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   else
559584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt      msg_type = BRW_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ;
560584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt
561584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   /* Each of the 8 channel enables is considered for whether each
562584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt    * dword is written.
563584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt    */
564584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   struct brw_instruction *send = brw_next_insn(p, BRW_OPCODE_SEND);
565584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   brw_set_dest(p, send, dst);
566ddf8e602a774ecfd1b660e398dd9bf763d86a074Eric Anholt   brw_set_src0(p, send, header);
567ddf8e602a774ecfd1b660e398dd9bf763d86a074Eric Anholt   if (intel->gen < 6)
568ddf8e602a774ecfd1b660e398dd9bf763d86a074Eric Anholt      send->header.destreg__conditionalmod = inst->base_mrf;
569584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   brw_set_dp_read_message(p, send,
570584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt			   255, /* binding table index: stateless access */
571584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt			   BRW_DATAPORT_OWORD_DUAL_BLOCK_1OWORD,
572584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt			   msg_type,
573584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt			   BRW_DATAPORT_READ_TARGET_RENDER_CACHE,
574584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt			   2, /* mlen */
575584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt			   1 /* rlen */);
576584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt}
577584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt
578584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholtvoid
579584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholtvec4_visitor::generate_scratch_write(vec4_instruction *inst,
580584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt				     struct brw_reg dst,
581584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt				     struct brw_reg src,
582584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt				     struct brw_reg index)
583584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt{
584ddf8e602a774ecfd1b660e398dd9bf763d86a074Eric Anholt   struct brw_reg header = brw_vec8_grf(0, 0);
5859367960ea64a087895caaadbd0353080c14b4babEric Anholt   bool write_commit;
586ddf8e602a774ecfd1b660e398dd9bf763d86a074Eric Anholt
587584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   /* If the instruction is predicated, we'll predicate the send, not
588584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt    * the header setup.
589584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt    */
590584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   brw_set_predicate_control(p, false);
591584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt
592ddf8e602a774ecfd1b660e398dd9bf763d86a074Eric Anholt   gen6_resolve_implied_move(p, &header, inst->base_mrf);
593584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt
594584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   generate_oword_dual_block_offsets(brw_message_reg(inst->base_mrf + 1),
595584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt				     index);
596584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt
597584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   brw_MOV(p,
598584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt	   retype(brw_message_reg(inst->base_mrf + 2), BRW_REGISTER_TYPE_D),
599584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt	   retype(src, BRW_REGISTER_TYPE_D));
600584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt
601584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   uint32_t msg_type;
602584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt
6030d4a9ba9b247664bc5662b3db774064778f9aa17Kenneth Graunke   if (intel->gen >= 7)
6040d4a9ba9b247664bc5662b3db774064778f9aa17Kenneth Graunke      msg_type = GEN7_DATAPORT_WRITE_MESSAGE_OWORD_DUAL_BLOCK_WRITE;
6050d4a9ba9b247664bc5662b3db774064778f9aa17Kenneth Graunke   else if (intel->gen == 6)
606584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt      msg_type = GEN6_DATAPORT_WRITE_MESSAGE_OWORD_DUAL_BLOCK_WRITE;
607584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   else
608584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt      msg_type = BRW_DATAPORT_WRITE_MESSAGE_OWORD_DUAL_BLOCK_WRITE;
609584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt
610584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   brw_set_predicate_control(p, inst->predicate);
611584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt
6129367960ea64a087895caaadbd0353080c14b4babEric Anholt   /* Pre-gen6, we have to specify write commits to ensure ordering
6139367960ea64a087895caaadbd0353080c14b4babEric Anholt    * between reads and writes within a thread.  Afterwards, that's
6149367960ea64a087895caaadbd0353080c14b4babEric Anholt    * guaranteed and write commits only matter for inter-thread
6159367960ea64a087895caaadbd0353080c14b4babEric Anholt    * synchronization.
6169367960ea64a087895caaadbd0353080c14b4babEric Anholt    */
6179367960ea64a087895caaadbd0353080c14b4babEric Anholt   if (intel->gen >= 6) {
6189367960ea64a087895caaadbd0353080c14b4babEric Anholt      write_commit = false;
6199367960ea64a087895caaadbd0353080c14b4babEric Anholt   } else {
6209367960ea64a087895caaadbd0353080c14b4babEric Anholt      /* The visitor set up our destination register to be g0.  This
6219367960ea64a087895caaadbd0353080c14b4babEric Anholt       * means that when the next read comes along, we will end up
6229367960ea64a087895caaadbd0353080c14b4babEric Anholt       * reading from g0 and causing a block on the write commit.  For
6239367960ea64a087895caaadbd0353080c14b4babEric Anholt       * write-after-read, we are relying on the value of the previous
6249367960ea64a087895caaadbd0353080c14b4babEric Anholt       * read being used (and thus blocking on completion) before our
6259367960ea64a087895caaadbd0353080c14b4babEric Anholt       * write is executed.  This means we have to be careful in
6269367960ea64a087895caaadbd0353080c14b4babEric Anholt       * instruction scheduling to not violate this assumption.
6279367960ea64a087895caaadbd0353080c14b4babEric Anholt       */
6289367960ea64a087895caaadbd0353080c14b4babEric Anholt      write_commit = true;
6299367960ea64a087895caaadbd0353080c14b4babEric Anholt   }
6309367960ea64a087895caaadbd0353080c14b4babEric Anholt
631584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   /* Each of the 8 channel enables is considered for whether each
632584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt    * dword is written.
633584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt    */
634584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   struct brw_instruction *send = brw_next_insn(p, BRW_OPCODE_SEND);
635584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   brw_set_dest(p, send, dst);
636ddf8e602a774ecfd1b660e398dd9bf763d86a074Eric Anholt   brw_set_src0(p, send, header);
637ddf8e602a774ecfd1b660e398dd9bf763d86a074Eric Anholt   if (intel->gen < 6)
638ddf8e602a774ecfd1b660e398dd9bf763d86a074Eric Anholt      send->header.destreg__conditionalmod = inst->base_mrf;
639584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   brw_set_dp_write_message(p, send,
640584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt			    255, /* binding table index: stateless access */
641584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt			    BRW_DATAPORT_OWORD_DUAL_BLOCK_1OWORD,
642584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt			    msg_type,
643584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt			    3, /* mlen */
644584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt			    true, /* header present */
64553798f90e818e9bf213c3ae4298751362a5ecd50Kenneth Graunke			    false, /* not a render target write */
6469367960ea64a087895caaadbd0353080c14b4babEric Anholt			    write_commit, /* rlen */
647584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt			    false, /* eot */
6489367960ea64a087895caaadbd0353080c14b4babEric Anholt			    write_commit);
649584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt}
650584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt
651584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholtvoid
652483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholtvec4_visitor::generate_pull_constant_load(vec4_instruction *inst,
653483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt					  struct brw_reg dst,
654bb020d09c382285210a5aebe412ddabfad19e4a0Eric Anholt					  struct brw_reg index,
655bb020d09c382285210a5aebe412ddabfad19e4a0Eric Anholt					  struct brw_reg offset)
656483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt{
657bb020d09c382285210a5aebe412ddabfad19e4a0Eric Anholt   assert(index.file == BRW_IMMEDIATE_VALUE &&
658bb020d09c382285210a5aebe412ddabfad19e4a0Eric Anholt	  index.type == BRW_REGISTER_TYPE_UD);
659bb020d09c382285210a5aebe412ddabfad19e4a0Eric Anholt   uint32_t surf_index = index.dw1.ud;
660bb020d09c382285210a5aebe412ddabfad19e4a0Eric Anholt
661259b65e2e7938de4aab323033cfe2b33369ddb07Kenneth Graunke   if (intel->gen == 7) {
662bb020d09c382285210a5aebe412ddabfad19e4a0Eric Anholt      gen6_resolve_implied_move(p, &offset, inst->base_mrf);
663259b65e2e7938de4aab323033cfe2b33369ddb07Kenneth Graunke      brw_instruction *insn = brw_next_insn(p, BRW_OPCODE_SEND);
664259b65e2e7938de4aab323033cfe2b33369ddb07Kenneth Graunke      brw_set_dest(p, insn, dst);
665bb020d09c382285210a5aebe412ddabfad19e4a0Eric Anholt      brw_set_src0(p, insn, offset);
666259b65e2e7938de4aab323033cfe2b33369ddb07Kenneth Graunke      brw_set_sampler_message(p, insn,
667bb020d09c382285210a5aebe412ddabfad19e4a0Eric Anholt                              surf_index,
668259b65e2e7938de4aab323033cfe2b33369ddb07Kenneth Graunke                              0, /* LD message ignores sampler unit */
669259b65e2e7938de4aab323033cfe2b33369ddb07Kenneth Graunke                              GEN5_SAMPLER_MESSAGE_SAMPLE_LD,
670259b65e2e7938de4aab323033cfe2b33369ddb07Kenneth Graunke                              1, /* rlen */
671259b65e2e7938de4aab323033cfe2b33369ddb07Kenneth Graunke                              1, /* mlen */
672259b65e2e7938de4aab323033cfe2b33369ddb07Kenneth Graunke                              false, /* no header */
673259b65e2e7938de4aab323033cfe2b33369ddb07Kenneth Graunke                              BRW_SAMPLER_SIMD_MODE_SIMD4X2,
674259b65e2e7938de4aab323033cfe2b33369ddb07Kenneth Graunke                              0);
675259b65e2e7938de4aab323033cfe2b33369ddb07Kenneth Graunke      return;
676259b65e2e7938de4aab323033cfe2b33369ddb07Kenneth Graunke   }
677259b65e2e7938de4aab323033cfe2b33369ddb07Kenneth Graunke
678483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt   struct brw_reg header = brw_vec8_grf(0, 0);
679483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt
680483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt   gen6_resolve_implied_move(p, &header, inst->base_mrf);
681483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt
682483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt   brw_MOV(p, retype(brw_message_reg(inst->base_mrf + 1), BRW_REGISTER_TYPE_D),
683bb020d09c382285210a5aebe412ddabfad19e4a0Eric Anholt	   offset);
684483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt
685483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt   uint32_t msg_type;
686483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt
687483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt   if (intel->gen >= 6)
688483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt      msg_type = GEN6_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ;
689483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt   else if (intel->gen == 5 || intel->is_g4x)
690483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt      msg_type = G45_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ;
691483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt   else
692483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt      msg_type = BRW_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ;
693483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt
694483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt   /* Each of the 8 channel enables is considered for whether each
695483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt    * dword is written.
696483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt    */
697483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt   struct brw_instruction *send = brw_next_insn(p, BRW_OPCODE_SEND);
698483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt   brw_set_dest(p, send, dst);
699483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt   brw_set_src0(p, send, header);
700ddf8e602a774ecfd1b660e398dd9bf763d86a074Eric Anholt   if (intel->gen < 6)
701ddf8e602a774ecfd1b660e398dd9bf763d86a074Eric Anholt      send->header.destreg__conditionalmod = inst->base_mrf;
702483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt   brw_set_dp_read_message(p, send,
703bb020d09c382285210a5aebe412ddabfad19e4a0Eric Anholt			   surf_index,
704483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt			   BRW_DATAPORT_OWORD_DUAL_BLOCK_1OWORD,
705483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt			   msg_type,
706483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt			   BRW_DATAPORT_READ_TARGET_DATA_CACHE,
707483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt			   2, /* mlen */
708483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt			   1 /* rlen */);
709483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt}
710483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt
711483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholtvoid
712af3c9803d818fd33139f1247a387d64b967b8992Eric Anholtvec4_visitor::generate_vs_instruction(vec4_instruction *instruction,
713af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt				      struct brw_reg dst,
714af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt				      struct brw_reg *src)
715af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt{
716af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   vec4_instruction *inst = (vec4_instruction *)instruction;
717af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
718af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   switch (inst->opcode) {
719af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   case SHADER_OPCODE_RCP:
720af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   case SHADER_OPCODE_RSQ:
721af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   case SHADER_OPCODE_SQRT:
722af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   case SHADER_OPCODE_EXP2:
723af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   case SHADER_OPCODE_LOG2:
724af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   case SHADER_OPCODE_SIN:
725af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   case SHADER_OPCODE_COS:
726a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke      if (intel->gen == 6) {
727af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 generate_math1_gen6(inst, dst, src[0]);
728af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      } else {
729a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke	 /* Also works for Gen7. */
730af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 generate_math1_gen4(inst, dst, src[0]);
731af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      }
732af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      break;
733af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
734af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   case SHADER_OPCODE_POW:
7351d4f3ca8f0442821c914b758b323e6e5124149a3Kenneth Graunke   case SHADER_OPCODE_INT_QUOTIENT:
7361d4f3ca8f0442821c914b758b323e6e5124149a3Kenneth Graunke   case SHADER_OPCODE_INT_REMAINDER:
737a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke      if (intel->gen >= 7) {
738a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke	 generate_math2_gen7(inst, dst, src[0], src[1]);
739a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke      } else if (intel->gen == 6) {
740abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt	 generate_math2_gen6(inst, dst, src[0], src[1]);
741abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt      } else {
742abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt	 generate_math2_gen4(inst, dst, src[0], src[1]);
743abf843a797876b5e3c5c91dbec25b6553d2cc281Eric Anholt      }
744af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      break;
745af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
746ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke   case SHADER_OPCODE_TEX:
747ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke   case SHADER_OPCODE_TXD:
748ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke   case SHADER_OPCODE_TXF:
749ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke   case SHADER_OPCODE_TXL:
750ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke   case SHADER_OPCODE_TXS:
751ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke      generate_tex(inst, dst, src[0]);
752ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke      break;
753ca182cd0fa338ad39d531cb1be6a5a1bbf455771Kenneth Graunke
754af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   case VS_OPCODE_URB_WRITE:
755af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      generate_urb_write(inst);
756af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      break;
757af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
758584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   case VS_OPCODE_SCRATCH_READ:
759584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt      generate_scratch_read(inst, dst, src[0]);
760584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt      break;
761584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt
762584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt   case VS_OPCODE_SCRATCH_WRITE:
763584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt      generate_scratch_write(inst, dst, src[0], src[1]);
764584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt      break;
765584ff407482fd3baf5ce081dbbf9653eb76c40f1Eric Anholt
766483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt   case VS_OPCODE_PULL_CONSTANT_LOAD:
767bb020d09c382285210a5aebe412ddabfad19e4a0Eric Anholt      generate_pull_constant_load(inst, dst, src[0], src[1]);
768483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt      break;
769483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt
770af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   default:
771af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      if (inst->opcode < (int)ARRAY_SIZE(brw_opcodes)) {
772af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 fail("unsupported opcode in `%s' in VS\n",
773af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	      brw_opcodes[inst->opcode].name);
774af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      } else {
775af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 fail("Unsupported opcode %d in VS", inst->opcode);
776af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      }
777af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   }
778af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt}
779af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
780af3c9803d818fd33139f1247a387d64b967b8992Eric Anholtbool
781af3c9803d818fd33139f1247a387d64b967b8992Eric Anholtvec4_visitor::run()
782af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt{
78318e2e19b07b312c978dfbb6d336f69fa84b3ffe2Paul Berry   if (c->key.userclip_active && !c->key.uses_clip_distance)
784e7da40afe84349a640fe15e3af408a0dfe880e85Paul Berry      setup_uniform_clipplane_values();
785e7da40afe84349a640fe15e3af408a0dfe880e85Paul Berry
786d0e4d71070cd7fa197ed98612782484ec1f27123Eric Anholt   /* Generate VS IR for main().  (the visitor only descends into
787af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt    * functions called "main").
788af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt    */
789905f3d03090c7b86e410959c5640054f5f6894efEric Anholt   visit_instructions(shader->ir);
790af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
791af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   emit_urb_writes();
792af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
793d0e4d71070cd7fa197ed98612782484ec1f27123Eric Anholt   /* Before any optimization, push array accesses out to scratch
794d0e4d71070cd7fa197ed98612782484ec1f27123Eric Anholt    * space where we need them to be.  This pass may allocate new
795d0e4d71070cd7fa197ed98612782484ec1f27123Eric Anholt    * virtual GRFs, so we want to do it early.  It also makes sure
796d0e4d71070cd7fa197ed98612782484ec1f27123Eric Anholt    * that we have reladdr computations available for CSE, since we'll
797d0e4d71070cd7fa197ed98612782484ec1f27123Eric Anholt    * often do repeated subexpressions for those.
798d0e4d71070cd7fa197ed98612782484ec1f27123Eric Anholt    */
799d0e4d71070cd7fa197ed98612782484ec1f27123Eric Anholt   move_grf_array_access_to_scratch();
800483f5b348b0f3c0ca7082fd2047c354e8af285e7Eric Anholt   move_uniform_array_access_to_pull_constants();
801f3ed973f53d2a621d915de2cdc8e09c0755db016Eric Anholt   pack_uniform_registers();
802df35d691807656d3627b6fa6f51a08674bdc043eEric Anholt   move_push_constants_to_pull_constants();
803d0e4d71070cd7fa197ed98612782484ec1f27123Eric Anholt
8048174945d3346dc049ae56dcb4bf1eab39f5c88aaEric Anholt   bool progress;
8058174945d3346dc049ae56dcb4bf1eab39f5c88aaEric Anholt   do {
8068174945d3346dc049ae56dcb4bf1eab39f5c88aaEric Anholt      progress = false;
8078174945d3346dc049ae56dcb4bf1eab39f5c88aaEric Anholt      progress = dead_code_eliminate() || progress;
80842ce13195b94d0d51ca8e7fa5eed07fde8f37988Eric Anholt      progress = opt_copy_propagation() || progress;
809f0c04e6c22babf2aee2ad1ee85dbd6f996be3712Eric Anholt      progress = opt_algebraic() || progress;
810c662764f4f9d9d0303fb2685dfdc93824fa15dcaEric Anholt      progress = opt_compute_to_mrf() || progress;
8118174945d3346dc049ae56dcb4bf1eab39f5c88aaEric Anholt   } while (progress);
8128174945d3346dc049ae56dcb4bf1eab39f5c88aaEric Anholt
81372cfc6f3778d8297e52c254a5861a88eb62e4d67Eric Anholt
814af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   if (failed)
815af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      return false;
816af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
817af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   setup_payload();
818b22de71c1bc2530e139d75d934e203f4eee89f41Kenneth Graunke
819b22de71c1bc2530e139d75d934e203f4eee89f41Kenneth Graunke   if (false) {
820b22de71c1bc2530e139d75d934e203f4eee89f41Kenneth Graunke      /* Debug of register spilling: Go spill everything. */
821b22de71c1bc2530e139d75d934e203f4eee89f41Kenneth Graunke      const int grf_count = virtual_grf_count;
822b22de71c1bc2530e139d75d934e203f4eee89f41Kenneth Graunke      float spill_costs[virtual_grf_count];
823b22de71c1bc2530e139d75d934e203f4eee89f41Kenneth Graunke      bool no_spill[virtual_grf_count];
824b22de71c1bc2530e139d75d934e203f4eee89f41Kenneth Graunke      evaluate_spill_costs(spill_costs, no_spill);
825b22de71c1bc2530e139d75d934e203f4eee89f41Kenneth Graunke      for (int i = 0; i < grf_count; i++) {
826b22de71c1bc2530e139d75d934e203f4eee89f41Kenneth Graunke         if (no_spill[i])
827b22de71c1bc2530e139d75d934e203f4eee89f41Kenneth Graunke            continue;
828b22de71c1bc2530e139d75d934e203f4eee89f41Kenneth Graunke         spill_reg(i);
829b22de71c1bc2530e139d75d934e203f4eee89f41Kenneth Graunke      }
830b22de71c1bc2530e139d75d934e203f4eee89f41Kenneth Graunke   }
831b22de71c1bc2530e139d75d934e203f4eee89f41Kenneth Graunke
8324e35ffa762d763820b7defc14af564b2a02c61c8Eric Anholt   while (!reg_allocate()) {
8334e35ffa762d763820b7defc14af564b2a02c61c8Eric Anholt      if (failed)
8344e35ffa762d763820b7defc14af564b2a02c61c8Eric Anholt         break;
8354e35ffa762d763820b7defc14af564b2a02c61c8Eric Anholt   }
836af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
837e8980c61b2932cd4c8791fcc5afdb54fa033c224Eric Anholt   if (failed)
838e8980c61b2932cd4c8791fcc5afdb54fa033c224Eric Anholt      return false;
839e8980c61b2932cd4c8791fcc5afdb54fa033c224Eric Anholt
840af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   brw_set_access_mode(p, BRW_ALIGN_16);
841af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
842af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   generate_code();
843af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
844af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   return !failed;
845af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt}
846af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
847af3c9803d818fd33139f1247a387d64b967b8992Eric Anholtvoid
848af3c9803d818fd33139f1247a387d64b967b8992Eric Anholtvec4_visitor::generate_code()
849af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt{
85081a0b2166991a3015f8336e184c34cf6a92adfe0Eric Anholt   int last_native_inst = 0;
851af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   const char *last_annotation_string = NULL;
852af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   ir_instruction *last_annotation_ir = NULL;
853af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
854af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   if (unlikely(INTEL_DEBUG & DEBUG_VS)) {
855af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      printf("Native code for vertex shader %d:\n", prog->Name);
856af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   }
857af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
858af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   foreach_list(node, &this->instructions) {
859af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      vec4_instruction *inst = (vec4_instruction *)node;
860af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      struct brw_reg src[3], dst;
861af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
862af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      if (unlikely(INTEL_DEBUG & DEBUG_VS)) {
863af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 if (last_annotation_ir != inst->ir) {
864af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	    last_annotation_ir = inst->ir;
865af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	    if (last_annotation_ir) {
866af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	       printf("   ");
867af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	       last_annotation_ir->print();
868af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	       printf("\n");
869af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	    }
870af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 }
871af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 if (last_annotation_string != inst->annotation) {
872af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	    last_annotation_string = inst->annotation;
873af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	    if (last_annotation_string)
874af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	       printf("   %s\n", last_annotation_string);
875af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 }
876af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      }
877af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
878af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      for (unsigned int i = 0; i < 3; i++) {
879af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 src[i] = inst->get_src(i);
880af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      }
881af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      dst = inst->get_dst();
882af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
883af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      brw_set_conditionalmod(p, inst->conditional_mod);
884af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      brw_set_predicate_control(p, inst->predicate);
885af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      brw_set_predicate_inverse(p, inst->predicate_inverse);
886af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      brw_set_saturate(p, inst->saturate);
887af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
888af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      switch (inst->opcode) {
889af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      case BRW_OPCODE_MOV:
890af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 brw_MOV(p, dst, src[0]);
891af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 break;
892af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      case BRW_OPCODE_ADD:
893af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 brw_ADD(p, dst, src[0], src[1]);
894af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 break;
895af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      case BRW_OPCODE_MUL:
896af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 brw_MUL(p, dst, src[0], src[1]);
897af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 break;
8980ddf0f1c3451eef8a7c7f46afca623dc4f7c5af6Eric Anholt      case BRW_OPCODE_MACH:
8990ddf0f1c3451eef8a7c7f46afca623dc4f7c5af6Eric Anholt	 brw_set_acc_write_control(p, 1);
9000ddf0f1c3451eef8a7c7f46afca623dc4f7c5af6Eric Anholt	 brw_MACH(p, dst, src[0], src[1]);
9010ddf0f1c3451eef8a7c7f46afca623dc4f7c5af6Eric Anholt	 brw_set_acc_write_control(p, 0);
9020ddf0f1c3451eef8a7c7f46afca623dc4f7c5af6Eric Anholt	 break;
903af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
904af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      case BRW_OPCODE_FRC:
905af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 brw_FRC(p, dst, src[0]);
906af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 break;
907af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      case BRW_OPCODE_RNDD:
908af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 brw_RNDD(p, dst, src[0]);
909af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 break;
910af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      case BRW_OPCODE_RNDE:
911af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 brw_RNDE(p, dst, src[0]);
912af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 break;
913af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      case BRW_OPCODE_RNDZ:
914af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 brw_RNDZ(p, dst, src[0]);
915af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 break;
916af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
917af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      case BRW_OPCODE_AND:
918af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 brw_AND(p, dst, src[0], src[1]);
919af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 break;
920af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      case BRW_OPCODE_OR:
921af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 brw_OR(p, dst, src[0], src[1]);
922af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 break;
923af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      case BRW_OPCODE_XOR:
924af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 brw_XOR(p, dst, src[0], src[1]);
925af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 break;
926af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      case BRW_OPCODE_NOT:
927af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 brw_NOT(p, dst, src[0]);
928af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 break;
929af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      case BRW_OPCODE_ASR:
930af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 brw_ASR(p, dst, src[0], src[1]);
931af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 break;
932af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      case BRW_OPCODE_SHR:
933af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 brw_SHR(p, dst, src[0], src[1]);
934af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 break;
935af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      case BRW_OPCODE_SHL:
936af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 brw_SHL(p, dst, src[0], src[1]);
937af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 break;
938af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
939af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      case BRW_OPCODE_CMP:
940af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 brw_CMP(p, dst, inst->conditional_mod, src[0], src[1]);
941af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 break;
942af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      case BRW_OPCODE_SEL:
943af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 brw_SEL(p, dst, src[0], src[1]);
944af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 break;
945af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
946c3752b399ab376aa53392afb8f2d4b526054f0a8Eric Anholt      case BRW_OPCODE_DP4:
947c3752b399ab376aa53392afb8f2d4b526054f0a8Eric Anholt	 brw_DP4(p, dst, src[0], src[1]);
948c3752b399ab376aa53392afb8f2d4b526054f0a8Eric Anholt	 break;
949c3752b399ab376aa53392afb8f2d4b526054f0a8Eric Anholt
950c3752b399ab376aa53392afb8f2d4b526054f0a8Eric Anholt      case BRW_OPCODE_DP3:
951c3752b399ab376aa53392afb8f2d4b526054f0a8Eric Anholt	 brw_DP3(p, dst, src[0], src[1]);
952c3752b399ab376aa53392afb8f2d4b526054f0a8Eric Anholt	 break;
953c3752b399ab376aa53392afb8f2d4b526054f0a8Eric Anholt
954c3752b399ab376aa53392afb8f2d4b526054f0a8Eric Anholt      case BRW_OPCODE_DP2:
955c3752b399ab376aa53392afb8f2d4b526054f0a8Eric Anholt	 brw_DP2(p, dst, src[0], src[1]);
956c3752b399ab376aa53392afb8f2d4b526054f0a8Eric Anholt	 break;
957c3752b399ab376aa53392afb8f2d4b526054f0a8Eric Anholt
958af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      case BRW_OPCODE_IF:
959af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 if (inst->src[0].file != BAD_FILE) {
960af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	    /* The instruction has an embedded compare (only allowed on gen6) */
961af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	    assert(intel->gen == 6);
962af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	    gen6_IF(p, inst->conditional_mod, src[0], src[1]);
963af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 } else {
9642b7632aeaa5f8b4ab3da7d33a3c71c71023a072aEric Anholt	    struct brw_instruction *brw_inst = brw_IF(p, BRW_EXECUTE_8);
9652b7632aeaa5f8b4ab3da7d33a3c71c71023a072aEric Anholt	    brw_inst->header.predicate_control = inst->predicate;
966af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 }
967af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 break;
968af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
969af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      case BRW_OPCODE_ELSE:
970af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 brw_ELSE(p);
971af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 break;
972af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      case BRW_OPCODE_ENDIF:
973af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 brw_ENDIF(p);
974af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 break;
975af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
976af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      case BRW_OPCODE_DO:
977ce6be334bbf7f44c71ad5d190f9fb075d2f9a38cEric Anholt	 brw_DO(p, BRW_EXECUTE_8);
978af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 break;
979af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
980af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      case BRW_OPCODE_BREAK:
981f1d89638c02afafbf82ef657cd6ba9965dad6738Eric Anholt	 brw_BREAK(p);
982af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 brw_set_predicate_control(p, BRW_PREDICATE_NONE);
983af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 break;
984af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      case BRW_OPCODE_CONTINUE:
985af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 /* FINISHME: We need to write the loop instruction support still. */
986af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 if (intel->gen >= 6)
9879f8814752f306cb9a26d283f0b7cf876639e10f7Eric Anholt	    gen6_CONT(p);
988af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 else
989f1d89638c02afafbf82ef657cd6ba9965dad6738Eric Anholt	    brw_CONT(p);
990af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 brw_set_predicate_control(p, BRW_PREDICATE_NONE);
991af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 break;
992af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
993ce6be334bbf7f44c71ad5d190f9fb075d2f9a38cEric Anholt      case BRW_OPCODE_WHILE:
994ce6be334bbf7f44c71ad5d190f9fb075d2f9a38cEric Anholt	 brw_WHILE(p);
995af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 break;
996af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
997af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      default:
998af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 generate_vs_instruction(inst, dst, src);
999af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 break;
1000af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      }
1001af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
1002af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      if (unlikely(INTEL_DEBUG & DEBUG_VS)) {
1003af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 for (unsigned int i = last_native_inst; i < p->nr_insn; i++) {
1004af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	    if (0) {
1005af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	       printf("0x%08x 0x%08x 0x%08x 0x%08x ",
1006af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt		      ((uint32_t *)&p->store[i])[3],
1007af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt		      ((uint32_t *)&p->store[i])[2],
1008af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt		      ((uint32_t *)&p->store[i])[1],
1009af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt		      ((uint32_t *)&p->store[i])[0]);
1010af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	    }
1011af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	    brw_disasm(stdout, &p->store[i], intel->gen);
1012af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 }
1013af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      }
1014af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
1015af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      last_native_inst = p->nr_insn;
1016af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   }
1017af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
1018af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   if (unlikely(INTEL_DEBUG & DEBUG_VS)) {
1019af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      printf("\n");
1020af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   }
1021af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
1022af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   brw_set_uip_jip(p);
1023af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
1024af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   /* OK, while the INTEL_DEBUG=vs above is very nice for debugging VS
1025af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt    * emit issues, it doesn't get the jump distances into the output,
1026af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt    * which is often something we want to debug.  So this is here in
1027af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt    * case you're doing that.
1028af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt    */
1029af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   if (0) {
1030af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      if (unlikely(INTEL_DEBUG & DEBUG_VS)) {
1031af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 for (unsigned int i = 0; i < p->nr_insn; i++) {
1032af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	    printf("0x%08x 0x%08x 0x%08x 0x%08x ",
1033af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt		   ((uint32_t *)&p->store[i])[3],
1034af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt		   ((uint32_t *)&p->store[i])[2],
1035af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt		   ((uint32_t *)&p->store[i])[1],
1036af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt		   ((uint32_t *)&p->store[i])[0]);
1037af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	    brw_disasm(stdout, &p->store[i], intel->gen);
1038af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt	 }
1039af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      }
1040af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   }
1041af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt}
1042af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
1043af3c9803d818fd33139f1247a387d64b967b8992Eric Anholtextern "C" {
1044af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
1045af3c9803d818fd33139f1247a387d64b967b8992Eric Anholtbool
10467fbe7fe13359d3f349664410ec73d7bd48824ed6Eric Anholtbrw_vs_emit(struct gl_shader_program *prog, struct brw_vs_compile *c)
1047af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt{
1048c20cb8d1f6cac0b98950828e69376bb9406761ffKenneth Graunke   struct brw_context *brw = c->func.brw;
1049006c1a3c652803e2ff8d5f7ea55c9cb5d8353279Eric Anholt   struct intel_context *intel = &c->func.brw->intel;
1050006c1a3c652803e2ff8d5f7ea55c9cb5d8353279Eric Anholt   bool start_busy = false;
1051006c1a3c652803e2ff8d5f7ea55c9cb5d8353279Eric Anholt   float start_time = 0;
1052006c1a3c652803e2ff8d5f7ea55c9cb5d8353279Eric Anholt
1053af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   if (!prog)
1054af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      return false;
1055af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
1056006c1a3c652803e2ff8d5f7ea55c9cb5d8353279Eric Anholt   if (unlikely(INTEL_DEBUG & DEBUG_PERF)) {
1057006c1a3c652803e2ff8d5f7ea55c9cb5d8353279Eric Anholt      start_busy = (intel->batch.last_bo &&
1058006c1a3c652803e2ff8d5f7ea55c9cb5d8353279Eric Anholt                    drm_intel_bo_busy(intel->batch.last_bo));
1059006c1a3c652803e2ff8d5f7ea55c9cb5d8353279Eric Anholt      start_time = get_time();
1060006c1a3c652803e2ff8d5f7ea55c9cb5d8353279Eric Anholt   }
1061006c1a3c652803e2ff8d5f7ea55c9cb5d8353279Eric Anholt
1062af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   struct brw_shader *shader =
1063af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt     (brw_shader *) prog->_LinkedShaders[MESA_SHADER_VERTEX];
1064af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   if (!shader)
1065af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      return false;
1066af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
1067af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   if (unlikely(INTEL_DEBUG & DEBUG_VS)) {
1068af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      printf("GLSL IR for native vertex shader %d:\n", prog->Name);
1069af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      _mesa_print_ir(shader->ir, NULL);
1070af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      printf("\n\n");
1071af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   }
1072af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
1073006c1a3c652803e2ff8d5f7ea55c9cb5d8353279Eric Anholt   if (unlikely(INTEL_DEBUG & DEBUG_PERF)) {
1074006c1a3c652803e2ff8d5f7ea55c9cb5d8353279Eric Anholt      if (shader->compiled_once) {
1075c20cb8d1f6cac0b98950828e69376bb9406761ffKenneth Graunke         brw_vs_debug_recompile(brw, prog, &c->key);
1076006c1a3c652803e2ff8d5f7ea55c9cb5d8353279Eric Anholt      }
1077006c1a3c652803e2ff8d5f7ea55c9cb5d8353279Eric Anholt      if (start_busy && !drm_intel_bo_busy(intel->batch.last_bo)) {
1078006c1a3c652803e2ff8d5f7ea55c9cb5d8353279Eric Anholt         perf_debug("VS compile took %.03f ms and stalled the GPU\n",
107943e3a7533d5537e48cef23588131dd25d938ee4bEric Anholt                    (get_time() - start_time) * 1000);
1080006c1a3c652803e2ff8d5f7ea55c9cb5d8353279Eric Anholt      }
1081fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt   }
1082fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt
1083af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   vec4_visitor v(c, prog, shader);
1084af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   if (!v.run()) {
10852e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke      prog->LinkStatus = false;
10867fbe7fe13359d3f349664410ec73d7bd48824ed6Eric Anholt      ralloc_strcat(&prog->InfoLog, v.fail_msg);
1087af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt      return false;
1088af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   }
1089af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
1090fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt   shader->compiled_once = true;
1091fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt
1092af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   return true;
1093af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt}
1094af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
1095af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt} /* extern "C" */
1096af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt
1097af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt} /* namespace brw */
1098