diff --git a/src/nouveau/compiler/.editorconfig b/src/nouveau/compiler/.editorconfig new file mode 100644 index 00000000000..df3b091d72d --- /dev/null +++ b/src/nouveau/compiler/.editorconfig @@ -0,0 +1,5 @@ +# To use this config on you editor, follow the instructions at: +# http://editorconfig.org + +[*.rs] +max_line_length = 80 diff --git a/src/nouveau/compiler/.rustfmt.toml b/src/nouveau/compiler/.rustfmt.toml new file mode 100644 index 00000000000..df99c69198f --- /dev/null +++ b/src/nouveau/compiler/.rustfmt.toml @@ -0,0 +1 @@ +max_width = 80 diff --git a/src/nouveau/compiler/meson.build b/src/nouveau/compiler/meson.build index ce1637f4603..1be46d4ba7c 100644 --- a/src/nouveau/compiler/meson.build +++ b/src/nouveau/compiler/meson.build @@ -1,18 +1,62 @@ +add_languages('rust', required: true) +rust = import('unstable-rust') + libnak_c_files = files( 'nak.h', 'nak_nir.c', ) +libnak_rs_files = files( + 'nak.rs', +) + libnak_deps = [ idep_mesautil, idep_nir_headers, ] +nak_bindings_rs = rust.bindgen( + input : ['nak.h'], + output : 'nak_bindings.rs', + args : [ + '--allowlist-type', 'nak_.*', + '--allowlist-function', 'nak_.*', + '--allowlist-type', 'nir_shader', + ], +) + +libnak_bindings_gen = static_library( + 'nak_bindings', + nak_bindings_rs, + gnu_symbol_visibility : 'hidden', + rust_crate_type : 'rlib', +) + +_libnak_rs = static_library( + 'nak_rs', + [libnak_rs_files], + gnu_symbol_visibility : 'hidden', + rust_crate_type : 'staticlib', + rust_args : [ + # we error on all clippy warnings unless they are disabled + '-Dclippy::all', + # we want to add asserts in control flow + '-Aclippy::assertions_on_constants', + # dunno, kind of looks nicier being explicit + '-Aclippy::redundant_field_names', + '-Aclippy::too_many_arguments', + '-Aclippy::type_complexity', + '-Anon_snake_case', + ], + link_with: [libnak_bindings_gen], +) + _libnak = static_library( 'nak', libnak_c_files, include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium], dependencies : libnak_deps, + link_with : [_libnak_rs], c_args : [no_override_init_args], gnu_symbol_visibility : 'hidden', ) diff --git a/src/nouveau/compiler/nak.h b/src/nouveau/compiler/nak.h index e05d3eb5a32..97712e7a4b0 100644 --- a/src/nouveau/compiler/nak.h +++ b/src/nouveau/compiler/nak.h @@ -43,6 +43,17 @@ struct nak_shader_info { uint32_t hdr[32]; }; +struct nak_shader_bin { + struct nak_shader_info info; + uint32_t code_size; + const void *code; +}; + +void nak_shader_bin_destroy(struct nak_shader_bin *bin); + +struct nak_shader_bin * +nak_compile_shader(nir_shader *nir, const struct nak_compiler *nak); + #ifdef __cplusplus } #endif diff --git a/src/nouveau/compiler/nak.rs b/src/nouveau/compiler/nak.rs new file mode 100644 index 00000000000..32c92f746ae --- /dev/null +++ b/src/nouveau/compiler/nak.rs @@ -0,0 +1,28 @@ +/* + * Copyright © 2022 Collabora, Ltd. + * SPDX-License-Identifier: MIT + */ + +use nak_bindings::*; + +#[repr(C)] +struct ShaderBin { + bin: nak_shader_bin, + instrs: Vec, +} + +#[no_mangle] +pub extern "C" fn nak_shader_bin_destroy(bin: *mut nak_shader_bin) { + unsafe { + Box::from_raw(bin as *mut ShaderBin); + }; +} + +#[no_mangle] +pub extern "C" fn nak_compile_shader( + _nir: *mut nir_shader, + _nak: *const nak_compiler, +) -> *mut nak_shader_bin { + println!("Hello from rust!"); + std::ptr::null_mut() +}