summaryrefslogtreecommitdiff
path: root/src/gallium/auxiliary/draw/draw_vs_aos.h
blob: f6f6af2dd907be914f3406d0d28d0e091f0b0af3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/**************************************************************************
 * 
 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sub license, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * 
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 * 
 **************************************************************************/

/* Authors:  Keith Whitwell <keith@tungstengraphics.com>
 */

#ifndef DRAW_VS_AOS_H
#define DRAW_VS_AOS_H

#include "pipe/p_config.h"

#ifdef PIPE_ARCH_X86

struct tgsi_token;
struct x86_function;

#include "pipe/p_state.h"
#include "rtasm/rtasm_x86sse.h"





#define X    0
#define Y    1
#define Z    2
#define W    3

#define MAX_INPUTS     PIPE_MAX_ATTRIBS
#define MAX_OUTPUTS    PIPE_MAX_ATTRIBS
#define MAX_TEMPS      PIPE_MAX_ATTRIBS /* say */
#define MAX_CONSTANTS  PIPE_MAX_ATTRIBS /* say */
#define MAX_IMMEDIATES PIPE_MAX_ATTRIBS /* say */
#define MAX_INTERNALS  8

#define AOS_FILE_INTERNAL TGSI_FILE_COUNT

#define FPU_RND_NEG    1
#define FPU_RND_NEAREST 2

struct aos_machine;
typedef void (PIPE_CDECL *lit_func)( struct aos_machine *,
                                    float *result,
                                    const float *in,
                                    unsigned count );

void PIPE_CDECL aos_do_lit( struct aos_machine *machine,
                            float *result,
                            const float *in,
                            unsigned count );

struct shine_tab {
   float exponent;
   float values[258];
   unsigned last_used;
};

struct lit_info {
   lit_func func;
   struct shine_tab *shine_tab;
};

#define MAX_SHINE_TAB    4
#define MAX_LIT_INFO     16

struct aos_attrib {
   const void *input_ptr;
   unsigned input_stride;
};




/* This is the temporary storage used by all the aos_sse vs varients.
 * Create one per context and reuse by passing a pointer in at
 * vs_varient creation??
 */
struct aos_machine {
   float input    [MAX_INPUTS    ][4];
   float output   [MAX_OUTPUTS   ][4];
   float temp     [MAX_TEMPS     ][4];
   float internal [MAX_INTERNALS ][4];

   float scale[4];              /* viewport */
   float translate[4];          /* viewport */

   float tmp[2][4];             /* scratch space for LIT */

   struct shine_tab shine_tab[MAX_SHINE_TAB];
   struct lit_info  lit_info[MAX_LIT_INFO];
   unsigned now;
   

   ushort fpu_rnd_nearest;
   ushort fpu_rnd_neg_inf;
   ushort fpu_restore;
   ushort fpucntl;              /* one of FPU_* above */

   const float (*immediates)[4];     /* points to shader data */
   const float (*constants)[4];      /* points to draw data */

   const struct aos_attrib *attrib; /* points to ? */
};




struct aos_compilation {
   struct x86_function *func;
   struct draw_vs_varient_aos_sse *vaos;

   unsigned insn_counter;
   unsigned num_immediates;
   unsigned count;
   unsigned lit_count;

   struct {
      unsigned idx:16;
      unsigned file:8;
      unsigned dirty:8;
      unsigned last_used;
   } xmm[8];

   unsigned ebp;                /* one of X86_* */

   boolean input_fetched[PIPE_MAX_ATTRIBS];
   unsigned output_last_write[PIPE_MAX_ATTRIBS];

   boolean have_sse2;
   boolean error;
   short fpucntl;

   /* these are actually known values, but putting them in a struct
    * like this is helpful to keep them in sync across the file.
    */
   struct x86_reg tmp_EAX;
   struct x86_reg idx_EBX;     /* either start+i or &elt[i] */
   struct x86_reg outbuf_ECX;
   struct x86_reg machine_EDX;
   struct x86_reg count_ESI;    /* decrements to zero */
   struct x86_reg temp_EBP;
   struct x86_reg stack_ESP;
};

struct x86_reg aos_get_xmm_reg( struct aos_compilation *cp );
void aos_release_xmm_reg( struct aos_compilation *cp, unsigned idx );

void aos_adopt_xmm_reg( struct aos_compilation *cp,
                        struct x86_reg reg,
                        unsigned file,
                        unsigned idx,
                        unsigned dirty );

struct x86_reg aos_get_shader_reg( struct aos_compilation *cp, 
                                   unsigned file,
                                   unsigned idx );

boolean aos_fetch_inputs( struct aos_compilation *cp,
                          boolean linear );

boolean aos_emit_outputs( struct aos_compilation *cp );


#define IMM_ONES     0              /* 1, 1,1,1 */
#define IMM_SWZ      1              /* 1,-1,0, 0xffffffff */
#define IMM_IDENTITY 2              /* 0, 0,0,1 */
#define IMM_INV_255  3              /* 1/255, 1/255, 1/255, 1/255 */
#define IMM_255      4              /* 255, 255, 255, 255 */
#define IMM_NEGS     5              /* -1,-1,-1,-1 */
#define IMM_RSQ      6              /* -.5,1.5,_,_ */
#define IMM_PSIZE    7              /* not really an immediate - updated each run */

struct x86_reg aos_get_internal( struct aos_compilation *cp,
                                 unsigned imm );
struct x86_reg aos_get_internal_xmm( struct aos_compilation *cp,
                                     unsigned imm );


#define ERROR(cp, msg)                                                  \
do {                                                                    \
   debug_printf("%s: x86 translation failed: %s\n", __FUNCTION__, msg); \
   cp->error = 1;                                                       \
   assert(0);                                                           \
} while (0)


#define X86_NULL       0
#define X86_IMMEDIATES 1
#define X86_CONSTANTS  2
#define X86_ATTRIBS    3

struct x86_reg aos_get_x86( struct aos_compilation *cp,
                            unsigned value );


typedef void (PIPE_CDECL *vaos_run_elts_func)( struct aos_machine *,
                                               const unsigned *elts,
                                               unsigned count,
                                               void *output_buffer);

typedef void (PIPE_CDECL *vaos_run_linear_func)( struct aos_machine *,
                                                unsigned start,
                                                unsigned count,
                                                void *output_buffer);


struct draw_vs_varient_aos_sse {
   struct draw_vs_varient base;
   struct draw_context *draw;

   struct aos_attrib *attrib;

   vaos_run_linear_func gen_run_linear;
   vaos_run_elts_func gen_run_elts;


   struct x86_function func[2];
};


#endif

#endif