1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * 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, sub license, 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 portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 /* Authors: Keith Whitwell <keith@tungstengraphics.com>
34 #include "pipe/p_config.h"
41 #include "pipe/p_state.h"
42 #include "rtasm/rtasm_x86sse.h"
53 #define MAX_INPUTS PIPE_MAX_ATTRIBS
54 #define MAX_OUTPUTS PIPE_MAX_SHADER_OUTPUTS
55 #define MAX_TEMPS TGSI_EXEC_NUM_TEMPS
56 #define MAX_CONSTANTS 1024 /** only used for sanity checking */
57 #define MAX_IMMEDIATES 1024 /** only used for sanity checking */
58 #define MAX_INTERNALS 8 /** see IMM_x values below */
60 #define AOS_FILE_INTERNAL TGSI_FILE_COUNT
63 #define FPU_RND_NEAREST 2
66 typedef void (PIPE_CDECL
*lit_func
)( struct aos_machine
*,
71 void PIPE_CDECL
aos_do_lit( struct aos_machine
*machine
,
84 struct shine_tab
*shine_tab
;
87 #define MAX_SHINE_TAB 4
88 #define MAX_LIT_INFO 16
91 const void *input_ptr
;
92 unsigned input_stride
;
98 /* This is the temporary storage used by all the aos_sse vs varients.
99 * Create one per context and reuse by passing a pointer in at
100 * vs_varient creation??
103 float input
[MAX_INPUTS
][4];
104 float output
[MAX_OUTPUTS
][4];
105 float temp
[MAX_TEMPS
][4];
106 float internal
[MAX_INTERNALS
][4];
108 float scale
[4]; /* viewport */
109 float translate
[4]; /* viewport */
111 float tmp
[2][4]; /* scratch space for LIT */
113 struct shine_tab shine_tab
[MAX_SHINE_TAB
];
114 struct lit_info lit_info
[MAX_LIT_INFO
];
118 ushort fpu_rnd_nearest
;
119 ushort fpu_rnd_neg_inf
;
121 ushort fpucntl
; /* one of FPU_* above */
123 const float (*immediates
)[4]; /* points to shader data */
124 const float (*constants
)[4]; /* points to draw data */
126 const struct aos_attrib
*attrib
; /* points to ? */
132 struct aos_compilation
{
133 struct x86_function
*func
;
134 struct draw_vs_varient_aos_sse
*vaos
;
136 unsigned insn_counter
;
137 unsigned num_immediates
;
148 unsigned x86_reg
[2]; /* one of X86_* */
150 boolean input_fetched
[PIPE_MAX_ATTRIBS
];
151 unsigned output_last_write
[PIPE_MAX_ATTRIBS
];
157 /* these are actually known values, but putting them in a struct
158 * like this is helpful to keep them in sync across the file.
160 struct x86_reg tmp_EAX
;
161 struct x86_reg idx_EBX
; /* either start+i or &elt[i] */
162 struct x86_reg outbuf_ECX
;
163 struct x86_reg machine_EDX
;
164 struct x86_reg count_ESI
; /* decrements to zero */
165 struct x86_reg temp_EBP
;
166 struct x86_reg stack_ESP
;
169 struct x86_reg
aos_get_xmm_reg( struct aos_compilation
*cp
);
170 void aos_release_xmm_reg( struct aos_compilation
*cp
, unsigned idx
);
172 void aos_adopt_xmm_reg( struct aos_compilation
*cp
,
178 struct x86_reg
aos_get_shader_reg( struct aos_compilation
*cp
,
182 boolean
aos_fetch_inputs( struct aos_compilation
*cp
,
185 boolean
aos_emit_outputs( struct aos_compilation
*cp
);
188 #define IMM_ONES 0 /* 1, 1,1,1 */
189 #define IMM_SWZ 1 /* 1,-1,0, 0xffffffff */
190 #define IMM_IDENTITY 2 /* 0, 0,0,1 */
191 #define IMM_INV_255 3 /* 1/255, 1/255, 1/255, 1/255 */
192 #define IMM_255 4 /* 255, 255, 255, 255 */
193 #define IMM_NEGS 5 /* -1,-1,-1,-1 */
194 #define IMM_RSQ 6 /* -.5,1.5,_,_ */
195 #define IMM_PSIZE 7 /* not really an immediate - updated each run */
197 struct x86_reg
aos_get_internal( struct aos_compilation
*cp
,
199 struct x86_reg
aos_get_internal_xmm( struct aos_compilation
*cp
,
203 #define ERROR(cp, msg) \
205 if (0) debug_printf("%s: x86 translation failed: %s\n", __FUNCTION__, msg); \
211 #define X86_IMMEDIATES 1
212 #define X86_CONSTANTS 2
213 #define X86_ATTRIBS 3
215 struct x86_reg
aos_get_x86( struct aos_compilation
*cp
,
220 typedef void (PIPE_CDECL
*vaos_run_elts_func
)( struct aos_machine
*,
221 const unsigned *elts
,
223 void *output_buffer
);
225 typedef void (PIPE_CDECL
*vaos_run_linear_func
)( struct aos_machine
*,
228 void *output_buffer
);
231 struct draw_vs_varient_aos_sse
{
232 struct draw_vs_varient base
;
233 struct draw_context
*draw
;
235 struct aos_attrib
*attrib
;
237 vaos_run_linear_func gen_run_linear
;
238 vaos_run_elts_func gen_run_elts
;
241 struct x86_function func
[2];