[Mesa-dev] [PATCH v2 02/10] nir: Add a pass-running infastructure
Jason Ekstrand
jason at jlekstrand.net
Tue Nov 3 13:41:08 PST 2015
Reviewed-by: Kristian Høgsberg <krh at bitplanet.net>
v2: (Jason Ekstrand):
- Make run_pass take a nir_shader** to allow for nir_shader_clone testing
v3: (Jason Ekstrand):
- Switch back to taking a nir_shader*
- Rework run_pass a bit with suggestions from Ken
- Add a NIR_DECL_PASS macro
---
src/glsl/nir/nir.h | 17 +++++++++++++++++
src/glsl/nir/nir_pass.c | 46 +++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 62 insertions(+), 1 deletion(-)
diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index ac42251..1d3e281 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -1582,6 +1582,23 @@ typedef struct nir_shader {
foreach_list_typed(nir_function_overload, overload, node, \
&(func)->overload_list)
+typedef struct nir_pass {
+ bool (*shader_pass_func)(nir_shader *shader, void *data);
+ bool (*impl_pass_func)(nir_function_impl *impl, void *data);
+ nir_metadata metadata_preserved;
+} nir_pass;
+
+bool nir_shader_run_pass(nir_shader *shader, const nir_pass *pass, void *data);
+bool nir_function_impl_run_pass(nir_function_impl *impl, const nir_pass *pass,
+ void *data);
+
+#define NIR_DECL_PASS(name) \
+ const extern nir_pass name##_pass; \
+ static inline bool name(nir_shader *shader) \
+ { \
+ return nir_shader_run_pass(shader, &name##_pass, NULL); \
+ }
+
nir_shader *nir_shader_create(void *mem_ctx,
gl_shader_stage stage,
const nir_shader_compiler_options *options);
diff --git a/src/glsl/nir/nir_pass.c b/src/glsl/nir/nir_pass.c
index a03e124..cc6c945 100644
--- a/src/glsl/nir/nir_pass.c
+++ b/src/glsl/nir/nir_pass.c
@@ -27,7 +27,7 @@
#include "nir.h"
/*
- * Handles management of the metadata.
+ * Handles management of NIR passes and metadata.
*/
void
@@ -52,3 +52,47 @@ nir_metadata_preserve(nir_function_impl *impl, nir_metadata preserved)
{
impl->valid_metadata &= preserved;
}
+
+bool
+nir_function_impl_run_pass(nir_function_impl *impl,
+ const nir_pass *pass, void *data)
+{
+ bool progress = pass->impl_pass_func(impl, data);
+ if (progress)
+ nir_metadata_preserve(impl, pass->metadata_preserved);
+
+ /* TODO: Add a way to validate a single function_impl */
+ nir_validate_shader(impl->overload->function->shader);
+
+ return progress;
+}
+
+bool
+nir_shader_run_pass(nir_shader *shader, const nir_pass *pass, void *data)
+{
+ bool progress;
+ if (pass->shader_pass_func) {
+ progress = pass->shader_pass_func(shader, data);
+
+ if (progress) {
+ nir_foreach_overload(shader, overload) {
+ if (overload->impl)
+ nir_metadata_preserve(overload->impl, pass->metadata_preserved);
+ }
+ }
+ } else {
+ progress = false;
+ nir_foreach_overload(shader, overload) {
+ if (overload->impl) {
+ bool pass_progress = pass->impl_pass_func(overload->impl, data);
+ if (pass_progress)
+ nir_metadata_preserve(overload->impl, pass->metadata_preserved);
+ progress |= pass_progress;
+ }
+ }
+ }
+
+ nir_validate_shader(shader);
+
+ return progress;
+}
--
2.5.0.400.gff86faf
More information about the mesa-dev
mailing list