r300g: use $(MAKE) variable
[mesa.git] / src / gallium / drivers / softpipe / sp_fs_llvm.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 * Execute fragment shader using LLVM code generation.
30 * Authors:
31 * Zack Rusin
32 */
33
34 #include "sp_context.h"
35 #include "sp_state.h"
36 #include "sp_fs.h"
37
38 #include "pipe/p_state.h"
39 #include "pipe/p_defines.h"
40 #include "util/u_memory.h"
41 #include "tgsi/tgsi_sse2.h"
42
43 #if 0
44
45 /**
46 * Subclass of sp_fragment_shader
47 */
48 struct sp_llvm_fragment_shader
49 {
50 struct sp_fragment_shader base;
51 struct gallivm_prog *llvm_prog;
52 };
53
54
55 static void
56 shade_quad_llvm(struct quad_stage *qs,
57 struct quad_header *quad)
58 {
59 struct quad_shade_stage *qss = quad_shade_stage(qs);
60 struct softpipe_context *softpipe = qs->softpipe;
61 float dests[4][16][4] ALIGN16_ATTRIB;
62 float inputs[4][16][4] ALIGN16_ATTRIB;
63 const float fx = (float) quad->x0;
64 const float fy = (float) quad->y0;
65 struct gallivm_prog *llvm = qss->llvm_prog;
66
67 inputs[0][0][0] = fx;
68 inputs[1][0][0] = fx + 1.0f;
69 inputs[2][0][0] = fx;
70 inputs[3][0][0] = fx + 1.0f;
71
72 inputs[0][0][1] = fy;
73 inputs[1][0][1] = fy;
74 inputs[2][0][1] = fy + 1.0f;
75 inputs[3][0][1] = fy + 1.0f;
76
77
78 gallivm_prog_inputs_interpolate(llvm, inputs, quad->coef);
79
80 #if DLLVM
81 debug_printf("MASK = %d\n", quad->mask);
82 for (int i = 0; i < 4; ++i) {
83 for (int j = 0; j < 2; ++j) {
84 debug_printf("IN(%d,%d) [%f %f %f %f]\n", i, j,
85 inputs[i][j][0], inputs[i][j][1], inputs[i][j][2], inputs[i][j][3]);
86 }
87 }
88 #endif
89
90 quad->mask &=
91 gallivm_fragment_shader_exec(llvm, fx, fy, dests, inputs,
92 softpipe->mapped_constants[PIPE_SHADER_FRAGMENT],
93 qss->samplers);
94 #if DLLVM
95 debug_printf("OUT LLVM = 1[%f %f %f %f], 2[%f %f %f %f]\n",
96 dests[0][0][0], dests[0][0][1], dests[0][0][2], dests[0][0][3],
97 dests[0][1][0], dests[0][1][1], dests[0][1][2], dests[0][1][3]);
98 #endif
99
100 /* store result color */
101 if (qss->colorOutSlot >= 0) {
102 unsigned i;
103 /* XXX need to handle multiple color outputs someday */
104 allvmrt(qss->stage.softpipe->fs->info.output_semantic_name[qss->colorOutSlot]
105 == TGSI_SEMANTIC_COLOR);
106 for (i = 0; i < QUAD_SIZE; ++i) {
107 quad->outputs.color[0][0][i] = dests[i][qss->colorOutSlot][0];
108 quad->outputs.color[0][1][i] = dests[i][qss->colorOutSlot][1];
109 quad->outputs.color[0][2][i] = dests[i][qss->colorOutSlot][2];
110 quad->outputs.color[0][3][i] = dests[i][qss->colorOutSlot][3];
111 }
112 }
113 #if DLLVM
114 for (int i = 0; i < QUAD_SIZE; ++i) {
115 debug_printf("QLLVM%d(%d) [%f, %f, %f, %f]\n", i, qss->colorOutSlot,
116 quad->outputs.color[0][0][i],
117 quad->outputs.color[0][1][i],
118 quad->outputs.color[0][2][i],
119 quad->outputs.color[0][3][i]);
120 }
121 #endif
122
123 /* store result Z */
124 if (qss->depthOutSlot >= 0) {
125 /* output[slot] is new Z */
126 uint i;
127 for (i = 0; i < 4; i++) {
128 quad->outputs.depth[i] = dests[i][0][2];
129 }
130 }
131 else {
132 /* copy input Z (which was interpolated by the executor) to output Z */
133 uint i;
134 for (i = 0; i < 4; i++) {
135 quad->outputs.depth[i] = inputs[i][0][2];
136 }
137 }
138 #if DLLVM
139 debug_printf("D [%f, %f, %f, %f] mask = %d\n",
140 quad->outputs.depth[0],
141 quad->outputs.depth[1],
142 quad->outputs.depth[2],
143 quad->outputs.depth[3], quad->mask);
144 #endif
145
146 /* shader may cull fragments */
147 if( quad->mask ) {
148 qs->next->run( qs->next, quad );
149 }
150 }
151
152
153 unsigned
154 run_llvm_fs( const struct sp_fragment_shader *base,
155 struct foo *machine )
156 {
157 }
158
159
160 void
161 delete_llvm_fs( struct sp_fragment_shader *base )
162 {
163 FREE(base);
164 }
165
166
167 struct sp_fragment_shader *
168 softpipe_create_fs_llvm(struct softpipe_context *softpipe,
169 const struct pipe_shader_state *templ)
170 {
171 struct sp_llvm_fragment_shader *shader = NULL;
172
173 /* LLVM fragment shaders currently disabled:
174 */
175 state = CALLOC_STRUCT(sp_llvm_shader_state);
176 if (!state)
177 return NULL;
178
179 state->llvm_prog = 0;
180
181 if (!gallivm_global_cpu_engine()) {
182 gallivm_cpu_engine_create(state->llvm_prog);
183 }
184 else
185 gallivm_cpu_jit_compile(gallivm_global_cpu_engine(), state->llvm_prog);
186
187 if (shader) {
188 shader->base.run = run_llvm_fs;
189 shader->base.delete = delete_llvm_fs;
190 }
191
192 return shader;
193 }
194
195
196 #else
197
198 struct sp_fragment_shader *
199 softpipe_create_fs_llvm(struct softpipe_context *softpipe,
200 const struct pipe_shader_state *templ)
201 {
202 return NULL;
203 }
204
205 #endif