[Mesa-dev] [PATCH 2/2] gallium: add NV_texture_barrier support to the interface and st/mesa

Marek Olšák maraeo at gmail.com
Thu Mar 10 21:05:42 PST 2011


---
 src/gallium/docs/source/context.rst           |   14 ++++++
 src/gallium/include/pipe/p_context.h          |    3 +
 src/mesa/SConscript                           |    1 +
 src/mesa/sources.mak                          |    1 +
 src/mesa/state_tracker/st_cb_texturebarrier.c |   60 +++++++++++++++++++++++++
 src/mesa/state_tracker/st_cb_texturebarrier.h |   37 +++++++++++++++
 src/mesa/state_tracker/st_context.c           |    2 +
 src/mesa/state_tracker/st_extensions.c        |    4 ++
 8 files changed, 122 insertions(+), 0 deletions(-)
 create mode 100644 src/mesa/state_tracker/st_cb_texturebarrier.c
 create mode 100644 src/mesa/state_tracker/st_cb_texturebarrier.h

diff --git a/src/gallium/docs/source/context.rst b/src/gallium/docs/source/context.rst
index c6812cd..a12452f 100644
--- a/src/gallium/docs/source/context.rst
+++ b/src/gallium/docs/source/context.rst
@@ -408,6 +408,20 @@ The width0 is redefined to ``MAX2(width0, offset+size)``.
 
 
 
+.. _resource_read_after_write_hazard
+
+resource_read_after_write_hazard
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+This function flushes any pending writes to and invalidates any read caches
+of the given resource, so that the next rendering operation can see and read
+the data written in the last operation. In 3D, this usually means flushing
+the surface write cache and invalidating the sampler read cache.
+If the resource is NULL, all caches of the currently-set surfaces and
+samplers are flushed and invalidated.
+
+
+
 .. _pipe_transfer:
 
 PIPE_TRANSFER
diff --git a/src/gallium/include/pipe/p_context.h b/src/gallium/include/pipe/p_context.h
index 211f99f..15073e7 100644
--- a/src/gallium/include/pipe/p_context.h
+++ b/src/gallium/include/pipe/p_context.h
@@ -390,6 +390,9 @@ struct pipe_context {
                                 struct pipe_resource *,
                                 unsigned offset,
                                 unsigned size);
+
+   void (*resource_read_after_write_hazard)(struct pipe_context *,
+                                            struct pipe_resource *);
 };
 
 
diff --git a/src/mesa/SConscript b/src/mesa/SConscript
index dc1a180..1d34892 100644
--- a/src/mesa/SConscript
+++ b/src/mesa/SConscript
@@ -201,6 +201,7 @@ statetracker_sources = [
     'state_tracker/st_cb_syncobj.c',
     'state_tracker/st_cb_strings.c',
     'state_tracker/st_cb_texture.c',
+    'state_tracker/st_cb_texturebarrier.c',
     'state_tracker/st_cb_viewport.c',
     'state_tracker/st_cb_xformfb.c',
     'state_tracker/st_context.c',
diff --git a/src/mesa/sources.mak b/src/mesa/sources.mak
index 4bd4ca4..577d592 100644
--- a/src/mesa/sources.mak
+++ b/src/mesa/sources.mak
@@ -219,6 +219,7 @@ STATETRACKER_SOURCES = \
 	state_tracker/st_cb_syncobj.c \
 	state_tracker/st_cb_strings.c \
 	state_tracker/st_cb_texture.c \
+	state_tracker/st_cb_texturebarrier.c \
 	state_tracker/st_cb_viewport.c \
 	state_tracker/st_cb_xformfb.c \
 	state_tracker/st_context.c \
diff --git a/src/mesa/state_tracker/st_cb_texturebarrier.c b/src/mesa/state_tracker/st_cb_texturebarrier.c
new file mode 100644
index 0000000..c3369d8
--- /dev/null
+++ b/src/mesa/state_tracker/st_cb_texturebarrier.c
@@ -0,0 +1,60 @@
+/**************************************************************************
+ *
+ * Copyright 2011 Marek Olšák <maraeo at gmail.com>
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+/**
+ * glTextureBarrierNV function
+ *
+ * \author Marek Olšák
+ */
+
+
+#include "main/imports.h"
+#include "main/context.h"
+
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+#include "st_context.h"
+#include "st_cb_texturebarrier.h"
+
+
+/**
+ * Called via ctx->Driver.TextureBarrier()
+ */
+static void
+st_TextureBarrier(struct gl_context *ctx)
+{
+   struct pipe_context *pipe = st_context(ctx)->pipe;
+
+   pipe->resource_read_after_write_hazard(pipe, NULL);
+}
+
+
+void st_init_texture_barrier_functions(struct dd_function_table *functions)
+{
+   functions->TextureBarrier = st_TextureBarrier;
+}
diff --git a/src/mesa/state_tracker/st_cb_texturebarrier.h b/src/mesa/state_tracker/st_cb_texturebarrier.h
new file mode 100644
index 0000000..3b7d377
--- /dev/null
+++ b/src/mesa/state_tracker/st_cb_texturebarrier.h
@@ -0,0 +1,37 @@
+/**************************************************************************
+ *
+ * Copyright 2011 Marek Olšák <maraeo at gmail.com>
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#ifndef ST_CB_TEXTUREBARRIER_H
+#define ST_CB_TEXTUREBARRIER_H
+
+
+struct dd_function_table;
+
+extern void st_init_texture_barrier_functions(struct dd_function_table *functions);
+
+
+#endif
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index 60972e0..5a39ab0 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -53,6 +53,7 @@
 #include "st_cb_flush.h"
 #include "st_cb_syncobj.h"
 #include "st_cb_strings.h"
+#include "st_cb_texturebarrier.h"
 #include "st_cb_viewport.h"
 #include "st_atom.h"
 #include "st_draw.h"
@@ -288,6 +289,7 @@ void st_init_driver_functions(struct dd_function_table *functions)
    st_init_cond_render_functions(functions);
    st_init_readpixels_functions(functions);
    st_init_texture_functions(functions);
+   st_init_texture_barrier_functions(functions);
    st_init_flush_functions(functions);
    st_init_string_functions(functions);
    st_init_viewport_functions(functions);
diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c
index a83e5db..0a2e4fd 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -526,4 +526,8 @@ void st_init_extensions(struct st_context *st)
    if (screen->fence_finish) {
       ctx->Extensions.ARB_sync = GL_TRUE;
    }
+
+   if (st->pipe->resource_read_after_write_hazard) {
+      ctx->Extensions.NV_texture_barrier = GL_TRUE;
+   }
 }
-- 
1.7.1



More information about the mesa-dev mailing list