From 49dd2380838b9f142406d906f754c8cafcaaa95d Mon Sep 17 00:00:00 2001 From: Ashley Hauck Date: Wed, 28 Apr 2021 15:53:33 +0200 Subject: [PATCH] Bump rust-toolchain to nightly-2021-04-25 (#605) * Bump rust-toolchain to nightly-2021-04-25 --- Cargo.lock | 6 +- crates/rustc_codegen_spirv/src/attr.rs | 8 +- .../src/builder/builder_methods.rs | 6 +- crates/rustc_codegen_spirv/src/builder/mod.rs | 4 - .../src/builder/spirv_asm.rs | 4 +- .../rustc_codegen_spirv/src/builder_spirv.rs | 2 +- .../rustc_codegen_spirv/src/codegen_cx/mod.rs | 10 +- crates/rustc_codegen_spirv/src/decorations.rs | 2 +- .../rustc_codegen_spirv/src/linker/inline.rs | 4 +- .../src/linker/new_structurizer.rs | 2 +- .../src/linker/simple_passes.rs | 4 +- .../src/linker/specializer.rs | 14 +- crates/rustc_codegen_spirv/src/spirv_type.rs | 18 +- crates/spirv-builder/src/depfile.rs | 4 +- crates/spirv-std/macros/src/image.rs | 6 +- crates/spirv-std/macros/src/lib.rs | 2 +- crates/spirv-std/src/arch/arithmetic.rs | 169 +++++------------- crates/spirv-std/src/arch/barrier.rs | 47 ++--- rust-toolchain | 2 +- tests/ui/arch/control_barrier.rs | 6 +- tests/ui/arch/memory_barrier.rs | 8 +- 21 files changed, 129 insertions(+), 199 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 897a822ca4..607f077380 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2400,7 +2400,8 @@ dependencies = [ [[package]] name = "spirv_headers" version = "1.5.0" -source = "git+https://github.com/gfx-rs/rspirv?rev=719cf08#719cf08e4af0436242707479e3509add5ec3d514" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f5b132530b1ac069df335577e3581765995cba5a13995cdbbdbc8fb057c532c" dependencies = [ "bitflags", "num-traits", @@ -2409,8 +2410,7 @@ dependencies = [ [[package]] name = "spirv_headers" version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f5b132530b1ac069df335577e3581765995cba5a13995cdbbdbc8fb057c532c" +source = "git+https://github.com/gfx-rs/rspirv?rev=719cf08#719cf08e4af0436242707479e3509add5ec3d514" dependencies = [ "bitflags", "num-traits", diff --git a/crates/rustc_codegen_spirv/src/attr.rs b/crates/rustc_codegen_spirv/src/attr.rs index d53d838f24..0194b5ad79 100644 --- a/crates/rustc_codegen_spirv/src/attr.rs +++ b/crates/rustc_codegen_spirv/src/attr.rs @@ -277,8 +277,7 @@ impl CheckSpirvAttrVisitor<'_> { SpirvAttribute::Entry(_) => match target { Target::Fn - | Target::Method(MethodKind::Trait { body: true }) - | Target::Method(MethodKind::Inherent) => { + | Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => { // FIXME(eddyb) further check entry-point attribute validity, // e.g. signature, shouldn't have `#[inline]` or generics, etc. Ok(()) @@ -339,8 +338,9 @@ impl CheckSpirvAttrVisitor<'_> { SpirvAttribute::UnrollLoops => match target { Target::Fn | Target::Closure - | Target::Method(MethodKind::Trait { body: true }) - | Target::Method(MethodKind::Inherent) => Ok(()), + | Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => { + Ok(()) + } _ => Err(Expected("function or closure")), }, diff --git a/crates/rustc_codegen_spirv/src/builder/builder_methods.rs b/crates/rustc_codegen_spirv/src/builder/builder_methods.rs index 2b5a3ce6b4..7cde901df7 100644 --- a/crates/rustc_codegen_spirv/src/builder/builder_methods.rs +++ b/crates/rustc_codegen_spirv/src/builder/builder_methods.rs @@ -803,6 +803,8 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { } } + // silly clippy, we can't rename this! + #[allow(clippy::wrong_self_convention)] fn to_immediate_scalar(&mut self, val: Self::Value, scalar: &Scalar) -> Self::Value { if scalar.is_bool() { let bool = SpirvType::Bool.def(self.span(), self); @@ -1142,10 +1144,6 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { None } - fn fptosui_may_trap(&self, _val: Self::Value, _dest_ty: Self::Type) -> bool { - false - } - fn fptoui(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value { if val.ty == dest_ty { val diff --git a/crates/rustc_codegen_spirv/src/builder/mod.rs b/crates/rustc_codegen_spirv/src/builder/mod.rs index edad67fabe..d7a84941ad 100644 --- a/crates/rustc_codegen_spirv/src/builder/mod.rs +++ b/crates/rustc_codegen_spirv/src/builder/mod.rs @@ -217,10 +217,6 @@ impl<'a, 'tcx> Deref for Builder<'a, 'tcx> { } impl<'a, 'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'a, 'tcx> { - fn create_pgo_func_name_var(&self, _instance: Instance<'tcx>) -> Self::Value { - todo!() - } - fn set_function_source_hash(&mut self, _: rustc_middle::ty::Instance<'tcx>, _: u64) -> bool { todo!() } diff --git a/crates/rustc_codegen_spirv/src/builder/spirv_asm.rs b/crates/rustc_codegen_spirv/src/builder/spirv_asm.rs index f1fa7632d6..4cb25479e1 100644 --- a/crates/rustc_codegen_spirv/src/builder/spirv_asm.rs +++ b/crates/rustc_codegen_spirv/src/builder/spirv_asm.rs @@ -562,7 +562,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> { match_ty_pat(cx, a, ty).or_else(|Unapplicable| match_ty_pat(cx, b, ty)) } _ => match (pat, cx.lookup_type(ty)) { - (TyPat::Any, _) | (&TyPat::T, _) | (TyPat::Either(..), _) => unreachable!(), + (TyPat::Any | &TyPat::T | TyPat::Either(..), _) => unreachable!(), (TyPat::Void, SpirvType::Void) => Ok([None]), (TyPat::Pointer(_, pat), SpirvType::Pointer { pointee: ty, .. }) @@ -978,7 +978,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> { Token::String(_) | Token::Placeholder(_, _) | Token::Typeof(_, _, _) => None, }; match (kind, word) { - (OperandKind::IdResultType, _) | (OperandKind::IdResult, _) => { + (OperandKind::IdResultType | OperandKind::IdResult, _) => { bug!("should be handled by parse_operands") } (OperandKind::IdMemorySemantics, _) => { diff --git a/crates/rustc_codegen_spirv/src/builder_spirv.rs b/crates/rustc_codegen_spirv/src/builder_spirv.rs index 45d15eb220..527eeab1a2 100644 --- a/crates/rustc_codegen_spirv/src/builder_spirv.rs +++ b/crates/rustc_codegen_spirv/src/builder_spirv.rs @@ -507,7 +507,7 @@ impl BuilderSpirv { Ok(()) => Ok(()), // `Shallow` becomes `Indirect` when placed behind a pointer. - Err(IllegalConst::Shallow(cause)) | Err(IllegalConst::Indirect(cause)) => { + Err(IllegalConst::Shallow(cause) | IllegalConst::Indirect(cause)) => { Err(IllegalConst::Indirect(cause)) } }, diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs b/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs index 43ead54a3b..9955e31c75 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs @@ -25,7 +25,7 @@ use rustc_middle::mir::Body; use rustc_middle::ty::layout::{HasParamEnv, HasTyCtxt}; use rustc_middle::ty::{Instance, ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt, TyS}; use rustc_session::Session; -use rustc_span::def_id::LOCAL_CRATE; +use rustc_span::def_id::{DefId, LOCAL_CRATE}; use rustc_span::symbol::{sym, Symbol}; use rustc_span::{SourceFile, Span, DUMMY_SP}; use rustc_target::abi::call::FnAbi; @@ -425,10 +425,16 @@ impl<'tcx> DebugInfoMethods<'tcx> for CodegenCx<'tcx> { } } -impl<'tcx> CoverageInfoMethods for CodegenCx<'tcx> { +impl<'tcx> CoverageInfoMethods<'tcx> for CodegenCx<'tcx> { fn coverageinfo_finalize(&self) { todo!() } + fn get_pgo_func_name_var(&self, _: Instance<'tcx>) -> SpirvValue { + todo!() + } + fn define_unused_fn(&self, _: DefId) { + todo!() + } } impl<'tcx> AsmMethods for CodegenCx<'tcx> { diff --git a/crates/rustc_codegen_spirv/src/decorations.rs b/crates/rustc_codegen_spirv/src/decorations.rs index 0646f14d1e..268d781f8a 100644 --- a/crates/rustc_codegen_spirv/src/decorations.rs +++ b/crates/rustc_codegen_spirv/src/decorations.rs @@ -218,7 +218,7 @@ impl SerializedSpan { // Sanity check - assuming `SerializedSpan` isn't corrupted, this assert // could only ever fail because of a hash collision. - assert!(self.lo <= self.hi && self.hi <= file.byte_length()); + assert!(self.lo <= self.hi && self.hi <= (file.end_pos.0 - file.start_pos.0)); Some(Span::with_root_ctxt( file.start_pos + Pos::from_u32(self.lo), diff --git a/crates/rustc_codegen_spirv/src/linker/inline.rs b/crates/rustc_codegen_spirv/src/linker/inline.rs index f7750c23fe..18d1cd6785 100644 --- a/crates/rustc_codegen_spirv/src/linker/inline.rs +++ b/crates/rustc_codegen_spirv/src/linker/inline.rs @@ -9,7 +9,7 @@ use super::simple_passes::outgoing_edges; use rspirv::dr::{Block, Function, Instruction, Module, ModuleHeader, Operand}; use rspirv::spirv::{FunctionControl, Op, StorageClass, Word}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use std::mem::replace; +use std::mem::take; type FunctionMap = FxHashMap; @@ -416,7 +416,7 @@ fn fuse_trivial_branches(function: &mut Function) { }; let pred_insts = &function.blocks[pred].instructions; if pred_insts.last().unwrap().class.opcode == Op::Branch { - let mut dest_insts = replace(&mut function.blocks[dest_block].instructions, Vec::new()); + let mut dest_insts = take(&mut function.blocks[dest_block].instructions); let pred_insts = &mut function.blocks[pred].instructions; pred_insts.pop(); // pop the branch pred_insts.append(&mut dest_insts); diff --git a/crates/rustc_codegen_spirv/src/linker/new_structurizer.rs b/crates/rustc_codegen_spirv/src/linker/new_structurizer.rs index 695e0d2ac7..2ddbef7fc4 100644 --- a/crates/rustc_codegen_spirv/src/linker/new_structurizer.rs +++ b/crates/rustc_codegen_spirv/src/linker/new_structurizer.rs @@ -327,7 +327,7 @@ impl Structurizer<'_> { // Also update the existing merge if it happens to be the `block` // we just moved (this should only be relevant to infinite loops). self.func.blocks_mut()[while_body_block].instructions = - mem::replace(&mut self.func.blocks_mut()[block].instructions, vec![]); + mem::take(&mut self.func.blocks_mut()[block].instructions); if region.merge == block { region.merge = while_body_block; region.merge_id = while_body_block_id; diff --git a/crates/rustc_codegen_spirv/src/linker/simple_passes.rs b/crates/rustc_codegen_spirv/src/linker/simple_passes.rs index 5a4c5959f6..4cf2c263d9 100644 --- a/crates/rustc_codegen_spirv/src/linker/simple_passes.rs +++ b/crates/rustc_codegen_spirv/src/linker/simple_passes.rs @@ -1,7 +1,7 @@ use rspirv::dr::{Block, Function, Module}; use rspirv::spirv::{Op, Word}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use std::mem::replace; +use std::mem::take; pub fn shift_ids(module: &mut Module, add: u32) { module.all_inst_iter_mut().for_each(|inst| { @@ -66,7 +66,7 @@ pub fn block_ordering_pass(func: &mut Function) { let entry_label = func.blocks[0].label_id().unwrap(); visit_postorder(func, &mut visited, &mut postorder, entry_label); - let mut old_blocks = replace(&mut func.blocks, Vec::new()); + let mut old_blocks = take(&mut func.blocks); // Order blocks according to reverse postorder for &block in postorder.iter().rev() { let index = old_blocks diff --git a/crates/rustc_codegen_spirv/src/linker/specializer.rs b/crates/rustc_codegen_spirv/src/linker/specializer.rs index 5a9a441f2c..4c4295ed30 100644 --- a/crates/rustc_codegen_spirv/src/linker/specializer.rs +++ b/crates/rustc_codegen_spirv/src/linker/specializer.rs @@ -2221,7 +2221,7 @@ impl<'a, S: Specialization> InferCx<'a, S> { /// are handled (using `generic_params` and `S::concrete_fallback()`). fn into_replacements(mut self, generic_params: RangeTo) -> Replacements { let mut with_instance: IndexMap<_, Vec<_>> = IndexMap::new(); - for (loc, instance) in mem::replace(&mut self.instantiated_operands, vec![]) { + for (loc, instance) in mem::take(&mut self.instantiated_operands) { with_instance .entry(Instance { generic_id: instance.generic_id, @@ -2233,7 +2233,7 @@ impl<'a, S: Specialization> InferCx<'a, S> { .push(loc); } - let with_concrete_or_param = mem::replace(&mut self.inferred_operands, vec![]) + let with_concrete_or_param = mem::take(&mut self.inferred_operands) .into_iter() .map(|(loc, v)| { ( @@ -2345,11 +2345,11 @@ impl<'a, S: Specialization> Expander<'a, S> { // HACK(eddyb) steal `Vec`s so that we can still call methods on `self` below. let module = self.builder.module_mut(); - let mut entry_points = mem::replace(&mut module.entry_points, vec![]); - let debugs = mem::replace(&mut module.debugs, vec![]); - let annotations = mem::replace(&mut module.annotations, vec![]); - let types_global_values = mem::replace(&mut module.types_global_values, vec![]); - let functions = mem::replace(&mut module.functions, vec![]); + let mut entry_points = mem::take(&mut module.entry_points); + let debugs = mem::take(&mut module.debugs); + let annotations = mem::take(&mut module.annotations); + let types_global_values = mem::take(&mut module.types_global_values); + let functions = mem::take(&mut module.functions); // Adjust `OpEntryPoint ...` in-place to use the new IDs for *Interface* // module-scoped `OpVariable`s (which should each have one instance). diff --git a/crates/rustc_codegen_spirv/src/spirv_type.rs b/crates/rustc_codegen_spirv/src/spirv_type.rs index 1581328017..fe98b54bc2 100644 --- a/crates/rustc_codegen_spirv/src/spirv_type.rs +++ b/crates/rustc_codegen_spirv/src/spirv_type.rs @@ -116,10 +116,11 @@ impl SpirvType { } 8 | 16 | 32 | 64 => (), 128 => cx.zombie_with_span(result, def_span, "u128"), - other => cx - .tcx - .sess - .fatal(&format!("Integer width {} invalid for spir-v", other)), + other => cx.zombie_with_span( + result, + def_span, + &format!("Integer width {} invalid for spir-v", other), + ), }; result } @@ -130,10 +131,11 @@ impl SpirvType { cx.zombie_with_span(result, def_span, "f64 without OpCapability Float64") } 32 | 64 => (), - other => cx - .tcx - .sess - .fatal(&format!("Float width {} invalid for spir-v", other)), + other => cx.zombie_with_span( + result, + def_span, + &format!("Float width {} invalid for spir-v", other), + ), }; result } diff --git a/crates/spirv-builder/src/depfile.rs b/crates/spirv-builder/src/depfile.rs index 38b08a6715..718c539a4a 100644 --- a/crates/spirv-builder/src/depfile.rs +++ b/crates/spirv-builder/src/depfile.rs @@ -4,7 +4,7 @@ use raw_string::{RawStr, RawString}; use std::fs::File; use std::io::{BufRead, BufReader, Error, ErrorKind, Read}; -use std::mem::replace; +use std::mem::{replace, take}; use std::path::Path; /// Read a Makfile-style dependency file. @@ -136,7 +136,7 @@ impl State { ) -> Result<(), Error> { self.finish_path()?; if let Some(target) = self.target.take() { - f(target, replace(&mut self.deps, Vec::new()))?; + f(target, take(&mut self.deps))?; } Ok(()) } diff --git a/crates/spirv-std/macros/src/image.rs b/crates/spirv-std/macros/src/image.rs index 14363f3407..63a7d543b4 100644 --- a/crates/spirv-std/macros/src/image.rs +++ b/crates/spirv-std/macros/src/image.rs @@ -77,9 +77,9 @@ impl Parse for ImageType { let int = input.parse::().unwrap(); set_unique!( dimensionality = match (int.base10_digits(), int.suffix()) { - ("1", "D") | ("1", "d") => Dimensionality::OneD, - ("2", "D") | ("2", "d") => Dimensionality::TwoD, - ("3", "D") | ("3", "d") => Dimensionality::ThreeD, + ("1", "D" | "d") => Dimensionality::OneD, + ("2", "D" | "d") => Dimensionality::TwoD, + ("3", "D" | "d") => Dimensionality::ThreeD, _ => return Err(syn::Error::new(int.span(), "Unexpected integer")), } ); diff --git a/crates/spirv-std/macros/src/lib.rs b/crates/spirv-std/macros/src/lib.rs index 787f7f670d..34dbde6244 100644 --- a/crates/spirv-std/macros/src/lib.rs +++ b/crates/spirv-std/macros/src/lib.rs @@ -218,7 +218,7 @@ fn create_vectored_fn( syn::Pat::Ident(pat) if pat.ident == COMPONENT_ARG_NAME => Some(&mut ty.ty), _ => None, }, - _ => None, + syn::FnArg::Receiver(_) => None, }); if component_type.is_none() { diff --git a/crates/spirv-std/src/arch/arithmetic.rs b/crates/spirv-std/src/arch/arithmetic.rs index 7ee0ab78d1..fa58e08517 100644 --- a/crates/spirv-std/src/arch/arithmetic.rs +++ b/crates/spirv-std/src/arch/arithmetic.rs @@ -23,14 +23,10 @@ where unsafe { asm! { - "%int_type = OpTypeInt {width} 1", - "%vec_type = OpTypeVector %int_type {length}", - "%operand = OpLoad %vec_type {operand}", - "%result = OpSNegate %vec_type %operand", + "%operand = OpLoad typeof*{operand} {operand}", + "%result = OpSNegate typeof*{operand} %operand", "OpStore {result} %result", operand = in(reg) &operand, - width = const S::WIDTH, - length = const N, result = in(reg) &mut result, } } @@ -52,14 +48,10 @@ where unsafe { asm! { - "%float_type = OpTypeFloat {width}", - "%vec_type = OpTypeVector %float_type {length}", - "%operand = OpLoad %vec_type {operand}", - "%result = OpFNegate %vec_type %operand", + "%operand = OpLoad typeof*{operand} {operand}", + "%result = OpFNegate typeof*{operand} %operand", "OpStore {result} %result", operand = in(reg) &operand, - width = const F::WIDTH, - length = const N, result = in(reg) &mut result, } } @@ -84,17 +76,12 @@ where unsafe { asm! { - "%int_type = OpTypeInt {width} {sign}", - "%vec_type = OpTypeVector %int_type {length}", - "%x = OpLoad %vec_type {x}", - "%y = OpLoad %vec_type {y}", - "%result = OpIAdd %vec_type %x %y", + "%x = OpLoad typeof*{x} {x}", + "%y = OpLoad typeof*{y} {y}", + "%result = OpIAdd typeof*{x} %x %y", "OpStore {result} %result", x = in(reg) &x, y = in(reg) &y, - sign = const I::SIGNED as u8, - width = const I::WIDTH, - length = const LEN, result = in(reg) &mut result, } } @@ -115,16 +102,12 @@ where unsafe { asm! { - "%float_type = OpTypeFloat {width}", - "%vec_type = OpTypeVector %float_type {length}", - "%x = OpLoad %vec_type {x}", - "%y = OpLoad %vec_type {y}", - "%result = OpFAdd %vec_type %x %y", + "%x = OpLoad typeof*{x} {x}", + "%y = OpLoad typeof*{y} {y}", + "%result = OpFAdd typeof*{x} %x %y", "OpStore {result} %result", x = in(reg) &x, y = in(reg) &y, - width = const F::WIDTH, - length = const LEN, result = in(reg) &mut result, } } @@ -149,17 +132,12 @@ where unsafe { asm! { - "%int_type = OpTypeInt {width} {sign}", - "%vec_type = OpTypeVector %int_type {length}", - "%x = OpLoad %vec_type {x}", - "%y = OpLoad %vec_type {y}", - "%result = OpISub %vec_type %x %y", + "%x = OpLoad typeof*{x} {x}", + "%y = OpLoad typeof*{y} {y}", + "%result = OpISub typeof*{x} %x %y", "OpStore {result} %result", x = in(reg) &x, y = in(reg) &y, - sign = const I::SIGNED as u8, - width = const I::WIDTH, - length = const LEN, result = in(reg) &mut result, } } @@ -180,16 +158,12 @@ where unsafe { asm! { - "%float_type = OpTypeFloat {width}", - "%vec_type = OpTypeVector %float_type {length}", - "%x = OpLoad %vec_type {x}", - "%y = OpLoad %vec_type {y}", - "%result = OpFSub %vec_type %x %y", + "%x = OpLoad typeof*{x} {x}", + "%y = OpLoad typeof*{y} {y}", + "%result = OpFSub typeof*{x} %x %y", "OpStore {result} %result", x = in(reg) &x, y = in(reg) &y, - width = const F::WIDTH, - length = const LEN, result = in(reg) &mut result, } } @@ -214,17 +188,12 @@ where unsafe { asm! { - "%int_type = OpTypeInt {width} {sign}", - "%vec_type = OpTypeVector %int_type {length}", - "%x = OpLoad %vec_type {x}", - "%y = OpLoad %vec_type {y}", - "%result = OpIMul %vec_type %x %y", + "%x = OpLoad typeof*{x} {x}", + "%y = OpLoad typeof*{y} {y}", + "%result = OpIMul typeof*{x} %x %y", "OpStore {result} %result", x = in(reg) &x, y = in(reg) &y, - sign = const I::SIGNED as u8, - width = const I::WIDTH, - length = const LEN, result = in(reg) &mut result, } } @@ -246,16 +215,12 @@ where unsafe { asm! { - "%float_type = OpTypeFloat {width}", - "%vec_type = OpTypeVector %float_type {length}", - "%x = OpLoad %vec_type {x}", - "%y = OpLoad %vec_type {y}", - "%result = OpFMul %vec_type %x %y", + "%x = OpLoad typeof*{x} {x}", + "%y = OpLoad typeof*{y} {y}", + "%result = OpFMul typeof*{x} %x %y", "OpStore {result} %result", x = in(reg) &x, y = in(reg) &y, - width = const F::WIDTH, - length = const LEN, result = in(reg) &mut result, } } @@ -280,16 +245,12 @@ where unsafe { asm! { - "%int_type = OpTypeInt {width} 0", - "%vec_type = OpTypeVector %int_type {length}", - "%x = OpLoad %vec_type {x}", - "%y = OpLoad %vec_type {y}", - "%result = OpUDiv %vec_type %x %y", + "%x = OpLoad typeof*{x} {x}", + "%y = OpLoad typeof*{y} {y}", + "%result = OpUDiv typeof*{x} %x %y", "OpStore {result} %result", x = in(reg) &x, y = in(reg) &y, - width = const I::WIDTH, - length = const LEN, result = in(reg) &mut result, } } @@ -316,16 +277,12 @@ where unsafe { asm! { - "%int_type = OpTypeInt {width} 1", - "%vec_type = OpTypeVector %int_type {length}", - "%x = OpLoad %vec_type {x}", - "%y = OpLoad %vec_type {y}", - "%result = OpSDiv %vec_type %x %y", + "%x = OpLoad typeof*{x} {x}", + "%y = OpLoad typeof*{y} {y}", + "%result = OpSDiv typeof*{y} %x %y", "OpStore {result} %result", x = in(reg) &x, y = in(reg) &y, - width = const I::WIDTH, - length = const LEN, result = in(reg) &mut result, } } @@ -350,16 +307,12 @@ where unsafe { asm! { - "%float_type = OpTypeFloat {width}", - "%vec_type = OpTypeVector %float_type {length}", - "%x = OpLoad %vec_type {x}", - "%y = OpLoad %vec_type {y}", - "%result = OpFDiv %vec_type %x %y", + "%x = OpLoad typeof*{x} {x}", + "%y = OpLoad typeof*{y} {y}", + "%result = OpFDiv typeof*{x} %x %y", "OpStore {result} %result", x = in(reg) &x, y = in(reg) &y, - width = const F::WIDTH, - length = const LEN, result = in(reg) &mut result, } } @@ -384,16 +337,12 @@ where unsafe { asm! { - "%int_type = OpTypeInt {width} 0", - "%vec_type = OpTypeVector %int_type {length}", - "%x = OpLoad %vec_type {x}", - "%y = OpLoad %vec_type {y}", - "%result = OpUMod %vec_type %x %y", + "%x = OpLoad typeof*{x} {x}", + "%y = OpLoad typeof*{y} {y}", + "%result = OpUMod typeof*{x} %x %y", "OpStore {result} %result", x = in(reg) &x, y = in(reg) &y, - width = const I::WIDTH, - length = const LEN, result = in(reg) &mut result, } } @@ -419,16 +368,12 @@ where unsafe { asm! { - "%int_type = OpTypeInt {width} 1", - "%vec_type = OpTypeVector %int_type {length}", - "%x = OpLoad %vec_type {x}", - "%y = OpLoad %vec_type {y}", - "%result = OpSRem %vec_type %x %y", + "%x = OpLoad typeof*{x} {x}", + "%y = OpLoad typeof*{y} {y}", + "%result = OpSRem typeof*{x} %x %y", "OpStore {result} %result", x = in(reg) &x, y = in(reg) &y, - width = const I::WIDTH, - length = const LEN, result = in(reg) &mut result, } } @@ -454,16 +399,12 @@ where unsafe { asm! { - "%int_type = OpTypeInt {width} 1", - "%vec_type = OpTypeVector %int_type {length}", - "%x = OpLoad %vec_type {x}", - "%y = OpLoad %vec_type {y}", - "%result = OpSMod %vec_type %x %y", + "%x = OpLoad typeof*{x} {x}", + "%y = OpLoad typeof*{y} {y}", + "%result = OpSMod typeof*{x} %x %y", "OpStore {result} %result", x = in(reg) &x, y = in(reg) &y, - width = const I::WIDTH, - length = const LEN, result = in(reg) &mut result, } } @@ -489,16 +430,12 @@ where unsafe { asm! { - "%float_type = OpTypeFloat {width}", - "%vec_type = OpTypeVector %float_type {length}", - "%x = OpLoad %vec_type {x}", - "%y = OpLoad %vec_type {y}", - "%result = OpFRem %vec_type %x %y", + "%x = OpLoad typeof*{x} {x}", + "%y = OpLoad typeof*{y} {y}", + "%result = OpFRem typeof*{x} %x %y", "OpStore {result} %result", x = in(reg) &x, y = in(reg) &y, - width = const F::WIDTH, - length = const LEN, result = in(reg) &mut result, } } @@ -524,16 +461,12 @@ where unsafe { asm! { - "%float_type = OpTypeFloat {width}", - "%vec_type = OpTypeVector %float_type {length}", - "%x = OpLoad %vec_type {x}", - "%y = OpLoad %vec_type {y}", - "%result = OpFMod %vec_type %x %y", + "%x = OpLoad typeof*{x} {x}", + "%y = OpLoad typeof*{y} {y}", + "%result = OpFMod typeof*{x} %x %y", "OpStore {result} %result", x = in(reg) &x, y = in(reg) &y, - width = const F::WIDTH, - length = const LEN, result = in(reg) &mut result, } } @@ -555,16 +488,12 @@ where unsafe { asm! { - "%float_type = OpTypeFloat {width}", - "%vec_type = OpTypeVector %float_type {length}", - "%vector = OpLoad %vec_type {vector}", - "%scalar = OpLoad %float_type {scalar}", - "%result = OpVectorTimesScalar %vec_type %vector %scalar", + "%vector = OpLoad typeof*{vector} {vector}", + "%scalar = OpLoad typeof*{scalar} {scalar}", + "%result = OpVectorTimesScalar typeof*{vector} %vector %scalar", "OpStore {result} %result", vector = in(reg) &vector, scalar = in(reg) &scalar, - width = const F::WIDTH, - length = const LEN, result = in(reg) &mut result, } } diff --git a/crates/spirv-std/src/arch/barrier.rs b/crates/spirv-std/src/arch/barrier.rs index d93fd67373..6420dc80f0 100644 --- a/crates/spirv-std/src/arch/barrier.rs +++ b/crates/spirv-std/src/arch/barrier.rs @@ -1,22 +1,23 @@ -use crate::memory::{Scope, Semantics}; - /// Wait for other invocations of this module to reach the current point /// of execution. /// /// All invocations of this module within Execution scope reach this point of /// execution before any invocation proceeds beyond it. /// -/// When Execution is [`Scope::Workgroup`] or larger, behavior is undefined -/// unless all invocations within Execution execute the same dynamic instance of -/// this instruction. When Execution is Subgroup or Invocation, the behavior of -/// this instruction in non-uniform control flow is defined by the client API. +/// When Execution is [`crate::memory::Scope::Workgroup`] or larger, behavior is +/// undefined unless all invocations within Execution execute the same dynamic +/// instance of this instruction. When Execution is Subgroup or Invocation, the +/// behavior of this instruction in non-uniform control flow is defined by the +/// client API. /// -/// If [`Semantics`] is not [`Semantics::NONE`], this instruction also serves as -/// an [`memory_barrier`] function call, and also performs and adheres to the -/// description and semantics of an [`memory_barrier`] function with the same -/// `MEMORY` and `SEMANTICS` operands. This allows atomically specifying both a -/// control barrier and a memory barrier (that is, without needing two -/// instructions). If [`Semantics`] is [`Semantics::NONE`], `MEMORY` is ignored. +/// If [`crate::memory::Semantics`] is not [`crate::memory::Semantics::NONE`], +/// this instruction also serves as an [`memory_barrier`] function call, and +/// also performs and adheres to the description and semantics of an +/// [`memory_barrier`] function with the same `MEMORY` and `SEMANTICS` operands. +/// This allows atomically specifying both a control barrier and a memory +/// barrier (that is, without needing two instructions). If +/// [`crate::memory::Semantics`] is [`crate::memory::Semantics::NONE`], `MEMORY` +/// is ignored. /// /// Before SPIRV-V version 1.3, it is only valid to use this instruction with /// `TessellationControl`, `GLCompute`, or `Kernel` execution models. There is @@ -30,9 +31,9 @@ use crate::memory::{Scope, Semantics}; #[doc(alias = "OpControlBarrier")] #[inline] pub unsafe fn control_barrier< - const EXECUTION: Scope, - const MEMORY: Scope, - const SEMANTICS: Semantics, + const EXECUTION: u32, // Scope + const MEMORY: u32, // Scope + const SEMANTICS: u32, // Semantics >() { asm! { "%u32 = OpTypeInt 32 0", @@ -40,9 +41,9 @@ pub unsafe fn control_barrier< "%memory = OpConstant %u32 {memory}", "%semantics = OpConstant %u32 {semantics}", "OpControlBarrier %execution %memory %semantics", - execution = const EXECUTION as u8, - memory = const MEMORY as u8, - semantics = const SEMANTICS.bits(), + execution = const EXECUTION, + memory = const MEMORY, + semantics = const SEMANTICS, } } @@ -64,14 +65,16 @@ pub unsafe fn control_barrier< #[spirv_std_macros::gpu_only] #[doc(alias = "OpMemoryBarrier")] #[inline] -// FIXME(eddyb) use a `bitflags!` `Semantics` for `SEMANTICS`. -pub unsafe fn memory_barrier() { +pub unsafe fn memory_barrier< + const MEMORY: u32, // Scope + const SEMANTICS: u32, // Semantics +>() { asm! { "%u32 = OpTypeInt 32 0", "%memory = OpConstant %u32 {memory}", "%semantics = OpConstant %u32 {semantics}", "OpMemoryBarrier %memory %semantics", - memory = const MEMORY as u8, - semantics = const SEMANTICS.bits(), + memory = const MEMORY, + semantics = const SEMANTICS, } } diff --git a/rust-toolchain b/rust-toolchain index 5e6cb31004..fc1bc24ce4 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -5,5 +5,5 @@ # to the user in the error, instead of "error: invalid channel name '[toolchain]'". [toolchain] -channel = "nightly-2021-03-21" +channel = "nightly-2021-04-25" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] diff --git a/tests/ui/arch/control_barrier.rs b/tests/ui/arch/control_barrier.rs index 45fc687bdd..6cc3bdd133 100644 --- a/tests/ui/arch/control_barrier.rs +++ b/tests/ui/arch/control_barrier.rs @@ -9,9 +9,9 @@ use spirv_std::memory::{Scope, Semantics}; pub fn main() { unsafe { spirv_std::arch::control_barrier::< - { Scope::Subgroup }, - { Scope::Subgroup }, - { Semantics::NONE }, + { Scope::Subgroup as u32 }, + { Scope::Subgroup as u32 }, + { Semantics::NONE.bits() }, >(); } } diff --git a/tests/ui/arch/memory_barrier.rs b/tests/ui/arch/memory_barrier.rs index 817071f06d..2219d8e2b4 100644 --- a/tests/ui/arch/memory_barrier.rs +++ b/tests/ui/arch/memory_barrier.rs @@ -9,12 +9,8 @@ use spirv_std::memory::{Scope, Semantics}; pub fn main() { unsafe { spirv_std::arch::memory_barrier::< - { Scope::Subgroup }, - { - Semantics::from_bits_truncate( - Semantics::ACQUIRE_RELEASE.bits() | Semantics::UNIFORM_MEMORY.bits(), - ) - }, + { Scope::Subgroup as u32 }, + { Semantics::ACQUIRE_RELEASE.bits() | Semantics::UNIFORM_MEMORY.bits() }, >(); } }