00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "sp_context.h"
00033 #include "sp_state.h"
00034 #include "sp_fs.h"
00035
00036
00037 #include "pipe/p_state.h"
00038 #include "pipe/p_defines.h"
00039 #include "util/u_memory.h"
00040 #include "pipe/p_inlines.h"
00041 #include "tgsi/tgsi_sse2.h"
00042
00043 #if 0
00044
00045 struct sp_llvm_fragment_shader {
00046 struct sp_fragment_shader base;
00047 struct gallivm_prog *llvm_prog;
00048 };
00049
00050 static void
00051 shade_quad_llvm(struct quad_stage *qs,
00052 struct quad_header *quad)
00053 {
00054 struct quad_shade_stage *qss = quad_shade_stage(qs);
00055 struct softpipe_context *softpipe = qs->softpipe;
00056 float dests[4][16][4] ALIGN16_ATTRIB;
00057 float inputs[4][16][4] ALIGN16_ATTRIB;
00058 const float fx = (float) quad->x0;
00059 const float fy = (float) quad->y0;
00060 struct gallivm_prog *llvm = qss->llvm_prog;
00061
00062 inputs[0][0][0] = fx;
00063 inputs[1][0][0] = fx + 1.0f;
00064 inputs[2][0][0] = fx;
00065 inputs[3][0][0] = fx + 1.0f;
00066
00067 inputs[0][0][1] = fy;
00068 inputs[1][0][1] = fy;
00069 inputs[2][0][1] = fy + 1.0f;
00070 inputs[3][0][1] = fy + 1.0f;
00071
00072
00073 gallivm_prog_inputs_interpolate(llvm, inputs, quad->coef);
00074
00075 #if DLLVM
00076 debug_printf("MASK = %d\n", quad->mask);
00077 for (int i = 0; i < 4; ++i) {
00078 for (int j = 0; j < 2; ++j) {
00079 debug_printf("IN(%d,%d) [%f %f %f %f]\n", i, j,
00080 inputs[i][j][0], inputs[i][j][1], inputs[i][j][2], inputs[i][j][3]);
00081 }
00082 }
00083 #endif
00084
00085 quad->mask &=
00086 gallivm_fragment_shader_exec(llvm, fx, fy, dests, inputs,
00087 softpipe->mapped_constants[PIPE_SHADER_FRAGMENT],
00088 qss->samplers);
00089 #if DLLVM
00090 debug_printf("OUT LLVM = 1[%f %f %f %f], 2[%f %f %f %f]\n",
00091 dests[0][0][0], dests[0][0][1], dests[0][0][2], dests[0][0][3],
00092 dests[0][1][0], dests[0][1][1], dests[0][1][2], dests[0][1][3]);
00093 #endif
00094
00095
00096 if (qss->colorOutSlot >= 0) {
00097 unsigned i;
00098
00099 allvmrt(qss->stage.softpipe->fs->info.output_semantic_name[qss->colorOutSlot]
00100 == TGSI_SEMANTIC_COLOR);
00101 for (i = 0; i < QUAD_SIZE; ++i) {
00102 quad->outputs.color[0][0][i] = dests[i][qss->colorOutSlot][0];
00103 quad->outputs.color[0][1][i] = dests[i][qss->colorOutSlot][1];
00104 quad->outputs.color[0][2][i] = dests[i][qss->colorOutSlot][2];
00105 quad->outputs.color[0][3][i] = dests[i][qss->colorOutSlot][3];
00106 }
00107 }
00108 #if DLLVM
00109 for (int i = 0; i < QUAD_SIZE; ++i) {
00110 debug_printf("QLLVM%d(%d) [%f, %f, %f, %f]\n", i, qss->colorOutSlot,
00111 quad->outputs.color[0][0][i],
00112 quad->outputs.color[0][1][i],
00113 quad->outputs.color[0][2][i],
00114 quad->outputs.color[0][3][i]);
00115 }
00116 #endif
00117
00118
00119 if (qss->depthOutSlot >= 0) {
00120
00121 uint i;
00122 for (i = 0; i < 4; i++) {
00123 quad->outputs.depth[i] = dests[i][0][2];
00124 }
00125 }
00126 else {
00127
00128 uint i;
00129 for (i = 0; i < 4; i++) {
00130 quad->outputs.depth[i] = inputs[i][0][2];
00131 }
00132 }
00133 #if DLLVM
00134 debug_printf("D [%f, %f, %f, %f] mask = %d\n",
00135 quad->outputs.depth[0],
00136 quad->outputs.depth[1],
00137 quad->outputs.depth[2],
00138 quad->outputs.depth[3], quad->mask);
00139 #endif
00140
00141
00142 if( quad->mask ) {
00143 qs->next->run( qs->next, quad );
00144 }
00145 }
00146
00147
00148 unsigned
00149 run_llvm_fs( const struct sp_fragment_shader *base,
00150 struct foo *machine )
00151 {
00152 }
00153
00154
00155 void
00156 delete_llvm_fs( struct sp_fragment_shader *base )
00157 {
00158 FREE(base);
00159 }
00160
00161
00162 struct sp_fragment_shader *
00163 softpipe_create_fs_llvm(struct softpipe_context *softpipe,
00164 const struct pipe_shader_state *templ)
00165 {
00166 struct sp_llvm_fragment_shader *shader = NULL;
00167
00168
00169
00170 state = CALLOC_STRUCT(sp_llvm_shader_state);
00171 if (!state)
00172 return NULL;
00173
00174 state->llvm_prog = 0;
00175
00176 if (!gallivm_global_cpu_engine()) {
00177 gallivm_cpu_engine_create(state->llvm_prog);
00178 }
00179 else
00180 gallivm_cpu_jit_compile(gallivm_global_cpu_engine(), state->llvm_prog);
00181
00182 if (shader) {
00183 shader->base.run = run_llvm_fs;
00184 shader->base.delete = delete_llvm_fs;
00185 }
00186
00187 return shader;
00188 }
00189
00190
00191 #else
00192
00193 struct sp_fragment_shader *
00194 softpipe_create_fs_llvm(struct softpipe_context *softpipe,
00195 const struct pipe_shader_state *templ)
00196 {
00197 return NULL;
00198 }
00199
00200 #endif