Skip to content
Draft
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
2 changes: 2 additions & 0 deletions crates/rustc_codegen_spirv-types/src/target.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::fmt::{Debug, Formatter};
use thiserror::Error;

pub const SPIRV_VENDOR: &str = "unknown";
pub const SPIRV_ARCH: &str = "spirv";
pub const SPIRV_TARGET_PREFIX: &str = "spirv-unknown-";

/// A well-formed rust-gpu target.
Expand Down
4 changes: 2 additions & 2 deletions crates/rustc_codegen_spirv/src/builder_spirv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::builder;
use crate::codegen_cx::CodegenCx;
use crate::spirv_type::SpirvType;
use crate::symbols::Symbols;
use crate::target::SpirvTarget;
use crate::target::{SpirvTarget, SpirvTargetVariant, SpirvVersion};
use crate::target_feature::TargetFeature;
use rspirv::dr::{Builder, Instruction, Module, Operand};
use rspirv::spirv::{
Expand Down Expand Up @@ -492,7 +492,7 @@ impl<'tcx> BuilderSpirv<'tcx> {

add_cap(&mut builder, &mut enabled_capabilities, Capability::Shader);
if memory_model == MemoryModel::Vulkan {
if version < (1, 5) {
if version < SpirvVersion::V1_5 {
add_ext(&mut builder, sym.spv_khr_vulkan_memory_model);
}
add_cap(
Expand Down
4 changes: 2 additions & 2 deletions crates/rustc_codegen_spirv/src/codegen_cx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use crate::builder_spirv::{
use crate::custom_decorations::{CustomDecoration, SrcLocDecoration, ZombieDecoration};
use crate::spirv_type::{SpirvType, SpirvTypePrinter, TypeCache};
use crate::symbols::Symbols;
use crate::target::SpirvTarget;

// HACK(eddyb) avoids rewriting all of the imports (see `lib.rs` and `build.rs`).
use crate::maybe_pqp_cg_ssa as rustc_codegen_ssa;

use crate::target::SpirvTarget;
use itertools::Itertools as _;
use rspirv::dr::{Module, Operand};
use rspirv::spirv::{Decoration, LinkageType, Word};
Expand Down Expand Up @@ -99,7 +99,7 @@ impl<'tcx> CodegenCx<'tcx> {
pub fn new(tcx: TyCtxt<'tcx>, codegen_unit: &'tcx CodegenUnit<'tcx>) -> Self {
// Validate the target spec, as the backend doesn't control `--target`.
let target_tuple = tcx.sess.opts.target_triple.tuple();
let target: SpirvTarget = target_tuple.parse().unwrap_or_else(|_| {
let target = SpirvTarget::parse(target_tuple).unwrap_or_else(|_| {
let qualifier = if !target_tuple.starts_with("spirv-") {
"non-SPIR-V "
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/rustc_codegen_spirv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ mod linker;
mod spirv_type;
mod spirv_type_constraints;
mod symbols;
mod target;
pub mod target;
mod target_feature;

use builder::Builder;
Expand Down
7 changes: 5 additions & 2 deletions crates/rustc_codegen_spirv/src/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use crate::maybe_pqp_cg_ssa as rustc_codegen_ssa;

use crate::codegen_cx::{CodegenArgs, SpirvMetadata};
use crate::target::{SpirvTarget, SpirvTargetVariant};
use crate::{SpirvCodegenBackend, SpirvModuleBuffer, linker};
use ar::{Archive, GnuBuilder, Header};
use rspirv::binary::Assemble;
Expand Down Expand Up @@ -336,7 +337,8 @@ fn do_spirv_opt(
opt::{self, Optimizer},
};

let mut optimizer = opt::create(sess.target.options.env.parse().ok());
let target = SpirvTarget::parse_env(&sess.target.options.env).unwrap();
let mut optimizer = opt::create(Some(target.to_spirv_tools()));

match sess.opts.optimize {
OptLevel::No => {}
Expand Down Expand Up @@ -398,7 +400,8 @@ fn do_spirv_val(
) {
use spirv_tools::val::{self, Validator};

let validator = val::create(sess.target.options.env.parse().ok());
let target = SpirvTarget::parse_env(&sess.target.options.env).unwrap();
let validator = val::create(Some(target.to_spirv_tools()));

if let Err(e) = validator.validate(spv_binary, Some(options)) {
let mut err = sess.dcx().struct_err(e.to_string());
Expand Down
6 changes: 2 additions & 4 deletions crates/rustc_codegen_spirv/src/linker/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::sync::{Arc, Mutex};
// We need to construct an emitter as yet another workaround,
// see https://github.com/rust-lang/rust/pull/102992.
extern crate termcolor;
use crate::target::SpirvTarget;
use termcolor::{ColorSpec, WriteColor};

// https://github.com/colin-kiegel/rust-pretty-assertions/issues/24
Expand Down Expand Up @@ -130,10 +131,7 @@ fn link_with_linker_opts(
.unwrap();
let sopts = rustc_session::config::build_session_options(&mut early_dcx, &matches);

let target = "spirv-unknown-spv1.0"
.parse::<crate::target::SpirvTarget>()
.unwrap()
.rustc_target();
let target = SpirvTarget::UNIVERSAL_1_0.rustc_target();
let sm_inputs = rustc_span::source_map::SourceMapInputs {
file_loader: Box::new(rustc_span::source_map::RealFileLoader),
path_mapping: sopts.file_path_mapping(),
Expand Down
Loading