From fb04e5da97d904ab1dc7e0182bcba77071bbe340 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Thu, 17 Oct 2019 21:28:56 -0400 Subject: [PATCH] gallium: add pipe_screen::finalize_nir Reviewed-by: Kenneth Graunke --- src/gallium/auxiliary/driver_ddebug/dd_screen.c | 9 +++++++++ src/gallium/auxiliary/driver_noop/noop_pipe.c | 5 +++++ src/gallium/auxiliary/driver_rbug/rbug_screen.c | 9 +++++++++ src/gallium/auxiliary/driver_trace/tr_screen.c | 9 +++++++++ src/gallium/include/pipe/p_screen.h | 11 +++++++++++ 5 files changed, 43 insertions(+) diff --git a/src/gallium/auxiliary/driver_ddebug/dd_screen.c b/src/gallium/auxiliary/driver_ddebug/dd_screen.c index b66d24babb9..7e8ea4cca48 100644 --- a/src/gallium/auxiliary/driver_ddebug/dd_screen.c +++ b/src/gallium/auxiliary/driver_ddebug/dd_screen.c @@ -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 diff --git a/src/gallium/auxiliary/driver_noop/noop_pipe.c b/src/gallium/auxiliary/driver_noop/noop_pipe.c index 6ac22504b65..290b9982376 100644 --- a/src/gallium/auxiliary/driver_noop/noop_pipe.c +++ b/src/gallium/auxiliary/driver_noop/noop_pipe.c @@ -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; } diff --git a/src/gallium/auxiliary/driver_rbug/rbug_screen.c b/src/gallium/auxiliary/driver_rbug/rbug_screen.c index 5f27b628e8f..86286cf9f29 100644 --- a/src/gallium/auxiliary/driver_rbug/rbug_screen.c +++ b/src/gallium/auxiliary/driver_rbug/rbug_screen.c @@ -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; diff --git a/src/gallium/auxiliary/driver_trace/tr_screen.c b/src/gallium/auxiliary/driver_trace/tr_screen.c index 380e3ea7511..0d2c99cda53 100644 --- a/src/gallium/auxiliary/driver_trace/tr_screen.c +++ b/src/gallium/auxiliary/driver_trace/tr_screen.c @@ -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; diff --git a/src/gallium/include/pipe/p_screen.h b/src/gallium/include/pipe/p_screen.h index 9a1fc37280e..0f2831b6eda 100644 --- a/src/gallium/include/pipe/p_screen.h +++ b/src/gallium/include/pipe/p_screen.h @@ -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); }; -- 2.30.2