nv50_program.c revision d2d19ea51fa3575a8d014a69a9b835c335728817
1857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs/*
2d2d19ea51fa3575a8d014a69a9b835c335728817Christoph Bumiller * Copyright 2010 Christoph Bumiller
3857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs *
4857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
5857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * copy of this software and associated documentation files (the "Software"),
6857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * to deal in the Software without restriction, including without limitation
7857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
9857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * Software is furnished to do so, subject to the following conditions:
10857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs *
11857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * The above copyright notice and this permission notice shall be included in
12857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * all copies or substantial portions of the Software.
13857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs *
14857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * SOFTWARE.
21857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs */
22857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs
23633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller#include "nv50_program.h"
24633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller#include "nv50_pc.h"
25633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller#include "nv50_context.h"
26f722fd937db2f3cacf1947d538c66528fd16eb89Ben Skeggs
27f722fd937db2f3cacf1947d538c66528fd16eb89Ben Skeggs#include "pipe/p_shader_tokens.h"
28fda01b584715c05696a0e6768fda669ef1eb5f3bBen Skeggs#include "tgsi/tgsi_parse.h"
29fda01b584715c05696a0e6768fda669ef1eb5f3bBen Skeggs#include "tgsi/tgsi_util.h"
303a68fcfb6b406cf864afbf200e436fc384fd0865Christoph Bumiller#include "tgsi/tgsi_dump.h"
31f722fd937db2f3cacf1947d538c66528fd16eb89Ben Skeggs
323afabfb929cf24a783c10c99bf0d86245e70a94aChristoph Bumiller#include "codegen/nv50_ir_driver.h"
333afabfb929cf24a783c10c99bf0d86245e70a94aChristoph Bumiller
346516594c8eec1088ee59e7c3254b2fdced2ff04bChristoph Bumillerstatic INLINE unsigned
35633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillerbitcount4(const uint32_t val)
36170cdb4507683fb9042620f7ab2ad96e57787d6cChristoph Bumiller{
37633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   static const unsigned cnt[16]
38633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 };
39633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   return cnt[val & 0xf];
40170cdb4507683fb9042620f7ab2ad96e57787d6cChristoph Bumiller}
41170cdb4507683fb9042620f7ab2ad96e57787d6cChristoph Bumiller
42633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillerstatic unsigned
43633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillernv50_tgsi_src_mask(const struct tgsi_full_instruction *inst, int c)
44633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller{
45633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   unsigned mask = inst->Dst[0].Register.WriteMask;
46633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
47633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   switch (inst->Instruction.Opcode) {
48633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_OPCODE_COS:
49633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_OPCODE_SIN:
50633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      return (mask & 0x8) | ((mask & 0x7) ? 0x1 : 0x0);
51633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_OPCODE_DP3:
52633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      return 0x7;
53633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_OPCODE_DP4:
54633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_OPCODE_DPH:
55633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_OPCODE_KIL: /* WriteMask ignored */
56633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      return 0xf;
57633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_OPCODE_DST:
58633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      return mask & (c ? 0xa : 0x6);
59633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_OPCODE_EX2:
60633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_OPCODE_EXP:
61633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_OPCODE_LG2:
62633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_OPCODE_LOG:
63633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_OPCODE_POW:
64633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_OPCODE_RCP:
65633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_OPCODE_RSQ:
66633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_OPCODE_SCS:
67633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      return 0x1;
68633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_OPCODE_IF:
69633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      return 0x1;
70633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_OPCODE_LIT:
71633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      return 0xb;
72633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_OPCODE_TEX:
73633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_OPCODE_TXB:
74633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_OPCODE_TXL:
75633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_OPCODE_TXP:
76633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   {
77633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      const struct tgsi_instruction_texture *tex;
78633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
79633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      assert(inst->Instruction.Texture);
80633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      tex = &inst->Texture;
81633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
82633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      mask = 0x7;
83633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      if (inst->Instruction.Opcode != TGSI_OPCODE_TEX &&
84633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller          inst->Instruction.Opcode != TGSI_OPCODE_TXD)
85633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         mask |= 0x8; /* bias, lod or proj */
86633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
87633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      switch (tex->Texture) {
88633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      case TGSI_TEXTURE_1D:
89633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         mask &= 0x9;
90633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
91633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      case TGSI_TEXTURE_SHADOW1D:
92633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         mask &= 0x5;
93633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
94633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      case TGSI_TEXTURE_2D:
95633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         mask &= 0xb;
96633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
97633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      default:
98633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
99633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      }
100633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
101633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller  	   return mask;
102633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_OPCODE_XPD:
103633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   {
104633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      unsigned x = 0;
105633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      if (mask & 1) x |= 0x6;
106633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      if (mask & 2) x |= 0x5;
107633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      if (mask & 4) x |= 0x3;
108633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      return x;
109633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
110633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   default:
111633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      break;
112633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
113633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
114633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   return mask;
115633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller}
116633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
117633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillerstatic void
118633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillernv50_indirect_inputs(struct nv50_translation_info *ti, int id)
119633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller{
120633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   int i, c;
121633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
122633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   for (i = 0; i < PIPE_MAX_SHADER_INPUTS; ++i)
123633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      for (c = 0; c < 4; ++c)
124633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         ti->input_access[i][c] = id;
125633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
126633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   ti->indirect_inputs = TRUE;
127633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller}
128633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
129633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillerstatic void
130633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillernv50_indirect_outputs(struct nv50_translation_info *ti, int id)
131633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller{
132633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   int i, c;
133633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
134633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   for (i = 0; i < PIPE_MAX_SHADER_OUTPUTS; ++i)
135633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      for (c = 0; c < 4; ++c)
136633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         ti->output_access[i][c] = id;
137633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
138633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   ti->indirect_outputs = TRUE;
139633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller}
140633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
141633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillerstatic void
142633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillerprog_inst(struct nv50_translation_info *ti,
143633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller          const struct tgsi_full_instruction *inst, int id)
144633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller{
145633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   const struct tgsi_dst_register *dst;
146633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   const struct tgsi_src_register *src;
147633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   int s, c, k;
148633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   unsigned mask;
149633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
150d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller   if (inst->Instruction.Opcode == TGSI_OPCODE_BGNSUB) {
151d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller      ti->subr[ti->subr_nr].pos = id - 1;
152d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller      ti->subr[ti->subr_nr].id = ti->subr_nr + 1; /* id 0 is main program */
153d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller      ++ti->subr_nr;
154d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller   }
155d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller
156633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   if (inst->Dst[0].Register.File == TGSI_FILE_OUTPUT) {
157d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller      dst = &inst->Dst[0].Register;
158d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller
159633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      for (c = 0; c < 4; ++c) {
160d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller         if (dst->Indirect)
161633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller            nv50_indirect_outputs(ti, id);
162633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         if (!(dst->WriteMask & (1 << c)))
163633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller            continue;
164633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         ti->output_access[dst->Index][c] = id;
165633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      }
166633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
167633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      if (inst->Instruction.Opcode == TGSI_OPCODE_MOV &&
168633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller          inst->Src[0].Register.File == TGSI_FILE_INPUT &&
169633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller          dst->Index == ti->edgeflag_out)
170633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         ti->p->vp.edgeflag = inst->Src[0].Register.Index;
171f30810cb68a53c4fef360778a230126ed0ee0ee3Christoph Bumiller   } else
172f30810cb68a53c4fef360778a230126ed0ee0ee3Christoph Bumiller   if (inst->Dst[0].Register.File == TGSI_FILE_TEMPORARY) {
173f30810cb68a53c4fef360778a230126ed0ee0ee3Christoph Bumiller      if (inst->Dst[0].Register.Indirect)
174f30810cb68a53c4fef360778a230126ed0ee0ee3Christoph Bumiller         ti->store_to_memory = TRUE;
175633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
176f722fd937db2f3cacf1947d538c66528fd16eb89Ben Skeggs
177633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   for (s = 0; s < inst->Instruction.NumSrcRegs; ++s) {
178633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      src = &inst->Src[s].Register;
179f30810cb68a53c4fef360778a230126ed0ee0ee3Christoph Bumiller      if (src->File == TGSI_FILE_TEMPORARY)
180f30810cb68a53c4fef360778a230126ed0ee0ee3Christoph Bumiller         if (inst->Src[s].Register.Indirect)
181f30810cb68a53c4fef360778a230126ed0ee0ee3Christoph Bumiller            ti->store_to_memory = TRUE;
182633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      if (src->File != TGSI_FILE_INPUT)
183633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         continue;
184633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      mask = nv50_tgsi_src_mask(inst, s);
185f722fd937db2f3cacf1947d538c66528fd16eb89Ben Skeggs
186633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      if (inst->Src[s].Register.Indirect)
187633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         nv50_indirect_inputs(ti, id);
188f722fd937db2f3cacf1947d538c66528fd16eb89Ben Skeggs
189633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      for (c = 0; c < 4; ++c) {
190633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         if (!(mask & (1 << c)))
191633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller            continue;
192633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         k = tgsi_util_get_full_src_register_swizzle(&inst->Src[s], c);
193633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         if (k <= TGSI_SWIZZLE_W)
194633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller            ti->input_access[src->Index][k] = id;
195633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      }
196633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
197f722fd937db2f3cacf1947d538c66528fd16eb89Ben Skeggs}
198f722fd937db2f3cacf1947d538c66528fd16eb89Ben Skeggs
199d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller/* Probably should introduce something like struct tgsi_function_declaration
200d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller * instead of trying to guess inputs/outputs.
201d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller */
202d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumillerstatic void
203d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumillerprog_subroutine_inst(struct nv50_subroutine *subr,
204d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller                     const struct tgsi_full_instruction *inst)
205d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller{
206d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller   const struct tgsi_dst_register *dst;
207d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller   const struct tgsi_src_register *src;
208d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller   int s, c, k;
209d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller   unsigned mask;
210d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller
211d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller   for (s = 0; s < inst->Instruction.NumSrcRegs; ++s) {
212d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller      src = &inst->Src[s].Register;
213d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller      if (src->File != TGSI_FILE_TEMPORARY)
214d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller         continue;
215d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller      mask = nv50_tgsi_src_mask(inst, s);
216d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller
217d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller      assert(!inst->Src[s].Register.Indirect);
218d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller
219d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller      for (c = 0; c < 4; ++c) {
220d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller         k = tgsi_util_get_full_src_register_swizzle(&inst->Src[s], c);
221d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller
222d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller         if ((mask & (1 << c)) && k < TGSI_SWIZZLE_W)
223d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller            if (!(subr->retv[src->Index / 32][k] & (1 << (src->Index % 32))))
224d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller               subr->argv[src->Index / 32][k] |= 1 << (src->Index % 32);
225d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller      }
226d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller   }
227d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller
228d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller   if (inst->Dst[0].Register.File == TGSI_FILE_TEMPORARY) {
229d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller      dst = &inst->Dst[0].Register;
230d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller
231d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller      for (c = 0; c < 4; ++c)
232d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller         if (dst->WriteMask & (1 << c))
233d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller            subr->retv[dst->Index / 32][c] |= 1 << (dst->Index % 32);
234d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller   }
235d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller}
236d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller
2377ab96f4f733437de693b9578c3649b56069e6f24Christoph Bumillerstatic void
238633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillerprog_immediate(struct nv50_translation_info *ti,
239633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller               const struct tgsi_full_immediate *imm)
2407ab96f4f733437de693b9578c3649b56069e6f24Christoph Bumiller{
241633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   int c;
242e08f70a41d1012a0270468866614485a3415168eChristoph Bumiller   unsigned n = ti->immd32_nr++;
2437ab96f4f733437de693b9578c3649b56069e6f24Christoph Bumiller
244e08f70a41d1012a0270468866614485a3415168eChristoph Bumiller   assert(ti->immd32_nr <= ti->scan.immediate_count);
2457ab96f4f733437de693b9578c3649b56069e6f24Christoph Bumiller
246633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   for (c = 0; c < 4; ++c)
247e08f70a41d1012a0270468866614485a3415168eChristoph Bumiller      ti->immd32[n * 4 + c] = imm->u[c].Uint;
248e08f70a41d1012a0270468866614485a3415168eChristoph Bumiller
249e08f70a41d1012a0270468866614485a3415168eChristoph Bumiller   ti->immd32_ty[n] = imm->Immediate.DataType;
2507ab96f4f733437de693b9578c3649b56069e6f24Christoph Bumiller}
2517ab96f4f733437de693b9578c3649b56069e6f24Christoph Bumiller
252633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillerstatic INLINE unsigned
253633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillertranslate_interpolate(const struct tgsi_full_declaration *decl)
254633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller{
255633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   unsigned mode;
256633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
257633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   if (decl->Declaration.Interpolate == TGSI_INTERPOLATE_CONSTANT)
258633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      mode = NV50_INTERP_FLAT;
259633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   else
260633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   if (decl->Declaration.Interpolate == TGSI_INTERPOLATE_PERSPECTIVE)
261633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      mode = 0;
262633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   else
263633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      mode = NV50_INTERP_LINEAR;
264633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
265633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   if (decl->Declaration.Centroid)
266633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      mode |= NV50_INTERP_CENTROID;
267633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
268633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   return mode;
269633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller}
270633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
271633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillerstatic void
272633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillerprog_decl(struct nv50_translation_info *ti,
273633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller          const struct tgsi_full_declaration *decl)
274633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller{
275633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   unsigned i, first, last, sn = 0, si = 0;
276633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
277633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   first = decl->Range.First;
278633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   last = decl->Range.Last;
279633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
280633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   if (decl->Declaration.Semantic) {
281633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      sn = decl->Semantic.Name;
282633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      si = decl->Semantic.Index;
283633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
284633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
285633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   switch (decl->Declaration.File) {
286633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_FILE_INPUT:
287633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      for (i = first; i <= last; ++i)
288633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         ti->interp_mode[i] = translate_interpolate(decl);
289633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
290633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      if (!decl->Declaration.Semantic)
291633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
292633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
293633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      for (i = first; i <= last; ++i) {
294633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         ti->p->in[i].sn = sn;
295633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         ti->p->in[i].si = si;
296633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      }
297633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
298633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      switch (sn) {
299633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      case TGSI_SEMANTIC_FACE:
300633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
301633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      case TGSI_SEMANTIC_COLOR:
302633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         if (ti->p->type == PIPE_SHADER_FRAGMENT)
303633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller            ti->p->vp.bfc[si] = first;
304633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
305633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      }
306633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      break;
307633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_FILE_OUTPUT:
308633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      if (!decl->Declaration.Semantic)
309633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
310633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
311633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      for (i = first; i <= last; ++i) {
312633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         ti->p->out[i].sn = sn;
313633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         ti->p->out[i].si = si;
314633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      }
315633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
316633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      switch (sn) {
317633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      case TGSI_SEMANTIC_BCOLOR:
318633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         ti->p->vp.bfc[si] = first;
319633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
320633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      case TGSI_SEMANTIC_PSIZE:
321633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         ti->p->vp.psiz = first;
322633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
323633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      case TGSI_SEMANTIC_EDGEFLAG:
324633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         ti->edgeflag_out = first;
325633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
326633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      default:
327633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
328633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      }
329633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      break;
330633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_FILE_SYSTEM_VALUE:
331533bf171d4c926e4ab6fcd0d51396b195b9e024fChristoph Bumiller      /* For VP/GP inputs, they are put in s[] after the last normal input.
332533bf171d4c926e4ab6fcd0d51396b195b9e024fChristoph Bumiller       * Let sysval_map reflect the order of the sysvals in s[] and fixup later.
333533bf171d4c926e4ab6fcd0d51396b195b9e024fChristoph Bumiller       */
334633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      switch (decl->Semantic.Name) {
335633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      case TGSI_SEMANTIC_FACE:
336633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
337633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      case TGSI_SEMANTIC_INSTANCEID:
338533bf171d4c926e4ab6fcd0d51396b195b9e024fChristoph Bumiller         ti->p->vp.attrs[2] |= NV50_3D_VP_GP_BUILTIN_ATTR_EN_INSTANCE_ID;
339533bf171d4c926e4ab6fcd0d51396b195b9e024fChristoph Bumiller         ti->sysval_map[first] = 2;
340633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
341633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      case TGSI_SEMANTIC_PRIMID:
342633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
343633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         /*
344633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      case TGSI_SEMANTIC_PRIMIDIN:
345633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
346633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      case TGSI_SEMANTIC_VERTEXID:
347633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
348633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         */
349633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      default:
350633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
351633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      }
352633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      break;
353633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_FILE_CONSTANT:
354633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      ti->p->parm_size = MAX2(ti->p->parm_size, (last + 1) * 16);
355633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      break;
356633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_FILE_ADDRESS:
357633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_FILE_SAMPLER:
358633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_FILE_TEMPORARY:
359633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      break;
360633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   default:
361633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      assert(0);
362633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      break;
363633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
364f722fd937db2f3cacf1947d538c66528fd16eb89Ben Skeggs}
365f722fd937db2f3cacf1947d538c66528fd16eb89Ben Skeggs
3663f66b72fdb4834c5211305698d22806eac80aa35Ben Skeggsstatic int
367633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillernv50_vertprog_prepare(struct nv50_translation_info *ti)
3683f66b72fdb4834c5211305698d22806eac80aa35Ben Skeggs{
369633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   struct nv50_program *p = ti->p;
370633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   int i, c;
371633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   unsigned num_inputs = 0;
3723f66b72fdb4834c5211305698d22806eac80aa35Ben Skeggs
373633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   ti->input_file = NV_FILE_MEM_S;
374633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   ti->output_file = NV_FILE_OUT;
3753f66b72fdb4834c5211305698d22806eac80aa35Ben Skeggs
376633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   for (i = 0; i <= ti->scan.file_max[TGSI_FILE_INPUT]; ++i) {
377633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->in[i].id = i;
378633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->in[i].hw = num_inputs;
3793f66b72fdb4834c5211305698d22806eac80aa35Ben Skeggs
380633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      for (c = 0; c < 4; ++c) {
381633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         if (!ti->input_access[i][c])
382633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller            continue;
383633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         ti->input_map[i][c] = num_inputs++;
384633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         p->vp.attrs[(4 * i + c) / 32] |= 1 << ((i * 4 + c) % 32);
385633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      }
386633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
3873f66b72fdb4834c5211305698d22806eac80aa35Ben Skeggs
388633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   for (i = 0; i <= ti->scan.file_max[TGSI_FILE_OUTPUT]; ++i) {
389633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->out[i].id = i;
390633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->out[i].hw = p->max_out;
3912a1fb44d75364f2492a1ae5d232218a92b8ca807Ben Skeggs
392633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      for (c = 0; c < 4; ++c) {
393633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         if (!ti->output_access[i][c])
394633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller            continue;
395633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         ti->output_map[i][c] = p->max_out++;
396633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         p->out[i].mask |= 1 << c;
397633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      }
398633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
3992a1fb44d75364f2492a1ae5d232218a92b8ca807Ben Skeggs
400116133af3499947500a6d0c877fbc8f564ee4c76Maxim Levitsky   p->vp.clpd = p->max_out;
401116133af3499947500a6d0c877fbc8f564ee4c76Maxim Levitsky   p->max_out += p->vp.clpd_nr;
402116133af3499947500a6d0c877fbc8f564ee4c76Maxim Levitsky
403533bf171d4c926e4ab6fcd0d51396b195b9e024fChristoph Bumiller   for (i = 0; i < TGSI_SEMANTIC_COUNT; ++i) {
404533bf171d4c926e4ab6fcd0d51396b195b9e024fChristoph Bumiller      switch (ti->sysval_map[i]) {
405533bf171d4c926e4ab6fcd0d51396b195b9e024fChristoph Bumiller      case 2:
406533bf171d4c926e4ab6fcd0d51396b195b9e024fChristoph Bumiller         if (!(ti->p->vp.attrs[2] & NV50_3D_VP_GP_BUILTIN_ATTR_EN_VERTEX_ID))
407533bf171d4c926e4ab6fcd0d51396b195b9e024fChristoph Bumiller            ti->sysval_map[i] = 1;
408533bf171d4c926e4ab6fcd0d51396b195b9e024fChristoph Bumiller         ti->sysval_map[i] = (ti->sysval_map[i] - 1) + num_inputs;
409533bf171d4c926e4ab6fcd0d51396b195b9e024fChristoph Bumiller         break;
410533bf171d4c926e4ab6fcd0d51396b195b9e024fChristoph Bumiller      default:
411533bf171d4c926e4ab6fcd0d51396b195b9e024fChristoph Bumiller         break;
412533bf171d4c926e4ab6fcd0d51396b195b9e024fChristoph Bumiller      }
413533bf171d4c926e4ab6fcd0d51396b195b9e024fChristoph Bumiller   }
414533bf171d4c926e4ab6fcd0d51396b195b9e024fChristoph Bumiller
415633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   if (p->vp.psiz < 0x40)
416633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->vp.psiz = p->out[p->vp.psiz].hw;
417d4d880199ead954e79cad141f7a29f7dd17fe7fcPatrice Mandin
418633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   return 0;
4192a1fb44d75364f2492a1ae5d232218a92b8ca807Ben Skeggs}
4202a1fb44d75364f2492a1ae5d232218a92b8ca807Ben Skeggs
42133e4d30d50344be26398a51365bea1be37487403Ben Skeggsstatic int
422633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillernv50_fragprog_prepare(struct nv50_translation_info *ti)
423633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller{
424633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   struct nv50_program *p = ti->p;
425633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   int i, j, c;
426633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   unsigned nvary, nintp, depr;
427633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   unsigned n = 0, m = 0, skip = 0;
428633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   ubyte sn[16], si[16];
429633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
430633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   /* FP flags */
431633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
432633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   if (ti->scan.writes_z) {
433633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->fp.flags[1] = 0x11;
434f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller      p->fp.flags[0] |= NV50_3D_FP_CONTROL_EXPORTS_Z;
435633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
436633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
437633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   if (ti->scan.uses_kill)
438f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller      p->fp.flags[0] |= NV50_3D_FP_CONTROL_USES_KIL;
439633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
440633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   /* FP inputs */
441633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
442633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   ti->input_file = NV_FILE_MEM_V;
443633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   ti->output_file = NV_FILE_GPR;
444633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
445633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   /* count non-flat inputs, save semantic info */
446633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   for (i = 0; i < p->in_nr; ++i) {
447633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      m += (ti->interp_mode[i] & NV50_INTERP_FLAT) ? 0 : 1;
448633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      sn[i] = p->in[i].sn;
449633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      si[i] = p->in[i].si;
450633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
451633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
452633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   /* reorder p->in[] so that non-flat inputs are first and
453633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller    * kick out special inputs that don't use VP/GP_RESULT_MAP
454633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller    */
455633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   nintp = 0;
456633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   for (i = 0; i < p->in_nr; ++i) {
457633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      if (sn[i] == TGSI_SEMANTIC_POSITION) {
458633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         for (c = 0; c < 4; ++c) {
459633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller            ti->input_map[i][c] = nintp;
460633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller            if (ti->input_access[i][c]) {
461633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller               p->fp.interp |= 1 << (24 + c);
462633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller               ++nintp;
463633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller            }
464633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         }
465633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         skip++;
466633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         continue;
467633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      } else
468633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      if (sn[i] == TGSI_SEMANTIC_FACE) {
469633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         ti->input_map[i][0] = 255;
470633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         skip++;
471633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         continue;
472633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      }
473633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
474633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      j = (ti->interp_mode[i] & NV50_INTERP_FLAT) ? m++ : n++;
475633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
476633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      if (sn[i] == TGSI_SEMANTIC_COLOR)
477633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         p->vp.bfc[si[i]] = j;
478633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
479633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->in[j].linear = (ti->interp_mode[i] & NV50_INTERP_LINEAR) ? 1 : 0;
480633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->in[j].id = i;
481633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->in[j].sn = sn[i];
482633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->in[j].si = si[i];
483633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
484633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   assert(n <= m);
485633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   p->in_nr -= skip;
486633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
487633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   if (!(p->fp.interp & (8 << 24))) {
488633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->fp.interp |= (8 << 24);
489633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      ++nintp;
490633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
491633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
4928f060df60d1f5ad63a341e39f2ec5a0c3c452cf5Christoph Bumiller   p->fp.colors = 4 << NV50_3D_MAP_SEMANTIC_0_FFC0_ID__SHIFT; /* after HPOS */
493633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
494633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   for (i = 0; i < p->in_nr; ++i) {
495633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      int j = p->in[i].id;
496633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->in[i].hw = nintp;
497633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
498633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      for (c = 0; c < 4; ++c) {
499633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         if (!ti->input_access[j][c])
500633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller            continue;
501633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         p->in[i].mask |= 1 << c;
502633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         ti->input_map[j][c] = nintp++;
503633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      }
504633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      /* count color inputs */
505633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      if (i == p->vp.bfc[0] || i == p->vp.bfc[1])
506633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         p->fp.colors += bitcount4(p->in[i].mask) << 16;
507633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
508633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   nintp -= bitcount4(p->fp.interp >> 24); /* subtract position inputs */
509633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   nvary = nintp;
510633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   if (n < m)
511633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      nvary -= p->in[n].hw;
512633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
513f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   p->fp.interp |= nvary << NV50_3D_FP_INTERPOLANT_CTRL_COUNT_NONFLAT__SHIFT;
514f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   p->fp.interp |= nintp << NV50_3D_FP_INTERPOLANT_CTRL_COUNT__SHIFT;
515633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
516633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   /* FP outputs */
517633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
518633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   if (p->out_nr > (1 + (ti->scan.writes_z ? 1 : 0)))
519f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller      p->fp.flags[0] |= NV50_3D_FP_CONTROL_MULTIPLE_RESULTS;
520633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
521633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   depr = p->out_nr;
522633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   for (i = 0; i < p->out_nr; ++i) {
523633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->out[i].id = i;
524633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      if (p->out[i].sn == TGSI_SEMANTIC_POSITION) {
525633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         depr = i;
526633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         continue;
527633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      }
528633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->out[i].hw = p->max_out;
529633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->out[i].mask = 0xf;
530633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
531633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      for (c = 0; c < 4; ++c)
532633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         ti->output_map[i][c] = p->max_out++;
533633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
534633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   if (depr < p->out_nr) {
535633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->out[depr].mask = 0x4;
5363844c365947082550565accefd996c10fbb15cc4Christoph Bumiller      p->out[depr].hw = ti->output_map[depr][2] = p->max_out++;
53784d170bbcef8e26017ac8e2f3bacbaeb20f889d3Christoph Bumiller   } else {
53884d170bbcef8e26017ac8e2f3bacbaeb20f889d3Christoph Bumiller      /* allowed values are 1, 4, 5, 8, 9, ... */
53984d170bbcef8e26017ac8e2f3bacbaeb20f889d3Christoph Bumiller      p->max_out = MAX2(4, p->max_out);
540633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
541633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
542633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   return 0;
54355b2fe1047b37d0d86641a252e1c745111030393Ben Skeggs}
54455b2fe1047b37d0d86641a252e1c745111030393Ben Skeggs
545633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillerstatic int
546633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillernv50_geomprog_prepare(struct nv50_translation_info *ti)
54744d8c9add2f095fc365ede751253d9fb7fc5c6e1Christoph Bumiller{
548633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   ti->input_file = NV_FILE_MEM_S;
549633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   ti->output_file = NV_FILE_OUT;
55044d8c9add2f095fc365ede751253d9fb7fc5c6e1Christoph Bumiller
551633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   assert(0);
552633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   return 1;
55344d8c9add2f095fc365ede751253d9fb7fc5c6e1Christoph Bumiller}
55444d8c9add2f095fc365ede751253d9fb7fc5c6e1Christoph Bumiller
555633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillerstatic int
556633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillernv50_prog_scan(struct nv50_translation_info *ti)
557633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller{
558633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   struct nv50_program *p = ti->p;
559633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   struct tgsi_parse_context parse;
560d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller   int ret, i;
561633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
5621bbbc8e0c8230d33cb1eae89cc47b5296edefc10Christoph Bumiller   p->vp.edgeflag = 0x40;
563633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   p->vp.psiz = 0x40;
564633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   p->vp.bfc[0] = 0x40;
565633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   p->vp.bfc[1] = 0x40;
566633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   p->gp.primid = 0x80;
567633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
568633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   tgsi_scan_shader(p->pipe.tokens, &ti->scan);
569633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
57074559abbef5e5bcd3dbe1b8bbb8a39391a8a8671Christoph Bumiller#if NV50_DEBUG & NV50_DEBUG_SHADER
571d90502b2b468732e2a42985580bbbe9d9fdfd14eChristoph Bumiller   tgsi_dump(p->pipe.tokens, 0);
572d90502b2b468732e2a42985580bbbe9d9fdfd14eChristoph Bumiller#endif
573d90502b2b468732e2a42985580bbbe9d9fdfd14eChristoph Bumiller
574d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller   ti->subr =
575d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller      CALLOC(ti->scan.opcode_count[TGSI_OPCODE_BGNSUB], sizeof(ti->subr[0]));
576d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller
577e08f70a41d1012a0270468866614485a3415168eChristoph Bumiller   ti->immd32 = (uint32_t *)MALLOC(ti->scan.immediate_count * 16);
578e08f70a41d1012a0270468866614485a3415168eChristoph Bumiller   ti->immd32_ty = (ubyte *)MALLOC(ti->scan.immediate_count * sizeof(ubyte));
579e08f70a41d1012a0270468866614485a3415168eChristoph Bumiller
580217542a061ef31150b1b04f1b45b6099bcc153feChristoph Bumiller   ti->insns = MALLOC(ti->scan.num_instructions * sizeof(ti->insns[0]));
581217542a061ef31150b1b04f1b45b6099bcc153feChristoph Bumiller
582633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   tgsi_parse_init(&parse, p->pipe.tokens);
583633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   while (!tgsi_parse_end_of_tokens(&parse)) {
584633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      tgsi_parse_token(&parse);
585633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
586633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      switch (parse.FullToken.Token.Type) {
587633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      case TGSI_TOKEN_TYPE_IMMEDIATE:
588633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         prog_immediate(ti, &parse.FullToken.FullImmediate);
589633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
590633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      case TGSI_TOKEN_TYPE_DECLARATION:
591633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         prog_decl(ti, &parse.FullToken.FullDeclaration);
592633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
593633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      case TGSI_TOKEN_TYPE_INSTRUCTION:
594217542a061ef31150b1b04f1b45b6099bcc153feChristoph Bumiller         ti->insns[ti->inst_nr] = parse.FullToken.FullInstruction;
595633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         prog_inst(ti, &parse.FullToken.FullInstruction, ++ti->inst_nr);
596633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
597633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      }
598633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
599633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
600d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller   /* Scan to determine which registers are inputs/outputs of a subroutine. */
601d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller   for (i = 0; i < ti->subr_nr; ++i) {
602d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller      int pc = ti->subr[i].id;
603d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller      while (ti->insns[pc].Instruction.Opcode != TGSI_OPCODE_ENDSUB)
604d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller         prog_subroutine_inst(&ti->subr[i], &ti->insns[pc++]);
605d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller   }
606d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller
607633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   p->in_nr = ti->scan.file_max[TGSI_FILE_INPUT] + 1;
608633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   p->out_nr = ti->scan.file_max[TGSI_FILE_OUTPUT] + 1;
609633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
610633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   switch (p->type) {
611633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case PIPE_SHADER_VERTEX:
612633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      ret = nv50_vertprog_prepare(ti);
613633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      break;
614633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case PIPE_SHADER_FRAGMENT:
615633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      ret = nv50_fragprog_prepare(ti);
616633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      break;
617633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case PIPE_SHADER_GEOMETRY:
618633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      ret = nv50_geomprog_prepare(ti);
619633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      break;
620633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   default:
621633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      assert(!"unsupported program type");
622633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      ret = -1;
623633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      break;
624633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
625633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
626633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   assert(!ret);
627633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   return ret;
628633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller}
629633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
6303afabfb929cf24a783c10c99bf0d86245e70a94aChristoph Bumiller/* Temporary, need a reference to nv50_ir_generate_code in libnv50 or
6313afabfb929cf24a783c10c99bf0d86245e70a94aChristoph Bumiller * it "gets disappeared" and cannot be used in libnvc0 ...
6323afabfb929cf24a783c10c99bf0d86245e70a94aChristoph Bumiller */
6333afabfb929cf24a783c10c99bf0d86245e70a94aChristoph Bumillerboolean
6343afabfb929cf24a783c10c99bf0d86245e70a94aChristoph Bumillernv50_program_translate_new(struct nv50_program *p)
6353afabfb929cf24a783c10c99bf0d86245e70a94aChristoph Bumiller{
6363afabfb929cf24a783c10c99bf0d86245e70a94aChristoph Bumiller   struct nv50_ir_prog_info info;
6373afabfb929cf24a783c10c99bf0d86245e70a94aChristoph Bumiller
6383afabfb929cf24a783c10c99bf0d86245e70a94aChristoph Bumiller   return nv50_ir_generate_code(&info);
6393afabfb929cf24a783c10c99bf0d86245e70a94aChristoph Bumiller}
6403afabfb929cf24a783c10c99bf0d86245e70a94aChristoph Bumiller
641633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillerboolean
642f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumillernv50_program_translate(struct nv50_program *p)
64344d8c9add2f095fc365ede751253d9fb7fc5c6e1Christoph Bumiller{
644633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   struct nv50_translation_info *ti;
645633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   int ret;
64644d8c9add2f095fc365ede751253d9fb7fc5c6e1Christoph Bumiller
647633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   ti = CALLOC_STRUCT(nv50_translation_info);
648633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   ti->p = p;
6492a1fb44d75364f2492a1ae5d232218a92b8ca807Ben Skeggs
650633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   ti->edgeflag_out = PIPE_MAX_SHADER_OUTPUTS;
6512a1fb44d75364f2492a1ae5d232218a92b8ca807Ben Skeggs
652633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   ret = nv50_prog_scan(ti);
653633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   if (ret) {
654633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      NOUVEAU_ERR("unsupported shader program\n");
655633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      goto out;
656633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
657708c711f8361ea82c1217e2614914ae047bc5bdfChristoph Bumiller
658633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   ret = nv50_generate_code(ti);
659633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   if (ret) {
660633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      NOUVEAU_ERR("error during shader translation\n");
661633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      goto out;
662633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
6632a1fb44d75364f2492a1ae5d232218a92b8ca807Ben Skeggs
664633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillerout:
665633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   if (ti->immd32)
666633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      FREE(ti->immd32);
667e08f70a41d1012a0270468866614485a3415168eChristoph Bumiller   if (ti->immd32_ty)
668e08f70a41d1012a0270468866614485a3415168eChristoph Bumiller      FREE(ti->immd32_ty);
669217542a061ef31150b1b04f1b45b6099bcc153feChristoph Bumiller   if (ti->insns)
670217542a061ef31150b1b04f1b45b6099bcc153feChristoph Bumiller      FREE(ti->insns);
671d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller   if (ti->subr)
672d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller      FREE(ti->subr);
673633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   FREE(ti);
674633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   return ret ? FALSE : TRUE;
6752a1fb44d75364f2492a1ae5d232218a92b8ca807Ben Skeggs}
6762a1fb44d75364f2492a1ae5d232218a92b8ca807Ben Skeggs
677633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillervoid
678633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillernv50_program_destroy(struct nv50_context *nv50, struct nv50_program *p)
6792a1fb44d75364f2492a1ae5d232218a92b8ca807Ben Skeggs{
680f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   if (p->res)
681f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller      nouveau_resource_free(&p->res);
682f722fd937db2f3cacf1947d538c66528fd16eb89Ben Skeggs
683633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   if (p->code)
684633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      FREE(p->code);
6857c745de74997e859d7e2640092bda9ad900e28a9Ben Skeggs
6863a62365f402b1159afd526fb4b510cdb51de1365Christoph Bumiller   if (p->fixups)
6873a62365f402b1159afd526fb4b510cdb51de1365Christoph Bumiller      FREE(p->fixups);
6883a62365f402b1159afd526fb4b510cdb51de1365Christoph Bumiller
689633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   p->translated = FALSE;
690f722fd937db2f3cacf1947d538c66528fd16eb89Ben Skeggs}
691