1 /**************************************************************************
3 * Copyright 2008 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 **************************************************************************/
30 * SPU functions accessed by shaders.
41 #include <simdmath/exp2f4.h>
42 #include <simdmath/log2f4.h>
43 #include <simdmath/powf4.h>
45 #include "cell/common.h"
47 #include "spu_funcs.h"
48 #include "spu_texture.h"
51 /** For "return"-ing four vectors */
59 spu_cos(vector float x)
65 spu_sin(vector float x)
71 spu_pow(vector float x, vector float y)
77 spu_exp2(vector float x)
83 spu_log2(vector float x)
90 spu_tex_2d(vector float s, vector float t, vector float r, vector float q,
93 struct vec_4x4 colors;
96 spu.sample_texture_2d[unit](s, t, unit, 0, 0, colors.v);
100 static struct vec_4x4
101 spu_tex_3d(vector float s, vector float t, vector float r, vector float q,
104 struct vec_4x4 colors;
107 spu.sample_texture_2d[unit](s, t, unit, 0, 0, colors.v);
111 static struct vec_4x4
112 spu_tex_cube(vector float s, vector float t, vector float r, vector float q,
115 struct vec_4x4 colors;
117 sample_texture_cube(s, t, r, unit, colors.v);
123 * Add named function to list of "exported" functions that will be
124 * made available to the PPU-hosted code generator.
127 export_func(struct cell_spu_function_info *spu_functions,
128 const char *name, void *addr)
130 uint n = spu_functions->num;
131 ASSERT(strlen(name) < 16);
132 strcpy(spu_functions->names[n], name);
133 spu_functions->addrs[n] = (uint) addr;
134 spu_functions->num++;
135 ASSERT(spu_functions->num <= 16);
140 * Return info about the SPU's function to the PPU / main memory.
141 * The PPU needs to know the address of some SPU-side functions so
142 * that we can generate shader code with function calls.
145 return_function_info(void)
147 PIPE_ALIGN_VAR(16) struct cell_spu_function_info funcs;
150 ASSERT(sizeof(funcs) == 256); /* must be multiple of 16 bytes */
153 export_func(&funcs, "spu_cos", &spu_cos);
154 export_func(&funcs, "spu_sin", &spu_sin);
155 export_func(&funcs, "spu_pow", &spu_pow);
156 export_func(&funcs, "spu_exp2", &spu_exp2);
157 export_func(&funcs, "spu_log2", &spu_log2);
158 export_func(&funcs, "spu_tex_2d", &spu_tex_2d);
159 export_func(&funcs, "spu_tex_3d", &spu_tex_3d);
160 export_func(&funcs, "spu_tex_cube", &spu_tex_cube);
162 /* Send the function info back to the PPU / main memory */
163 mfc_put((void *) &funcs, /* src in local store */
164 (unsigned int) spu.init.spu_functions, /* dst in main memory */
165 sizeof(funcs), /* bytes */
169 wait_on_mask(1 << tag);