Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions crates/rustc_codegen_spirv/src/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,12 @@ fn link_exe(

let cg_args = CodegenArgs::from_session(sess);

// HACK(eddyb) this removes the `.json` in `.spv.json`, from `out_filename`.
let target = SpirvTarget::parse_target(sess.opts.target_triple.tuple())
.expect("parsing should fail earlier");
// this removes the `.json` in `.spv.json`, from `out_filename`.
let out_path_spv = out_filename.with_extension("");
// this replaces the `.spv` with a target-specific file extension, like `.wgsl` for `naga-wgsl`
let out_path_spv = out_path_spv.with_extension(target.file_extension());

let link_result = do_link(
sess,
Expand All @@ -188,7 +192,7 @@ fn link_exe(
let compile_result = match link_result {
linker::LinkResult::SingleModule(module) => {
let entry_points = entry_points(&module);
post_link_single_module(sess, &cg_args, *module, &out_path_spv, None);
post_link_single_module(sess, &cg_args, target, *module, &out_path_spv, None);
CompileResult {
entry_points,
module: ModuleResult::SingleModule(out_path_spv),
Expand All @@ -211,6 +215,7 @@ fn link_exe(
post_link_single_module(
sess,
&cg_args,
target,
module,
&out_file_path,
Some(disambiguated_crate_name_for_dumps),
Expand Down Expand Up @@ -243,6 +248,7 @@ fn entry_points(module: &rspirv::dr::Module) -> Vec<String> {
fn post_link_single_module(
sess: &Session,
cg_args: &CodegenArgs,
target: SpirvTarget,
module: Module,
out_filename: &Path,
dump_prefix: Option<&OsStr>,
Expand Down Expand Up @@ -304,7 +310,7 @@ fn post_link_single_module(

let binary = {
let _transpile_timer = sess.timer("link_transpile");
match transpile(sess, cg_args, &spv_binary) {
match transpile(sess, target, cg_args, &spv_binary) {
Ok(e) => e,
Err(_) => return,
}
Expand Down
3 changes: 1 addition & 2 deletions crates/rustc_codegen_spirv/src/naga_transpile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ use rustc_span::ErrorGuaranteed;

pub fn transpile(
sess: &Session,
target: SpirvTarget,
cg_args: &CodegenArgs,
spv_binary: &[u32],
) -> Result<Vec<u8>, ErrorGuaranteed> {
let target = SpirvTarget::parse_target(sess.opts.target_triple.tuple())
.expect("parsing should fail earlier");
match target {
#[cfg(feature = "naga")]
SpirvTarget::Naga(NagaTarget::NAGA_WGSL) => {
Expand Down
15 changes: 15 additions & 0 deletions crates/rustc_codegen_spirv/src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,12 @@ impl NagaTarget {
pub const fn new(out: NagaOut) -> Self {
Self { out }
}

pub fn file_extension(&self) -> String {
match self.out {
NagaOut::WGSL => "wgsl".to_string(),
}
}
}

impl SpirvTargetVariant for NagaTarget {
Expand Down Expand Up @@ -617,6 +623,15 @@ impl SpirvTarget {
format!("{}{}", SPIRV_TARGET_PREFIX, self.env())
}

pub fn file_extension(&self) -> String {
match self {
SpirvTarget::Universal(_) | SpirvTarget::Vulkan(_) | SpirvTarget::OpenGL(_) => {
"spv".to_string()
}
SpirvTarget::Naga(t) => t.file_extension(),
}
}

pub fn all_targets() -> impl Iterator<Item = Self> {
UniversalTarget::ALL_UNIVERSAL_TARGETS
.iter()
Expand Down
Loading