[Mesa-dev] [PATCH 2/7] gallium: implement ARB/KHR_parallel_shader_compile

Marek Olšák maraeo at gmail.com
Thu Nov 29 02:59:25 UTC 2018


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

---
 src/gallium/include/pipe/p_screen.h    | 13 ++++++
 src/mesa/state_tracker/st_cb_program.c | 59 +++++++++++++++++++++++++-
 2 files changed, 71 insertions(+), 1 deletion(-)

diff --git a/src/gallium/include/pipe/p_screen.h b/src/gallium/include/pipe/p_screen.h
index c4d6e1cc94f..d4e2d9f63ac 100644
--- a/src/gallium/include/pipe/p_screen.h
+++ b/src/gallium/include/pipe/p_screen.h
@@ -435,20 +435,33 @@ struct pipe_screen {
     * \param uuid    pointer to a memory region of PIPE_UUID_SIZE bytes
     */
    void (*get_driver_uuid)(struct pipe_screen *screen, char *uuid);
 
    /**
     * Fill @uuid with a unique device identifier
     *
     * \param uuid    pointer to a memory region of PIPE_UUID_SIZE bytes
     */
    void (*get_device_uuid)(struct pipe_screen *screen, char *uuid);
+
+   /**
+    * Set the maximum number of parallel shader compiler threads.
+    */
+   void (*set_max_shader_compiler_threads)(struct pipe_screen *screen,
+                                           unsigned max_threads);
+
+   /**
+    * Return whether parallel shader compilation has finished.
+    */
+   bool (*is_parallel_shader_compilation_finished)(struct pipe_screen *screen,
+                                                   void *shader,
+                                                   unsigned shader_type);
 };
 
 
 /**
  * Global configuration options for screen creation.
  */
 struct pipe_screen_config {
    const struct driOptionCache *options;
 };
 
diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c
index 555fc5d5ad9..cc96ec552bb 100644
--- a/src/mesa/state_tracker/st_cb_program.c
+++ b/src/mesa/state_tracker/st_cb_program.c
@@ -259,23 +259,80 @@ st_program_string_notify( struct gl_context *ctx,
 static struct gl_program *
 st_new_ati_fs(struct gl_context *ctx, struct ati_fragment_shader *curProg)
 {
    struct gl_program *prog = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB,
          curProg->Id, true);
    struct st_fragment_program *stfp = (struct st_fragment_program *)prog;
    stfp->ati_fs = curProg;
    return prog;
 }
 
+static void
+st_max_shader_compiler_threads(struct gl_context *ctx, unsigned count)
+{
+   struct pipe_screen *screen = st_context(ctx)->pipe->screen;
+
+   if (screen->set_max_shader_compiler_threads)
+      screen->set_max_shader_compiler_threads(screen, count);
+}
+
+static bool
+st_get_shader_program_completion_status(struct gl_context *ctx,
+                                        struct gl_shader_program *shprog)
+{
+   struct pipe_screen *screen = st_context(ctx)->pipe->screen;
+
+   if (!screen->is_parallel_shader_compilation_finished)
+      return true;
+
+   for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
+      struct gl_linked_shader *linked = shprog->_LinkedShaders[i];
+      void *sh = NULL;
+
+      if (!linked || !linked->Program)
+         continue;
+
+      switch (i) {
+      case MESA_SHADER_VERTEX:
+         if (st_vertex_program(linked->Program)->variants)
+            sh = st_vertex_program(linked->Program)->variants->driver_shader;
+         break;
+      case MESA_SHADER_FRAGMENT:
+         if (st_fragment_program(linked->Program)->variants)
+            sh = st_fragment_program(linked->Program)->variants->driver_shader;
+         break;
+      case MESA_SHADER_TESS_CTRL:
+      case MESA_SHADER_TESS_EVAL:
+      case MESA_SHADER_GEOMETRY:
+         if (st_common_program(linked->Program)->variants)
+            sh = st_common_program(linked->Program)->variants->driver_shader;
+         break;
+      case MESA_SHADER_COMPUTE:
+         if (st_compute_program(linked->Program)->variants)
+            sh = st_compute_program(linked->Program)->variants->driver_shader;
+         break;
+      }
+
+      unsigned type = pipe_shader_type_from_mesa(i);
+
+      if (sh &&
+          !screen->is_parallel_shader_compilation_finished(screen, sh, type))
+         return false;
+   }
+   return true;
+}
+
 /**
  * Plug in the program and shader-related device driver functions.
  */
 void
 st_init_program_functions(struct dd_function_table *functions)
 {
    functions->NewProgram = st_new_program;
    functions->DeleteProgram = st_delete_program;
    functions->ProgramStringNotify = st_program_string_notify;
    functions->NewATIfs = st_new_ati_fs;
-   
    functions->LinkShader = st_link_shader;
+   functions->SetMaxShaderCompilerThreads = st_max_shader_compiler_threads;
+   functions->GetShaderProgramCompletionStatus =
+      st_get_shader_program_completion_status;
 }
-- 
2.17.1



More information about the mesa-dev mailing list