softpipe: rename some functions to disambiguate
[mesa.git] / src / gallium / drivers / softpipe / sp_fs_sse.c
1 /**************************************************************************
2 *
3 * Copyright 2007 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:
13 *
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.
17 *
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.
25 *
26 **************************************************************************/
27
28
29 #include "sp_context.h"
30 #include "sp_state.h"
31 #include "sp_fs.h"
32 #include "sp_headers.h"
33
34
35 #include "pipe/p_state.h"
36 #include "pipe/p_defines.h"
37 #include "pipe/p_util.h"
38 #include "pipe/p_inlines.h"
39 #include "tgsi/exec/tgsi_exec.h"
40 #include "tgsi/exec/tgsi_sse2.h"
41
42
43 #if defined(__i386__) || defined(__386__)
44
45 #include "x86/rtasm/x86sse.h"
46
47 /* Surely this should be defined somewhere in a tgsi header:
48 */
49 typedef void (XSTDCALL *codegen_function)(
50 const struct tgsi_exec_vector *input,
51 struct tgsi_exec_vector *output,
52 float (*constant)[4],
53 struct tgsi_exec_vector *temporary,
54 const struct tgsi_interp_coef *coef
55 //, const struct tgsi_exec_vector *quadPos
56 );
57
58
59 struct sp_sse_fragment_shader {
60 struct sp_fragment_shader base;
61 struct x86_function sse2_program;
62 codegen_function func;
63 };
64
65
66 /**
67 * Compute quad X,Y,Z,W for the four fragments in a quad.
68 *
69 * This should really be part of the compiled shader.
70 */
71 void
72 sp_setup_pos_vector(const struct tgsi_interp_coef *coef,
73 float x, float y,
74 struct tgsi_exec_vector *quadpos)
75 {
76 uint chan;
77 /* do X */
78 quadpos->xyzw[0].f[0] = x;
79 quadpos->xyzw[0].f[1] = x + 1;
80 quadpos->xyzw[0].f[2] = x;
81 quadpos->xyzw[0].f[3] = x + 1;
82
83 /* do Y */
84 quadpos->xyzw[1].f[0] = y;
85 quadpos->xyzw[1].f[1] = y;
86 quadpos->xyzw[1].f[2] = y + 1;
87 quadpos->xyzw[1].f[3] = y + 1;
88
89 /* do Z and W for all fragments in the quad */
90 for (chan = 2; chan < 4; chan++) {
91 const float dadx = coef->dadx[chan];
92 const float dady = coef->dady[chan];
93 const float a0 = coef->a0[chan] + dadx * x + dady * y;
94 quadpos->xyzw[chan].f[0] = a0;
95 quadpos->xyzw[chan].f[1] = a0 + dadx;
96 quadpos->xyzw[chan].f[2] = a0 + dady;
97 quadpos->xyzw[chan].f[3] = a0 + dadx + dady;
98 }
99 }
100
101
102 static void
103 fs_sse_prepare( struct sp_fragment_shader *base,
104 struct tgsi_exec_machine *machine,
105 struct tgsi_sampler *samplers )
106 {
107 }
108
109
110 /* TODO: codegenerate the whole run function, skip this wrapper.
111 * TODO: break dependency on tgsi_exec_machine struct
112 * TODO: push Position calculation into the generated shader
113 * TODO: process >1 quad at a time
114 */
115 static unsigned
116 fs_sse_run( struct sp_fragment_shader *base,
117 struct tgsi_exec_machine *machine,
118 struct quad_header *quad )
119 {
120 struct sp_sse_fragment_shader *shader = (struct sp_sse_fragment_shader *) base;
121
122 /* Compute X, Y, Z, W vals for this quad -- place in temp[0] for now */
123 sp_setup_pos_vector(quad->posCoef,
124 (float)quad->x0, (float)quad->y0,
125 machine->Temps);
126
127 shader->func( machine->Inputs,
128 machine->Outputs,
129 machine->Consts,
130 machine->Temps,
131 machine->InterpCoefs
132 // , &machine->QuadPos
133 );
134
135 return ~(machine->Temps[TGSI_EXEC_TEMP_KILMASK_I].xyzw[TGSI_EXEC_TEMP_KILMASK_C].u[0]);
136 }
137
138
139 static void
140 fs_sse_delete( struct sp_fragment_shader *base )
141 {
142 struct sp_sse_fragment_shader *shader = (struct sp_sse_fragment_shader *) base;
143
144 x86_release_func( &shader->sse2_program );
145 FREE(shader);
146 }
147
148
149 struct sp_fragment_shader *
150 softpipe_create_fs_sse(struct softpipe_context *softpipe,
151 const struct pipe_shader_state *templ)
152 {
153 struct sp_sse_fragment_shader *shader;
154
155 if (!softpipe->use_sse)
156 return NULL;
157
158 shader = CALLOC_STRUCT(sp_sse_fragment_shader);
159 if (!shader)
160 return NULL;
161
162 x86_init_func( &shader->sse2_program );
163
164 if (!tgsi_emit_sse2_fs( templ->tokens, &shader->sse2_program )) {
165 FREE(shader);
166 return NULL;
167 }
168
169 shader->func = (codegen_function) x86_get_func( &shader->sse2_program );
170 assert(shader->func);
171
172 shader->base.shader = *templ;
173 shader->base.prepare = fs_sse_prepare;
174 shader->base.run = fs_sse_run;
175 shader->base.delete = fs_sse_delete;
176
177 return &shader->base;
178 }
179
180
181 #else
182
183 /* Maybe put this varient in the header file.
184 */
185 struct sp_fragment_shader *
186 softpipe_create_fs_sse(struct softpipe_context *softpipe,
187 const struct pipe_shader_state *templ)
188 {
189 return NULL;
190 }
191
192 #endif