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
00033
00034
00035
00036
00037
00038 #include "util/u_math.h"
00039 #include "util/u_memory.h"
00040 #include "pipe/p_defines.h"
00041 #include "pipe/p_shader_tokens.h"
00042
00043 #include "sp_context.h"
00044 #include "sp_state.h"
00045 #include "sp_headers.h"
00046 #include "sp_quad.h"
00047 #include "sp_texture.h"
00048 #include "sp_tex_sample.h"
00049
00050
00051 struct quad_shade_stage
00052 {
00053 struct quad_stage stage;
00054 struct tgsi_sampler samplers[PIPE_MAX_SAMPLERS];
00055 struct tgsi_exec_machine machine;
00056 struct tgsi_exec_vector *inputs, *outputs;
00057 };
00058
00059
00061 static INLINE struct quad_shade_stage *
00062 quad_shade_stage(struct quad_stage *qs)
00063 {
00064 return (struct quad_shade_stage *) qs;
00065 }
00066
00067
00068
00072 static void
00073 shade_quad(
00074 struct quad_stage *qs,
00075 struct quad_header *quad )
00076 {
00077 struct quad_shade_stage *qss = quad_shade_stage( qs );
00078 struct softpipe_context *softpipe = qs->softpipe;
00079 struct tgsi_exec_machine *machine = &qss->machine;
00080 boolean z_written;
00081
00082
00083 machine->Consts = softpipe->mapped_constants[PIPE_SHADER_FRAGMENT];
00084
00085 machine->InterpCoefs = quad->coef;
00086
00087
00088 quad->inout.mask &= softpipe->fs->run( softpipe->fs,
00089 &qss->machine,
00090 quad );
00091
00092
00093 z_written = FALSE;
00094 {
00095 const ubyte *sem_name = softpipe->fs->info.output_semantic_name;
00096 const ubyte *sem_index = softpipe->fs->info.output_semantic_index;
00097 const uint n = qss->stage.softpipe->fs->info.num_outputs;
00098 uint i;
00099 for (i = 0; i < n; i++) {
00100 switch (sem_name[i]) {
00101 case TGSI_SEMANTIC_COLOR:
00102 {
00103 uint cbuf = sem_index[i];
00104 memcpy(quad->output.color[cbuf],
00105 &machine->Outputs[i].xyzw[0].f[0],
00106 sizeof(quad->output.color[0]) );
00107 }
00108 break;
00109 case TGSI_SEMANTIC_POSITION:
00110 {
00111 uint j;
00112 for (j = 0; j < 4; j++) {
00113 quad->output.depth[j] = machine->Outputs[0].xyzw[2].f[j];
00114 }
00115 z_written = TRUE;
00116 }
00117 break;
00118 }
00119 }
00120 }
00121
00122 if (!z_written) {
00123
00124
00125 const float fx = (float) quad->input.x0;
00126 const float fy = (float) quad->input.y0;
00127 const float dzdx = quad->posCoef->dadx[2];
00128 const float dzdy = quad->posCoef->dady[2];
00129 const float z0 = quad->posCoef->a0[2] + dzdx * fx + dzdy * fy;
00130
00131 quad->output.depth[0] = z0;
00132 quad->output.depth[1] = z0 + dzdx;
00133 quad->output.depth[2] = z0 + dzdy;
00134 quad->output.depth[3] = z0 + dzdx + dzdy;
00135 }
00136
00137
00138 if( quad->inout.mask ) {
00139 qs->next->run( qs->next, quad );
00140 }
00141 }
00142
00146 static void shade_begin(struct quad_stage *qs)
00147 {
00148 struct quad_shade_stage *qss = quad_shade_stage(qs);
00149 struct softpipe_context *softpipe = qs->softpipe;
00150 unsigned i;
00151 unsigned num = MAX2(softpipe->num_textures, softpipe->num_samplers);
00152
00153
00154 for (i = 0; i < num; i++) {
00155 qss->samplers[i].state = softpipe->sampler[i];
00156 qss->samplers[i].texture = softpipe->texture[i];
00157 }
00158
00159 softpipe->fs->prepare( softpipe->fs,
00160 &qss->machine,
00161 qss->samplers );
00162
00163 qs->next->begin(qs->next);
00164 }
00165
00166
00167 static void shade_destroy(struct quad_stage *qs)
00168 {
00169 struct quad_shade_stage *qss = (struct quad_shade_stage *) qs;
00170
00171 tgsi_exec_machine_free_data(&qss->machine);
00172 FREE( qss->inputs );
00173 FREE( qss->outputs );
00174 FREE( qs );
00175 }
00176
00177
00178 struct quad_stage *sp_quad_shade_stage( struct softpipe_context *softpipe )
00179 {
00180 struct quad_shade_stage *qss = CALLOC_STRUCT(quad_shade_stage);
00181 uint i;
00182
00183
00184 qss->inputs = MALLOC(PIPE_MAX_ATTRIBS * sizeof(*qss->inputs) + 16);
00185 qss->outputs = MALLOC(PIPE_MAX_ATTRIBS * sizeof(*qss->outputs) + 16);
00186 qss->machine.Inputs = align16(qss->inputs);
00187 qss->machine.Outputs = align16(qss->outputs);
00188
00189 qss->stage.softpipe = softpipe;
00190 qss->stage.begin = shade_begin;
00191 qss->stage.run = shade_quad;
00192 qss->stage.destroy = shade_destroy;
00193
00194
00195 for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
00196 assert(softpipe->tex_cache[i]);
00197 qss->samplers[i].get_samples = sp_get_samples;
00198 qss->samplers[i].pipe = &softpipe->pipe;
00199 qss->samplers[i].cache = softpipe->tex_cache[i];
00200 }
00201
00202 tgsi_exec_machine_init( &qss->machine );
00203
00204 return &qss->stage;
00205 }