[Mesa-dev] [PATCH 3/3] st/mesa: set PIPE_RESOURCE_FLAG_UNNORMALIZED_COORDS_HINT for GL_TEXTURE_RECTANGLE (v2)

Luca Barbieri luca at luca-barbieri.com
Wed Aug 11 21:37:55 PDT 2010


Changes in v2:
- compress_with_blit no longer sets the unnormalized hint flag for NPOT
  textures: the driver should do that if it wants to

Allow to pass flags to st_texture_create and take advantage of that
to tell the pipe driver that a texture is going to be used with unnormalized
coordinates.

This is useful for hardware with no mipmapped NPOT support that needs to
allocate texture rectangles in a special way (e.g. nv30).
---
 src/mesa/state_tracker/st_atom_pixeltransfer.c |    2 +-
 src/mesa/state_tracker/st_cb_bitmap.c          |    4 ++--
 src/mesa/state_tracker/st_cb_drawpixels.c      |    2 +-
 src/mesa/state_tracker/st_cb_texture.c         |   17 ++++++++++++++---
 src/mesa/state_tracker/st_gen_mipmap.c         |    8 ++++++--
 src/mesa/state_tracker/st_texture.c            |    5 +++--
 src/mesa/state_tracker/st_texture.h            |    3 ++-
 7 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c
index 8a8d175..449847c 100644
--- a/src/mesa/state_tracker/st_atom_pixeltransfer.c
+++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c
@@ -128,7 +128,7 @@ create_color_map_texture(GLcontext *ctx)
 
    /* create texture for color map/table */
    pt = st_texture_create(st, PIPE_TEXTURE_2D, format, 0,
-                          texSize, texSize, 1, PIPE_BIND_SAMPLER_VIEW);
+                          texSize, texSize, 1, PIPE_BIND_SAMPLER_VIEW, 0);
    return pt;
 }
 
diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c
index 0b8ecd2..9e9c8b2 100644
--- a/src/mesa/state_tracker/st_cb_bitmap.c
+++ b/src/mesa/state_tracker/st_cb_bitmap.c
@@ -277,7 +277,7 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height,
     */
    pt = st_texture_create(st, PIPE_TEXTURE_2D, st->bitmap.tex_format,
                           0, width, height, 1,
-                          PIPE_BIND_SAMPLER_VIEW);
+                          PIPE_BIND_SAMPLER_VIEW, 0);
    if (!pt) {
       _mesa_unmap_pbo_source(ctx, unpack);
       return NULL;
@@ -544,7 +544,7 @@ reset_cache(struct st_context *st)
                                       st->bitmap.tex_format, 0,
                                       BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT,
                                       1,
-				      PIPE_BIND_SAMPLER_VIEW);
+				      PIPE_BIND_SAMPLER_VIEW, 0);
 }
 
 
diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c
index 69a3dd4..8b6a025 100644
--- a/src/mesa/state_tracker/st_cb_drawpixels.c
+++ b/src/mesa/state_tracker/st_cb_drawpixels.c
@@ -331,7 +331,7 @@ alloc_texture(struct st_context *st, GLsizei width, GLsizei height,
    }
 
    pt = st_texture_create(st, PIPE_TEXTURE_2D, texFormat, 0,
-                          ptw, pth, 1, PIPE_BIND_SAMPLER_VIEW);
+                          ptw, pth, 1, PIPE_BIND_SAMPLER_VIEW, 0);
 
    return pt;
 }
diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
index 4c3e368..1ebe7b8 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -265,7 +265,7 @@ guess_and_alloc_texture(struct st_context *st,
 {
    const GLuint dims = get_texture_dims(stObj->base.Target);
    GLuint level, lastLevel, width, height, depth;
-   GLuint bindings;
+   GLuint bindings, flags;
    enum pipe_format fmt;
 
    DBG("%s\n", __FUNCTION__);
@@ -343,6 +343,11 @@ guess_and_alloc_texture(struct st_context *st,
 
    bindings = default_bindings(st, fmt);
 
+   flags = 0;
+
+   if(stObj->base.Target == GL_TEXTURE_RECTANGLE)
+      flags |= PIPE_RESOURCE_FLAG_UNNORMALIZED_COORDS_HINT;
+
    stObj->pt = st_texture_create(st,
                                  gl_target_to_pipe(stObj->base.Target),
                                  fmt,
@@ -350,7 +355,8 @@ guess_and_alloc_texture(struct st_context *st,
                                  width,
                                  height,
                                  depth,
-                                 bindings);
+                                 bindings,
+                                 flags);
 
    DBG("%s returning %d\n", __FUNCTION__, (stObj->pt != NULL));
 
@@ -1867,6 +1873,10 @@ st_finalize_texture(GLcontext *ctx,
     */
    if (!stObj->pt) {
       GLuint bindings = default_bindings(st, firstImageFormat);
+      GLuint flags = 0;
+
+      if(stObj->base.Target == GL_TEXTURE_RECTANGLE)
+         flags |= PIPE_RESOURCE_FLAG_UNNORMALIZED_COORDS_HINT;
 
       stObj->pt = st_texture_create(st,
                                     gl_target_to_pipe(stObj->base.Target),
@@ -1875,7 +1885,8 @@ st_finalize_texture(GLcontext *ctx,
                                     stObj->width0,
                                     stObj->height0,
                                     stObj->depth0,
-                                    bindings);
+                                    bindings,
+                                    flags);
 
       if (!stObj->pt) {
          _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c
index 2d587df..298d8b2 100644
--- a/src/mesa/state_tracker/st_gen_mipmap.c
+++ b/src/mesa/state_tracker/st_gen_mipmap.c
@@ -340,7 +340,10 @@ st_generate_mipmap(GLcontext *ctx, GLenum target,
        */
       struct pipe_resource *oldTex = stObj->pt;
 
-      /* create new texture with space for more levels */
+      /* Create new texture with space for more levels.
+       * We never set UNNORMALIZED_COORDS_HINT here since, in OpenGL,
+       * mipmaps always mean normalized coords as well.
+       */
       stObj->pt = st_texture_create(st,
                                     oldTex->target,
                                     oldTex->format,
@@ -348,7 +351,8 @@ st_generate_mipmap(GLcontext *ctx, GLenum target,
                                     oldTex->width0,
                                     oldTex->height0,
                                     oldTex->depth0,
-                                    oldTex->bind);
+                                    oldTex->bind,
+                                    0);
 
       /* The texture isn't in a "complete" state yet so set the expected
        * lastLevel here, since it won't get done in st_finalize_texture().
diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c
index add6e94..95abb3b 100644
--- a/src/mesa/state_tracker/st_texture.c
+++ b/src/mesa/state_tracker/st_texture.c
@@ -59,7 +59,8 @@ st_texture_create(struct st_context *st,
 		  GLuint width0,
 		  GLuint height0,
 		  GLuint depth0,
-                  GLuint bind )
+                  GLuint bind,
+                  GLuint flags)
 {
    struct pipe_resource pt, *newtex;
    struct pipe_screen *screen = st->pipe->screen;
@@ -86,7 +87,7 @@ st_texture_create(struct st_context *st,
    pt.depth0 = depth0;
    pt.usage = PIPE_USAGE_DEFAULT;
    pt.bind = bind;
-   pt.flags = 0;
+   pt.flags = flags;
 
    newtex = screen->resource_create(screen, &pt);
 
diff --git a/src/mesa/state_tracker/st_texture.h b/src/mesa/state_tracker/st_texture.h
index ed5d271..3908e2a 100644
--- a/src/mesa/state_tracker/st_texture.h
+++ b/src/mesa/state_tracker/st_texture.h
@@ -158,7 +158,8 @@ st_texture_create(struct st_context *st,
                   GLuint width0,
                   GLuint height0,
                   GLuint depth0,
-                  GLuint tex_usage );
+                  GLuint tex_usage,
+                  GLuint flags);
 
 
 /* Check if an image fits into an existing texture object.
-- 
1.7.0.4



More information about the mesa-dev mailing list