On 12/22/2012 05:49 AM, Christoph Bumiller wrote:
v2: Update to handle BufferSize being -1 and return a NULL sampler
view if the specified range would cause out of bounds access.
---
  src/mesa/state_tracker/st_atom_texture.c |   22 +++++++++++++++++++++-
  src/mesa/state_tracker/st_extensions.c   |    6 ++++++
  2 files changed, 27 insertions(+), 1 deletions(-)

diff --git a/src/mesa/state_tracker/st_atom_texture.c 
b/src/mesa/state_tracker/st_atom_texture.c
index dba1d82..4b43b2a 100644
--- a/src/mesa/state_tracker/st_atom_texture.c
+++ b/src/mesa/state_tracker/st_atom_texture.c
@@ -152,7 +152,27 @@ st_create_texture_sampler_view_from_stobj(struct 
pipe_context *pipe,
     u_sampler_view_default_template(&templ,
                                     stObj->pt,
                                     format);
-   templ.u.tex.first_level = stObj->base.BaseLevel;
+
+   if (stObj->pt->target == PIPE_BUFFER) {
+      unsigned base, size;
+      unsigned f, n;
+      const struct util_format_description *desc
+         = util_format_description(templ.format);
+
+      base = stObj->base.BufferOffset;
+      if (base>= stObj->pt->width0)
+         return NULL;
+      size = MIN2(stObj->pt->width0 - base, (unsigned)stObj->base.BufferSize);
+
+      f = ((base * 8) / desc->block.bits) * desc->block.width;
+      n = ((size * 8) / desc->block.bits) * desc->block.width;
+      if (!n)
+         return NULL;
+      templ.u.buf.first_element = f;
+      templ.u.buf.last_element  = f + (n - 1);
+   } else {
+      templ.u.tex.first_level = stObj->base.BaseLevel;
+   }

     if (swizzle != SWIZZLE_NOOP) {
        templ.swizzle_r = GET_SWZ(swizzle, 0);
diff --git a/src/mesa/state_tracker/st_extensions.c 
b/src/mesa/state_tracker/st_extensions.c
index e7cf4f3..5011e97 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -673,7 +673,13 @@ void st_init_extensions(struct st_context *st)
        ctx->Extensions.ARB_map_buffer_alignment = GL_TRUE;
     }
     if (screen->get_param(screen, PIPE_CAP_TEXTURE_BUFFER_OBJECTS)) {
+      ctx->Const.TextureBufferOffsetAlignment =
+         screen->get_param(screen, PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT);
+
        ctx->Extensions.ARB_texture_buffer_object = GL_TRUE;
+      if (ctx->Const.TextureBufferOffsetAlignment)
+         ctx->Extensions.ARB_texture_buffer_range = GL_TRUE;
+
        init_format_extensions(st, tbo_rgb32, Elements(tbo_rgb32),
                               PIPE_BUFFER, PIPE_BIND_SAMPLER_VIEW);
     }

I'd re-order the lines in that last chunk:

  if (screen->get_param(screen, PIPE_CAP_TEXTURE_BUFFER_OBJECTS)) {
     ctx->Extensions.ARB_texture_buffer_object = GL_TRUE;

     ctx->Const.TextureBufferOffsetAlignment =
screen->get_param(screen, PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT);

     if (ctx->Const.TextureBufferOffsetAlignment)
        ctx->Extensions.ARB_texture_buffer_range = GL_TRUE;
  ...


Otherwise, for patches 2 and 3, Reviewed-by: Brian Paul <bri...@vmware.com>

-Brian
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to