nak: Add initial stubs for rust code

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
This commit is contained in:
Faith Ekstrand 2023-01-30 20:53:16 -06:00 committed by Marge Bot
parent c778d39fa4
commit 79ff2d9a33
5 changed files with 89 additions and 0 deletions

View file

@ -0,0 +1,5 @@
# To use this config on you editor, follow the instructions at:
# http://editorconfig.org
[*.rs]
max_line_length = 80

View file

@ -0,0 +1 @@
max_width = 80

View file

@ -1,18 +1,62 @@
add_languages('rust', required: true)
rust = import('unstable-rust')
libnak_c_files = files( libnak_c_files = files(
'nak.h', 'nak.h',
'nak_nir.c', 'nak_nir.c',
) )
libnak_rs_files = files(
'nak.rs',
)
libnak_deps = [ libnak_deps = [
idep_mesautil, idep_mesautil,
idep_nir_headers, 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( _libnak = static_library(
'nak', 'nak',
libnak_c_files, libnak_c_files,
include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium], include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium],
dependencies : libnak_deps, dependencies : libnak_deps,
link_with : [_libnak_rs],
c_args : [no_override_init_args], c_args : [no_override_init_args],
gnu_symbol_visibility : 'hidden', gnu_symbol_visibility : 'hidden',
) )

View file

@ -43,6 +43,17 @@ struct nak_shader_info {
uint32_t hdr[32]; 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 #ifdef __cplusplus
} }
#endif #endif

View file

@ -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<u32>,
}
#[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()
}