OSDN Git Service

295fed851bb609d13294f1be1ce75d69e9afe749
[android-x86/external-mesa.git] / src / mesa / drivers / dri / i965 / brw_wm.h
1 /*
2  Copyright (C) Intel Corp.  2006.  All Rights Reserved.
3  Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4  develop this 3D driver.
5  
6  Permission is hereby granted, free of charge, to any person obtaining
7  a copy of this software and associated documentation files (the
8  "Software"), to deal in the Software without restriction, including
9  without limitation the rights to use, copy, modify, merge, publish,
10  distribute, sublicense, and/or sell copies of the Software, and to
11  permit persons to whom the Software is furnished to do so, subject to
12  the following conditions:
13  
14  The above copyright notice and this permission notice (including the
15  next paragraph) shall be included in all copies or substantial
16  portions of the Software.
17  
18  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21  IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  
26  **********************************************************************/
27  /*
28   * Authors:
29   *   Keith Whitwell <keith@tungstengraphics.com>
30   */
31               
32
33 #ifndef BRW_WM_H
34 #define BRW_WM_H
35
36
37 #include "shader/prog_instruction.h"
38 #include "brw_context.h"
39 #include "brw_eu.h"
40
41 /* A big lookup table is used to figure out which and how many
42  * additional regs will inserted before the main payload in the WM
43  * program execution.  These mainly relate to depth and stencil
44  * processing and the early-depth-test optimization.
45  */
46 #define IZ_PS_KILL_ALPHATEST_BIT    0x1
47 #define IZ_PS_COMPUTES_DEPTH_BIT    0x2
48 #define IZ_DEPTH_WRITE_ENABLE_BIT   0x4
49 #define IZ_DEPTH_TEST_ENABLE_BIT    0x8
50 #define IZ_STENCIL_WRITE_ENABLE_BIT 0x10
51 #define IZ_STENCIL_TEST_ENABLE_BIT  0x20
52 #define IZ_BIT_MAX                  0x40
53
54 #define AA_NEVER     0
55 #define AA_SOMETIMES 1
56 #define AA_ALWAYS    2
57
58 struct brw_wm_prog_key {
59    GLuint source_depth_reg:3;
60    GLuint aa_dest_stencil_reg:3;
61    GLuint dest_depth_reg:3;
62    GLuint nr_depth_regs:3;
63    GLuint computes_depth:1;     /* could be derived from program string */
64    GLuint source_depth_to_render_target:1;
65    GLuint flat_shade:1;
66    GLuint runtime_check_aads_emit:1;
67    
68    GLbitfield proj_attrib_mask; /**< one bit per fragment program attribute */
69    GLuint shadowtex_mask:16;
70    GLuint yuvtex_mask:16;
71    GLuint yuvtex_swap_mask:16;  /* UV swaped */
72
73    GLuint tex_swizzles[BRW_MAX_TEX_UNIT];
74
75    GLuint program_string_id:32;
76    GLuint origin_x, origin_y;
77    GLuint drawable_height;
78    GLuint vp_outputs_written;
79 };
80
81
82 /* A bit of a glossary:
83  *
84  * brw_wm_value: A computed value or program input.  Values are
85  * constant, they are created once and are never modified.  When a
86  * fragment program register is written or overwritten, new values are
87  * created fresh, preserving the rule that values are constant.
88  *
89  * brw_wm_ref: A reference to a value.  Wherever a value used is by an
90  * instruction or as a program output, that is tracked with an
91  * instance of this struct.  All references to a value occur after it
92  * is created.  After the last reference, a value is dead and can be
93  * discarded.
94  *
95  * brw_wm_grf: Represents a physical hardware register.  May be either
96  * empty or hold a value.  Register allocation is the process of
97  * assigning values to grf registers.  This occurs in pass2 and the
98  * brw_wm_grf struct is not used before that.
99  *
100  * Fragment program registers: These are time-varying constructs that
101  * are hard to reason about and which we translate away in pass0.  A
102  * single fragment program register element (eg. temp[0].x) will be
103  * translated to one or more brw_wm_value structs, one for each time
104  * that temp[0].x is written to during the program. 
105  */
106
107
108
109 /* Used in pass2 to track register allocation.
110  */
111 struct brw_wm_grf {
112    struct brw_wm_value *value;
113    GLuint nextuse;
114 };
115
116 struct brw_wm_value {
117    struct brw_reg hw_reg;       /* emitted to this reg, may not always be there */
118    struct brw_wm_ref *lastuse;
119    struct brw_wm_grf *resident; 
120    GLuint contributes_to_output:1;
121    GLuint spill_slot:16;        /* if non-zero, spill immediately after calculation */
122 };
123
124 struct brw_wm_ref {
125    struct brw_reg hw_reg;       /* nr filled in in pass2, everything else, pass0 */
126    struct brw_wm_value *value;
127    struct brw_wm_ref *prevuse;
128    GLuint unspill_reg:7;        /* unspill to reg */
129    GLuint emitted:1;
130    GLuint insn:24;
131 };
132
133 struct brw_wm_constref {
134    const struct brw_wm_ref *ref;
135    GLfloat constval;
136 };
137
138
139 struct brw_wm_instruction {
140    struct brw_wm_value *dst[4];
141    struct brw_wm_ref *src[3][4];
142    GLuint opcode:8;
143    GLuint saturate:1;
144    GLuint writemask:4;
145    GLuint tex_unit:4;   /* texture unit for TEX, TXD, TXP instructions */
146    GLuint tex_idx:3;    /* TEXTURE_1D,2D,3D,CUBE,RECT_INDEX source target */
147    GLuint tex_shadow:1; /* do shadow comparison? */
148    GLuint eot:1;        /* End of thread indicator for FB_WRITE*/
149    GLuint target:10;    /* target binding table index for FB_WRITE*/
150 };
151
152
153 #define BRW_WM_MAX_INSN  (MAX_NV_FRAGMENT_PROGRAM_INSTRUCTIONS*3 + FRAG_ATTRIB_MAX + 3)
154 #define BRW_WM_MAX_GRF   128            /* hardware limit */
155 #define BRW_WM_MAX_VREG  (BRW_WM_MAX_INSN * 4)
156 #define BRW_WM_MAX_REF   (BRW_WM_MAX_INSN * 12)
157 #define BRW_WM_MAX_PARAM 256
158 #define BRW_WM_MAX_CONST 256
159 #define BRW_WM_MAX_KILLS MAX_NV_FRAGMENT_PROGRAM_INSTRUCTIONS
160 #define BRW_WM_MAX_SUBROUTINE 16
161
162
163
164 /* New opcodes to track internal operations required for WM unit.
165  * These are added early so that the registers used can be tracked,
166  * freed and reused like those of other instructions.
167  */
168 #define WM_PIXELXY        (MAX_OPCODE)
169 #define WM_DELTAXY        (MAX_OPCODE + 1)
170 #define WM_PIXELW         (MAX_OPCODE + 2)
171 #define WM_LINTERP        (MAX_OPCODE + 3)
172 #define WM_PINTERP        (MAX_OPCODE + 4)
173 #define WM_CINTERP        (MAX_OPCODE + 5)
174 #define WM_WPOSXY         (MAX_OPCODE + 6)
175 #define WM_FB_WRITE       (MAX_OPCODE + 7)
176 #define WM_FRONTFACING    (MAX_OPCODE + 8)
177 #define MAX_WM_OPCODE     (MAX_OPCODE + 9)
178
179 #define PROGRAM_PAYLOAD   (PROGRAM_FILE_MAX)
180 #define PAYLOAD_DEPTH     (FRAG_ATTRIB_MAX)
181
182 struct brw_wm_compile {
183    struct brw_compile func;
184    struct brw_wm_prog_key key;
185    struct brw_wm_prog_data prog_data;
186
187    struct brw_fragment_program *fp;
188
189    GLfloat (*env_param)[4];
190
191    enum {
192       START,
193       PASS2_DONE
194    } state;
195
196    /* Initial pass - translate fp instructions to fp instructions,
197     * simplifying and adding instructions for interpolation and
198     * framebuffer writes.
199     */
200    struct prog_instruction prog_instructions[BRW_WM_MAX_INSN];
201    GLuint nr_fp_insns;
202    GLuint fp_temp;
203    GLuint fp_interp_emitted;
204    GLuint fp_fragcolor_emitted;
205    GLuint fp_deriv_emitted;
206
207    struct prog_src_register pixel_xy;
208    struct prog_src_register delta_xy;
209    struct prog_src_register pixel_w;
210
211
212    struct brw_wm_value vreg[BRW_WM_MAX_VREG];
213    GLuint nr_vreg;
214
215    struct brw_wm_value creg[BRW_WM_MAX_PARAM];
216    GLuint nr_creg;
217
218    struct {
219       struct brw_wm_value depth[4]; /* includes r0/r1 */
220       struct brw_wm_value input_interp[FRAG_ATTRIB_MAX];
221    } payload;
222
223
224    const struct brw_wm_ref *pass0_fp_reg[PROGRAM_PAYLOAD+1][256][4];
225
226    struct brw_wm_ref undef_ref;
227    struct brw_wm_value undef_value;
228
229    struct brw_wm_ref refs[BRW_WM_MAX_REF];
230    GLuint nr_refs;
231
232    struct brw_wm_instruction instruction[BRW_WM_MAX_INSN];
233    GLuint nr_insns;
234
235    struct brw_wm_constref constref[BRW_WM_MAX_CONST];
236    GLuint nr_constrefs;
237
238    struct brw_wm_grf pass2_grf[BRW_WM_MAX_GRF/2];
239
240    GLuint grf_limit;
241    GLuint max_wm_grf;
242    GLuint last_scratch;
243
244    /** Mapping from Mesa registers to hardware registers */
245    struct {
246       GLboolean inited;
247       struct brw_reg reg;
248    } wm_regs[PROGRAM_PAYLOAD+1][256][4];
249
250    struct brw_reg stack;
251    struct brw_reg emit_mask_reg;
252    GLuint reg_index;  /**< Index of next free GRF register */
253    GLuint tmp_regs[BRW_WM_MAX_GRF];
254    GLuint tmp_index;
255    GLuint tmp_max;
256    GLuint subroutines[BRW_WM_MAX_SUBROUTINE];
257
258    /** we may need up to 3 constants per instruction (if use_const_buffer) */
259    struct {
260       GLint index;
261       struct brw_reg reg;
262    } current_const[3];
263 };
264
265
266 GLuint brw_wm_nr_args( GLuint opcode );
267 GLuint brw_wm_is_scalar_result( GLuint opcode );
268
269 void brw_wm_pass_fp( struct brw_wm_compile *c );
270 void brw_wm_pass0( struct brw_wm_compile *c );
271 void brw_wm_pass1( struct brw_wm_compile *c );
272 void brw_wm_pass2( struct brw_wm_compile *c );
273 void brw_wm_emit( struct brw_wm_compile *c );
274
275 void brw_wm_print_value( struct brw_wm_compile *c,
276                          struct brw_wm_value *value );
277
278 void brw_wm_print_ref( struct brw_wm_compile *c,
279                        struct brw_wm_ref *ref );
280
281 void brw_wm_print_insn( struct brw_wm_compile *c,
282                         struct brw_wm_instruction *inst );
283
284 void brw_wm_print_program( struct brw_wm_compile *c,
285                            const char *stage );
286
287 void brw_wm_lookup_iz( GLuint line_aa,
288                        GLuint lookup,
289                        struct brw_wm_prog_key *key );
290
291 GLboolean brw_wm_is_glsl(const struct gl_fragment_program *fp);
292 void brw_wm_glsl_emit(struct brw_context *brw, struct brw_wm_compile *c);
293
294
295 #endif