st/mesa: implement Driver.InvalidateBufferSubData
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Sat, 9 Jan 2016 23:05:58 +0000 (18:05 -0500)
committerNicolai Hähnle <nicolai.haehnle@amd.com>
Thu, 14 Jan 2016 14:39:57 +0000 (09:39 -0500)
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/mesa/state_tracker/st_cb_bufferobjects.c
src/mesa/state_tracker/st_cb_bufferobjects.h
src/mesa/state_tracker/st_context.c

index 0c5fecea51fec81947ea926661040c752915d540..68be8ba64ac8e51fe76ffd331f68bbc798fa3db0 100644 (file)
@@ -332,6 +332,31 @@ st_bufferobj_data(struct gl_context *ctx,
 }
 
 
+/**
+ * Called via glInvalidateBuffer(Sub)Data.
+ */
+static void
+st_bufferobj_invalidate(struct gl_context *ctx,
+                        struct gl_buffer_object *obj,
+                        GLintptr offset,
+                        GLsizeiptr size)
+{
+   struct st_context *st = st_context(ctx);
+   struct pipe_context *pipe = st->pipe;
+   struct st_buffer_object *st_obj = st_buffer_object(obj);
+
+   /* We ignore partial invalidates. */
+   if (offset != 0 || size != obj->Size)
+      return;
+
+   /* Nothing to invalidate. */
+   if (!st_obj->buffer)
+      return;
+
+   pipe->invalidate_resource(pipe, st_obj->buffer);
+}
+
+
 /**
  * Called via glMapBufferRange().
  */
@@ -517,7 +542,8 @@ st_bufferobj_validate_usage(struct st_context *st,
 
 
 void
-st_init_bufferobject_functions(struct dd_function_table *functions)
+st_init_bufferobject_functions(struct pipe_screen *screen,
+                               struct dd_function_table *functions)
 {
    /* plug in default driver fallbacks (such as for ClearBufferSubData) */
    _mesa_init_buffer_object_functions(functions);
@@ -532,4 +558,7 @@ st_init_bufferobject_functions(struct dd_function_table *functions)
    functions->UnmapBuffer = st_bufferobj_unmap;
    functions->CopyBufferSubData = st_copy_buffer_subdata;
    functions->ClearBufferSubData = st_clear_buffer_subdata;
+
+   if (screen->get_param(screen, PIPE_CAP_INVALIDATE_BUFFER))
+      functions->InvalidateBufferSubData = st_bufferobj_invalidate;
 }
index 647efe4cc9c4958be595fd5b090befe3f35ddd01..f55e2ef542bee172144569d73830964ce2783d37 100644 (file)
@@ -62,7 +62,8 @@ st_bufferobj_validate_usage(struct st_context *st,
 
 
 extern void
-st_init_bufferobject_functions(struct dd_function_table *functions);
+st_init_bufferobject_functions(struct pipe_screen *screen,
+                               struct dd_function_table *functions);
 
 
 #endif
index 87193a9d478f17e94b6cd701ffa9dc775d69a4ce..4add50e3ed9369298480352917414bd157f850fa 100644 (file)
@@ -446,7 +446,7 @@ void st_init_driver_functions(struct pipe_screen *screen,
    _mesa_init_sampler_object_functions(functions);
 
    st_init_blit_functions(functions);
-   st_init_bufferobject_functions(functions);
+   st_init_bufferobject_functions(screen, functions);
    st_init_clear_functions(functions);
    st_init_bitmap_functions(functions);
    st_init_copy_image_functions(functions);