rusticl/program: add debugging for OpenCL C compilation

Signed-off-by: Karol Herbst <git@karolherbst.de>
Reviewed-by: Nora Allen <blackcatgames@protonmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23818>
This commit is contained in:
Karol Herbst 2023-05-30 12:52:29 +02:00 committed by Marge Bot
parent 2362fd502b
commit 2b2a513890
4 changed files with 28 additions and 1 deletions

View file

@ -945,6 +945,7 @@ Rusticl environment variables
a comma-separated list of debug channels to enable.
- ``clc`` dumps all OpenCL C source being compiled
- ``program`` dumps compilation logs to stderr
.. _clc-env-var:

View file

@ -17,6 +17,7 @@ pub struct Platform {
}
pub struct PlatformDebug {
pub clc: bool,
pub program: bool,
}
@ -55,7 +56,10 @@ static mut PLATFORM: Platform = Platform {
dispatch: &DISPATCH,
devs: Vec::new(),
};
static mut PLATFORM_DBG: PlatformDebug = PlatformDebug { program: false };
static mut PLATFORM_DBG: PlatformDebug = PlatformDebug {
clc: false,
program: false,
};
static mut PLATFORM_FEATURES: PlatformFeatures = PlatformFeatures {
fp16: false,
fp64: false,
@ -66,6 +70,7 @@ fn load_env() {
if let Ok(debug_flags) = env::var("RUSTICL_DEBUG") {
for flag in debug_flags.split(',') {
match flag {
"clc" => debug.clc = true,
"program" => debug.program = true,
_ => eprintln!("Unknown RUSTICL_DEBUG flag found: {}", flag),
}

View file

@ -563,6 +563,17 @@ impl Program {
}
ProgramSourceType::Src(src) => {
let args = prepare_options(&options, dev);
if Platform::dbg().clc {
let src = src.to_string_lossy();
eprintln!("dumping compilation inputs:");
eprintln!("compilation arguments: {args:?}");
if !headers.is_empty() {
eprintln!("headers: {headers:#?}");
}
eprintln!("source code:\n{src}");
}
spirv::SPIRVBin::from_clc(
src,
&args,

View file

@ -7,6 +7,7 @@ use mesa_rust_util::serialize::*;
use mesa_rust_util::string::*;
use std::ffi::CString;
use std::fmt::Debug;
use std::os::raw::c_char;
use std::os::raw::c_void;
use std::ptr;
@ -37,6 +38,15 @@ pub struct CLCHeader<'a> {
pub source: &'a CString,
}
impl<'a> Debug for CLCHeader<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let name = self.name.to_string_lossy();
let source = self.source.to_string_lossy();
f.write_fmt(format_args!("[{name}]:\n{source}"))
}
}
unsafe fn callback_impl(data: *mut c_void, msg: *const c_char) {
let data = data as *mut Vec<String>;
let msgs = unsafe { data.as_mut() }.unwrap();