[Mesa-dev] [PATCH 2/6] st/mesa: add texture buffer object support to state tracker

Dave Airlie airlied at gmail.com
Wed Dec 5 22:24:30 PST 2012


From: Dave Airlie <airlied at redhat.com>

This adds the necessary changes to the st to allow texture buffer object
support if the driver advertises it.

Signed-off-by: Dave Airlie <airlied at redhat.com>
---
 src/mesa/state_tracker/st_atom_texture.c   | 18 ++++++++++++------
 src/mesa/state_tracker/st_cb_texture.c     | 16 ++++++++++++++++
 src/mesa/state_tracker/st_extensions.c     |  2 ++
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |  2 +-
 src/mesa/state_tracker/st_mesa_to_tgsi.c   |  1 +
 5 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c
index df05e83..dba1d82 100644
--- a/src/mesa/state_tracker/st_atom_texture.c
+++ b/src/mesa/state_tracker/st_atom_texture.c
@@ -215,13 +215,19 @@ update_single_texture(struct st_context *st,
 
    /* Determine the format of the texture sampler view */
    st_view_format = stObj->pt->format;
-   {
-      const struct st_texture_image *firstImage =
-	 st_texture_image(stObj->base.Image[0][stObj->base.BaseLevel]);
-      const gl_format texFormat = firstImage->base.TexFormat;
-      enum pipe_format firstImageFormat =
-	 st_mesa_format_to_pipe_format(texFormat);
 
+   {
+      gl_format texFormat;
+      enum pipe_format firstImageFormat;
+
+      if (texObj->Target == GL_TEXTURE_BUFFER) {
+         texFormat = stObj->base._BufferObjectFormat;
+      } else {
+         const struct st_texture_image *firstImage =
+            st_texture_image(stObj->base.Image[0][stObj->base.BaseLevel]);
+         texFormat = firstImage->base.TexFormat;
+      }
+      firstImageFormat = st_mesa_format_to_pipe_format(texFormat);
       if ((samp->sRGBDecode == GL_SKIP_DECODE_EXT) &&
 	  (_mesa_get_format_color_encoding(texFormat) == GL_SRGB)) {
          /* Don't do sRGB->RGB conversion.  Interpret the texture data as
diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
index f06814f..48a18d2 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -48,6 +48,7 @@
 #include "state_tracker/st_cb_fbo.h"
 #include "state_tracker/st_cb_flush.h"
 #include "state_tracker/st_cb_texture.h"
+#include "state_tracker/st_cb_bufferobjects.h"
 #include "state_tracker/st_format.h"
 #include "state_tracker/st_texture.h"
 #include "state_tracker/st_gen_mipmap.h"
@@ -1182,6 +1183,21 @@ st_finalize_texture(struct gl_context *ctx,
          stObj->lastLevel = stObj->base._MaxLevel;
    }
 
+   if (tObj->Target == GL_TEXTURE_BUFFER) {
+      struct st_buffer_object *st_obj = st_buffer_object(tObj->BufferObject);
+      
+      if (st_obj->buffer != stObj->pt) {
+         pipe_resource_reference(&stObj->pt, st_obj->buffer);
+         pipe_sampler_view_release(st->pipe, &stObj->sampler_view);
+         stObj->width0 = stObj->pt->width0 / _mesa_get_format_bytes(tObj->_BufferObjectFormat);
+         stObj->height0 = 1;
+         stObj->depth0 = 1;
+
+      }
+      return GL_TRUE;
+
+   }
+
    firstImage = st_texture_image(stObj->base.Image[0][stObj->base.BaseLevel]);
    assert(firstImage);
 
diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c
index 62a736b..0c61795 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -643,4 +643,6 @@ void st_init_extensions(struct st_context *st)
    if (ctx->Const.MinMapBufferAlignment >= 64) {
       ctx->Extensions.ARB_map_buffer_alignment = GL_TRUE;
    }
+   if (screen->get_param(screen, PIPE_CAP_TEXTURE_BUFFER_OBJECTS))
+      ctx->Extensions.ARB_texture_buffer_object = GL_TRUE;
 }
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index c030a6b..ae3b8b2 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -2776,7 +2776,7 @@ glsl_to_tgsi_visitor::visit(ir_texture *ir)
       inst->tex_target = TEXTURE_RECT_INDEX;
       break;
    case GLSL_SAMPLER_DIM_BUF:
-      assert(!"FINISHME: Implement ARB_texture_buffer_object");
+      inst->tex_target = TEXTURE_BUFFER_INDEX;
       break;
    case GLSL_SAMPLER_DIM_EXTERNAL:
       inst->tex_target = TEXTURE_EXTERNAL_INDEX;
diff --git a/src/mesa/state_tracker/st_mesa_to_tgsi.c b/src/mesa/state_tracker/st_mesa_to_tgsi.c
index 81a870f..e326bcc 100644
--- a/src/mesa/state_tracker/st_mesa_to_tgsi.c
+++ b/src/mesa/state_tracker/st_mesa_to_tgsi.c
@@ -269,6 +269,7 @@ st_translate_texture_target( GLuint textarget,
    }
 
    switch( textarget ) {
+   case TEXTURE_BUFFER_INDEX: return TGSI_TEXTURE_BUFFER;
    case TEXTURE_1D_INDEX:   return TGSI_TEXTURE_1D;
    case TEXTURE_2D_INDEX:   return TGSI_TEXTURE_2D;
    case TEXTURE_3D_INDEX:   return TGSI_TEXTURE_3D;
-- 
1.8.0.1



More information about the mesa-dev mailing list