Skip to content

Commit 20250ae

Browse files
committed
Pass Module directly to do_spirv_val instead of re-parsing binary
Avoids assembling the original module to a binary and then parsing it back. The validation error context can now use the Module directly for span lookups.
1 parent 7ff8b9d commit 20250ae

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

  • crates/rustc_codegen_spirv/src

crates/rustc_codegen_spirv/src/link.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ fn post_link_single_module(
273273
// Disassemble the stripped module (unless preserving decorations)
274274
cg_args.do_disassemble(&module_for_output);
275275
let spv_binary = module_for_output.assemble();
276-
let original_binary_for_spans = original_module_for_spans.assemble();
277276

278277
if let Some(dir) = &cg_args.dump_post_link {
279278
// FIXME(eddyb) rename `filename` with `file_path` to make this less confusing.
@@ -324,7 +323,7 @@ fn post_link_single_module(
324323
};
325324

326325
if cg_args.run_spirv_val {
327-
do_spirv_val(sess, &spv_binary, &original_binary_for_spans, out_filename, val_options);
326+
do_spirv_val(sess, &spv_binary, &original_module_for_spans, out_filename, val_options);
328327
}
329328

330329
{
@@ -412,7 +411,7 @@ fn do_spirv_opt(
412411
fn do_spirv_val(
413412
sess: &Session,
414413
spv_binary: &[u32],
415-
original_binary_for_spans: &[u32],
414+
original_module_for_spans: &Module,
416415
filename: &Path,
417416
options: spirv_tools::val::ValidatorOptions,
418417
) {
@@ -422,14 +421,9 @@ fn do_spirv_val(
422421
let validator = val::create(sess.target.options.env.parse().ok());
423422

424423
if let Err(e) = validator.validate(spv_binary, Some(options)) {
425-
// Parse the ORIGINAL binary (with SrcLocDecoration) to look up source spans
424+
// Use the ORIGINAL module (with SrcLocDecoration) to look up source spans
426425
// Note: We validate the stripped binary, but look up spans in the original
427-
let module = with_rspirv_loader(|loader| {
428-
rspirv::binary::parse_words(original_binary_for_spans, loader)
429-
})
430-
.ok();
431-
432-
let mut ctx = ValidationErrorContext::new(sess, module.as_ref(), filename);
426+
let mut ctx = ValidationErrorContext::new(sess, Some(original_module_for_spans), filename);
433427
ctx.emit_error(&e);
434428
}
435429
}

0 commit comments

Comments
 (0)