revert 213 commits (to 56092) from the last month. 10 still need work to resolve...
[AROS.git] / workbench / libs / mesa / src / gallium / auxiliary / draw / draw_vs_ppc.c
blobb9aa9c00d9856df2c5208e356b5ab587401c7c95
1 /**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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
16 * of the Software.
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 **************************************************************************/
29 * Authors:
30 * Keith Whitwell <keith@tungstengraphics.com>
31 * Brian Paul
34 #include "util/u_math.h"
35 #include "util/u_memory.h"
36 #include "pipe/p_config.h"
38 #include "draw_vs.h"
40 #if defined(PIPE_ARCH_PPC)
42 #include "pipe/p_shader_tokens.h"
44 #include "draw_private.h"
45 #include "draw_context.h"
47 #include "rtasm/rtasm_cpu.h"
48 #include "rtasm/rtasm_ppc.h"
49 #include "tgsi/tgsi_ppc.h"
50 #include "tgsi/tgsi_parse.h"
51 #include "tgsi/tgsi_exec.h"
55 typedef void (PIPE_CDECL *codegen_function) (float (*inputs)[4][4],
56 float (*outputs)[4][4],
57 float (*temps)[4][4],
58 float (*immeds)[4],
59 float (*consts)[4],
60 const float *builtins);
63 struct draw_ppc_vertex_shader {
64 struct draw_vertex_shader base;
65 struct ppc_function ppc_program;
67 codegen_function func;
71 static void
72 vs_ppc_prepare( struct draw_vertex_shader *base,
73 struct draw_context *draw )
75 /* nothing */
79 /**
80 * Simplified vertex shader interface for the pt paths. Given the
81 * complexity of code-generating all the above operations together,
82 * it's time to try doing all the other stuff separately.
84 static void
85 vs_ppc_run_linear( struct draw_vertex_shader *base,
86 const float (*input)[4],
87 float (*output)[4],
88 const void *constants[PIPE_MAX_CONSTANT_BUFFERS],
89 const unsigned const_size[PIPE_MAX_CONSTANT_BUFFERS],
90 unsigned count,
91 unsigned input_stride,
92 unsigned output_stride )
94 struct draw_ppc_vertex_shader *shader = (struct draw_ppc_vertex_shader *)base;
95 unsigned int i;
97 #define MAX_VERTICES 4
99 /* loop over verts */
100 for (i = 0; i < count; i += MAX_VERTICES) {
101 const uint max_vertices = MIN2(MAX_VERTICES, count - i);
102 PIPE_ALIGN_VAR(16) float inputs_soa[PIPE_MAX_SHADER_INPUTS][4][4];
103 PIPE_ALIGN_VAR(16) float outputs_soa[PIPE_MAX_SHADER_OUTPUTS][4][4];
104 PIPE_ALIGN_VAR(16) float temps_soa[TGSI_EXEC_NUM_TEMPS][4][4];
105 uint attr;
107 /* convert (up to) four input verts to SoA format */
108 for (attr = 0; attr < base->info.num_inputs; attr++) {
109 const float *vIn = (const float *) input;
110 uint vert;
111 for (vert = 0; vert < max_vertices; vert++) {
112 #if 0
113 if (attr==0)
114 printf("Input v%d a%d: %f %f %f %f\n",
115 vert, attr, vIn[0], vIn[1], vIn[2], vIn[3]);
116 #endif
117 inputs_soa[attr][0][vert] = vIn[attr * 4 + 0];
118 inputs_soa[attr][1][vert] = vIn[attr * 4 + 1];
119 inputs_soa[attr][2][vert] = vIn[attr * 4 + 2];
120 inputs_soa[attr][3][vert] = vIn[attr * 4 + 3];
121 vIn += input_stride / 4;
125 /* run compiled shader
127 shader->func(inputs_soa, outputs_soa, temps_soa,
128 (float (*)[4]) shader->base.immediates,
129 (float (*)[4])constants[0],
130 ppc_builtin_constants);
132 /* convert (up to) four output verts from SoA back to AoS format */
133 for (attr = 0; attr < base->info.num_outputs; attr++) {
134 float *vOut = (float *) output;
135 uint vert;
136 for (vert = 0; vert < max_vertices; vert++) {
137 vOut[attr * 4 + 0] = outputs_soa[attr][0][vert];
138 vOut[attr * 4 + 1] = outputs_soa[attr][1][vert];
139 vOut[attr * 4 + 2] = outputs_soa[attr][2][vert];
140 vOut[attr * 4 + 3] = outputs_soa[attr][3][vert];
141 #if 0
142 if (attr==0)
143 printf("Output v%d a%d: %f %f %f %f\n",
144 vert, attr, vOut[0], vOut[1], vOut[2], vOut[3]);
145 #endif
146 vOut += output_stride / 4;
150 /* advance to next group of four input/output verts */
151 input = (const float (*)[4])((const char *)input + input_stride * max_vertices);
152 output = (float (*)[4])((char *)output + output_stride * max_vertices);
157 static void
158 vs_ppc_delete( struct draw_vertex_shader *base )
160 struct draw_ppc_vertex_shader *shader = (struct draw_ppc_vertex_shader *)base;
162 ppc_release_func( &shader->ppc_program );
164 align_free( (void *) shader->base.immediates );
166 FREE( (void*) shader->base.state.tokens );
167 FREE( shader );
171 struct draw_vertex_shader *
172 draw_create_vs_ppc(struct draw_context *draw,
173 const struct pipe_shader_state *templ)
175 struct draw_ppc_vertex_shader *vs;
177 vs = CALLOC_STRUCT( draw_ppc_vertex_shader );
178 if (vs == NULL)
179 return NULL;
181 /* we make a private copy of the tokens */
182 vs->base.state.tokens = tgsi_dup_tokens(templ->tokens);
183 if (!vs->base.state.tokens)
184 goto fail;
186 tgsi_scan_shader(templ->tokens, &vs->base.info);
188 vs->base.draw = draw;
189 #if 0
190 if (1)
191 vs->base.create_variant = draw_vs_variant_aos_ppc;
192 else
193 #endif
194 vs->base.create_variant = draw_vs_create_variant_generic;
195 vs->base.prepare = vs_ppc_prepare;
196 vs->base.run_linear = vs_ppc_run_linear;
197 vs->base.delete = vs_ppc_delete;
199 vs->base.immediates = align_malloc(TGSI_EXEC_NUM_IMMEDIATES * 4 *
200 sizeof(float), 16);
202 ppc_init_func( &vs->ppc_program );
204 #if 0
205 ppc_print_code(&vs->ppc_program, TRUE);
206 ppc_indent(&vs->ppc_program, 8);
207 #endif
209 if (!tgsi_emit_ppc( (struct tgsi_token *) vs->base.state.tokens,
210 &vs->ppc_program,
211 (float (*)[4]) vs->base.immediates,
212 TRUE ))
213 goto fail;
215 vs->func = (codegen_function) ppc_get_func( &vs->ppc_program );
216 if (!vs->func) {
217 goto fail;
220 return &vs->base;
222 fail:
224 debug_error("tgsi_emit_ppc() failed, falling back to interpreter\n");
227 ppc_release_func( &vs->ppc_program );
229 FREE(vs);
230 return NULL;
235 #else /* PIPE_ARCH_PPC */
238 struct draw_vertex_shader *
239 draw_create_vs_ppc( struct draw_context *draw,
240 const struct pipe_shader_state *templ )
242 return (void *) 0;
246 #endif /* PIPE_ARCH_PPC */