From 78dd9f4a42f359f61f63c8b06994054ff28dc95e Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Tue, 21 Feb 2023 16:52:23 +0100 Subject: [PATCH] rusticl/nir: add helper functions we need for a NIR_PASS macro Signed-off-by: Karol Herbst Part-of: --- src/gallium/frontends/rusticl/mesa/compiler/nir.rs | 32 ++++++++++++++++++++++ src/gallium/frontends/rusticl/meson.build | 1 + .../rusticl/rusticl_mesa_inline_bindings_wrapper.c | 12 ++++++++ .../rusticl/rusticl_mesa_inline_bindings_wrapper.h | 6 ++++ 4 files changed, 51 insertions(+) diff --git a/src/gallium/frontends/rusticl/mesa/compiler/nir.rs b/src/gallium/frontends/rusticl/mesa/compiler/nir.rs index 5c342e8..98d5dba 100644 --- a/src/gallium/frontends/rusticl/mesa/compiler/nir.rs +++ b/src/gallium/frontends/rusticl/mesa/compiler/nir.rs @@ -150,6 +150,38 @@ impl NirShader { unsafe { pass(self.nir.as_ptr(), a, b, c) } } + #[cfg(debug_assertions)] + pub fn metadata_check_validation_flag(&self) { + unsafe { nir_metadata_check_validation_flag(self.nir.as_ptr()) } + } + + #[cfg(debug_assertions)] + pub fn metadata_set_validation_flag(&mut self) { + unsafe { nir_metadata_set_validation_flag(self.nir.as_ptr()) } + } + + #[cfg(debug_assertions)] + pub fn validate(&self, when: &str) { + let cstr = CString::new(when).unwrap(); + unsafe { nir_validate_shader(self.nir.as_ptr(), cstr.as_ptr()) } + } + + pub fn should_print(&self) -> bool { + unsafe { should_print_nir(self.nir.as_ptr()) } + } + + pub fn validate_serialize_deserialize(&self) { + unsafe { nir_shader_serialize_deserialize(self.nir.as_ptr()) } + } + + pub fn validate_clone(&mut self) { + unsafe { + let nir_ptr = self.nir.as_ptr(); + let clone = nir_shader_clone(ralloc_parent(nir_ptr.cast()), nir_ptr); + nir_shader_replace(nir_ptr, clone) + } + } + pub fn entrypoint(&self) -> *mut nir_function_impl { unsafe { nir_shader_get_entrypoint(self.nir.as_ptr()) } } diff --git a/src/gallium/frontends/rusticl/meson.build b/src/gallium/frontends/rusticl/meson.build index 5479a6f..e1fbf70 100644 --- a/src/gallium/frontends/rusticl/meson.build +++ b/src/gallium/frontends/rusticl/meson.build @@ -270,6 +270,7 @@ rusticl_mesa_bindings_rs = rust.bindgen( '--bitfield-enum', 'nir_lower_int64_options', '--bitfield-enum', 'nir_opt_if_options', '--bitfield-enum', 'nir_variable_mode', + '--allowlist-function', 'should_.*_nir', '--allowlist-function', 'spirv_.*', # gallium diff --git a/src/gallium/frontends/rusticl/rusticl_mesa_inline_bindings_wrapper.c b/src/gallium/frontends/rusticl/rusticl_mesa_inline_bindings_wrapper.c index 3b33a29..d89fb5b 100644 --- a/src/gallium/frontends/rusticl/rusticl_mesa_inline_bindings_wrapper.c +++ b/src/gallium/frontends/rusticl/rusticl_mesa_inline_bindings_wrapper.c @@ -31,6 +31,18 @@ pipe_resource_reference(struct pipe_resource **dst, struct pipe_resource *src) __pipe_resource_reference_wraped(dst, src); } +bool +should_skip_nir(const char *name) +{ + return __should_skip_nir(name); +} + +bool +should_print_nir(nir_shader *shader) +{ + return __should_print_nir(shader); +} + void util_format_pack_rgba(enum pipe_format format, void *dst, const void *src, unsigned w) { diff --git a/src/gallium/frontends/rusticl/rusticl_mesa_inline_bindings_wrapper.h b/src/gallium/frontends/rusticl/rusticl_mesa_inline_bindings_wrapper.h index 8c70f18..8e7a458 100644 --- a/src/gallium/frontends/rusticl/rusticl_mesa_inline_bindings_wrapper.h +++ b/src/gallium/frontends/rusticl/rusticl_mesa_inline_bindings_wrapper.h @@ -3,6 +3,8 @@ #define mesa_bytes_to_hex __mesa_bytes_to_hex #define nir_shader_get_entrypoint __nir_shader_get_entrypoint_wraped #define pipe_resource_reference __pipe_resource_reference_wraped +#define should_print_nir __should_print_nir +#define should_skip_nir __should_skip_nir #define util_format_pack_rgba __util_format_pack_rgba #include "nir.h" #include "util/blob.h" @@ -15,6 +17,8 @@ #undef disk_cache_get_function_identifier #undef nir_shader_get_entrypoint #undef pipe_resource_reference +#undef should_print_nir +#undef should_skip_nir #undef util_format_pack_rgba void blob_finish(struct blob *); @@ -23,4 +27,6 @@ bool disk_cache_get_function_identifier(void *ptr, struct mesa_sha1 *ctx); const char* mesa_version_string(void); nir_function_impl *nir_shader_get_entrypoint(const nir_shader *shader); void pipe_resource_reference(struct pipe_resource **dst, struct pipe_resource *src); +bool should_skip_nir(const char *); +bool should_print_nir(nir_shader *); void util_format_pack_rgba(enum pipe_format format, void *dst, const void *src, unsigned w); -- 2.7.4