brw_sf_state.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_state.h"
00035 #include "brw_defines.h"
00036 #include "util/u_math.h"
00037 #include "util/u_memory.h"
00038 
00039 
00040 static void upload_sf_vp(struct brw_context *brw)
00041 {
00042    struct brw_sf_viewport sfv;
00043 
00044    memset(&sfv, 0, sizeof(sfv));
00045 
00046 
00047    /* BRW_NEW_VIEWPORT */
00048    {
00049       const float *scale = brw->attribs.Viewport.scale;
00050       const float *trans = brw->attribs.Viewport.translate;
00051 
00052       sfv.viewport.m00 = scale[0];
00053       sfv.viewport.m11 = scale[1];
00054       sfv.viewport.m22 = scale[2]; 
00055       sfv.viewport.m30 = trans[0];
00056       sfv.viewport.m31 = trans[1];
00057       sfv.viewport.m32 = trans[2];
00058    }
00059 
00060    /* _NEW_SCISSOR */
00061    sfv.scissor.xmin = brw->attribs.Scissor.minx;
00062    sfv.scissor.xmax = brw->attribs.Scissor.maxx - 1;
00063    sfv.scissor.ymin = brw->attribs.Scissor.miny;
00064    sfv.scissor.ymax = brw->attribs.Scissor.maxy - 1;
00065 
00066    brw->sf.vp_gs_offset = brw_cache_data( &brw->cache[BRW_SF_VP], &sfv );
00067 }
00068 
00069 const struct brw_tracked_state brw_sf_vp = {
00070    .dirty = {
00071       .brw   = (BRW_NEW_SCISSOR |
00072                 BRW_NEW_VIEWPORT),
00073       .cache = 0
00074    },
00075    .update = upload_sf_vp
00076 };
00077 
00078 static void upload_sf_unit( struct brw_context *brw )
00079 {
00080    struct brw_sf_unit_state sf;
00081    memset(&sf, 0, sizeof(sf));
00082 
00083    /* CACHE_NEW_SF_PROG */
00084    sf.thread0.grf_reg_count = align(brw->sf.prog_data->total_grf, 16) / 16 - 1;
00085    sf.thread0.kernel_start_pointer = brw->sf.prog_gs_offset >> 6;
00086    sf.thread3.urb_entry_read_length = brw->sf.prog_data->urb_read_length;
00087 
00088    sf.thread1.floating_point_mode = BRW_FLOATING_POINT_NON_IEEE_754;
00089    sf.thread3.dispatch_grf_start_reg = 3;
00090    sf.thread3.urb_entry_read_offset = 1;
00091 
00092    /* BRW_NEW_URB_FENCE */
00093    sf.thread4.nr_urb_entries = brw->urb.nr_sf_entries;
00094    sf.thread4.urb_entry_allocation_size = brw->urb.sfsize - 1;
00095    sf.thread4.max_threads = MIN2(12, brw->urb.nr_sf_entries / 2) - 1;
00096 
00097    if (BRW_DEBUG & DEBUG_SINGLE_THREAD)
00098       sf.thread4.max_threads = 0;
00099 
00100    if (BRW_DEBUG & DEBUG_STATS)
00101       sf.thread4.stats_enable = 1;
00102 
00103    /* CACHE_NEW_SF_VP */
00104    sf.sf5.sf_viewport_state_offset = brw->sf.vp_gs_offset >> 5;
00105    sf.sf5.viewport_transform = 1;
00106 
00107    /* BRW_NEW_RASTER */
00108    if (brw->attribs.Raster->scissor)
00109       sf.sf6.scissor = 1;
00110 
00111 #if 0
00112    if (brw->attribs.Polygon->FrontFace == GL_CCW)
00113       sf.sf5.front_winding = BRW_FRONTWINDING_CCW;
00114    else
00115       sf.sf5.front_winding = BRW_FRONTWINDING_CW;
00116 
00117 
00118    if (brw->attribs.Polygon->CullFlag) {
00119       switch (brw->attribs.Polygon->CullFaceMode) {
00120       case GL_FRONT:
00121          sf.sf6.cull_mode = BRW_CULLMODE_FRONT;
00122          break;
00123       case GL_BACK:
00124          sf.sf6.cull_mode = BRW_CULLMODE_BACK;
00125          break;
00126       case GL_FRONT_AND_BACK:
00127          sf.sf6.cull_mode = BRW_CULLMODE_BOTH;
00128          break;
00129       default:
00130          assert(0);
00131          break;
00132       }
00133    }
00134    else
00135       sf.sf6.cull_mode = BRW_CULLMODE_NONE;
00136 #else
00137    sf.sf5.front_winding = BRW_FRONTWINDING_CCW;
00138    sf.sf6.cull_mode = BRW_CULLMODE_NONE;
00139 #endif
00140 
00141    sf.sf6.line_width = CLAMP(brw->attribs.Raster->line_width, 1.0, 5.0) * (1<<1);
00142 
00143    sf.sf6.line_endcap_aa_region_width = 1;
00144    if (brw->attribs.Raster->line_smooth)
00145       sf.sf6.aa_enable = 1;
00146    else if (sf.sf6.line_width <= 0x2)
00147        sf.sf6.line_width = 0;
00148 
00149    sf.sf6.point_rast_rule = 1;  /* opengl conventions */
00150 
00151    sf.sf7.sprite_point = brw->attribs.Raster->point_sprite;
00152    sf.sf7.point_size = CLAMP(brw->attribs.Raster->line_width, 1.0, 255.0) * (1<<3);
00153    sf.sf7.use_point_size_state = !brw->attribs.Raster->point_size_per_vertex;
00154 
00155    /* might be BRW_NEW_PRIMITIVE if we have to adjust pv for polygons:
00156     */
00157    sf.sf7.trifan_pv = 2;
00158    sf.sf7.linestrip_pv = 1;
00159    sf.sf7.tristrip_pv = 2;
00160    sf.sf7.line_last_pixel_enable = 0;
00161 
00162    /* Set bias for OpenGL rasterization rules:
00163     */
00164    sf.sf6.dest_org_vbias = 0x8;
00165    sf.sf6.dest_org_hbias = 0x8;
00166 
00167    brw->sf.state_gs_offset = brw_cache_data( &brw->cache[BRW_SF_UNIT], &sf );
00168 }
00169 
00170 
00171 const struct brw_tracked_state brw_sf_unit = {
00172    .dirty = {
00173       .brw   = (BRW_NEW_RASTERIZER |
00174                 BRW_NEW_URB_FENCE),
00175       .cache = (CACHE_NEW_SF_VP |
00176                 CACHE_NEW_SF_PROG)
00177    },
00178    .update = upload_sf_unit
00179 };
00180 
00181 

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