st/mesa: add texture buffer object support to state tracker (v1.1)
authorDave Airlie <airlied@redhat.com>
Thu, 6 Dec 2012 06:12:11 +0000 (16:12 +1000)
committerDave Airlie <airlied@redhat.com>
Sat, 8 Dec 2012 03:32:33 +0000 (13:32 +1000)
This adds the necessary changes to the st to allow texture buffer object
support if the driver advertises it.

v1.1: remove extra blank line and whitespace

Reviewed-by: Brian Paul <brianp@vmware.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
src/mesa/state_tracker/st_atom_texture.c
src/mesa/state_tracker/st_cb_texture.c
src/mesa/state_tracker/st_extensions.c
src/mesa/state_tracker/st_glsl_to_tgsi.cpp
src/mesa/state_tracker/st_mesa_to_tgsi.c

index df05e83c2d48fc87624bf7f21c24e50c9d168fa2..dba1d829c200b32614cd83fdf925da2e165173d1 100644 (file)
@@ -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
index 10db5bcb51af237184e58c006ca54304f83d60a3..ae069eb2cba9a11422ab630cff80ad6c7d90c2bd 100644 (file)
@@ -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"
@@ -1229,6 +1230,20 @@ 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);
 
index 62a736bb61b23f58fd07b0aea5b490932b459255..0c6179577c6d06ac0303339d29340d466ef3a85b 100644 (file)
@@ -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;
 }
index c030a6b372edf53270b4d4da7a5e8bc440a7b036..ae3b8b2c0d1f44054e36f50459ecd665610982aa 100644 (file)
@@ -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;
index 81a870f86854b53297a5415fb4e00cdb17387bbd..e326bcc7031fbf1c61fbffb923e598ec17f68624 100644 (file)
@@ -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;