gallium: add pipe_screen::finalize_nir
authorMarek Olšák <marek.olsak@amd.com>
Fri, 18 Oct 2019 01:28:56 +0000 (21:28 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Thu, 24 Oct 2019 01:12:52 +0000 (21:12 -0400)
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/gallium/auxiliary/driver_ddebug/dd_screen.c
src/gallium/auxiliary/driver_noop/noop_pipe.c
src/gallium/auxiliary/driver_rbug/rbug_screen.c
src/gallium/auxiliary/driver_trace/tr_screen.c
src/gallium/include/pipe/p_screen.h

index b66d24b..7e8ea4c 100644 (file)
@@ -412,6 +412,14 @@ dd_screen_memobj_destroy(struct pipe_screen *_screen,
  */
 
 static void
+dd_screen_finalize_nir(struct pipe_screen *_screen, void *nir, bool optimize)
+{
+   struct pipe_screen *screen = dd_screen(_screen)->screen;
+
+   screen->finalize_nir(screen, nir, optimize);
+}
+
+static void
 dd_screen_destroy(struct pipe_screen *_screen)
 {
    struct dd_screen *dscreen = dd_screen(_screen);
@@ -597,6 +605,7 @@ ddebug_screen_create(struct pipe_screen *screen)
    SCR_INIT(get_compiler_options);
    SCR_INIT(get_driver_uuid);
    SCR_INIT(get_device_uuid);
+   SCR_INIT(finalize_nir);
 
 #undef SCR_INIT
 
index 6ac2250..290b998 100644 (file)
@@ -514,6 +514,10 @@ static const void *noop_get_compiler_options(struct pipe_screen *pscreen,
    return screen->get_compiler_options(screen, ir, shader);
 }
 
+static void noop_finalize_nir(struct pipe_screen *pscreen, void *nir, bool optimize)
+{
+}
+
 struct pipe_screen *noop_screen_create(struct pipe_screen *oscreen)
 {
    struct noop_pipe_screen *noop_screen;
@@ -553,6 +557,7 @@ struct pipe_screen *noop_screen_create(struct pipe_screen *oscreen)
    screen->query_memory_info = noop_query_memory_info;
    screen->get_disk_shader_cache = noop_get_disk_shader_cache;
    screen->get_compiler_options = noop_get_compiler_options;
+   screen->finalize_nir = noop_finalize_nir;
 
    return screen;
 }
index 5f27b62..86286cf 100644 (file)
@@ -370,6 +370,14 @@ rbug_screen_fence_get_fd(struct pipe_screen *_screen,
    return screen->fence_get_fd(screen, fence);
 }
 
+static void
+rbug_screen_finalize_nir(struct pipe_screen *_screen, void *nir, bool optimize)
+{
+   struct pipe_screen *screen = rbug_screen(_screen)->screen;
+
+   return screen->finalize_nir(screen, nir, optimize);
+}
+
 bool
 rbug_enabled()
 {
@@ -422,6 +430,7 @@ rbug_screen_create(struct pipe_screen *screen)
    rb_screen->base.fence_reference = rbug_screen_fence_reference;
    rb_screen->base.fence_finish = rbug_screen_fence_finish;
    rb_screen->base.fence_get_fd = rbug_screen_fence_get_fd;
+   SCR_INIT(finalize_nir);
 
    rb_screen->screen = screen;
 
index 380e3ea..0d2c99c 100644 (file)
@@ -644,6 +644,14 @@ trace_screen_get_timestamp(struct pipe_screen *_screen)
 }
 
 static void
+trace_screen_finalize_nir(struct pipe_screen *_screen, void *nir, bool optimize)
+{
+   struct pipe_screen *screen = trace_screen(_screen)->screen;
+
+   screen->finalize_nir(screen, nir, optimize);
+}
+
+static void
 trace_screen_destroy(struct pipe_screen *_screen)
 {
    struct trace_screen *tr_scr = trace_screen(_screen);
@@ -722,6 +730,7 @@ trace_screen_create(struct pipe_screen *screen)
    tr_scr->base.get_timestamp = trace_screen_get_timestamp;
    SCR_INIT(get_driver_uuid);
    SCR_INIT(get_device_uuid);
+   SCR_INIT(finalize_nir);
 
    tr_scr->screen = screen;
 
index 9a1fc37..0f2831b 100644 (file)
@@ -500,6 +500,17 @@ struct pipe_screen {
                              struct pipe_resource *resource,
                              unsigned int nrects,
                              const struct pipe_box *rects);
+
+   /**
+    * Run driver-specific NIR lowering and optimization passes.
+    *
+    * State trackers should call this before passing shaders to drivers,
+    * and ideally also before shader caching.
+    *
+    * \param optimize  Whether the input shader hasn't been optimized and
+    *                  should be.
+    */
+   void (*finalize_nir)(struct pipe_screen *screen, void *nir, bool optimize);
 };