Exploring rust-gpu internals: MIR to SPIR-V + debugging questions #260
Replies: 2 comments 3 replies
-
Hi there, just checking again, if someone has any pointers on this. TL;DRThere doesn’t seem to be a supported or documented way to directly step through Any pointers on this kind of low-level integration with Question:Is there a way to directly debug From what I’ve explored so far, I haven’t found a clear path to doing this. The only debugging avenues currently available seem to be:
My Approach: Programmatic MIR Generation and Backend Invocation
Here’s a minimal example I tried: use rustc_driver::{Callbacks, Compilation};
use rustc_interface::{interface, Queries};
struct SpirvCaller;
impl Callbacks for SpirvCaller {
fn after_analysis<'tcx>(
&mut self,
_compiler: &interface::Compiler,
queries: &'tcx Queries<'tcx>,
) -> Compilation {
queries.global_ctxt().unwrap().enter(|tcx| {
let metadata = rustc_metadata::EncodedMetadata::from_path(
PathBuf::from("../../examples/shaders/simplest-shader/src/lib.rs"),
None,
).unwrap();
let backend = SpirvCodegenBackend;
let result = backend.codegen_crate(tcx, metadata, false);
println!("SPIR-V codegen result: {:?}", result.type_id());
});
Compilation::Stop
}
} To drive this setup, I used rustc directly with the required arguments: rustc_driver::RunCompiler::new(&args, &mut SpirvCaller)
.run()
.expect("Failed to run rustc driver"); The arguments were extracted from a working cargo build-plan
and adjusted for use with
These errors suggest that
|
Beta Was this translation helpful? Give feedback.
-
Hi @LegNeato — do you happen to have any thoughts on this? The only other option I can think of is to start instrumenting |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
I finally found some time to explore this project —
rust-gpu
has been on my to-do list for a long while! I recorded a (relatively) short stream where I dig into its internals, primarily to build a mental model of how the MIR → SPIR-V mapping works. I plan to make more of these as I continue exploring.I’d really appreciate any corrections or feedback if I got anything wrong in the video.
Also, I have a question:
rustc_codegen_spirv
and breakpoint-debug the entire backend flow? The current examples use a build script that precompiles the backend and stores it in a known location, which makes breakpoint debugging the actual backend code quite difficult.SpirvCodegenBackend::codegen_crate
programmatically to trace the flow end-to-end during debugging. This should work -right?YouTube link
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions