nv50: put low limit on REG_ALLOC_TEMP and FP_RESULT_COUNT
[mesa.git] / src / gallium / drivers / nv50 / nv50_program.h
1 /*
2 * Copyright 2010 Ben Skeggs
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 #ifndef __NV50_PROG_H__
24 #define __NV50_PROG_H__
25
26 #include "pipe/p_state.h"
27 #include "tgsi/tgsi_scan.h"
28 #include "nouveau/nouveau_class.h"
29
30 #define NV50_CAP_MAX_PROGRAM_TEMPS 64
31
32 struct nv50_varying {
33 uint8_t id; /* tgsi index */
34 uint8_t hw; /* hw index, nv50 wants flat FP inputs last */
35
36 uint8_t mask : 4;
37 uint8_t linear : 1;
38 uint8_t pad : 3;
39
40 ubyte sn; /* semantic name */
41 ubyte si; /* semantic index */
42 };
43
44 struct nv50_program {
45 struct pipe_shader_state pipe;
46
47 ubyte type;
48 boolean translated;
49
50 struct nouveau_bo *bo;
51 struct nouveau_stateobj *so;
52
53 uint32_t *code;
54 unsigned code_size;
55 unsigned code_start; /* offset inside bo */
56 uint32_t *immd;
57 unsigned immd_size;
58 unsigned parm_size; /* size limit of uniform buffer */
59
60 ubyte max_gpr; /* REG_ALLOC_TEMP */
61 ubyte max_out; /* REG_ALLOC_RESULT or FP_RESULT_COUNT */
62
63 ubyte in_nr;
64 ubyte out_nr;
65 struct nv50_varying in[16];
66 struct nv50_varying out[16];
67
68 struct {
69 uint32_t attrs[3]; /* VP_ATTR_EN_0,1 and VP_GP_BUILTIN_ATTR_EN */
70 ubyte psiz;
71 ubyte bfc[2];
72 ubyte edgeflag;
73 ubyte clpd;
74 ubyte clpd_nr;
75 } vp;
76
77 struct {
78 uint32_t flags[2]; /* 0x19a8, 196c */
79 uint32_t interp; /* 0x1988 */
80 uint32_t colors; /* 0x1904 */
81 } fp;
82
83 struct {
84 ubyte primid; /* primitive id output register */
85 uint8_t vert_count;
86 uint8_t prim_type; /* point, line strip or tri strip */
87 } gp;
88
89 void *fixups;
90 unsigned num_fixups;
91 };
92
93 #define NV50_INTERP_LINEAR (1 << 0)
94 #define NV50_INTERP_FLAT (1 << 1)
95 #define NV50_INTERP_CENTROID (1 << 2)
96
97 /* analyze TGSI and see which TEMP[] are used as subroutine inputs/outputs */
98 struct nv50_subroutine {
99 unsigned id;
100 unsigned pos;
101 /* function inputs and outputs */
102 uint32_t argv[NV50_CAP_MAX_PROGRAM_TEMPS][4];
103 uint32_t retv[NV50_CAP_MAX_PROGRAM_TEMPS][4];
104 };
105
106 struct nv50_translation_info {
107 struct nv50_program *p;
108 unsigned inst_nr;
109 struct tgsi_full_instruction *insns;
110 ubyte input_file;
111 ubyte output_file;
112 ubyte input_map[PIPE_MAX_SHADER_INPUTS][4];
113 ubyte output_map[PIPE_MAX_SHADER_OUTPUTS][4];
114 ubyte interp_mode[PIPE_MAX_SHADER_INPUTS];
115 int input_access[PIPE_MAX_SHADER_INPUTS][4];
116 int output_access[PIPE_MAX_SHADER_OUTPUTS][4];
117 boolean indirect_inputs;
118 boolean indirect_outputs;
119 boolean store_to_memory;
120 struct tgsi_shader_info scan;
121 uint32_t *immd32;
122 unsigned immd32_nr;
123 ubyte *immd32_ty;
124 ubyte edgeflag_out;
125 struct nv50_subroutine *subr;
126 unsigned subr_nr;
127 };
128
129 int nv50_generate_code(struct nv50_translation_info *ti);
130 boolean nv50_program_tx(struct nv50_program *p);
131
132 #endif /* __NV50_PROG_H__ */