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 b66d24babb9d608fb520db96c6b6968107085b41..7e8ea4cca48282d8654ec6b0dbe2f1fa95469bf0 100644 (file)
@@ -411,6 +411,14 @@ dd_screen_memobj_destroy(struct pipe_screen *_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)
 {
@@ -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 6ac22504b6560519e2f78409f753ad18f12539f2..290b99823767b940472e8fc90feb6cb8661797af 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 5f27b628e8f7c3d382940626d4b3691523ab473b..86286cf9f29553239ac3caa460bfdf0ab1db29b2 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 380e3ea7511570007acb4226fb149b83b0ce3e37..0d2c99cda539987ee80e6da3078f75a7f44eda83 100644 (file)
@@ -643,6 +643,14 @@ trace_screen_get_timestamp(struct pipe_screen *_screen)
    return result;
 }
 
+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)
 {
@@ -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 9a1fc37280e7f6909b779e12666f0378f349e017..0f2831b6eda72b36ccb9f80e3811243568470dda 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);
 };