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 #include "brw_context.h"
00034 #include "brw_util.h"
00035 #include "brw_wm.h"
00036 #include "brw_eu.h"
00037 #include "brw_state.h"
00038 #include "util/u_memory.h"
00039
00040
00041
00042 static void do_wm_prog( struct brw_context *brw,
00043 struct brw_fragment_program *fp,
00044 struct brw_wm_prog_key *key)
00045 {
00046 struct brw_wm_compile *c = CALLOC_STRUCT(brw_wm_compile);
00047 const unsigned *program;
00048 unsigned program_size;
00049
00050 c->key = *key;
00051 c->fp = fp;
00052
00053 c->delta_xy[0] = brw_null_reg();
00054 c->delta_xy[1] = brw_null_reg();
00055 c->pixel_xy[0] = brw_null_reg();
00056 c->pixel_xy[1] = brw_null_reg();
00057 c->pixel_w = brw_null_reg();
00058
00059
00060 debug_printf("XXXXXXXX FP\n");
00061
00062 brw_wm_glsl_emit(c);
00063
00064
00065
00066 program = brw_get_program(&c->func, &program_size);
00067
00068
00069
00070 brw->wm.prog_gs_offset = brw_upload_cache( &brw->cache[BRW_WM_PROG],
00071 &c->key,
00072 sizeof(c->key),
00073 program,
00074 program_size,
00075 &c->prog_data,
00076 &brw->wm.prog_data );
00077
00078 FREE(c);
00079 }
00080
00081
00082
00083 static void brw_wm_populate_key( struct brw_context *brw,
00084 struct brw_wm_prog_key *key )
00085 {
00086
00087 struct brw_fragment_program *fp =
00088 (struct brw_fragment_program *)brw->attribs.FragmentProgram;
00089 unsigned lookup = 0;
00090 unsigned line_aa;
00091
00092 memset(key, 0, sizeof(*key));
00093
00094
00095
00096
00097 if (fp->info.uses_kill ||
00098 brw->attribs.DepthStencil->alpha.enabled)
00099 lookup |= IZ_PS_KILL_ALPHATEST_BIT;
00100
00101 if (fp->info.writes_z)
00102 lookup |= IZ_PS_COMPUTES_DEPTH_BIT;
00103
00104 if (brw->attribs.DepthStencil->depth.enabled)
00105 lookup |= IZ_DEPTH_TEST_ENABLE_BIT;
00106
00107 if (brw->attribs.DepthStencil->depth.enabled &&
00108 brw->attribs.DepthStencil->depth.writemask)
00109 lookup |= IZ_DEPTH_WRITE_ENABLE_BIT;
00110
00111 if (brw->attribs.DepthStencil->stencil[0].enabled) {
00112 lookup |= IZ_STENCIL_TEST_ENABLE_BIT;
00113
00114 if (brw->attribs.DepthStencil->stencil[0].write_mask ||
00115 brw->attribs.DepthStencil->stencil[1].write_mask)
00116 lookup |= IZ_STENCIL_WRITE_ENABLE_BIT;
00117 }
00118
00119
00120
00121 if (1)
00122 lookup |= IZ_EARLY_DEPTH_TEST_BIT;
00123
00124
00125 line_aa = AA_NEVER;
00126
00127
00128 if (brw->attribs.Raster->line_smooth) {
00129 if (brw->reduced_primitive == PIPE_PRIM_LINES) {
00130 line_aa = AA_ALWAYS;
00131 }
00132 else if (brw->reduced_primitive == PIPE_PRIM_TRIANGLES) {
00133 if (brw->attribs.Raster->fill_ccw == PIPE_POLYGON_MODE_LINE) {
00134 line_aa = AA_SOMETIMES;
00135
00136 if (brw->attribs.Raster->fill_cw == PIPE_POLYGON_MODE_LINE ||
00137 (brw->attribs.Raster->cull_mode == PIPE_WINDING_CW))
00138 line_aa = AA_ALWAYS;
00139 }
00140 else if (brw->attribs.Raster->fill_cw == PIPE_POLYGON_MODE_LINE) {
00141 line_aa = AA_SOMETIMES;
00142
00143 if (brw->attribs.Raster->cull_mode == PIPE_WINDING_CCW)
00144 line_aa = AA_ALWAYS;
00145 }
00146 }
00147 }
00148
00149 brw_wm_lookup_iz(line_aa,
00150 lookup,
00151 key);
00152
00153
00154 #if 0
00155
00156
00157
00158
00159 for (i = 0; i < BRW_MAX_TEX_UNIT; i++) {
00160 const struct pipe_sampler_state *unit = brw->attribs.Samplers[i];
00161
00162 if (unit) {
00163
00164 if (unit->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) {
00165 key->shadowtex_mask |= 1<<i;
00166 }
00167 if (t->Image[0][t->BaseLevel]->InternalFormat == GL_YCBCR_MESA)
00168 key->yuvtex_mask |= 1<<i;
00169 }
00170 }
00171 #endif
00172
00173
00174
00175
00176 key->program_string_id = fp->id;
00177
00178 }
00179
00180
00181 static void brw_upload_wm_prog( struct brw_context *brw )
00182 {
00183 struct brw_wm_prog_key key;
00184 struct brw_fragment_program *fp = (struct brw_fragment_program *)
00185 brw->attribs.FragmentProgram;
00186
00187 brw_wm_populate_key(brw, &key);
00188
00189
00190
00191 if (brw_search_cache(&brw->cache[BRW_WM_PROG],
00192 &key, sizeof(key),
00193 &brw->wm.prog_data,
00194 &brw->wm.prog_gs_offset))
00195 return;
00196
00197 do_wm_prog(brw, fp, &key);
00198 }
00199
00200
00201 const struct brw_tracked_state brw_wm_prog = {
00202 .dirty = {
00203 .brw = (BRW_NEW_FS |
00204 BRW_NEW_REDUCED_PRIMITIVE),
00205 .cache = 0
00206 },
00207 .update = brw_upload_wm_prog
00208 };
00209