st/mesa: move utility functions, macros into new st_util.h file
authorBrian Paul <brianp@vmware.com>
Thu, 7 Mar 2019 16:21:53 +0000 (09:21 -0700)
committerBrian Paul <brianp@vmware.com>
Tue, 12 Mar 2019 02:08:16 +0000 (20:08 -0600)
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

Reviewed-by: Neha Bhende <bhenden@vmware.com>
33 files changed:
src/mesa/Makefile.sources
src/mesa/meson.build
src/mesa/state_tracker/st_atom.c
src/mesa/state_tracker/st_atom_framebuffer.c
src/mesa/state_tracker/st_atom_msaa.c
src/mesa/state_tracker/st_atom_rasterizer.c
src/mesa/state_tracker/st_atom_scissor.c
src/mesa/state_tracker/st_atom_viewport.c
src/mesa/state_tracker/st_cb_bitmap.c
src/mesa/state_tracker/st_cb_blit.c
src/mesa/state_tracker/st_cb_bufferobjects.c
src/mesa/state_tracker/st_cb_clear.c
src/mesa/state_tracker/st_cb_compute.c
src/mesa/state_tracker/st_cb_copyimage.c
src/mesa/state_tracker/st_cb_drawpixels.c
src/mesa/state_tracker/st_cb_drawtex.c
src/mesa/state_tracker/st_cb_fbo.c
src/mesa/state_tracker/st_cb_feedback.c
src/mesa/state_tracker/st_cb_memoryobjects.c
src/mesa/state_tracker/st_cb_perfmon.c
src/mesa/state_tracker/st_cb_program.c
src/mesa/state_tracker/st_cb_queryobj.c
src/mesa/state_tracker/st_cb_rasterpos.c
src/mesa/state_tracker/st_cb_readpixels.c
src/mesa/state_tracker/st_cb_semaphoreobjects.c
src/mesa/state_tracker/st_cb_texture.c
src/mesa/state_tracker/st_context.c
src/mesa/state_tracker/st_context.h
src/mesa/state_tracker/st_draw.c
src/mesa/state_tracker/st_draw_feedback.c
src/mesa/state_tracker/st_gen_mipmap.c
src/mesa/state_tracker/st_shader_cache.c
src/mesa/state_tracker/st_util.h [new file with mode: 0644]

index d554408d01b3519f55cb320572565ef1f6068871..89bcfe40bb598e822e4d48493b8281cc3ec946ef 100644 (file)
@@ -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
 
index 05a8bb5e10033b751c6c1d46fc2b9f8cb115a172..2d9b673fbe73e32bdc27db9ed5722b243bf01fa2 100644 (file)
@@ -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',
 )
index df1a94e831eaf54463344ef5ed34a021de29a791..49f79ad9d49a0df1d46ccb8ef738b2aafd24ddbb 100644 (file)
@@ -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);
 
index a0dd0d1f649d4b015dcfeadf77ef3c63f5d44e45..f18c40dbe7b3a4e4c1ad2c7deacd846c7f433e3d 100644 (file)
@@ -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"
index c6affec5525150568525820db90d19138f84b467..594e6397242276433bcbfbcf37da362af36154c5 100644 (file)
@@ -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"
index 2bffa684a25336599c6ff9d2627268b8deeb8478..fee992e4c4a6fe2203d0befdb0a1d20d2a5a35ff 100644 (file)
@@ -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"
index a87d02941ca26e0c77f56444c0739254922067f9..04135a3a3408a143210e851bb07e592fa140e04c 100644 (file)
@@ -36,6 +36,7 @@
 #include "st_context.h"
 #include "pipe/p_context.h"
 #include "st_atom.h"
+#include "st_util.h"
 
 
 /**
index 6e3347e7cfaf226fa2249c2fee5790ca209c8736..4a07b2d0914ef00160fa3f70bbe3d521b02c9c62 100644 (file)
@@ -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"
 
index 7ef0d7ea5c621f04fcc26be31e7f5392a01f0b55..d7e2ccb3815df7757a408aee35306e04dd35bf9f 100644 (file)
@@ -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"
index 564ad6666550382b673c2470bc8dc189457b680a..cc8649eb39295cbaa811e60aa13f635bb5e96a4a 100644 (file)
@@ -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"
 
index b05f2516980348d831b092bd4f66184ed0d1ea3a..4f77dad7874dabfb74a06d0c08f25dc4baa21bb6 100644 (file)
@@ -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"
index 2de8e49c8cc34f94424da43b70332a9c1b561c86..3a49bd4d6c1c65138533663345f5e3a864a46c4d 100644 (file)
@@ -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"
index f91df4bd177fc7e9fb444d356f12e7a44f2725b7..a99484e4f2e0dab9384493e9d18d831974e7d1a0 100644 (file)
@@ -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"
 
index 6d3eda014dc7bca7790ff26b847de0f37ed071c1..8c5be5049856e74030c37ad370cb5e4c403ba8ec 100644 (file)
@@ -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"
index 119f018cd0b3d9d3b5696666d8d245affa2b421c..6b7d4f28167c28984eb997ef362e2d8858b11e17 100644 (file)
@@ -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"
index 3c583b3927f9885ce96aa91aa7f023f05324419f..111767d88a42bce66ca82773edeaf66110d7fd12 100644 (file)
@@ -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"
index 3bd7fd4ad27cace950d8abc84e7869834277747c..5fe6c79a93afe23ddd33c5a9bb10b0cfe85b0bc4 100644 (file)
@@ -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"
index 6e48be6f5d26574130eec24ef7748dc8c27c9865..ce236c05d98c00ddd954891a97ad9584986fdcae 100644 (file)
@@ -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"
index 39174bc9f757d174eac946ff374be86773293fa1..7e5cd2a04cbee7a0b21f66c0e60bf92211a4fcdc 100644 (file)
@@ -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"
index 23d32dcad4722b722839ae1d847f2154517b29b2..e1873d7c408641e430a640846679e3227f64e83a 100644 (file)
@@ -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"
 
index 825a09d7fdab2410832a10db9d088ba99227c7eb..349ed7fa3f8a81c3a300d16db379970c92d09724 100644 (file)
@@ -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"
 
 
 /**
index 642b901d05adff94754a85a32a47ed0bde9e6074..460c3e71ff9f4445b072dfd76a0069778c19a0a7 100644 (file)
@@ -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 *
index c54b50dc75498555e2e017ec29010c056d26605f..52ead76baab8bd3a3e8dc5cbcdff1eeca268960d 100644 (file)
@@ -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"
index f614849b9562a19a1ecab1a61aa8c247594e92da..e887d8de6d7570784cdab8238b70cbf2c25ec8f2 100644 (file)
@@ -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.
index 4a3faf575381b5982a880ac5ebb5909779a2fa01..4b1f21e6b1736b47a58f5f3cc4b89f418efd11a9 100644 (file)
@@ -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"
index f16f8762278475616517c0da2cc1a80a3d7d38b8..47d06122ec11d4a2b294f9c206a03d142c3103a6 100644 (file)
@@ -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"
index 45451531df927ea8a94b4dabc046d66d5111714f..68b6ddbb855fdaca82dba80ed303a8ac07a210be 100644 (file)
@@ -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()
  */
index 324a7f241782c7d5f3f98f8d03aed1b63d725645..58a1ead5c0db9e16aef595822190a6e9523755ad 100644 (file)
@@ -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
index 0a190bd8ba8e3ba84d5fa145a1b2a6e1a7eaa78d..7485fc82b18ab075e61d89b106345a4c9fec6619 100644 (file)
@@ -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"
index b83f63811dd31ef1fd4936fc2ef49a9909f8bf29..275e1090735d5b909c615b83c14e62e1e4c4c236 100644 (file)
@@ -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"
index 3f105871a5e2eccc1338743b1f4dd3dd551d56eb..d6e9136384ed26f656facc49966314b0ca7090e6 100644 (file)
@@ -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"
index c82ce3eaa2d8dc32e199f196e7d68d4659929203..b18829754cb15907f577a4eb09df5dd6a942cdc2 100644 (file)
@@ -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 (file)
index 0000000..b6454e5
--- /dev/null
@@ -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 */