nv50_program.c revision 3a62365f402b1159afd526fb4b510cdb51de1365
1857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs/*
2633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller * Copyright 2010 Chrsitoph 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
23d90502b2b468732e2a42985580bbbe9d9fdfd14eChristoph Bumiller/* #define NV50_PROGRAM_DEBUG */
24d90502b2b468732e2a42985580bbbe9d9fdfd14eChristoph Bumiller
25633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller#include "nv50_program.h"
26633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller#include "nv50_pc.h"
27633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller#include "nv50_context.h"
28f722fd937db2f3cacf1947d538c66528fd16eb89Ben Skeggs
29f722fd937db2f3cacf1947d538c66528fd16eb89Ben Skeggs#include "pipe/p_shader_tokens.h"
30fda01b584715c05696a0e6768fda669ef1eb5f3bBen Skeggs#include "tgsi/tgsi_parse.h"
31fda01b584715c05696a0e6768fda669ef1eb5f3bBen Skeggs#include "tgsi/tgsi_util.h"
323a68fcfb6b406cf864afbf200e436fc384fd0865Christoph Bumiller#include "tgsi/tgsi_dump.h"
33f722fd937db2f3cacf1947d538c66528fd16eb89Ben Skeggs
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:
331633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      switch (decl->Semantic.Name) {
332633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      case TGSI_SEMANTIC_FACE:
333633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
334633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      case TGSI_SEMANTIC_INSTANCEID:
335633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
336633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      case TGSI_SEMANTIC_PRIMID:
337633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
338633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         /*
339633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      case TGSI_SEMANTIC_PRIMIDIN:
340633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
341633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      case TGSI_SEMANTIC_VERTEXID:
342633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
343633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         */
344633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      default:
345633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
346633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      }
347633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      break;
348633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_FILE_CONSTANT:
349633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      ti->p->parm_size = MAX2(ti->p->parm_size, (last + 1) * 16);
350633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      break;
351633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_FILE_ADDRESS:
352633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_FILE_SAMPLER:
353633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case TGSI_FILE_TEMPORARY:
354633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      break;
355633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   default:
356633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      assert(0);
357633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      break;
358633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
359f722fd937db2f3cacf1947d538c66528fd16eb89Ben Skeggs}
360f722fd937db2f3cacf1947d538c66528fd16eb89Ben Skeggs
3613f66b72fdb4834c5211305698d22806eac80aa35Ben Skeggsstatic int
362633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillernv50_vertprog_prepare(struct nv50_translation_info *ti)
3633f66b72fdb4834c5211305698d22806eac80aa35Ben Skeggs{
364633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   struct nv50_program *p = ti->p;
365633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   int i, c;
366633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   unsigned num_inputs = 0;
3673f66b72fdb4834c5211305698d22806eac80aa35Ben Skeggs
368633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   ti->input_file = NV_FILE_MEM_S;
369633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   ti->output_file = NV_FILE_OUT;
3703f66b72fdb4834c5211305698d22806eac80aa35Ben Skeggs
371633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   for (i = 0; i <= ti->scan.file_max[TGSI_FILE_INPUT]; ++i) {
372633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->in[i].id = i;
373633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->in[i].hw = num_inputs;
3743f66b72fdb4834c5211305698d22806eac80aa35Ben Skeggs
375633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      for (c = 0; c < 4; ++c) {
376633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         if (!ti->input_access[i][c])
377633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller            continue;
378633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         ti->input_map[i][c] = num_inputs++;
379633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         p->vp.attrs[(4 * i + c) / 32] |= 1 << ((i * 4 + c) % 32);
380633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      }
381633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
3823f66b72fdb4834c5211305698d22806eac80aa35Ben Skeggs
383633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   for (i = 0; i <= ti->scan.file_max[TGSI_FILE_OUTPUT]; ++i) {
384633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->out[i].id = i;
385633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->out[i].hw = p->max_out;
3862a1fb44d75364f2492a1ae5d232218a92b8ca807Ben Skeggs
387633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      for (c = 0; c < 4; ++c) {
388633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         if (!ti->output_access[i][c])
389633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller            continue;
390633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         ti->output_map[i][c] = p->max_out++;
391633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         p->out[i].mask |= 1 << c;
392633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      }
393633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
3942a1fb44d75364f2492a1ae5d232218a92b8ca807Ben Skeggs
395633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   if (p->vp.psiz < 0x40)
396633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->vp.psiz = p->out[p->vp.psiz].hw;
397d4d880199ead954e79cad141f7a29f7dd17fe7fcPatrice Mandin
398633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   return 0;
3992a1fb44d75364f2492a1ae5d232218a92b8ca807Ben Skeggs}
4002a1fb44d75364f2492a1ae5d232218a92b8ca807Ben Skeggs
40133e4d30d50344be26398a51365bea1be37487403Ben Skeggsstatic int
402633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillernv50_fragprog_prepare(struct nv50_translation_info *ti)
403633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller{
404633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   struct nv50_program *p = ti->p;
405633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   int i, j, c;
406633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   unsigned nvary, nintp, depr;
407633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   unsigned n = 0, m = 0, skip = 0;
408633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   ubyte sn[16], si[16];
409633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
410633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   /* FP flags */
411633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
412633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   if (ti->scan.writes_z) {
413633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->fp.flags[1] = 0x11;
414633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->fp.flags[0] |= NV50TCL_FP_CONTROL_EXPORTS_Z;
415633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
416633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
417633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   if (ti->scan.uses_kill)
418633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->fp.flags[0] |= NV50TCL_FP_CONTROL_USES_KIL;
419633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
420633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   /* FP inputs */
421633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
422633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   ti->input_file = NV_FILE_MEM_V;
423633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   ti->output_file = NV_FILE_GPR;
424633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
425633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   /* count non-flat inputs, save semantic info */
426633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   for (i = 0; i < p->in_nr; ++i) {
427633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      m += (ti->interp_mode[i] & NV50_INTERP_FLAT) ? 0 : 1;
428633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      sn[i] = p->in[i].sn;
429633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      si[i] = p->in[i].si;
430633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
431633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
432633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   /* reorder p->in[] so that non-flat inputs are first and
433633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller    * kick out special inputs that don't use VP/GP_RESULT_MAP
434633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller    */
435633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   nintp = 0;
436633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   for (i = 0; i < p->in_nr; ++i) {
437633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      if (sn[i] == TGSI_SEMANTIC_POSITION) {
438633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         for (c = 0; c < 4; ++c) {
439633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller            ti->input_map[i][c] = nintp;
440633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller            if (ti->input_access[i][c]) {
441633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller               p->fp.interp |= 1 << (24 + c);
442633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller               ++nintp;
443633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller            }
444633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         }
445633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         skip++;
446633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         continue;
447633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      } else
448633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      if (sn[i] == TGSI_SEMANTIC_FACE) {
449633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         ti->input_map[i][0] = 255;
450633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         skip++;
451633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         continue;
452633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      }
453633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
454633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      j = (ti->interp_mode[i] & NV50_INTERP_FLAT) ? m++ : n++;
455633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
456633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      if (sn[i] == TGSI_SEMANTIC_COLOR)
457633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         p->vp.bfc[si[i]] = j;
458633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
459633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->in[j].linear = (ti->interp_mode[i] & NV50_INTERP_LINEAR) ? 1 : 0;
460633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->in[j].id = i;
461633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->in[j].sn = sn[i];
462633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->in[j].si = si[i];
463633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
464633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   assert(n <= m);
465633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   p->in_nr -= skip;
466633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
467633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   if (!(p->fp.interp & (8 << 24))) {
468633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->fp.interp |= (8 << 24);
469633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      ++nintp;
470633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
471633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
472633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   p->fp.colors = (1 << 24) | 4; /* CLAMP, FFC0_ID = 4 */
473633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
474633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   for (i = 0; i < p->in_nr; ++i) {
475633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      int j = p->in[i].id;
476633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->in[i].hw = nintp;
477633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
478633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      for (c = 0; c < 4; ++c) {
479633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         if (!ti->input_access[j][c])
480633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller            continue;
481633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         p->in[i].mask |= 1 << c;
482633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         ti->input_map[j][c] = nintp++;
483633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      }
484633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      /* count color inputs */
485633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      if (i == p->vp.bfc[0] || i == p->vp.bfc[1])
486633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         p->fp.colors += bitcount4(p->in[i].mask) << 16;
487633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
488633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   nintp -= bitcount4(p->fp.interp >> 24); /* subtract position inputs */
489633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   nvary = nintp;
490633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   if (n < m)
491633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      nvary -= p->in[n].hw;
492633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
493633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   p->fp.interp |= nvary << NV50TCL_FP_INTERPOLANT_CTRL_COUNT_NONFLAT_SHIFT;
494633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   p->fp.interp |= nintp << NV50TCL_FP_INTERPOLANT_CTRL_COUNT_SHIFT;
495633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
496633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   /* FP outputs */
497633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
498633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   if (p->out_nr > (1 + (ti->scan.writes_z ? 1 : 0)))
499633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->fp.flags[0] |= NV50TCL_FP_CONTROL_MULTIPLE_RESULTS;
500633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
501633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   depr = p->out_nr;
502633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   for (i = 0; i < p->out_nr; ++i) {
503633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->out[i].id = i;
504633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      if (p->out[i].sn == TGSI_SEMANTIC_POSITION) {
505633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         depr = i;
506633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         continue;
507633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      }
508633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->out[i].hw = p->max_out;
509633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->out[i].mask = 0xf;
510633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
511633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      for (c = 0; c < 4; ++c)
512633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         ti->output_map[i][c] = p->max_out++;
513633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
514633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   if (depr < p->out_nr) {
515633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      p->out[depr].mask = 0x4;
5163844c365947082550565accefd996c10fbb15cc4Christoph Bumiller      p->out[depr].hw = ti->output_map[depr][2] = p->max_out++;
51784d170bbcef8e26017ac8e2f3bacbaeb20f889d3Christoph Bumiller   } else {
51884d170bbcef8e26017ac8e2f3bacbaeb20f889d3Christoph Bumiller      /* allowed values are 1, 4, 5, 8, 9, ... */
51984d170bbcef8e26017ac8e2f3bacbaeb20f889d3Christoph Bumiller      p->max_out = MAX2(4, p->max_out);
520633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
521633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
522633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   return 0;
52355b2fe1047b37d0d86641a252e1c745111030393Ben Skeggs}
52455b2fe1047b37d0d86641a252e1c745111030393Ben Skeggs
525633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillerstatic int
526633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillernv50_geomprog_prepare(struct nv50_translation_info *ti)
52744d8c9add2f095fc365ede751253d9fb7fc5c6e1Christoph Bumiller{
528633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   ti->input_file = NV_FILE_MEM_S;
529633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   ti->output_file = NV_FILE_OUT;
53044d8c9add2f095fc365ede751253d9fb7fc5c6e1Christoph Bumiller
531633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   assert(0);
532633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   return 1;
53344d8c9add2f095fc365ede751253d9fb7fc5c6e1Christoph Bumiller}
53444d8c9add2f095fc365ede751253d9fb7fc5c6e1Christoph Bumiller
535633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillerstatic int
536633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillernv50_prog_scan(struct nv50_translation_info *ti)
537633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller{
538633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   struct nv50_program *p = ti->p;
539633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   struct tgsi_parse_context parse;
540d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller   int ret, i;
541633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
5421bbbc8e0c8230d33cb1eae89cc47b5296edefc10Christoph Bumiller   p->vp.edgeflag = 0x40;
543633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   p->vp.psiz = 0x40;
544633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   p->vp.bfc[0] = 0x40;
545633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   p->vp.bfc[1] = 0x40;
546633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   p->gp.primid = 0x80;
547633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
548633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   tgsi_scan_shader(p->pipe.tokens, &ti->scan);
549633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
550d90502b2b468732e2a42985580bbbe9d9fdfd14eChristoph Bumiller#ifdef NV50_PROGRAM_DEBUG
551d90502b2b468732e2a42985580bbbe9d9fdfd14eChristoph Bumiller   tgsi_dump(p->pipe.tokens, 0);
552d90502b2b468732e2a42985580bbbe9d9fdfd14eChristoph Bumiller#endif
553d90502b2b468732e2a42985580bbbe9d9fdfd14eChristoph Bumiller
554d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller   ti->subr =
555d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller      CALLOC(ti->scan.opcode_count[TGSI_OPCODE_BGNSUB], sizeof(ti->subr[0]));
556d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller
557e08f70a41d1012a0270468866614485a3415168eChristoph Bumiller   ti->immd32 = (uint32_t *)MALLOC(ti->scan.immediate_count * 16);
558e08f70a41d1012a0270468866614485a3415168eChristoph Bumiller   ti->immd32_ty = (ubyte *)MALLOC(ti->scan.immediate_count * sizeof(ubyte));
559e08f70a41d1012a0270468866614485a3415168eChristoph Bumiller
560217542a061ef31150b1b04f1b45b6099bcc153feChristoph Bumiller   ti->insns = MALLOC(ti->scan.num_instructions * sizeof(ti->insns[0]));
561217542a061ef31150b1b04f1b45b6099bcc153feChristoph Bumiller
562633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   tgsi_parse_init(&parse, p->pipe.tokens);
563633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   while (!tgsi_parse_end_of_tokens(&parse)) {
564633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      tgsi_parse_token(&parse);
565633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
566633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      switch (parse.FullToken.Token.Type) {
567633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      case TGSI_TOKEN_TYPE_IMMEDIATE:
568633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         prog_immediate(ti, &parse.FullToken.FullImmediate);
569633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
570633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      case TGSI_TOKEN_TYPE_DECLARATION:
571633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         prog_decl(ti, &parse.FullToken.FullDeclaration);
572633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
573633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      case TGSI_TOKEN_TYPE_INSTRUCTION:
574217542a061ef31150b1b04f1b45b6099bcc153feChristoph Bumiller         ti->insns[ti->inst_nr] = parse.FullToken.FullInstruction;
575633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         prog_inst(ti, &parse.FullToken.FullInstruction, ++ti->inst_nr);
576633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller         break;
577633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      }
578633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
579633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
580d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller   /* Scan to determine which registers are inputs/outputs of a subroutine. */
581d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller   for (i = 0; i < ti->subr_nr; ++i) {
582d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller      int pc = ti->subr[i].id;
583d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller      while (ti->insns[pc].Instruction.Opcode != TGSI_OPCODE_ENDSUB)
584d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller         prog_subroutine_inst(&ti->subr[i], &ti->insns[pc++]);
585d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller   }
586d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller
587633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   p->in_nr = ti->scan.file_max[TGSI_FILE_INPUT] + 1;
588633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   p->out_nr = ti->scan.file_max[TGSI_FILE_OUTPUT] + 1;
589633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
590633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   switch (p->type) {
591633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case PIPE_SHADER_VERTEX:
592633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      ret = nv50_vertprog_prepare(ti);
593633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      break;
594633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case PIPE_SHADER_FRAGMENT:
595633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      ret = nv50_fragprog_prepare(ti);
596633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      break;
597633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   case PIPE_SHADER_GEOMETRY:
598633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      ret = nv50_geomprog_prepare(ti);
599633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      break;
600633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   default:
601633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      assert(!"unsupported program type");
602633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      ret = -1;
603633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      break;
604633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
605633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
606633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   assert(!ret);
607633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   return ret;
608633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller}
609633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller
610633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillerboolean
611633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillernv50_program_tx(struct nv50_program *p)
61244d8c9add2f095fc365ede751253d9fb7fc5c6e1Christoph Bumiller{
613633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   struct nv50_translation_info *ti;
614633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   int ret;
61544d8c9add2f095fc365ede751253d9fb7fc5c6e1Christoph Bumiller
616633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   ti = CALLOC_STRUCT(nv50_translation_info);
617633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   ti->p = p;
6182a1fb44d75364f2492a1ae5d232218a92b8ca807Ben Skeggs
619633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   ti->edgeflag_out = PIPE_MAX_SHADER_OUTPUTS;
6202a1fb44d75364f2492a1ae5d232218a92b8ca807Ben Skeggs
621633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   ret = nv50_prog_scan(ti);
622633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   if (ret) {
623633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      NOUVEAU_ERR("unsupported shader program\n");
624633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      goto out;
625633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
626708c711f8361ea82c1217e2614914ae047bc5bdfChristoph Bumiller
627633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   ret = nv50_generate_code(ti);
628633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   if (ret) {
629633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      NOUVEAU_ERR("error during shader translation\n");
630633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      goto out;
631633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   }
6322a1fb44d75364f2492a1ae5d232218a92b8ca807Ben Skeggs
633633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillerout:
634633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   if (ti->immd32)
635633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      FREE(ti->immd32);
636e08f70a41d1012a0270468866614485a3415168eChristoph Bumiller   if (ti->immd32_ty)
637e08f70a41d1012a0270468866614485a3415168eChristoph Bumiller      FREE(ti->immd32_ty);
638217542a061ef31150b1b04f1b45b6099bcc153feChristoph Bumiller   if (ti->insns)
639217542a061ef31150b1b04f1b45b6099bcc153feChristoph Bumiller      FREE(ti->insns);
640d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller   if (ti->subr)
641d91b8865ec2bb41f9b58ad5ce2df7f6f48f98281Christoph Bumiller      FREE(ti->subr);
642633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   FREE(ti);
643633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   return ret ? FALSE : TRUE;
6442a1fb44d75364f2492a1ae5d232218a92b8ca807Ben Skeggs}
6452a1fb44d75364f2492a1ae5d232218a92b8ca807Ben Skeggs
646633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillervoid
647633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumillernv50_program_destroy(struct nv50_context *nv50, struct nv50_program *p)
6482a1fb44d75364f2492a1ae5d232218a92b8ca807Ben Skeggs{
649633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   nouveau_bo_ref(NULL, &p->bo);
650f722fd937db2f3cacf1947d538c66528fd16eb89Ben Skeggs
651633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   so_ref(NULL, &p->so);
652f722fd937db2f3cacf1947d538c66528fd16eb89Ben Skeggs
653633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   if (p->code)
654633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller      FREE(p->code);
6557c745de74997e859d7e2640092bda9ad900e28a9Ben Skeggs
6563a62365f402b1159afd526fb4b510cdb51de1365Christoph Bumiller   if (p->fixups)
6573a62365f402b1159afd526fb4b510cdb51de1365Christoph Bumiller      FREE(p->fixups);
6583a62365f402b1159afd526fb4b510cdb51de1365Christoph Bumiller
659633f5ac6124b1b57152c09becba92d176e905ae9Christoph Bumiller   p->translated = FALSE;
660f722fd937db2f3cacf1947d538c66528fd16eb89Ben Skeggs}
661