mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-23 19:50:11 +01:00
nak: Add initial stubs for rust code
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
This commit is contained in:
parent
c778d39fa4
commit
79ff2d9a33
5 changed files with 89 additions and 0 deletions
5
src/nouveau/compiler/.editorconfig
Normal file
5
src/nouveau/compiler/.editorconfig
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# To use this config on you editor, follow the instructions at:
|
||||
# http://editorconfig.org
|
||||
|
||||
[*.rs]
|
||||
max_line_length = 80
|
||||
1
src/nouveau/compiler/.rustfmt.toml
Normal file
1
src/nouveau/compiler/.rustfmt.toml
Normal file
|
|
@ -0,0 +1 @@
|
|||
max_width = 80
|
||||
|
|
@ -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',
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
28
src/nouveau/compiler/nak.rs
Normal file
28
src/nouveau/compiler/nak.rs
Normal 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()
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue