gallium: clean-up, simplification of mipmapped textures
[mesa.git] / src / mesa / pipe / i915simple / i915_state_sampler.c
index 3b736f9c551bbd9c3806e44313a9f359e3e8d68b..9c1a5bbbd65808aa64d76f2f1c093e66a6a65f14 100644 (file)
  * 
  **************************************************************************/
 
-//#include "mtypes.h"
-//#include "enums.h"
-//#include "texformat.h"
-//#include "macros.h"
-//#include "dri_bufmgr.h"
-
-
 #include "pipe/p_context.h"
 #include "pipe/p_state.h"
 #include "pipe/p_util.h"
 #include "i915_context.h"
 #include "i915_reg.h"
 #include "i915_state.h"
-//#include "i915_cache.h"
-
-static uint
-bitcount(uint k)
-{
-   uint count = 0;
-   while (k) {
-      if (k & 1)
-         count++;
-      k = k >> 1;
-   }
-   return count;
-}
-
-
-static boolean
-is_power_of_two_texture(const struct pipe_mipmap_tree *mt)
-{
-   if (bitcount(mt->width0) == 1 &&
-       bitcount(mt->height0) == 1 &&
-       bitcount(mt->depth0) == 1) {
-      return 1;
-   }
-   else
-      return 0;
-}
 
 
 /**
@@ -79,9 +46,11 @@ is_power_of_two_texture(const struct pipe_mipmap_tree *mt)
 static void update_sampler(struct i915_context *i915,
                            uint unit,
                           const struct i915_sampler_state *sampler,
-                          const struct pipe_mipmap_tree *mt,
+                          const struct i915_texture *tex,
                           unsigned state[3] )
 {
+   const struct pipe_texture *pt = &tex->base;
+
    /* Need to do this after updating the maps, which call the
     * intel_finalize_mipmap_tree and hence can update firstLevel:
     */
@@ -89,8 +58,8 @@ static void update_sampler(struct i915_context *i915,
    state[1] = sampler->state[1];
    state[2] = sampler->state[2];
 
-   if (mt->format == PIPE_FORMAT_YCBCR ||
-       mt->format == PIPE_FORMAT_YCBCR_REV)
+   if (pt->format == PIPE_FORMAT_YCBCR ||
+       pt->format == PIPE_FORMAT_YCBCR_REV)
       state[0] |= SS2_COLORSPACE_CONVERSION;
 
    /* 3D textures don't seem to respect the border color.
@@ -108,7 +77,7 @@ static void update_sampler(struct i915_context *i915,
       const unsigned ws = sampler->templ->wrap_s;
       const unsigned wt = sampler->templ->wrap_t;
       const unsigned wr = sampler->templ->wrap_r;
-      if (mt->target == PIPE_TEXTURE_3D &&
+      if (pt->target == PIPE_TEXTURE_3D &&
           (sampler->templ->min_img_filter != PIPE_TEX_FILTER_NEAREST ||
            sampler->templ->mag_img_filter != PIPE_TEX_FILTER_NEAREST) &&
           (ws == PIPE_TEX_WRAP_CLAMP ||
@@ -127,12 +96,9 @@ static void update_sampler(struct i915_context *i915,
 #endif
 
    state[1] |= (unit << SS3_TEXTUREMAP_INDEX_SHIFT);
-
-   if (is_power_of_two_texture(mt)) {
-      state[1] |= SS3_NORMALIZED_COORDS;
-   }
 }
 
+
 void i915_update_samplers( struct i915_context *i915 )
 {
    uint unit;
@@ -141,13 +107,13 @@ void i915_update_samplers( struct i915_context *i915 )
    i915->current.sampler_enable_flags = 0x0;
 
    for (unit = 0; unit < I915_TEX_UNITS; unit++) {
-      /* determine unit enable/disable by looking for a bound mipmap tree */
+      /* determine unit enable/disable by looking for a bound texture */
       /* could also examine the fragment program? */
       if (i915->texture[unit]) {
         update_sampler( i915,
                          unit,
                          i915->sampler[unit],       /* sampler state */
-                         i915->texture[unit],        /* mipmap tree */
+                         i915->texture[unit],        /* texture */
                         i915->current.sampler[unit] /* the result */
                          );
 
@@ -160,10 +126,8 @@ void i915_update_samplers( struct i915_context *i915 )
 }
 
 
-
-
 static uint
-translate_texture_format(uint pipeFormat)
+translate_texture_format(enum pipe_format pipeFormat)
 {
    switch (pipeFormat) {
    case PIPE_FORMAT_U_L8:
@@ -174,13 +138,13 @@ translate_texture_format(uint pipeFormat)
       return MAPSURF_8BIT | MT_8BIT_A8;
    case PIPE_FORMAT_U_A8_L8:
       return MAPSURF_16BIT | MT_16BIT_AY88;
-   case PIPE_FORMAT_U_R5_G6_B5:
+   case PIPE_FORMAT_R5G6B5_UNORM:
       return MAPSURF_16BIT | MT_16BIT_RGB565;
-   case PIPE_FORMAT_U_A1_R5_G5_B5:
+   case PIPE_FORMAT_A1R5G5B5_UNORM:
       return MAPSURF_16BIT | MT_16BIT_ARGB1555;
-   case PIPE_FORMAT_U_A4_R4_G4_B4:
+   case PIPE_FORMAT_A4R4G4B4_UNORM:
       return MAPSURF_16BIT | MT_16BIT_ARGB4444;
-   case PIPE_FORMAT_U_A8_R8_G8_B8:
+   case PIPE_FORMAT_A8R8G8B8_UNORM:
       return MAPSURF_32BIT | MT_32BIT_ARGB8888;
    case PIPE_FORMAT_YCBCR_REV:
       return (MAPSURF_422 | MT_422_YCRCB_NORMAL);
@@ -191,7 +155,7 @@ translate_texture_format(uint pipeFormat)
    case PIPE_FORMAT_RGBA_FXT1:
       return (MAPSURF_COMPRESSED | MT_COMPRESS_FXT1);
 #endif
-   case PIPE_FORMAT_U_Z16:
+   case PIPE_FORMAT_Z16_UNORM:
       return (MAPSURF_16BIT | MT_16BIT_L16);
 #if 0
    case PIPE_FORMAT_RGBA_DXT1:
@@ -202,10 +166,10 @@ translate_texture_format(uint pipeFormat)
    case PIPE_FORMAT_RGBA_DXT5:
       return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT4_5);
 #endif
-   case PIPE_FORMAT_S8_Z24:
+   case PIPE_FORMAT_S8Z24_UNORM:
       return (MAPSURF_32BIT | MT_32BIT_xL824);
    default:
-      fprintf(stderr, "i915: translate_texture_format() bad image format %x\n",
+      debug_printf("i915: translate_texture_format() bad image format %x\n",
               pipeFormat);
       assert(0);
       return 0;
@@ -213,54 +177,27 @@ translate_texture_format(uint pipeFormat)
 }
 
 
-#define I915_TEXREG_MS3        1
-#define I915_TEXREG_MS4        2
-
-
 static void
 i915_update_texture(struct i915_context *i915, uint unit,
                     uint state[6])
 {
-   const struct pipe_mipmap_tree *mt = i915->texture[unit];
+   const struct i915_texture *tex = i915->texture[unit];
+   const struct pipe_texture *pt = &tex->base;
    uint format, pitch;
-   const uint width = mt->width0, height = mt->height0, depth = mt->depth0;
-   const uint num_levels = mt->last_level - mt->first_level;
+   const uint width = pt->width[0], height = pt->height[0], depth = pt->depth[0];
+   const uint num_levels = pt->last_level;
 
-   assert(mt);
+   assert(tex);
    assert(width);
    assert(height);
    assert(depth);
 
-#if 0
-   if (i915->state.tex_buffer[unit] != NULL) {
-       driBOUnReference(i915->state.tex_buffer[unit]);
-       i915->state.tex_buffer[unit] = NULL;
-   }
-#endif
-
-
-   {
-      /*struct pipe_buffer_handle *p =*/ driBOReference(mt->region->buffer);
-   }
-
-#if 0
-   i915->state.tex_buffer[unit] = driBOReference(intelObj->mt->region->
-                                                 buffer);
-   i915->state.tex_offset[unit] =  intel_miptree_image_offset(intelObj->mt,
-                                                              0, intelObj->
-                                                              firstLevel);
-#endif
-
-   format = translate_texture_format(mt->format);
-   pitch = mt->pitch * mt->cpp;
+   format = translate_texture_format(pt->format);
+   pitch = tex->pitch * pt->cpp;
 
    assert(format);
    assert(pitch);
 
-   /*
-   printf("texture format = 0x%x\n", format);
-   */
-
    /* MS3 state */
    state[0] =
       (((height - 1) << MS3_HEIGHT_SHIFT)
@@ -277,14 +214,13 @@ i915_update_texture(struct i915_context *i915, uint unit,
 }
 
 
-
 void
 i915_update_textures(struct i915_context *i915)
 {
    uint unit;
 
    for (unit = 0; unit < I915_TEX_UNITS; unit++) {
-      /* determine unit enable/disable by looking for a bound mipmap tree */
+      /* determine unit enable/disable by looking for a bound texture */
       /* could also examine the fragment program? */
       if (i915->texture[unit]) {
          i915_update_texture(i915, unit, i915->current.texbuffer[unit]);