Mesa (main): mesa/st: move program new/delete into mesa

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jan 26 01:12:49 UTC 2022


Module: Mesa
Branch: main
Commit: 8dfe3c83b6ec7a09223313ce5312445ac8ff9e8a
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=8dfe3c83b6ec7a09223313ce5312445ac8ff9e8a

Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Dec 20 16:20:48 2021 +1000

mesa/st: move program new/delete into mesa

Reviewed-by: Kristian H. Kristensen <hoegsberg at google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14700>

---

 src/mesa/main/shared.c                 |  4 +---
 src/mesa/program/program.c             | 33 +++++++++++++++++++++++---
 src/mesa/program/program.h             |  4 ++++
 src/mesa/state_tracker/st_cb_program.c | 42 +---------------------------------
 src/mesa/state_tracker/st_cb_program.h |  1 -
 5 files changed, 36 insertions(+), 48 deletions(-)

diff --git a/src/mesa/main/shared.c b/src/mesa/main/shared.c
index a00940290ee..2085b280e00 100644
--- a/src/mesa/main/shared.c
+++ b/src/mesa/main/shared.c
@@ -47,8 +47,6 @@
 #include "util/set.h"
 #include "util/u_memory.h"
 
-#include "state_tracker/st_cb_program.h"
-
 static void
 free_shared_state(struct gl_context *ctx, struct gl_shared_state *shared);
 
@@ -195,7 +193,7 @@ delete_program_cb(void *data, void *userData)
    if(prog != &_mesa_DummyProgram) {
       assert(prog->RefCount == 1); /* should only be referenced by hash table */
       prog->RefCount = 0;  /* now going away */
-      st_delete_program(ctx, prog);
+      _mesa_delete_program(ctx, prog);
    }
 }
 
diff --git a/src/mesa/program/program.c b/src/mesa/program/program.c
index 2124f1bff61..cd3b4668877 100644
--- a/src/mesa/program/program.c
+++ b/src/mesa/program/program.c
@@ -44,7 +44,9 @@
 #include "util/ralloc.h"
 #include "util/u_atomic.h"
 
-#include "state_tracker/st_cb_program.h"
+#include "state_tracker/st_program.h"
+#include "state_tracker/st_glsl_to_tgsi.h"
+#include "state_tracker/st_context.h"
 
 /**
  * A pointer to this dummy program is put into the hash table when
@@ -217,6 +219,24 @@ _mesa_init_gl_program(struct gl_program *prog, gl_shader_stage stage,
    return prog;
 }
 
+struct gl_program *
+_mesa_new_program(struct gl_context *ctx, gl_shader_stage stage, GLuint id,
+                  bool is_arb_asm)
+{
+   struct gl_program *prog;
+
+   switch (stage) {
+   case MESA_SHADER_VERTEX:
+      prog = (struct gl_program*)rzalloc(NULL, struct gl_vertex_program);
+      break;
+   default:
+      prog = rzalloc(NULL, struct gl_program);
+      break;
+   }
+
+   return _mesa_init_gl_program(prog, stage, id, is_arb_asm);
+}
+
 /**
  * Delete a program and remove it from the hash table, ignoring the
  * reference count.
@@ -224,10 +244,17 @@ _mesa_init_gl_program(struct gl_program *prog, gl_shader_stage stage,
 void
 _mesa_delete_program(struct gl_context *ctx, struct gl_program *prog)
 {
-   (void) ctx;
+   struct st_context *st = st_context(ctx);
    assert(prog);
    assert(prog->RefCount==0);
 
+   st_release_variants(st, prog);
+
+   if (prog->glsl_to_tgsi)
+      free_glsl_to_tgsi_visitor(prog->glsl_to_tgsi);
+
+   free(prog->serialized_nir);
+
    if (prog == &_mesa_DummyProgram)
       return;
 
@@ -302,7 +329,7 @@ _mesa_reference_program_(struct gl_context *ctx,
       if (p_atomic_dec_zero(&oldProg->RefCount)) {
          assert(ctx);
          _mesa_reference_shader_program_data(&oldProg->sh.data, NULL);
-         st_delete_program(ctx, oldProg);
+         _mesa_delete_program(ctx, oldProg);
       }
 
       *ptr = NULL;
diff --git a/src/mesa/program/program.h b/src/mesa/program/program.h
index ab10cd84f98..3df5e988995 100644
--- a/src/mesa/program/program.h
+++ b/src/mesa/program/program.h
@@ -66,6 +66,10 @@ extern struct gl_program *
 _mesa_init_gl_program(struct gl_program *prog, gl_shader_stage stage,
                       GLuint id, bool is_arb_asm);
 
+extern struct gl_program *
+_mesa_new_program(struct gl_context *ctx, gl_shader_stage stage, GLuint id,
+                  bool is_arb_asm);
+
 extern void
 _mesa_delete_program(struct gl_context *ctx, struct gl_program *prog);
 
diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c
index 2d0670365c0..7e43934d472 100644
--- a/src/mesa/state_tracker/st_cb_program.c
+++ b/src/mesa/state_tracker/st_cb_program.c
@@ -48,46 +48,6 @@
 #include "st_atifs_to_nir.h"
 #include "st_util.h"
 
-
-/**
- * Called via ctx->Driver.NewProgram() to allocate a new vertex or
- * fragment program.
- */
-static struct gl_program *
-st_new_program(struct gl_context *ctx, gl_shader_stage stage, GLuint id,
-               bool is_arb_asm)
-{
-   struct gl_program *prog;
-
-   switch (stage) {
-   case MESA_SHADER_VERTEX:
-      prog = (struct gl_program*)rzalloc(NULL, struct gl_vertex_program);
-      break;
-   default:
-      prog = rzalloc(NULL, struct gl_program);
-      break;
-   }
-
-   return _mesa_init_gl_program(prog, stage, id, is_arb_asm);
-}
-
-
-void
-st_delete_program(struct gl_context *ctx, struct gl_program *prog)
-{
-   struct st_context *st = st_context(ctx);
-
-   st_release_variants(st, prog);
-
-   if (prog->glsl_to_tgsi)
-      free_glsl_to_tgsi_visitor(prog->glsl_to_tgsi);
-
-   free(prog->serialized_nir);
-
-   /* delete base class */
-   _mesa_delete_program( ctx, prog );
-}
-
 /**
  * Called when the program's text/code is changed.  We have to free
  * all shader variants and corresponding gallium shaders when this happens.
@@ -133,5 +93,5 @@ st_program_string_notify( struct gl_context *ctx,
 void
 st_init_program_functions(struct dd_function_table *functions)
 {
-   functions->NewProgram = st_new_program;
+   functions->NewProgram = _mesa_new_program;
 }
diff --git a/src/mesa/state_tracker/st_cb_program.h b/src/mesa/state_tracker/st_cb_program.h
index fdeebaa67b0..9bee1b9d861 100644
--- a/src/mesa/state_tracker/st_cb_program.h
+++ b/src/mesa/state_tracker/st_cb_program.h
@@ -36,7 +36,6 @@ struct dd_function_table;
 
 extern void
 st_init_program_functions(struct dd_function_table *functions);
-void st_delete_program(struct gl_context *ctx, struct gl_program *prog);
 GLboolean st_program_string_notify(struct gl_context *ctx,
                                    GLenum target,
                                    struct gl_program *prog);



More information about the mesa-commit mailing list