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