brw_wm.c

Go to the documentation of this file.
00001 /*
00002  Copyright (C) Intel Corp.  2006.  All Rights Reserved.
00003  Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
00004  develop this 3D driver.
00005 
00006  Permission is hereby granted, free of charge, to any person obtaining
00007  a copy of this software and associated documentation files (the
00008  "Software"), to deal in the Software without restriction, including
00009  without limitation the rights to use, copy, modify, merge, publish,
00010  distribute, sublicense, and/or sell copies of the Software, and to
00011  permit persons to whom the Software is furnished to do so, subject to
00012  the following conditions:
00013 
00014  The above copyright notice and this permission notice (including the
00015  next paragraph) shall be included in all copies or substantial
00016  portions of the Software.
00017 
00018  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00019  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00021  IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
00022  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00023  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00024  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025 
00026  **********************************************************************/
00027  /*
00028   * Authors:
00029   *   Keith Whitwell <keith@tungstengraphics.com>
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    /* get the program
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    /* BRW_NEW_FRAGMENT_PROGRAM */
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    /* Build the index for table lookup
00095     */
00096    /* BRW_NEW_DEPTH_STENCIL */
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    /* XXX: when should this be disabled?
00120     */
00121    if (1)
00122       lookup |= IZ_EARLY_DEPTH_TEST_BIT;
00123 
00124 
00125    line_aa = AA_NEVER;
00126 
00127    /* _NEW_LINE, _NEW_POLYGON, BRW_NEW_REDUCED_PRIMITIVE */
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    /* BRW_NEW_SAMPLER 
00156     *
00157     * Not doing any of this at the moment:
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    /* Extra info:
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    /* Make an early check for the key.
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 

Generated on Tue Sep 29 06:25:17 2009 for Gallium3D by  doxygen 1.5.4