Remove pipe->max_texture_size(), use get_param() instead.
authorBrian <brian.paul@tungstengraphics.com>
Tue, 6 Nov 2007 16:41:45 +0000 (09:41 -0700)
committerBrian <brian.paul@tungstengraphics.com>
Tue, 6 Nov 2007 16:41:45 +0000 (09:41 -0700)
Also, in st_init_limits(), clamp driver's values against Mesa's internal limits.

src/mesa/pipe/failover/fo_context.c
src/mesa/pipe/i915simple/i915_context.c
src/mesa/pipe/p_context.h
src/mesa/pipe/p_defines.h
src/mesa/pipe/softpipe/sp_context.c
src/mesa/state_tracker/st_cb_drawpixels.c
src/mesa/state_tracker/st_extensions.c

index aa5d088..e18b349 100644 (file)
@@ -117,9 +117,9 @@ struct pipe_context *failover_create( struct pipe_context *hw,
    failover->pipe.winsys = hw->winsys;
    failover->pipe.destroy = failover_destroy;
    failover->pipe.is_format_supported = hw->is_format_supported;
-   failover->pipe.max_texture_size = hw->max_texture_size;
    failover->pipe.get_name = hw->get_name;
    failover->pipe.get_vendor = hw->get_vendor;
+   failover->pipe.get_param = hw->get_param;
 
    failover->pipe.draw_arrays = failover_draw_arrays;
    failover->pipe.draw_elements = failover_draw_elements;
index 6de1e68..50503a8 100644 (file)
@@ -108,36 +108,6 @@ i915_is_format_supported( struct pipe_context *pipe,
 }
 
 
-/**
- * We might want to return max texture levels instead...
- */
-static void
-i915_max_texture_size(struct pipe_context *pipe, unsigned textureType,
-                      unsigned *maxWidth, unsigned *maxHeight, unsigned *maxDepth)
-{
-   switch (textureType) {
-   case PIPE_TEXTURE_1D:
-      *maxWidth = 2048;
-      break; 
-   case PIPE_TEXTURE_2D:
-      *maxWidth =
-      *maxHeight = 2048;
-      break; 
-   case PIPE_TEXTURE_3D:
-      *maxWidth =
-      *maxHeight =
-      *maxDepth = 256;
-      break; 
-   case PIPE_TEXTURE_CUBE:
-      *maxWidth =
-      *maxHeight = 2048;
-      break; 
-   default:
-      assert(0);
-   }
-}
-
-
 static int
 i915_get_param(struct pipe_context *pipe, int param)
 {
@@ -162,6 +132,12 @@ i915_get_param(struct pipe_context *pipe, int param)
       return 0;
    case PIPE_CAP_TEXTURE_SHADOW_MAP:
       return 0;
+   case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
+      return 11; /* max 1024x1024 */
+   case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
+      return 8;  /* max 128x128x128 */
+   case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
+      return 11; /* max 1024x1024 */
    default:
       return 0;
    }
@@ -324,7 +300,6 @@ struct pipe_context *i915_create( struct pipe_winsys *pipe_winsys,
 
    i915->pipe.destroy = i915_destroy;
    i915->pipe.is_format_supported = i915_is_format_supported;
-   i915->pipe.max_texture_size = i915_max_texture_size;
    i915->pipe.get_param = i915_get_param;
 
    i915->pipe.clear = i915_clear;
index 4f5e786..ddc7acc 100644 (file)
@@ -51,12 +51,6 @@ struct pipe_context {
    boolean (*is_format_supported)( struct pipe_context *pipe,
                                    uint format );
 
-   void (*max_texture_size)(struct pipe_context *pipe,
-                            unsigned textureType, /* PIPE_TEXTURE_x */
-                            unsigned *maxWidth,
-                            unsigned *maxHeight,
-                            unsigned *maxDepth);
-
    const char *(*get_name)( struct pipe_context *pipe );
 
    const char *(*get_vendor)( struct pipe_context *pipe );
index cc0232c..ca9929b 100644 (file)
 #define PIPE_CAP_POINT_SPRITE            7
 #define PIPE_CAP_MAX_RENDER_TARGETS      8
 #define PIPE_CAP_OCCLUSION_QUERY         9
-#define PIPE_CAP_TEXTURE_SHADOW_MAP     10
+#define PIPE_CAP_TEXTURE_SHADOW_MAP      10
+#define PIPE_CAP_MAX_TEXTURE_2D_LEVELS   11
+#define PIPE_CAP_MAX_TEXTURE_3D_LEVELS   12
+#define PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS 13
 
 #endif
index effecda..954884e 100644 (file)
@@ -83,39 +83,6 @@ softpipe_is_format_supported( struct pipe_context *pipe,
 }
 
 
-/** XXX remove these? */
-#define MAX_TEXTURE_LEVELS 11
-#define MAX_TEXTURE_RECT_SIZE 2048
-#define MAX_3D_TEXTURE_LEVELS 8
-
-static void
-softpipe_max_texture_size(struct pipe_context *pipe, unsigned textureType,
-                          unsigned *maxWidth, unsigned *maxHeight,
-                          unsigned *maxDepth)
-{
-   switch (textureType) {
-   case PIPE_TEXTURE_1D:
-      *maxWidth = 1 << (MAX_TEXTURE_LEVELS - 1);
-      break;
-   case PIPE_TEXTURE_2D:
-      *maxWidth =
-      *maxHeight = 1 << (MAX_TEXTURE_LEVELS - 1);
-      break;
-   case PIPE_TEXTURE_3D:
-      *maxWidth =
-      *maxHeight =
-      *maxDepth = 1 << (MAX_3D_TEXTURE_LEVELS - 1);
-      break;
-   case PIPE_TEXTURE_CUBE:
-      *maxWidth =
-      *maxHeight = MAX_TEXTURE_RECT_SIZE;
-      break;
-   default:
-      assert(0);
-   }
-}
-
-
 /**
  * Map any drawing surfaces which aren't already mapped
  */
@@ -297,6 +264,12 @@ static int softpipe_get_param(struct pipe_context *pipe, int param)
       return 1;
    case PIPE_CAP_TEXTURE_SHADOW_MAP:
       return 1;
+   case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
+      return 12; /* max 2Kx2K */
+   case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
+      return 8;  /* max 128x128x128 */
+   case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
+      return 12; /* max 2Kx2K */
    default:
       return 0;
    }
@@ -321,7 +294,7 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys,
 
    /* queries */
    softpipe->pipe.is_format_supported = softpipe_is_format_supported;
-   softpipe->pipe.max_texture_size = softpipe_max_texture_size;
+   //softpipe->pipe.max_texture_size = softpipe_max_texture_size;
    softpipe->pipe.get_param = softpipe_get_param;
 
    /* state setters */
index fc58035..df41d5c 100644 (file)
@@ -703,15 +703,15 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
    const GLuint unit = 0;
    struct pipe_context *pipe = ctx->st->pipe;
    GLfloat x0, y0, x1, y1;
-   GLuint maxWidth, maxHeight;
+   GLuint maxSize;
 
    /* limit checks */
    /* XXX if DrawPixels image is larger than max texture size, break
     * it up into chunks.
     */
-   pipe->max_texture_size(pipe, PIPE_TEXTURE_2D, &maxWidth, &maxHeight, NULL);
-   assert(width <= maxWidth);
-   assert(height <= maxHeight);
+   maxSize = 1 << (pipe->get_param(pipe, PIPE_CAP_MAX_TEXTURE_2D_LEVELS) - 1);
+   assert(width <= maxSize);
+   assert(height <= maxSize);
 
    /* setup state: just scissor */
    {
index 3f56b53..0707c48 100644 (file)
 #include "st_extensions.h"
 
 
-/*
- * Compute floor(log_base_2(n)).
- * If n < 0 return -1.
- */
-static int
-logbase2( int n )
+static int min(int a, int b)
 {
-   GLint i = 1;
-   GLint log2 = 0;
-
-   if (n < 0)
-      return -1;
-
-   if (n == 0)
-      return 0;
+   return (a < b) ? a : b;
+}
 
-   while ( n > i ) {
-      i *= 2;
-      log2++;
-   }
-   if (i != n) {
-      return log2 - 1;
-   }
-   else {
-      return log2;
-   }
+static int clamp(int a, int min, int max)
+{
+   if (a < min)
+      return min;
+   else if (a > max)
+      return max;
+   else
+      return a;
 }
 
 
+/**
+ * Query driver to get implementation limits.
+ * Note that we have to limit/clamp against Mesa's internal limits too.
+ */
 void st_init_limits(struct st_context *st)
 {
    struct pipe_context *pipe = st->pipe;
-   GLcontext *ctx = st->ctx;
-   uint w, h, d;
+   struct gl_constants *c = &st->ctx->Const;
+
+   c->MaxTextureLevels
+      = min(pipe->get_param(pipe, PIPE_CAP_MAX_TEXTURE_2D_LEVELS),
+            MAX_TEXTURE_LEVELS);
 
-   ctx->Const.MaxTextureImageUnits
-      = ctx->Const.MaxTextureCoordUnits
-      = pipe->get_param(pipe, PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS);
+   c->Max3DTextureLevels
+      = min(pipe->get_param(pipe, PIPE_CAP_MAX_TEXTURE_3D_LEVELS),
+            MAX_3D_TEXTURE_LEVELS);
 
-   pipe->max_texture_size(pipe, PIPE_TEXTURE_2D, &w, &h, &d);
-   ctx->Const.MaxTextureLevels = logbase2(w) + 1;
-   ctx->Const.MaxTextureRectSize = w;
+   c->MaxCubeTextureLevels
+      = min(pipe->get_param(pipe, PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS),
+            MAX_CUBE_TEXTURE_LEVELS);
 
-   pipe->max_texture_size(pipe, PIPE_TEXTURE_3D, &w, &h, &d);
-   ctx->Const.Max3DTextureLevels = logbase2(d) + 1;
+   c->MaxTextureRectSize
+      = min(1 << (c->MaxTextureLevels - 1), MAX_TEXTURE_RECT_SIZE);
 
-   pipe->max_texture_size(pipe, PIPE_TEXTURE_CUBE, &w, &h, &d);
-   ctx->Const.MaxCubeTextureLevels = logbase2(w) + 1;
-   
-   ctx->Const.MaxDrawBuffers = MAX2(1, pipe->get_param(pipe, PIPE_CAP_MAX_RENDER_TARGETS));
+   c->MaxTextureImageUnits
+      = c->MaxTextureCoordUnits
+      = min(pipe->get_param(pipe, PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS),
+            MAX_TEXTURE_IMAGE_UNITS);
 
+   c->MaxDrawBuffers
+      = clamp(pipe->get_param(pipe, PIPE_CAP_MAX_RENDER_TARGETS),
+              1, MAX_DRAW_BUFFERS);
 }