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>
33 #include "brw_context.h"
34 #include "brw_defines.h"
39 /* How does predicate control work when execution_size != 8? Do I
40 * need to test/set for 0xffff when execution_size is 16?
42 void brw_set_predicate_control_flag_value( struct brw_compile
*p
, GLuint value
)
44 p
->current
->header
.predicate_control
= BRW_PREDICATE_NONE
;
47 if (value
!= p
->flag_value
) {
48 brw_push_insn_state(p
);
49 brw_MOV(p
, brw_flag_reg(), brw_imm_uw(value
));
50 p
->flag_value
= value
;
51 brw_pop_insn_state(p
);
54 p
->current
->header
.predicate_control
= BRW_PREDICATE_NORMAL
;
58 void brw_set_predicate_control( struct brw_compile
*p
, GLuint pc
)
60 p
->current
->header
.predicate_control
= pc
;
63 void brw_set_conditionalmod( struct brw_compile
*p
, GLuint conditional
)
65 p
->current
->header
.destreg__conditonalmod
= conditional
;
68 void brw_set_access_mode( struct brw_compile
*p
, GLuint access_mode
)
70 p
->current
->header
.access_mode
= access_mode
;
73 void brw_set_compression_control( struct brw_compile
*p
, GLboolean compression_control
)
75 p
->current
->header
.compression_control
= compression_control
;
78 void brw_set_mask_control( struct brw_compile
*p
, GLuint value
)
80 p
->current
->header
.mask_control
= value
;
83 void brw_set_saturate( struct brw_compile
*p
, GLuint value
)
85 p
->current
->header
.saturate
= value
;
88 void brw_push_insn_state( struct brw_compile
*p
)
90 assert(p
->current
!= &p
->stack
[BRW_EU_MAX_INSN_STACK
-1]);
91 memcpy(p
->current
+1, p
->current
, sizeof(struct brw_instruction
));
95 void brw_pop_insn_state( struct brw_compile
*p
)
97 assert(p
->current
!= p
->stack
);
102 /***********************************************************************
104 void brw_init_compile( struct brw_context
*brw
, struct brw_compile
*p
)
108 p
->current
= p
->stack
;
109 memset(p
->current
, 0, sizeof(p
->current
[0]));
113 brw_set_mask_control(p
, BRW_MASK_ENABLE
); /* what does this do? */
114 brw_set_saturate(p
, 0);
115 brw_set_compression_control(p
, BRW_COMPRESSION_NONE
);
116 brw_set_predicate_control_flag_value(p
, 0xff);
120 const GLuint
*brw_get_program( struct brw_compile
*p
,
125 for (i
= 0; i
< 8; i
++)
128 *sz
= p
->nr_insn
* sizeof(struct brw_instruction
);
129 return (const GLuint
*)p
->store
;
135 * Subroutine calls require special attention.
136 * Mesa instructions may be expanded into multiple hardware instructions
137 * so the prog_instruction::BranchTarget field can't be used as an index
138 * into the hardware instructions.
140 * The BranchTarget field isn't needed, however. Mesa's GLSL compiler
141 * emits CAL and BGNSUB instructions with labels that can be used to map
142 * subroutine calls to actual subroutine code blocks.
144 * The structures and function here implement patching of CAL instructions
145 * so they jump to the right subroutine code...
150 * For each OPCODE_BGNSUB we create one of these.
152 struct brw_glsl_label
154 const char *name
; /**< the label string */
155 GLuint position
; /**< the position of the brw instruction for this label */
156 struct brw_glsl_label
*next
; /**< next in linked list */
161 * For each OPCODE_CAL we create one of these.
165 GLuint call_inst_pos
; /**< location of the CAL instruction */
166 const char *sub_name
; /**< name of subroutine to call */
167 struct brw_glsl_call
*next
; /**< next in linked list */
172 * Called for each OPCODE_BGNSUB.
175 brw_save_label(struct brw_compile
*c
, const char *name
, GLuint position
)
177 struct brw_glsl_label
*label
= CALLOC_STRUCT(brw_glsl_label
);
179 label
->position
= position
;
180 label
->next
= c
->first_label
;
181 c
->first_label
= label
;
186 * Called for each OPCODE_CAL.
189 brw_save_call(struct brw_compile
*c
, const char *name
, GLuint call_pos
)
191 struct brw_glsl_call
*call
= CALLOC_STRUCT(brw_glsl_call
);
192 call
->call_inst_pos
= call_pos
;
193 call
->sub_name
= name
;
194 call
->next
= c
->first_call
;
195 c
->first_call
= call
;
200 * Lookup a label, return label's position/offset.
203 brw_lookup_label(struct brw_compile
*c
, const char *name
)
205 const struct brw_glsl_label
*label
;
206 for (label
= c
->first_label
; label
; label
= label
->next
) {
207 if (strcmp(name
, label
->name
) == 0) {
208 return label
->position
;
211 abort(); /* should never happen */
217 * When we're done generating code, this function is called to resolve
221 brw_resolve_cals(struct brw_compile
*c
)
223 const struct brw_glsl_call
*call
;
225 for (call
= c
->first_call
; call
; call
= call
->next
) {
226 const GLuint sub_loc
= brw_lookup_label(c
, call
->sub_name
);
227 struct brw_instruction
*brw_call_inst
= &c
->store
[call
->call_inst_pos
];
228 struct brw_instruction
*brw_sub_inst
= &c
->store
[sub_loc
];
229 GLint offset
= brw_sub_inst
- brw_call_inst
;
231 /* patch brw_inst1 to point to brw_inst2 */
232 brw_set_src1(brw_call_inst
, brw_imm_d(offset
* 16));
235 /* free linked list of calls */
237 struct brw_glsl_call
*call
, *next
;
238 for (call
= c
->first_call
; call
; call
= next
) {
242 c
->first_call
= NULL
;
245 /* free linked list of labels */
247 struct brw_glsl_label
*label
, *next
;
248 for (label
= c
->first_label
; label
; label
= next
) {
252 c
->first_label
= NULL
;