2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
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:
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.
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.
26 **********************************************************************/
29 * Keith Whitwell <keith@tungstengraphics.com>
31 #include "tgsi/tgsi_info.h"
33 #include "brw_context.h"
34 #include "brw_screen.h"
36 #include "brw_state.h"
37 #include "brw_debug.h"
38 #include "brw_pipe_rast.h"
41 /** Return number of src args for given instruction */
42 GLuint
brw_wm_nr_args( GLuint opcode
)
62 /* sampler arg is held as a field in the instruction, not in an
65 return tgsi_get_opcode_info(opcode
)->num_src
- 1;
68 assert(opcode
< MAX_OPCODE
);
69 return tgsi_get_opcode_info(opcode
)->num_src
;
74 GLuint
brw_wm_is_scalar_result( GLuint opcode
)
97 * Do GPU code generation for shaders without flow control. Shaders
98 * without flow control instructions can more readily be analysed for
99 * SSA-style optimizations.
102 brw_wm_linear_shader_emit(struct brw_context
*brw
, struct brw_wm_compile
*c
)
104 /* Augment fragment program. Add instructions for pre- and
105 * post-fragment-program tasks such as interpolation and fogging.
109 /* Translate to intermediate representation. Build register usage
114 /* Dead code removal.
118 /* Register allocation.
119 * Divide by two because we operate on 16 pixels at a time and require
120 * two GRF entries for each logical shader register.
122 c
->grf_limit
= BRW_WM_MAX_GRF
/ 2;
126 /* how many general-purpose registers are used */
127 c
->prog_data
.total_grf
= c
->max_wm_grf
;
129 /* Scratch space is used for register spilling */
130 if (c
->last_scratch
) {
131 c
->prog_data
.total_scratch
= c
->last_scratch
+ 0x40;
134 c
->prog_data
.total_scratch
= 0;
144 * All Mesa program -> GPU code generation goes through this function.
145 * Depending on the instructions used (i.e. flow control instructions)
146 * we'll use one of two code generators.
148 static enum pipe_error
do_wm_prog( struct brw_context
*brw
,
149 struct brw_fragment_shader
*fp
,
150 struct brw_wm_prog_key
*key
,
151 struct brw_winsys_buffer
**bo_out
)
154 struct brw_wm_compile
*c
;
155 const GLuint
*program
;
158 if (brw
->wm
.compile_data
== NULL
) {
159 brw
->wm
.compile_data
= MALLOC(sizeof(*brw
->wm
.compile_data
));
160 if (!brw
->wm
.compile_data
)
161 return PIPE_ERROR_OUT_OF_MEMORY
;
164 c
= brw
->wm
.compile_data
;
165 memset(c
, 0, sizeof *c
);
169 c
->env_param
= NULL
; /*brw->intel.ctx.FragmentProgram.Parameters;*/
171 brw_init_compile(brw
, &c
->func
);
174 * Shader which use GLSL features such as flow control are handled
175 * differently from "simple" shaders.
177 if (fp
->has_flow_control
) {
178 c
->dispatch_width
= 8;
182 /* brw_wm_branching_shader_emit(brw, c); */
185 c
->dispatch_width
= 16;
186 brw_wm_linear_shader_emit(brw
, c
);
189 if (BRW_DEBUG
& DEBUG_WM
)
194 ret
= brw_get_program(&c
->func
, &program
, &program_size
);
198 ret
= brw_upload_cache( &brw
->cache
, BRW_WM_PROG
,
199 &c
->key
, sizeof(c
->key
),
201 program
, program_size
,
213 static void brw_wm_populate_key( struct brw_context
*brw
,
214 struct brw_wm_prog_key
*key
)
216 unsigned lookup
, line_aa
;
219 memset(key
, 0, sizeof(*key
));
221 /* PIPE_NEW_FRAGMENT_SHADER
222 * PIPE_NEW_DEPTH_STENCIL_ALPHA
224 lookup
= (brw
->curr
.zstencil
->iz_lookup
|
225 brw
->curr
.fragment_shader
->iz_lookup
);
229 * BRW_NEW_REDUCED_PRIMITIVE
231 switch (brw
->reduced_primitive
) {
232 case PIPE_PRIM_POINTS
:
235 case PIPE_PRIM_LINES
:
236 line_aa
= (brw
->curr
.rast
->templ
.line_smooth
?
237 AA_ALWAYS
: AA_NEVER
);
240 line_aa
= brw
->curr
.rast
->unfilled_aa_line
;
244 brw_wm_lookup_iz(line_aa
,
246 brw
->curr
.fragment_shader
->uses_depth
,
250 key
->flat_shade
= brw
->curr
.rast
->templ
.flatshade
;
253 /* PIPE_NEW_BOUND_TEXTURES */
254 for (i
= 0; i
< brw
->curr
.num_fragment_sampler_views
; i
++) {
255 const struct brw_texture
*tex
= brw_texture(brw
->curr
.fragment_sampler_views
[i
]->texture
);
257 if (tex
->base
.format
== PIPE_FORMAT_UYVY
)
258 key
->yuvtex_mask
|= 1 << i
;
260 if (tex
->base
.format
== PIPE_FORMAT_YUYV
)
261 key
->yuvtex_swap_mask
|= 1 << i
;
263 /* XXX: shadow texture
265 /* key->shadowtex_mask |= 1<<i; */
268 /* CACHE_NEW_VS_PROG */
269 key
->vp_nr_outputs
= brw
->vs
.prog_data
->nr_outputs
;
271 key
->nr_cbufs
= brw
->curr
.fb
.nr_cbufs
;
273 key
->nr_inputs
= brw
->curr
.fragment_shader
->info
.num_inputs
;
275 /* The unique fragment program ID */
276 key
->program_string_id
= brw
->curr
.fragment_shader
->id
;
280 static enum pipe_error
brw_prepare_wm_prog(struct brw_context
*brw
)
282 struct brw_wm_prog_key key
;
283 struct brw_fragment_shader
*fs
= brw
->curr
.fragment_shader
;
286 brw_wm_populate_key(brw
, &key
);
288 /* Make an early check for the key.
290 if (brw_search_cache(&brw
->cache
, BRW_WM_PROG
,
297 ret
= do_wm_prog(brw
, fs
, &key
, &brw
->wm
.prog_bo
);
305 const struct brw_tracked_state brw_wm_prog
= {
307 .mesa
= (PIPE_NEW_FRAGMENT_SHADER
|
308 PIPE_NEW_DEPTH_STENCIL_ALPHA
|
311 PIPE_NEW_BOUND_TEXTURES
),
312 .brw
= (BRW_NEW_WM_INPUT_DIMENSIONS
|
313 BRW_NEW_REDUCED_PRIMITIVE
),
314 .cache
= CACHE_NEW_VS_PROG
,
316 .prepare
= brw_prepare_wm_prog