Merge remote branch 'origin/master' into nv50-compiler
[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 struct nv50_varying {
31 uint8_t id; /* tgsi index */
32 uint8_t hw; /* hw index, nv50 wants flat FP inputs last */
33
34 uint8_t mask : 4;
35 uint8_t linear : 1;
36 uint8_t pad : 3;
37
38 ubyte sn; /* semantic name */
39 ubyte si; /* semantic index */
40 };
41
42 struct nv50_program {
43 struct pipe_shader_state pipe;
44
45 ubyte type;
46 boolean translated;
47
48 struct nouveau_bo *bo;
49 struct nouveau_stateobj *so;
50
51 uint32_t *code;
52 unsigned code_size;
53 unsigned code_start; /* offset inside bo */
54 uint32_t *immd;
55 unsigned immd_size;
56 unsigned parm_size; /* size limit of uniform buffer */
57
58 ubyte max_gpr; /* REG_ALLOC_TEMP */
59 ubyte max_out; /* REG_ALLOC_RESULT or FP_RESULT_COUNT */
60
61 ubyte in_nr;
62 ubyte out_nr;
63 struct nv50_varying in[16];
64 struct nv50_varying out[16];
65
66 struct {
67 uint32_t attrs[3]; /* VP_ATTR_EN_0,1 and VP_GP_BUILTIN_ATTR_EN */
68 ubyte psiz;
69 ubyte bfc[2];
70 ubyte edgeflag;
71 ubyte clpd;
72 ubyte clpd_nr;
73 } vp;
74
75 struct {
76 uint32_t flags[2]; /* 0x19a8, 196c */
77 uint32_t interp; /* 0x1988 */
78 uint32_t colors; /* 0x1904 */
79 } fp;
80
81 struct {
82 ubyte primid; /* primitive id output register */
83 uint8_t vert_count;
84 uint8_t prim_type; /* point, line strip or tri strip */
85 } gp;
86
87 void *fixups;
88 unsigned num_fixups;
89 };
90
91 #define NV50_INTERP_LINEAR (1 << 0)
92 #define NV50_INTERP_FLAT (1 << 1)
93 #define NV50_INTERP_CENTROID (1 << 2)
94
95 #define NV50_PROG_MAX_SUBROUTINES 8
96
97 /* analyze TGSI and see which TEMP[] are used as subroutine inputs/outputs */
98 struct nv50_subroutine {
99 int id;
100 uint32_t argv[4][1]; /* 4 bitmasks, for each of xyzw, only allow 32 TEMPs */
101 uint32_t retv[4][1];
102 };
103
104 struct nv50_translation_info {
105 struct nv50_program *p;
106 unsigned inst_nr;
107 ubyte input_file;
108 ubyte output_file;
109 ubyte input_map[PIPE_MAX_SHADER_INPUTS][4];
110 ubyte output_map[PIPE_MAX_SHADER_OUTPUTS][4];
111 ubyte interp_mode[PIPE_MAX_SHADER_INPUTS];
112 int input_access[PIPE_MAX_SHADER_INPUTS][4];
113 int output_access[PIPE_MAX_SHADER_OUTPUTS][4];
114 boolean indirect_inputs;
115 boolean indirect_outputs;
116 struct tgsi_shader_info scan;
117 uint32_t *immd32;
118 unsigned immd32_nr;
119 ubyte *immd32_ty;
120 ubyte edgeflag_out;
121 struct nv50_subroutine subr[NV50_PROG_MAX_SUBROUTINES];
122 int subr_nr;
123 };
124
125 int nv50_generate_code(struct nv50_translation_info *ti);
126 boolean nv50_program_tx(struct nv50_program *p);
127
128 #endif /* __NV50_PROG_H__ */