mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-06-09 23:08:18 +02:00
kraid: Plumb through Model::encode_shader()
Of course, we can't actually encode anything yet but this gives us the model hook and deals with the util_dynarray so that everything inside the model hook is safe code. Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41841>
This commit is contained in:
parent
11ceef9295
commit
1631ebbc5a
2 changed files with 22 additions and 2 deletions
|
|
@ -46,11 +46,23 @@ fn dump_shader(s: &Shader, suffix: &str) {
|
|||
eprintln!("Kraid shader {suffix}:{out}");
|
||||
}
|
||||
|
||||
fn dynarray_append_vec<T: Copy>(buf: &mut util_dynarray, vec: Vec<T>) {
|
||||
unsafe {
|
||||
let p = util_dynarray_grow_bytes(
|
||||
buf,
|
||||
vec.len().try_into().unwrap(),
|
||||
std::mem::size_of::<T>(),
|
||||
);
|
||||
assert!(!p.is_null(), "util_dynarray_grow_bytes() failed");
|
||||
std::ptr::copy_nonoverlapping(vec.as_ptr(), p as *mut T, vec.len());
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn kraid_compile_nir(
|
||||
nir: &mut nir_shader,
|
||||
inputs: &pan_compile_inputs,
|
||||
_binary: &mut util_dynarray,
|
||||
binary: &mut util_dynarray,
|
||||
_info: &mut pan_shader_info,
|
||||
) {
|
||||
let model = model_for_gpu_id(inputs.gpu_id).unwrap();
|
||||
|
|
@ -65,5 +77,6 @@ pub extern "C" fn kraid_compile_nir(
|
|||
dump_shader(&s, "after register assignment");
|
||||
s.validate();
|
||||
|
||||
todo!("Compile to binaries");
|
||||
let bin = model.encode_shader(&s);
|
||||
dynarray_append_vec(binary, bin);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
// Copyright © 2026 Collabora, Ltd.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use crate::ir::*;
|
||||
use kraid_bindings::*;
|
||||
|
||||
pub trait Model {
|
||||
fn arch(&self) -> u8;
|
||||
|
||||
fn encode_shader(&self, s: &Shader<'_>) -> Vec<u32>;
|
||||
}
|
||||
|
||||
struct ValhallModel {
|
||||
|
|
@ -15,6 +18,10 @@ impl Model for ValhallModel {
|
|||
fn arch(&self) -> u8 {
|
||||
self.arch
|
||||
}
|
||||
|
||||
fn encode_shader(&self, _s: &Shader<'_>) -> Vec<u32> {
|
||||
todo!("Implement Valhall shader encoding");
|
||||
}
|
||||
}
|
||||
|
||||
pub fn model_for_gpu_id(gpu_id: u64) -> Result<Box<dyn Model>, &'static str> {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue