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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
|
/**************************************************************************
*
* 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.
*
**************************************************************************/
#include "pipe/p_util.h"
#include "pipe/p_shader_tokens.h"
#include "tgsi/util/tgsi_parse.h"
#include "tgsi/util/tgsi_util.h"
#include "tgsi/exec/tgsi_exec.h"
#include "draw_vs.h"
#include "draw_vs_aos.h"
#include "draw_vertex.h"
#include "rtasm/rtasm_x86sse.h"
#ifdef PIPE_ARCH_X86
/* Note - don't yet have to worry about interacting with the code in
* draw_vs_aos.c as there is no intermingling of generated code...
* That may have to change, we'll see.
*/
static void emit_load_R32G32B32A32( struct aos_compilation *cp,
struct x86_reg data,
struct x86_reg src_ptr )
{
sse_movups(cp->func, data, src_ptr);
}
static void emit_load_R32G32B32( struct aos_compilation *cp,
struct x86_reg data,
struct x86_reg src_ptr )
{
sse_movss(cp->func, data, x86_make_disp(src_ptr, 8));
sse_shufps(cp->func, data, aos_get_internal_xmm( cp, IMM_IDENTITY ), SHUF(X,Y,Z,W) );
sse_shufps(cp->func, data, data, SHUF(Y,Z,X,W) );
sse_movlps(cp->func, data, src_ptr);
}
static void emit_load_R32G32( struct aos_compilation *cp,
struct x86_reg data,
struct x86_reg src_ptr )
{
sse_movups(cp->func, data, aos_get_internal_xmm( cp, IMM_IDENTITY ) );
sse_movlps(cp->func, data, src_ptr);
}
static void emit_load_R32( struct aos_compilation *cp,
struct x86_reg data,
struct x86_reg src_ptr )
{
sse_movss(cp->func, data, src_ptr);
sse_orps(cp->func, data, aos_get_internal_xmm( cp, IMM_IDENTITY ) );
}
static void emit_load_R8G8B8A8_UNORM( struct aos_compilation *cp,
struct x86_reg data,
struct x86_reg src_ptr )
{
sse_movss(cp->func, data, src_ptr);
sse2_punpcklbw(cp->func, data, aos_get_internal_xmm( cp, IMM_IDENTITY ));
sse2_punpcklbw(cp->func, data, aos_get_internal_xmm( cp, IMM_IDENTITY ));
sse2_cvtdq2ps(cp->func, data, data);
sse_mulps(cp->func, data, aos_get_internal(cp, IMM_INV_255));
}
static void get_src_ptr( struct aos_compilation *cp,
struct x86_reg src,
struct x86_reg elt,
unsigned a )
{
struct x86_reg attrib = x86_make_disp(aos_get_x86( cp, 0, X86_ATTRIBS ),
a * sizeof(struct aos_attrib));
struct x86_reg input_ptr = x86_make_disp(attrib,
Offset(struct aos_attrib, input_ptr));
struct x86_reg input_stride = x86_make_disp(attrib,
Offset(struct aos_attrib, input_stride));
/* Calculate pointer to current attrib:
*/
x86_mov(cp->func, src, input_stride);
x86_imul(cp->func, src, elt);
x86_add(cp->func, src, input_ptr);
}
/* Extended swizzles? Maybe later.
*/
static void emit_swizzle( struct aos_compilation *cp,
struct x86_reg dest,
struct x86_reg src,
ubyte shuffle )
{
sse_shufps(cp->func, dest, src, shuffle);
}
static boolean load_input( struct aos_compilation *cp,
unsigned idx,
boolean linear )
{
unsigned format = cp->vaos->base.key.element[idx].in.format;
struct x86_reg src = cp->tmp_EAX;
struct x86_reg dataXMM = aos_get_xmm_reg(cp);
/* Figure out source pointer address:
*/
get_src_ptr(cp,
src,
linear ? cp->idx_EBX : x86_deref(cp->idx_EBX),
idx);
src = x86_deref(src);
aos_adopt_xmm_reg( cp,
dataXMM,
TGSI_FILE_INPUT,
idx,
TRUE );
switch (format) {
case PIPE_FORMAT_R32_FLOAT:
emit_load_R32(cp, dataXMM, src);
break;
case PIPE_FORMAT_R32G32_FLOAT:
emit_load_R32G32(cp, dataXMM, src);
break;
case PIPE_FORMAT_R32G32B32_FLOAT:
emit_load_R32G32B32(cp, dataXMM, src);
break;
case PIPE_FORMAT_R32G32B32A32_FLOAT:
emit_load_R32G32B32A32(cp, dataXMM, src);
break;
case PIPE_FORMAT_B8G8R8A8_UNORM:
emit_load_R8G8B8A8_UNORM(cp, dataXMM, src);
emit_swizzle(cp, dataXMM, dataXMM, SHUF(Z,Y,X,W));
break;
case PIPE_FORMAT_R8G8B8A8_UNORM:
emit_load_R8G8B8A8_UNORM(cp, dataXMM, src);
break;
default:
ERROR(cp, "unhandled input format");
return FALSE;
}
return TRUE;
}
boolean aos_fetch_inputs( struct aos_compilation *cp, boolean linear )
{
unsigned i;
for (i = 0; i < cp->vaos->base.key.nr_inputs; i++) {
if (!load_input( cp, i, linear ))
return FALSE;
cp->insn_counter++;
debug_printf("\n");
}
return TRUE;
}
static void emit_store_R32G32B32A32( struct aos_compilation *cp,
struct x86_reg dst_ptr,
struct x86_reg dataXMM )
{
sse_movups(cp->func, dst_ptr, dataXMM);
}
static void emit_store_R32G32B32( struct aos_compilation *cp,
struct x86_reg dst_ptr,
struct x86_reg dataXMM )
{
sse_movlps(cp->func, dst_ptr, dataXMM);
sse_shufps(cp->func, dataXMM, dataXMM, SHUF(Z,Z,Z,Z) ); /* NOTE! destructive */
sse_movss(cp->func, x86_make_disp(dst_ptr,8), dataXMM);
}
static void emit_store_R32G32( struct aos_compilation *cp,
struct x86_reg dst_ptr,
struct x86_reg dataXMM )
{
sse_movlps(cp->func, dst_ptr, dataXMM);
}
static void emit_store_R32( struct aos_compilation *cp,
struct x86_reg dst_ptr,
struct x86_reg dataXMM )
{
sse_movss(cp->func, dst_ptr, dataXMM);
}
static void emit_store_R8G8B8A8_UNORM( struct aos_compilation *cp,
struct x86_reg dst_ptr,
struct x86_reg dataXMM )
{
sse_mulps(cp->func, dataXMM, aos_get_internal(cp, IMM_255));
sse2_cvtps2dq(cp->func, dataXMM, dataXMM);
sse2_packssdw(cp->func, dataXMM, dataXMM);
sse2_packuswb(cp->func, dataXMM, dataXMM);
sse_movss(cp->func, dst_ptr, dataXMM);
}
static boolean emit_output( struct aos_compilation *cp,
struct x86_reg ptr,
struct x86_reg dataXMM,
unsigned format )
{
switch (format) {
case EMIT_1F:
case EMIT_1F_PSIZE:
emit_store_R32(cp, ptr, dataXMM);
break;
case EMIT_2F:
emit_store_R32G32(cp, ptr, dataXMM);
break;
case EMIT_3F:
emit_store_R32G32B32(cp, ptr, dataXMM);
break;
case EMIT_4F:
emit_store_R32G32B32A32(cp, ptr, dataXMM);
break;
case EMIT_4UB:
if (1) {
emit_swizzle(cp, dataXMM, dataXMM, SHUF(Z,Y,X,W));
emit_store_R8G8B8A8_UNORM(cp, ptr, dataXMM);
}
else {
emit_store_R8G8B8A8_UNORM(cp, ptr, dataXMM);
}
break;
default:
ERROR(cp, "unhandled output format");
return FALSE;
}
return TRUE;
}
boolean aos_emit_outputs( struct aos_compilation *cp )
{
unsigned i;
for (i = 0; i < cp->vaos->base.key.nr_outputs; i++) {
unsigned format = cp->vaos->base.key.element[i].out.format;
unsigned offset = cp->vaos->base.key.element[i].out.offset;
unsigned vs_output = cp->vaos->base.key.element[i].out.vs_output;
struct x86_reg data;
if (format == EMIT_1F_PSIZE) {
data = aos_get_internal_xmm( cp, IMM_PSIZE );
}
else {
data = aos_get_shader_reg( cp,
TGSI_FILE_OUTPUT,
vs_output );
}
if (data.file != file_XMM) {
struct x86_reg tmp = aos_get_xmm_reg( cp );
sse_movups(cp->func, tmp, data);
data = tmp;
}
if (!emit_output( cp,
x86_make_disp( cp->outbuf_ECX, offset ),
data,
format ))
return FALSE;
aos_release_xmm_reg( cp, data.idx );
cp->insn_counter++;
debug_printf("\n");
}
return TRUE;
}
#endif
|