i965: Add support for GL_ARB_texture_buffer_range.
authorEric Anholt <eric@anholt.net>
Sat, 5 Oct 2013 00:46:04 +0000 (17:46 -0700)
committerEric Anholt <eric@anholt.net>
Wed, 23 Oct 2013 22:33:10 +0000 (15:33 -0700)
Supporting this extension turns out to simplify our code a bit over not
supporting this extension, once the glBufferSubData() synchronization code
lands.

v2: Use 16 byte alignment like we do for uniform buffers, due to unaligned
    access penalties.

Reviewed-by: Jordan Justen <jordan.l.justen@intel.com> (v1)
docs/GL3.txt
src/mesa/drivers/dri/i965/brw_context.c
src/mesa/drivers/dri/i965/brw_wm_surface_state.c
src/mesa/drivers/dri/i965/gen7_wm_surface_state.c
src/mesa/drivers/dri/i965/intel_extensions.c

index af75b0946196250d4ca5614cccf036fec8d00c9f..ff28ea6a813adab7ccc5878095956d58bfe6f31a 100644 (file)
@@ -157,7 +157,7 @@ ARB_robust_buffer_access_behavior                    not started
 ARB_shader_image_size                                not started
 ARB_shader_storage_buffer_object                     not started
 ARB_stencil_texturing                                not started
-ARB_texture_buffer_range                             DONE (nv50, nvc0)
+ARB_texture_buffer_range                             DONE (nv50, nvc0, i965)
 ARB_texture_query_levels                             DONE (i965)
 ARB_texture_storage_multisample                      DONE (i965)
 ARB_texture_view                                     not started
index 55856b3663794924613310a629e86f137ffcf37d..cb82fb042ef39411f99c9097b4f278c25997fbd0 100644 (file)
@@ -394,7 +394,18 @@ brw_initialize_context_constants(struct brw_context *brw)
 
    ctx->Const.NativeIntegers = true;
    ctx->Const.UniformBooleanTrue = 1;
+
+   /* From the gen4 PRM, volume 4 page 127:
+    *
+    *     "For SURFTYPE_BUFFER non-rendertarget surfaces, this field specifies
+    *      the base address of the first element of the surface, computed in
+    *      software by adding the surface base address to the byte offset of
+    *      the element in the buffer."
+    *
+    * However, unaligned accesses are slower, so enforce buffer alignment.
+    */
    ctx->Const.UniformBufferOffsetAlignment = 16;
+   ctx->Const.TextureBufferOffsetAlignment = 16;
 
    if (brw->gen >= 6) {
       ctx->Const.MaxVarying = 32;
index c7a0be5975056f6e254531b59eecdea68cfbdc14..a78ebf00405ede34e6e55f21098fd3a9d317e441 100644 (file)
@@ -232,20 +232,27 @@ brw_update_buffer_texture_surface(struct gl_context *ctx,
    struct gl_texture_object *tObj = ctx->Texture.Unit[unit]._Current;
    struct intel_buffer_object *intel_obj =
       intel_buffer_object(tObj->BufferObject);
-   drm_intel_bo *bo = intel_obj ? intel_obj->buffer : NULL;
+   uint32_t size = tObj->BufferSize;
+   drm_intel_bo *bo = NULL;
    gl_format format = tObj->_BufferObjectFormat;
    uint32_t brw_format = brw_format_for_mesa_format(format);
    int texel_size = _mesa_get_format_bytes(format);
-   int w = intel_obj ? intel_obj->Base.Size / texel_size : 0;
+
+   if (intel_obj) {
+      bo = intel_obj->buffer;
+      size = MIN2(size, intel_obj->Base.Size);
+   }
 
    if (brw_format == 0 && format != MESA_FORMAT_RGBA_FLOAT32) {
       _mesa_problem(NULL, "bad format %s for texture buffer\n",
                    _mesa_get_format_name(format));
    }
 
-   gen4_emit_buffer_surface_state(brw, surf_offset, bo, 0,
+   gen4_emit_buffer_surface_state(brw, surf_offset, bo,
+                                  tObj->BufferOffset,
                                   brw_format,
-                                  w, texel_size);
+                                  size / texel_size,
+                                  texel_size);
 }
 
 static void
index 4488d48e59bd589853181c2457f0f655afe360ec..9880c14dd1b871e72a952920149ad0ff91a546be 100644 (file)
@@ -274,7 +274,14 @@ gen7_update_buffer_texture_surface(struct gl_context *ctx,
    struct gl_texture_object *tObj = ctx->Texture.Unit[unit]._Current;
    struct intel_buffer_object *intel_obj =
       intel_buffer_object(tObj->BufferObject);
-   drm_intel_bo *bo = intel_obj ? intel_obj->buffer : NULL;
+   uint32_t size = tObj->BufferSize;
+   drm_intel_bo *bo = NULL;
+
+   if (intel_obj) {
+      bo = intel_obj->buffer;
+      size = MIN2(size, intel_obj->Base.Size);
+   }
+
    gl_format format = tObj->_BufferObjectFormat;
 
    uint32_t surface_format = brw_format_for_mesa_format(format);
@@ -284,14 +291,13 @@ gen7_update_buffer_texture_surface(struct gl_context *ctx,
    }
 
    int texel_size = _mesa_get_format_bytes(format);
-   int w = intel_obj ? intel_obj->Base.Size / texel_size : 0;
 
    gen7_emit_buffer_surface_state(brw,
                                   surf_offset,
                                   bo,
-                                  0,
+                                  tObj->BufferOffset,
                                   surface_format,
-                                  w,
+                                  size / texel_size,
                                   texel_size,
                                   0 /* mocs */);
 }
index 87cc87d4f5ffbedfb11b217104157cc30684a0af..22e4aa2c5ad2a5cc248243240ae0055330b79cd2 100644 (file)
@@ -147,6 +147,7 @@ intelInitExtensions(struct gl_context *ctx)
       ctx->Extensions.ARB_shading_language_420pack = true;
       ctx->Extensions.ARB_texture_buffer_object = true;
       ctx->Extensions.ARB_texture_buffer_object_rgb32 = true;
+      ctx->Extensions.ARB_texture_buffer_range = true;
       ctx->Extensions.ARB_texture_cube_map_array = true;
       ctx->Extensions.OES_depth_texture_cube_map = true;
       ctx->Extensions.ARB_shading_language_packing = true;