mirror of
https://github.com/EmbarkStudios/rust-gpu.git
synced 2024-10-29 21:42:20 +00:00
Implement capabilities through target-features
This commit is contained in:
parent
3d710e7c4b
commit
301e81a7da
@ -303,7 +303,7 @@ pub struct BuilderSpirv {
|
||||
}
|
||||
|
||||
impl BuilderSpirv {
|
||||
pub fn new(target: &SpirvTarget) -> Self {
|
||||
pub fn new<'target, 'tcx>(target: &'target SpirvTarget, features: impl Iterator<Item=&'tcx rustc_span::symbol::Symbol>) -> Self {
|
||||
let version = target.spirv_version();
|
||||
let memory_model = target.memory_model();
|
||||
|
||||
@ -324,10 +324,10 @@ impl BuilderSpirv {
|
||||
|
||||
// The linker will always be ran on this module
|
||||
builder.capability(Capability::Linkage);
|
||||
builder.capability(Capability::Int8);
|
||||
builder.capability(Capability::Int16);
|
||||
builder.capability(Capability::Int64);
|
||||
builder.capability(Capability::Float64);
|
||||
|
||||
for feature in features {
|
||||
builder.capability(feature.as_str().parse().unwrap());
|
||||
}
|
||||
|
||||
let addressing_model = if target.is_kernel() {
|
||||
builder.capability(Capability::Addresses);
|
||||
|
@ -80,16 +80,13 @@ pub struct CodegenCx<'tcx> {
|
||||
impl<'tcx> CodegenCx<'tcx> {
|
||||
pub fn new(tcx: TyCtxt<'tcx>, codegen_unit: &'tcx CodegenUnit<'tcx>) -> Self {
|
||||
let sym = Symbols::get();
|
||||
for &feature in &tcx.sess.target_features {
|
||||
tcx.sess.err(&format!("Unknown feature {}", feature));
|
||||
}
|
||||
let codegen_args = CodegenArgs::from_session(tcx.sess);
|
||||
let target = tcx.sess.target.llvm_target.parse().unwrap();
|
||||
|
||||
Self {
|
||||
builder: BuilderSpirv::new(&target, tcx.sess.target_features.iter()),
|
||||
tcx,
|
||||
codegen_unit,
|
||||
builder: BuilderSpirv::new(&target),
|
||||
instances: Default::default(),
|
||||
function_parameter_values: Default::default(),
|
||||
type_cache: Default::default(),
|
||||
|
@ -257,12 +257,19 @@ impl CodegenBackend for SpirvCodegenBackend {
|
||||
fn target_features(&self, sess: &Session) -> Vec<Symbol> {
|
||||
let cmdline = sess.opts.cg.target_feature.split(',');
|
||||
let cfg = sess.target.options.features.split(',');
|
||||
cfg.chain(cmdline)
|
||||
let result = cfg.chain(cmdline)
|
||||
.filter(|l| l.starts_with('+'))
|
||||
.map(|l| &l[1..])
|
||||
.filter(|l| !l.is_empty())
|
||||
.map(Symbol::intern)
|
||||
.collect()
|
||||
.map(|l| l.parse::<rspirv::spirv::Capability>().map(|_| Symbol::intern(l)).map_err(|_| l))
|
||||
.collect::<Result<Vec<_>, _>>();
|
||||
|
||||
match result {
|
||||
Ok(val) => val,
|
||||
Err(input) => {
|
||||
sess.err(&format!("Invalid capability: `{}`", input));
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn target_override(&self, opts: &config::Options) -> Option<Target> {
|
||||
@ -353,8 +360,8 @@ impl CodegenBackend for SpirvCodegenBackend {
|
||||
codegen_results: CodegenResults,
|
||||
outputs: &OutputFilenames,
|
||||
) -> Result<(), ErrorReported> {
|
||||
// TODO: Can we merge this sym with the one in symbols.rs?
|
||||
let legalize = !sess.target_features.contains(&Symbol::intern("kernel"));
|
||||
let target = sess.target.llvm_target.parse::<target::SpirvTarget>().unwrap();
|
||||
let legalize = !target.is_kernel();
|
||||
let codegen_args = CodegenArgs::from_session(sess);
|
||||
let emit_multiple_modules = codegen_args.module_output_type == ModuleOutputType::Multiple;
|
||||
|
||||
|
@ -5,11 +5,6 @@ use rustc_data_structures::fx::FxHashSet;
|
||||
pub fn remove_extra_capabilities(module: &mut Module) {
|
||||
let used_capabilities = used_capabilities(module);
|
||||
let removable_capabilities: FxHashSet<Capability> = [
|
||||
Capability::Int8,
|
||||
Capability::Int16,
|
||||
Capability::Int64,
|
||||
Capability::Float16,
|
||||
Capability::Float64,
|
||||
Capability::IntegerFunctions2INTEL,
|
||||
Capability::DemoteToHelperInvocationEXT,
|
||||
Capability::DerivativeControl,
|
||||
|
0
tests/ui/lang/target_features/invalid.rs
Normal file
0
tests/ui/lang/target_features/invalid.rs
Normal file
Loading…
Reference in New Issue
Block a user