diff --git a/src/gallium/frontends/rusticl/core/program.rs b/src/gallium/frontends/rusticl/core/program.rs index fe0403203f9..2df9d9ab574 100644 --- a/src/gallium/frontends/rusticl/core/program.rs +++ b/src/gallium/frontends/rusticl/core/program.rs @@ -40,9 +40,13 @@ static mut DISK_CACHE: Option = None; static DISK_CACHE_ONCE: Once = Once::new(); fn get_disk_cache() -> &'static Option { + let func_ptrs = [ + // ourselves + get_disk_cache as _, + ]; unsafe { DISK_CACHE_ONCE.call_once(|| { - DISK_CACHE = DiskCache::new("rusticl", "rusticl", 0); + DISK_CACHE = DiskCache::new("rusticl", &func_ptrs, 0); }); &DISK_CACHE } diff --git a/src/gallium/frontends/rusticl/mesa/util/disk_cache.rs b/src/gallium/frontends/rusticl/mesa/util/disk_cache.rs index 55f7dbd60b8..d07d57ed071 100644 --- a/src/gallium/frontends/rusticl/mesa/util/disk_cache.rs +++ b/src/gallium/frontends/rusticl/mesa/util/disk_cache.rs @@ -1,6 +1,6 @@ use mesa_rust_gen::*; -use std::ffi::CString; +use std::ffi::{c_void, CString}; use std::ops::Deref; use std::ptr; use std::ptr::NonNull; @@ -74,10 +74,28 @@ impl DiskCacheBorrowed { } impl DiskCache { - pub fn new(name: &str, driver_id: &str, flags: u64) -> Option { + pub fn new(name: &str, func_ptrs: &[*mut c_void], flags: u64) -> Option { let c_name = CString::new(name).unwrap(); - let c_id = CString::new(driver_id).unwrap(); - let cache = unsafe { disk_cache_create(c_name.as_ptr(), c_id.as_ptr(), flags) }; + let mut sha_ctx = SHA1_CTX::default(); + let mut sha = [0; SHA1_DIGEST_LENGTH as usize]; + let mut cache_id = [0; SHA1_DIGEST_STRING_LENGTH as usize]; + + let cache = unsafe { + SHA1Init(&mut sha_ctx); + + for &func_ptr in func_ptrs { + if !disk_cache_get_function_identifier(func_ptr, &mut sha_ctx) { + return None; + } + } + SHA1Final(&mut sha, &mut sha_ctx); + mesa_bytes_to_hex( + cache_id.as_mut_ptr(), + sha.as_ptr(), + (cache_id.len() - 1) as u32, + ); + disk_cache_create(c_name.as_ptr(), cache_id.as_ptr(), flags) + }; DiskCacheBorrowed::from_ptr(cache).map(|c| Self { inner: c }) }