st/mesa: add support for GL_ARB_texture_buffer_range
authorChristoph Bumiller <e0425955@student.tuwien.ac.at>
Sat, 22 Dec 2012 12:46:27 +0000 (13:46 +0100)
committerChristoph Bumiller <e0425955@student.tuwien.ac.at>
Wed, 30 Jan 2013 12:10:11 +0000 (13:10 +0100)
v2: Update to handle BufferSize being -1 and return a NULL sampler
view if the specified range would cause out of bounds access.

Reviewed-by: Brian Paul <brianp@vmware.com>
Acked-by: Ian Romanick <ian.d.romanick@intel.com>
src/mesa/state_tracker/st_atom_texture.c
src/mesa/state_tracker/st_extensions.c

index dba1d829c200b32614cd83fdf925da2e165173d1..4b43b2a7da22076fe0bdc46d7e0bb1bb3d6f423e 100644 (file)
@@ -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);
index 34c0d7b40520ac9ed2aa5f2b6d30e998c92de0f6..214588f1fdf2bbe1a4b2d219e7d6b6521788c429 100644 (file)
@@ -685,6 +685,13 @@ void st_init_extensions(struct st_context *st)
    }
    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;
+
       init_format_extensions(st, tbo_rgb32, Elements(tbo_rgb32),
                              PIPE_BUFFER, PIPE_BIND_SAMPLER_VIEW);
    }