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>
38 #include "pipe/p_state.h"
39 #include "rtasm/rtasm_x86sse.h"
50 #define MAX_INPUTS PIPE_MAX_ATTRIBS
51 #define MAX_OUTPUTS PIPE_MAX_ATTRIBS
52 #define MAX_TEMPS PIPE_MAX_ATTRIBS /* say */
53 #define MAX_CONSTANTS PIPE_MAX_ATTRIBS /* say */
54 #define MAX_IMMEDIATES PIPE_MAX_ATTRIBS /* say */
55 #define MAX_INTERNALS 8
57 #define AOS_FILE_INTERNAL TGSI_FILE_COUNT
60 #define FPU_RND_NEAREST 2
63 typedef void (PIPE_CDECL
*lit_func
)( struct aos_machine
*,
68 void PIPE_CDECL
aos_do_lit( struct aos_machine
*machine
,
81 struct shine_tab
*shine_tab
;
84 #define MAX_SHINE_TAB 4
85 #define MAX_LIT_INFO 16
88 const void *input_ptr
;
89 unsigned input_stride
;
95 /* This is the temporary storage used by all the aos_sse vs varients.
96 * Create one per context and reuse by passing a pointer in at
97 * vs_varient creation??
100 float input
[MAX_INPUTS
][4];
101 float output
[MAX_OUTPUTS
][4];
102 float temp
[MAX_TEMPS
][4];
103 float internal
[MAX_INTERNALS
][4];
105 float scale
[4]; /* viewport */
106 float translate
[4]; /* viewport */
108 float tmp
[2][4]; /* scratch space for LIT */
110 struct shine_tab shine_tab
[MAX_SHINE_TAB
];
111 struct lit_info lit_info
[MAX_LIT_INFO
];
115 ushort fpu_rnd_nearest
;
116 ushort fpu_rnd_neg_inf
;
118 ushort fpucntl
; /* one of FPU_* above */
120 const float (*immediates
)[4]; /* points to shader data */
121 const float (*constants
)[4]; /* points to draw data */
123 const struct aos_attrib
*attrib
; /* points to ? */
129 struct aos_compilation
{
130 struct x86_function
*func
;
131 struct draw_vs_varient_aos_sse
*vaos
;
133 unsigned insn_counter
;
134 unsigned num_immediates
;
145 unsigned ebp
; /* one of X86_* */
147 boolean input_fetched
[PIPE_MAX_ATTRIBS
];
148 unsigned output_last_write
[PIPE_MAX_ATTRIBS
];
154 /* these are actually known values, but putting them in a struct
155 * like this is helpful to keep them in sync across the file.
157 struct x86_reg tmp_EAX
;
158 struct x86_reg idx_EBX
; /* either start+i or &elt[i] */
159 struct x86_reg outbuf_ECX
;
160 struct x86_reg machine_EDX
;
161 struct x86_reg count_ESI
; /* decrements to zero */
162 struct x86_reg temp_EBP
;
163 struct x86_reg stack_ESP
;
166 struct x86_reg
aos_get_xmm_reg( struct aos_compilation
*cp
);
167 void aos_release_xmm_reg( struct aos_compilation
*cp
, unsigned idx
);
169 void aos_adopt_xmm_reg( struct aos_compilation
*cp
,
175 struct x86_reg
aos_get_shader_reg( struct aos_compilation
*cp
,
179 boolean
aos_fetch_inputs( struct aos_compilation
*cp
,
182 boolean
aos_emit_outputs( struct aos_compilation
*cp
);
185 #define IMM_ONES 0 /* 1, 1,1,1 */
186 #define IMM_SWZ 1 /* 1,-1,0, 0xffffffff */
187 #define IMM_IDENTITY 2 /* 0, 0,0,1 */
188 #define IMM_INV_255 3 /* 1/255, 1/255, 1/255, 1/255 */
189 #define IMM_255 4 /* 255, 255, 255, 255 */
190 #define IMM_NEGS 5 /* -1,-1,-1,-1 */
191 #define IMM_RSQ 6 /* -.5,1.5,_,_ */
192 #define IMM_PSIZE 7 /* not really an immediate - updated each run */
194 struct x86_reg
aos_get_internal( struct aos_compilation
*cp
,
196 struct x86_reg
aos_get_internal_xmm( struct aos_compilation
*cp
,
200 #define ERROR(cp, msg) \
202 debug_printf("%s: x86 translation failed: %s\n", __FUNCTION__, msg); \
209 #define X86_IMMEDIATES 1
210 #define X86_CONSTANTS 2
211 #define X86_ATTRIBS 3
213 struct x86_reg
aos_get_x86( struct aos_compilation
*cp
,
217 typedef void (PIPE_CDECL
*vaos_run_elts_func
)( struct aos_machine
*,
218 const unsigned *elts
,
220 void *output_buffer
);
222 typedef void (PIPE_CDECL
*vaos_run_linear_func
)( struct aos_machine
*,
225 void *output_buffer
);
228 struct draw_vs_varient_aos_sse
{
229 struct draw_vs_varient base
;
230 struct draw_context
*draw
;
232 struct aos_attrib
*attrib
;
234 vaos_run_linear_func gen_run_linear
;
235 vaos_run_elts_func gen_run_elts
;
238 struct x86_function func
[2];