[Mesa-dev] [PATCH 1/5] st/mesa: move utility functions, macros into new st_util.h file

Brian Paul brianp at vmware.com
Fri Mar 8 15:52:49 UTC 2019


To de-clutter st_context.h.

Clean up remaining function prototypes in st_context.h.

The st_vp_uses_current_values() helper is only used in st_context.c
so move it there.

The st_get_active_states() function is only used in st_context.c so
remove its prototype in st_context.h
---
 src/mesa/Makefile.sources                       |   1 +
 src/mesa/meson.build                            |   1 +
 src/mesa/state_tracker/st_atom.c                |   2 +
 src/mesa/state_tracker/st_atom_framebuffer.c    |   1 +
 src/mesa/state_tracker/st_atom_msaa.c           |   1 +
 src/mesa/state_tracker/st_atom_rasterizer.c     |   1 +
 src/mesa/state_tracker/st_atom_scissor.c        |   1 +
 src/mesa/state_tracker/st_atom_viewport.c       |   1 +
 src/mesa/state_tracker/st_cb_bitmap.c           |   1 +
 src/mesa/state_tracker/st_cb_blit.c             |   1 +
 src/mesa/state_tracker/st_cb_bufferobjects.c    |   1 +
 src/mesa/state_tracker/st_cb_clear.c            |   1 +
 src/mesa/state_tracker/st_cb_compute.c          |   1 +
 src/mesa/state_tracker/st_cb_copyimage.c        |   1 +
 src/mesa/state_tracker/st_cb_drawpixels.c       |   1 +
 src/mesa/state_tracker/st_cb_drawtex.c          |   1 +
 src/mesa/state_tracker/st_cb_fbo.c              |   1 +
 src/mesa/state_tracker/st_cb_feedback.c         |   1 +
 src/mesa/state_tracker/st_cb_memoryobjects.c    |   1 +
 src/mesa/state_tracker/st_cb_perfmon.c          |   1 +
 src/mesa/state_tracker/st_cb_program.c          |   1 +
 src/mesa/state_tracker/st_cb_queryobj.c         |   1 +
 src/mesa/state_tracker/st_cb_rasterpos.c        |   1 +
 src/mesa/state_tracker/st_cb_readpixels.c       |   2 +
 src/mesa/state_tracker/st_cb_semaphoreobjects.c |   1 +
 src/mesa/state_tracker/st_cb_texture.c          |   1 +
 src/mesa/state_tracker/st_context.c             |  11 ++-
 src/mesa/state_tracker/st_context.h             | 118 ++++++------------------
 src/mesa/state_tracker/st_draw.c                |   1 +
 src/mesa/state_tracker/st_draw_feedback.c       |   1 +
 src/mesa/state_tracker/st_gen_mipmap.c          |   1 +
 src/mesa/state_tracker/st_shader_cache.c        |   1 +
 src/mesa/state_tracker/st_util.h                | 114 +++++++++++++++++++++++
 33 files changed, 184 insertions(+), 91 deletions(-)
 create mode 100644 src/mesa/state_tracker/st_util.h

diff --git a/src/mesa/Makefile.sources b/src/mesa/Makefile.sources
index d554408..89bcfe4 100644
--- a/src/mesa/Makefile.sources
+++ b/src/mesa/Makefile.sources
@@ -556,6 +556,7 @@ STATETRACKER_FILES = \
 	state_tracker/st_texture.h \
 	state_tracker/st_tgsi_lower_yuv.c \
 	state_tracker/st_tgsi_lower_yuv.h \
+	state_tracker/st_util.h \
 	state_tracker/st_vdpau.c \
 	state_tracker/st_vdpau.h
 
diff --git a/src/mesa/meson.build b/src/mesa/meson.build
index 05a8bb5..2d9b673 100644
--- a/src/mesa/meson.build
+++ b/src/mesa/meson.build
@@ -600,6 +600,7 @@ files_libmesa_gallium = files(
   'state_tracker/st_texture.h',
   'state_tracker/st_tgsi_lower_yuv.c',
   'state_tracker/st_tgsi_lower_yuv.h',
+  'state_tracker/st_util.h',
   'state_tracker/st_vdpau.c',
   'state_tracker/st_vdpau.h',
 )
diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c
index df1a94e..49f79ad 100644
--- a/src/mesa/state_tracker/st_atom.c
+++ b/src/mesa/state_tracker/st_atom.c
@@ -36,6 +36,8 @@
 #include "st_atom.h"
 #include "st_program.h"
 #include "st_manager.h"
+#include "st_util.h"
+
 
 typedef void (*update_func_t)(struct st_context *st);
 
diff --git a/src/mesa/state_tracker/st_atom_framebuffer.c b/src/mesa/state_tracker/st_atom_framebuffer.c
index a0dd0d1..f18c40d 100644
--- a/src/mesa/state_tracker/st_atom_framebuffer.c
+++ b/src/mesa/state_tracker/st_atom_framebuffer.c
@@ -38,6 +38,7 @@
 #include "st_cb_bitmap.h"
 #include "st_cb_fbo.h"
 #include "st_texture.h"
+#include "st_util.h"
 #include "pipe/p_context.h"
 #include "cso_cache/cso_context.h"
 #include "util/u_math.h"
diff --git a/src/mesa/state_tracker/st_atom_msaa.c b/src/mesa/state_tracker/st_atom_msaa.c
index c6affec..594e639 100644
--- a/src/mesa/state_tracker/st_atom_msaa.c
+++ b/src/mesa/state_tracker/st_atom_msaa.c
@@ -31,6 +31,7 @@
 #include "pipe/p_context.h"
 #include "st_atom.h"
 #include "st_program.h"
+#include "st_util.h"
 
 #include "cso_cache/cso_context.h"
 #include "util/u_framebuffer.h"
diff --git a/src/mesa/state_tracker/st_atom_rasterizer.c b/src/mesa/state_tracker/st_atom_rasterizer.c
index 2bffa68..fee992e 100644
--- a/src/mesa/state_tracker/st_atom_rasterizer.c
+++ b/src/mesa/state_tracker/st_atom_rasterizer.c
@@ -37,6 +37,7 @@
 #include "st_atom.h"
 #include "st_debug.h"
 #include "st_program.h"
+#include "st_util.h"
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
 #include "cso_cache/cso_context.h"
diff --git a/src/mesa/state_tracker/st_atom_scissor.c b/src/mesa/state_tracker/st_atom_scissor.c
index a87d029..04135a3 100644
--- a/src/mesa/state_tracker/st_atom_scissor.c
+++ b/src/mesa/state_tracker/st_atom_scissor.c
@@ -36,6 +36,7 @@
 #include "st_context.h"
 #include "pipe/p_context.h"
 #include "st_atom.h"
+#include "st_util.h"
 
 
 /**
diff --git a/src/mesa/state_tracker/st_atom_viewport.c b/src/mesa/state_tracker/st_atom_viewport.c
index 6e3347e..4a07b2d 100644
--- a/src/mesa/state_tracker/st_atom_viewport.c
+++ b/src/mesa/state_tracker/st_atom_viewport.c
@@ -30,6 +30,7 @@
 #include "main/viewport.h"
 #include "st_context.h"
 #include "st_atom.h"
+#include "st_util.h"
 #include "pipe/p_context.h"
 #include "cso_cache/cso_context.h"
 
diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c
index 7ef0d7e..d7e2ccb 100644
--- a/src/mesa/state_tracker/st_cb_bitmap.c
+++ b/src/mesa/state_tracker/st_cb_bitmap.c
@@ -49,6 +49,7 @@
 #include "st_cb_drawpixels.h"
 #include "st_sampler_view.h"
 #include "st_texture.h"
+#include "st_util.h"
 
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
diff --git a/src/mesa/state_tracker/st_cb_blit.c b/src/mesa/state_tracker/st_cb_blit.c
index 564ad66..cc8649e 100644
--- a/src/mesa/state_tracker/st_cb_blit.c
+++ b/src/mesa/state_tracker/st_cb_blit.c
@@ -41,6 +41,7 @@
 #include "st_cb_fbo.h"
 #include "st_manager.h"
 #include "st_scissor.h"
+#include "st_util.h"
 
 #include "util/u_format.h"
 
diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c
index b05f251..4f77dad 100644
--- a/src/mesa/state_tracker/st_cb_bufferobjects.c
+++ b/src/mesa/state_tracker/st_cb_bufferobjects.c
@@ -43,6 +43,7 @@
 #include "st_cb_bufferobjects.h"
 #include "st_cb_memoryobjects.h"
 #include "st_debug.h"
+#include "st_util.h"
 
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c
index 2de8e49..3a49bd4 100644
--- a/src/mesa/state_tracker/st_cb_clear.c
+++ b/src/mesa/state_tracker/st_cb_clear.c
@@ -50,6 +50,7 @@
 #include "st_format.h"
 #include "st_nir.h"
 #include "st_program.h"
+#include "st_util.h"
 
 #include "pipe/p_context.h"
 #include "pipe/p_shader_tokens.h"
diff --git a/src/mesa/state_tracker/st_cb_compute.c b/src/mesa/state_tracker/st_cb_compute.c
index f91df4b..a99484e 100644
--- a/src/mesa/state_tracker/st_cb_compute.c
+++ b/src/mesa/state_tracker/st_cb_compute.c
@@ -31,6 +31,7 @@
 #include "st_cb_bitmap.h"
 #include "st_cb_bufferobjects.h"
 #include "st_cb_compute.h"
+#include "st_util.h"
 
 #include "pipe/p_context.h"
 
diff --git a/src/mesa/state_tracker/st_cb_copyimage.c b/src/mesa/state_tracker/st_cb_copyimage.c
index 6d3eda0..8c5be50 100644
--- a/src/mesa/state_tracker/st_cb_copyimage.c
+++ b/src/mesa/state_tracker/st_cb_copyimage.c
@@ -27,6 +27,7 @@
 #include "state_tracker/st_cb_copyimage.h"
 #include "state_tracker/st_cb_fbo.h"
 #include "state_tracker/st_texture.h"
+#include "state_tracker/st_util.h"
 
 #include "util/u_box.h"
 #include "util/u_format.h"
diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c
index 119f018..6b7d4f2 100644
--- a/src/mesa/state_tracker/st_cb_drawpixels.c
+++ b/src/mesa/state_tracker/st_cb_drawpixels.c
@@ -65,6 +65,7 @@
 #include "st_sampler_view.h"
 #include "st_scissor.h"
 #include "st_texture.h"
+#include "st_util.h"
 #include "st_nir.h"
 
 #include "pipe/p_context.h"
diff --git a/src/mesa/state_tracker/st_cb_drawtex.c b/src/mesa/state_tracker/st_cb_drawtex.c
index 3c583b3..111767d 100644
--- a/src/mesa/state_tracker/st_cb_drawtex.c
+++ b/src/mesa/state_tracker/st_cb_drawtex.c
@@ -25,6 +25,7 @@
 #include "st_cb_bitmap.h"
 #include "st_cb_drawtex.h"
 #include "st_nir.h"
+#include "st_util.h"
 
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c
index 3bd7fd4..5fe6c79 100644
--- a/src/mesa/state_tracker/st_cb_fbo.c
+++ b/src/mesa/state_tracker/st_cb_fbo.c
@@ -53,6 +53,7 @@
 #include "st_cb_texture.h"
 #include "st_format.h"
 #include "st_texture.h"
+#include "st_util.h"
 #include "st_manager.h"
 
 #include "util/u_format.h"
diff --git a/src/mesa/state_tracker/st_cb_feedback.c b/src/mesa/state_tracker/st_cb_feedback.c
index 6e48be6..ce236c0 100644
--- a/src/mesa/state_tracker/st_cb_feedback.c
+++ b/src/mesa/state_tracker/st_cb_feedback.c
@@ -48,6 +48,7 @@
 #include "st_draw.h"
 #include "st_cb_feedback.h"
 #include "st_program.h"
+#include "st_util.h"
 
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
diff --git a/src/mesa/state_tracker/st_cb_memoryobjects.c b/src/mesa/state_tracker/st_cb_memoryobjects.c
index 39174bc..7e5cd2a 100644
--- a/src/mesa/state_tracker/st_cb_memoryobjects.c
+++ b/src/mesa/state_tracker/st_cb_memoryobjects.c
@@ -29,6 +29,7 @@
 
 #include "st_context.h"
 #include "st_cb_memoryobjects.h"
+#include "st_util.h"
 
 #include "state_tracker/drm_driver.h"
 #include "pipe/p_context.h"
diff --git a/src/mesa/state_tracker/st_cb_perfmon.c b/src/mesa/state_tracker/st_cb_perfmon.c
index 23d32dc..e1873d7 100644
--- a/src/mesa/state_tracker/st_cb_perfmon.c
+++ b/src/mesa/state_tracker/st_cb_perfmon.c
@@ -29,6 +29,7 @@
 #include "st_context.h"
 #include "st_cb_bitmap.h"
 #include "st_cb_perfmon.h"
+#include "st_util.h"
 
 #include "util/bitset.h"
 
diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c
index 825a09d..349ed7f 100644
--- a/src/mesa/state_tracker/st_cb_program.c
+++ b/src/mesa/state_tracker/st_cb_program.c
@@ -47,6 +47,7 @@
 #include "st_cb_program.h"
 #include "st_glsl_to_ir.h"
 #include "st_atifs_to_tgsi.h"
+#include "st_util.h"
 
 
 /**
diff --git a/src/mesa/state_tracker/st_cb_queryobj.c b/src/mesa/state_tracker/st_cb_queryobj.c
index 642b901..460c3e7 100644
--- a/src/mesa/state_tracker/st_cb_queryobj.c
+++ b/src/mesa/state_tracker/st_cb_queryobj.c
@@ -45,6 +45,7 @@
 #include "st_cb_queryobj.h"
 #include "st_cb_bitmap.h"
 #include "st_cb_bufferobjects.h"
+#include "st_util.h"
 
 
 static struct gl_query_object *
diff --git a/src/mesa/state_tracker/st_cb_rasterpos.c b/src/mesa/state_tracker/st_cb_rasterpos.c
index c54b50d..52ead76 100644
--- a/src/mesa/state_tracker/st_cb_rasterpos.c
+++ b/src/mesa/state_tracker/st_cb_rasterpos.c
@@ -49,6 +49,7 @@
 #include "st_draw.h"
 #include "st_program.h"
 #include "st_cb_rasterpos.h"
+#include "st_util.h"
 #include "draw/draw_context.h"
 #include "draw/draw_pipe.h"
 #include "vbo/vbo.h"
diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c
index f614849..e887d8d 100644
--- a/src/mesa/state_tracker/st_cb_readpixels.c
+++ b/src/mesa/state_tracker/st_cb_readpixels.c
@@ -46,6 +46,8 @@
 #include "state_tracker/st_format.h"
 #include "state_tracker/st_pbo.h"
 #include "state_tracker/st_texture.h"
+#include "state_tracker/st_util.h"
+
 
 /* The readpixels cache caches a blitted staging texture so that back-to-back
  * calls to glReadPixels with user pointers require less CPU-GPU synchronization.
diff --git a/src/mesa/state_tracker/st_cb_semaphoreobjects.c b/src/mesa/state_tracker/st_cb_semaphoreobjects.c
index 4a3faf5..4b1f21e 100644
--- a/src/mesa/state_tracker/st_cb_semaphoreobjects.c
+++ b/src/mesa/state_tracker/st_cb_semaphoreobjects.c
@@ -29,6 +29,7 @@
 
 #include "st_context.h"
 #include "st_texture.h"
+#include "st_util.h"
 #include "st_cb_bitmap.h"
 #include "st_cb_bufferobjects.h"
 #include "st_cb_semaphoreobjects.h"
diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
index f16f876..47d0612 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -62,6 +62,7 @@
 #include "state_tracker/st_gen_mipmap.h"
 #include "state_tracker/st_atom.h"
 #include "state_tracker/st_sampler_view.h"
+#include "state_tracker/st_util.h"
 
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index 4545153..68b6ddb 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -78,6 +78,7 @@
 #include "st_shader_cache.h"
 #include "st_vdpau.h"
 #include "st_texture.h"
+#include "st_util.h"
 #include "pipe/p_context.h"
 #include "util/u_cpu_detect.h"
 #include "util/u_inlines.h"
@@ -132,7 +133,7 @@ st_query_memory_info(struct gl_context *ctx, struct gl_memory_info *out)
 }
 
 
-uint64_t
+static uint64_t
 st_get_active_states(struct gl_context *ctx)
 {
    struct st_vertex_program *vp =
@@ -184,6 +185,14 @@ st_invalidate_buffers(struct st_context *st)
 }
 
 
+static inline bool
+st_vp_uses_current_values(const struct gl_context *ctx)
+{
+   const uint64_t inputs = ctx->VertexProgram._Current->info.inputs_read;
+   return _mesa_draw_current_bits(ctx) & inputs;
+}
+
+
 /**
  * Called via ctx->Driver.UpdateState()
  */
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index 324a7f2..58a1ead 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -54,14 +54,6 @@ struct st_perf_monitor_group;
 struct u_upload_mgr;
 
 
-/** For drawing quads for glClear, glDraw/CopyPixels, glBitmap, etc. */
-struct st_util_vertex
-{
-   float x, y, z;
-   float r, g, b, a;
-   float s, t;
-};
-
 struct st_bitmap_cache
 {
    /** Window pos to render the cached image */
@@ -317,14 +309,40 @@ struct st_context
 };
 
 
-/* Need this so that we can implement Mesa callbacks in this module.
+/*
+ * Get the state tracker context for the given Mesa context.
  */
-static inline struct st_context *st_context(struct gl_context *ctx)
+static inline struct st_context *
+st_context(struct gl_context *ctx)
 {
    return ctx->st;
 }
 
 
+extern struct st_context *
+st_create_context(gl_api api, struct pipe_context *pipe,
+                  const struct gl_config *visual,
+                  struct st_context *share,
+                  const struct st_config_options *options,
+                  bool no_error);
+
+extern void
+st_destroy_context(struct st_context *st);
+
+
+extern void
+st_init_driver_functions(struct pipe_screen *screen,
+                         struct dd_function_table *functions);
+
+
+extern void
+st_invalidate_buffers(struct st_context *st);
+
+
+extern uint64_t
+st_get_active_states(struct gl_context *ctx);
+
+
 /**
  * Wrapper for struct gl_framebuffer.
  * This is an opaque type to the outside world.
@@ -345,86 +363,6 @@ struct st_framebuffer
 };
 
 
-extern void st_init_driver_functions(struct pipe_screen *screen,
-                                     struct dd_function_table *functions);
-
-void
-st_invalidate_buffers(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).
-       *
-       * Negate Y scale to flip image vertically.
-       * The NDC Y coords prior to viewport transformation are in the range
-       * [y=-1=bottom, y=1=top]
-       * Hardware window coords are in the range [y=0=top, y=H-1=bottom] where
-       * H is the window height.
-       * Use the viewport transformation to invert Y.
-       */
-      return Y_0_TOP;
-   }
-   else {
-      /* Drawing into user-created FBO (very likely a texture).
-       *
-       * For textures, T=0=Bottom, so by extension Y=0=Bottom for rendering.
-       */
-      return Y_0_BOTTOM;
-   }
-}
-
-
-static inline bool
-st_user_clip_planes_enabled(struct gl_context *ctx)
-{
-   return (ctx->API == API_OPENGL_COMPAT ||
-           ctx->API == API_OPENGLES) && /* only ES 1.x */
-          ctx->Transform.ClipPlanesEnabled;
-}
-
-
-static inline bool
-st_vp_uses_current_values(const struct gl_context *ctx)
-{
-   const uint64_t inputs = ctx->VertexProgram._Current->info.inputs_read;
-   return _mesa_draw_current_bits(ctx) & inputs;
-}
-
-/** clear-alloc a struct-sized object, with casting */
-#define ST_CALLOC_STRUCT(T)   (struct T *) calloc(1, sizeof(struct T))
-
-
-extern struct st_context *
-st_create_context(gl_api api, struct pipe_context *pipe,
-                  const struct gl_config *visual,
-                  struct st_context *share,
-                  const struct st_config_options *options,
-                  bool no_error);
-
-extern void
-st_destroy_context(struct st_context *st);
-
-uint64_t
-st_get_active_states(struct gl_context *ctx);
-
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c
index 0a190bd..7485fc8 100644
--- a/src/mesa/state_tracker/st_draw.c
+++ b/src/mesa/state_tracker/st_draw.c
@@ -55,6 +55,7 @@
 #include "st_debug.h"
 #include "st_draw.h"
 #include "st_program.h"
+#include "st_util.h"
 
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
diff --git a/src/mesa/state_tracker/st_draw_feedback.c b/src/mesa/state_tracker/st_draw_feedback.c
index b83f638..275e109 100644
--- a/src/mesa/state_tracker/st_draw_feedback.c
+++ b/src/mesa/state_tracker/st_draw_feedback.c
@@ -39,6 +39,7 @@
 #include "st_cb_bufferobjects.h"
 #include "st_draw.h"
 #include "st_program.h"
+#include "st_util.h"
 
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c
index 3f10587..d6e9136 100644
--- a/src/mesa/state_tracker/st_gen_mipmap.c
+++ b/src/mesa/state_tracker/st_gen_mipmap.c
@@ -40,6 +40,7 @@
 #include "st_debug.h"
 #include "st_context.h"
 #include "st_texture.h"
+#include "st_util.h"
 #include "st_gen_mipmap.h"
 #include "st_cb_bitmap.h"
 #include "st_cb_texture.h"
diff --git a/src/mesa/state_tracker/st_shader_cache.c b/src/mesa/state_tracker/st_shader_cache.c
index c82ce3e..b188297 100644
--- a/src/mesa/state_tracker/st_shader_cache.c
+++ b/src/mesa/state_tracker/st_shader_cache.c
@@ -25,6 +25,7 @@
 #include "st_debug.h"
 #include "st_program.h"
 #include "st_shader_cache.h"
+#include "st_util.h"
 #include "compiler/glsl/program.h"
 #include "compiler/nir/nir.h"
 #include "compiler/nir/nir_serialize.h"
diff --git a/src/mesa/state_tracker/st_util.h b/src/mesa/state_tracker/st_util.h
new file mode 100644
index 0000000..b6454e5
--- /dev/null
+++ b/src/mesa/state_tracker/st_util.h
@@ -0,0 +1,114 @@
+/**************************************************************************
+ *
+ * Copyright 2019 VMware, Inc.
+ * 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 VMWARE 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.
+ *
+ **************************************************************************/
+
+
+/*
+ * Miscellantous state tracker utility functions, macros.
+ */
+
+
+#ifndef ST_UTIL
+#define ST_UTIL
+
+
+#include "state_tracker/st_context.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/** For drawing quads for glClear, glDraw/CopyPixels, glBitmap, etc. */
+struct st_util_vertex
+{
+   float x, y, z;
+   float r, g, b, a;
+   float s, t;
+};
+
+
+
+/* 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).
+       *
+       * Negate Y scale to flip image vertically.
+       * The NDC Y coords prior to viewport transformation are in the range
+       * [y=-1=bottom, y=1=top]
+       * Hardware window coords are in the range [y=0=top, y=H-1=bottom] where
+       * H is the window height.
+       * Use the viewport transformation to invert Y.
+       */
+      return Y_0_TOP;
+   }
+   else {
+      /* Drawing into user-created FBO (very likely a texture).
+       *
+       * For textures, T=0=Bottom, so by extension Y=0=Bottom for rendering.
+       */
+      return Y_0_BOTTOM;
+   }
+}
+
+
+static inline bool
+st_user_clip_planes_enabled(struct gl_context *ctx)
+{
+   return (ctx->API == API_OPENGL_COMPAT ||
+           ctx->API == API_OPENGLES) && /* only ES 1.x */
+          ctx->Transform.ClipPlanesEnabled;
+}
+
+
+/** clear-alloc a struct-sized object, with casting */
+#define ST_CALLOC_STRUCT(T)   (struct T *) calloc(1, sizeof(struct T))
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* ST_UTIL */
-- 
1.8.5.6



More information about the mesa-dev mailing list