[Mesa-dev] [PATCH 4/7] st/mesa: inline and optimize st_invalidate_readpix_cache

Marek Olšák maraeo at gmail.com
Fri Apr 14 15:07:11 UTC 2017


From: Marek Olšák <marek.olsak at amd.com>

---
 src/mesa/state_tracker/st_cb_readpixels.c |  8 --------
 src/mesa/state_tracker/st_context.h       | 13 +++++++++++--
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c
index 795519d..0bcf2eb 100644
--- a/src/mesa/state_tracker/st_cb_readpixels.c
+++ b/src/mesa/state_tracker/st_cb_readpixels.c
@@ -244,28 +244,20 @@ try_pbo_readpixels(struct st_context *st, struct st_renderbuffer *strb,
    /* Buffer written via shader images needs explicit synchronization. */
    pipe->memory_barrier(pipe, PIPE_BARRIER_ALL);
 
 fail:
    cso_restore_state(cso);
    cso_restore_constant_buffer_slot0(cso, PIPE_SHADER_FRAGMENT);
 
    return success;
 }
 
-/* Invalidate the readpixels cache to ensure we don't read stale data.
- */
-void st_invalidate_readpix_cache(struct st_context *st)
-{
-   pipe_resource_reference(&st->readpix_cache.src, NULL);
-   pipe_resource_reference(&st->readpix_cache.cache, NULL);
-}
-
 /**
  * Create a staging texture and blit the requested region to it.
  */
 static struct pipe_resource *
 blit_to_staging(struct st_context *st, struct st_renderbuffer *strb,
                    bool invert_y,
                    GLint x, GLint y, GLsizei width, GLsizei height,
                    GLenum format,
                    enum pipe_format src_format, enum pipe_format dst_format)
 {
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index bb00384..dfee927 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -22,24 +22,24 @@
  * 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_CONTEXT_H
 #define ST_CONTEXT_H
 
 #include "main/mtypes.h"
-#include "pipe/p_state.h"
 #include "state_tracker/st_api.h"
 #include "main/fbobject.h"
 #include "state_tracker/st_atom.h"
+#include "util/u_inlines.h"
 
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 
 struct bitmap_cache;
 struct dd_function_table;
 struct draw_context;
@@ -280,21 +280,30 @@ struct st_framebuffer
    int32_t stamp;
    int32_t iface_stamp;
 };
 
 
 extern void st_init_driver_functions(struct pipe_screen *screen,
                                      struct dd_function_table *functions);
 
 void st_invalidate_state(struct gl_context * ctx, GLbitfield new_state);
 
-void st_invalidate_readpix_cache(struct st_context *st);
+/* Invalidate the readpixels cache to ensure we don't read stale data.
+ */
+static inline void
+st_invalidate_readpix_cache(struct st_context *st)
+{
+   if (unlikely(st->readpix_cache.src)) {
+      pipe_resource_reference(&st->readpix_cache.src, NULL);
+      pipe_resource_reference(&st->readpix_cache.cache, NULL);
+   }
+}
 
 
 #define Y_0_TOP 1
 #define Y_0_BOTTOM 2
 
 static inline GLuint
 st_fb_orientation(const struct gl_framebuffer *fb)
 {
    if (fb && _mesa_is_winsys_fbo(fb)) {
       /* Drawing into a window (on-screen buffer).
-- 
2.7.4



More information about the mesa-dev mailing list