brw_wm_surface_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 #include "brw_context.h"
00033 #include "brw_state.h"
00034 #include "brw_defines.h"
00035 
00036 static unsigned translate_tex_target( enum pipe_texture_target target )
00037 {
00038    switch (target) {
00039    case PIPE_TEXTURE_1D:
00040       return BRW_SURFACE_1D;
00041 
00042    case PIPE_TEXTURE_2D:
00043       return BRW_SURFACE_2D;
00044 
00045    case PIPE_TEXTURE_3D:
00046       return BRW_SURFACE_3D;
00047 
00048    case PIPE_TEXTURE_CUBE:
00049       return BRW_SURFACE_CUBE;
00050 
00051    default:
00052       assert(0);
00053       return 0;
00054    }
00055 }
00056 
00057 static unsigned translate_tex_format( enum pipe_format pipe_format )
00058 {
00059    switch( pipe_format ) {
00060    case PIPE_FORMAT_L8_UNORM:
00061       return BRW_SURFACEFORMAT_L8_UNORM;
00062 
00063    case PIPE_FORMAT_I8_UNORM:
00064       return BRW_SURFACEFORMAT_I8_UNORM;
00065 
00066    case PIPE_FORMAT_A8_UNORM:
00067       return BRW_SURFACEFORMAT_A8_UNORM;
00068 
00069    case PIPE_FORMAT_A8L8_UNORM:
00070       return BRW_SURFACEFORMAT_L8A8_UNORM;
00071 
00072    case PIPE_FORMAT_R8G8B8_UNORM:
00073       assert(0);                /* not supported for sampling */
00074       return BRW_SURFACEFORMAT_R8G8B8_UNORM;
00075 
00076    case PIPE_FORMAT_B8G8R8A8_UNORM:
00077       return BRW_SURFACEFORMAT_B8G8R8A8_UNORM;
00078 
00079    case PIPE_FORMAT_R8G8B8A8_UNORM:
00080       return BRW_SURFACEFORMAT_R8G8B8A8_UNORM;
00081 
00082    case PIPE_FORMAT_R5G6B5_UNORM:
00083       return BRW_SURFACEFORMAT_B5G6R5_UNORM;
00084 
00085    case PIPE_FORMAT_A1R5G5B5_UNORM:
00086       return BRW_SURFACEFORMAT_B5G5R5A1_UNORM;
00087 
00088    case PIPE_FORMAT_A4R4G4B4_UNORM:
00089       return BRW_SURFACEFORMAT_B4G4R4A4_UNORM;
00090 
00091    case PIPE_FORMAT_YCBCR_REV:
00092       return BRW_SURFACEFORMAT_YCRCB_NORMAL;
00093 
00094    case PIPE_FORMAT_YCBCR:
00095       return BRW_SURFACEFORMAT_YCRCB_SWAPUVY;
00096 #if 0
00097    case PIPE_FORMAT_RGB_FXT1:
00098    case PIPE_FORMAT_RGBA_FXT1:
00099       return BRW_SURFACEFORMAT_FXT1;
00100 #endif
00101 
00102    case PIPE_FORMAT_Z16_UNORM:
00103       return BRW_SURFACEFORMAT_I16_UNORM;
00104 #if 0
00105    case PIPE_FORMAT_RGB_DXT1:
00106        return BRW_SURFACEFORMAT_DXT1_RGB;
00107 
00108    case PIPE_FORMAT_RGBA_DXT1:
00109        return BRW_SURFACEFORMAT_BC1_UNORM;
00110 
00111    case PIPE_FORMAT_RGBA_DXT3:
00112        return BRW_SURFACEFORMAT_BC2_UNORM;
00113 
00114    case PIPE_FORMAT_RGBA_DXT5:
00115        return BRW_SURFACEFORMAT_BC3_UNORM;
00116 
00117    case PIPE_FORMAT_SRGBA8:
00118       return BRW_SURFACEFORMAT_R8G8B8A8_UNORM_SRGB;
00119    case PIPE_FORMAT_SRGB_DXT1:
00120       return BRW_SURFACEFORMAT_BC1_UNORM_SRGB;
00121 #endif
00122 
00123    default:
00124       assert(0);
00125       return 0;
00126    }
00127 }
00128 
00129 static unsigned brw_buffer_offset(struct brw_context *brw,
00130                                   struct pipe_buffer *buffer)
00131 {
00132    return brw->winsys->get_buffer_offset(brw->winsys,
00133                                          buffer,
00134                                          0);
00135 }
00136 
00137 static
00138 void brw_update_texture_surface( struct brw_context *brw,
00139                                  unsigned unit )
00140 {
00141    const struct brw_texture *tObj = brw->attribs.Texture[unit];
00142    struct brw_surface_state surf;
00143 
00144    memset(&surf, 0, sizeof(surf));
00145 
00146    surf.ss0.mipmap_layout_mode = BRW_SURFACE_MIPMAPLAYOUT_BELOW;
00147    surf.ss0.surface_type = translate_tex_target(tObj->base.target);
00148    surf.ss0.surface_format = translate_tex_format(tObj->base.format);
00149 
00150    /* This is ok for all textures with channel width 8bit or less:
00151     */
00152 /*    surf.ss0.data_return_format = BRW_SURFACERETURNFORMAT_S1; */
00153 
00154    /* Updated in emit_reloc */
00155    surf.ss1.base_addr = brw_buffer_offset( brw, tObj->buffer );
00156 
00157    surf.ss2.mip_count = tObj->base.last_level;
00158    surf.ss2.width = tObj->base.width[0] - 1;
00159    surf.ss2.height = tObj->base.height[0] - 1;
00160 
00161    surf.ss3.tile_walk = BRW_TILEWALK_XMAJOR;
00162    surf.ss3.tiled_surface = 0; /* always zero */
00163    surf.ss3.pitch = tObj->stride - 1;
00164    surf.ss3.depth = tObj->base.depth[0] - 1;
00165 
00166    surf.ss4.min_lod = 0;
00167 
00168    if (tObj->base.target == PIPE_TEXTURE_CUBE) {
00169       surf.ss0.cube_pos_x = 1;
00170       surf.ss0.cube_pos_y = 1;
00171       surf.ss0.cube_pos_z = 1;
00172       surf.ss0.cube_neg_x = 1;
00173       surf.ss0.cube_neg_y = 1;
00174       surf.ss0.cube_neg_z = 1;
00175    }
00176 
00177    brw->wm.bind.surf_ss_offset[unit + 1] =
00178       brw_cache_data( &brw->cache[BRW_SS_SURFACE], &surf );
00179 }
00180 
00181 
00182 
00183 #define OFFSET(TYPE, FIELD) ( (unsigned)&(((TYPE *)0)->FIELD) )
00184 
00185 
00186 static void upload_wm_surfaces(struct brw_context *brw )
00187 {
00188    unsigned i;
00189 
00190    {
00191       struct brw_surface_state surf;
00192 
00193       /* BRW_NEW_FRAMEBUFFER
00194        */
00195       struct pipe_surface *pipe_surface = brw->attribs.FrameBuffer.cbufs[0];/*fixme*/
00196 
00197       memset(&surf, 0, sizeof(surf));
00198 
00199       if (pipe_surface != NULL) {
00200          if (pipe_surface->block.size == 4)
00201             surf.ss0.surface_format = BRW_SURFACEFORMAT_B8G8R8A8_UNORM;
00202          else
00203             surf.ss0.surface_format = BRW_SURFACEFORMAT_B5G6R5_UNORM;
00204 
00205          surf.ss0.surface_type = BRW_SURFACE_2D;
00206 
00207          surf.ss1.base_addr = brw_buffer_offset( brw, pipe_surface->buffer );
00208 
00209          surf.ss2.width = pipe_surface->width - 1;
00210          surf.ss2.height = pipe_surface->height - 1;
00211          surf.ss3.tile_walk = BRW_TILEWALK_XMAJOR;
00212          surf.ss3.tiled_surface = 0;
00213          surf.ss3.pitch = pipe_surface->stride - 1;
00214       } else {
00215          surf.ss0.surface_format = BRW_SURFACEFORMAT_B8G8R8A8_UNORM;
00216          surf.ss0.surface_type = BRW_SURFACE_NULL;
00217       }
00218 
00219       /* BRW_NEW_BLEND */
00220       surf.ss0.color_blend = (!brw->attribs.Blend->logicop_enable &&
00221                               brw->attribs.Blend->blend_enable);
00222 
00223 
00224       surf.ss0.writedisable_red =   !(brw->attribs.Blend->colormask & PIPE_MASK_R);
00225       surf.ss0.writedisable_green = !(brw->attribs.Blend->colormask & PIPE_MASK_G);
00226       surf.ss0.writedisable_blue =  !(brw->attribs.Blend->colormask & PIPE_MASK_B);
00227       surf.ss0.writedisable_alpha = !(brw->attribs.Blend->colormask & PIPE_MASK_A);
00228 
00229 
00230 
00231 
00232       brw->wm.bind.surf_ss_offset[0] = brw_cache_data( &brw->cache[BRW_SS_SURFACE], &surf );
00233 
00234       brw->wm.nr_surfaces = 1;
00235    }
00236 
00237 
00238    /* BRW_NEW_TEXTURE
00239     */
00240    for (i = 0; i < brw->num_textures && i < brw->num_samplers; i++) {
00241       const struct brw_texture *texUnit = brw->attribs.Texture[i];
00242 
00243       if (texUnit &&
00244           texUnit->base.refcount/*(texUnit->refcount > 0) == really used */) {
00245 
00246          brw_update_texture_surface(brw, i);
00247 
00248          brw->wm.nr_surfaces = i+2;
00249       }
00250       else {
00251          brw->wm.bind.surf_ss_offset[i+1] = 0;
00252       }
00253    }
00254 
00255    brw->wm.bind_ss_offset = brw_cache_data( &brw->cache[BRW_SS_SURF_BIND],
00256                                             &brw->wm.bind );
00257 }
00258 
00259 
00260 /* KW: Will find a different way to acheive this, see for example the
00261  * state caches with relocs in the i915 swz driver.
00262  */
00263 #if 0
00264 static void emit_reloc_wm_surfaces(struct brw_context *brw)
00265 {
00266    int unit;
00267 
00268    if (brw->state.draw_region != NULL) {
00269       /* Emit framebuffer relocation */
00270       dri_emit_reloc(brw_cache_buffer(brw, BRW_SS_SURFACE),
00271                      DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE,
00272                      0,
00273                      brw->wm.bind.surf_ss_offset[0] +
00274                      offsetof(struct brw_surface_state, ss1),
00275                      brw->state.draw_region->buffer);
00276    }
00277 
00278    /* Emit relocations for texture buffers */
00279    for (unit = 0; unit < BRW_MAX_TEX_UNIT; unit++) {
00280       struct gl_texture_unit *texUnit = &brw->attribs.Texture->Unit[unit];
00281       struct gl_texture_object *tObj = texUnit->_Current;
00282       struct intel_texture_object *intelObj = intel_texture_object(tObj);
00283 
00284       if (texUnit->_ReallyEnabled && intelObj->mt != NULL) {
00285          dri_emit_reloc(brw_cache_buffer(brw, BRW_SS_SURFACE),
00286                         DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_READ,
00287                         0,
00288                         brw->wm.bind.surf_ss_offset[unit + 1] +
00289                         offsetof(struct brw_surface_state, ss1),
00290                         intelObj->mt->region->buffer);
00291       }
00292    }
00293 }
00294 #endif
00295 
00296 const struct brw_tracked_state brw_wm_surfaces = {
00297    .dirty = {
00298       .brw = (BRW_NEW_FRAMEBUFFER |
00299               BRW_NEW_BLEND |
00300               BRW_NEW_TEXTURE),
00301       .cache = 0
00302    },
00303    .update = upload_wm_surfaces,
00304 };

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