Skip to content

Update to nightly-2020-12-11. #338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 11, 2020
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
4 changes: 2 additions & 2 deletions crates/rustc_codegen_spirv/src/builder/builder_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,8 +1156,8 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
.bitcast(dest_ty, None, val.def(self))
.unwrap()
.with_type(dest_ty);
let val_is_ptr = matches!(self.lookup_type(val.ty), SpirvType::Pointer{..});
let dest_is_ptr = matches!(self.lookup_type(dest_ty), SpirvType::Pointer{..});
let val_is_ptr = matches!(self.lookup_type(val.ty), SpirvType::Pointer { .. });
let dest_is_ptr = matches!(self.lookup_type(dest_ty), SpirvType::Pointer { .. });
if val_is_ptr || dest_is_ptr {
self.zombie_bitcast_ptr(result.def(self), val.ty, dest_ty);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rustc_codegen_spirv/src/builder_spirv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl BuilderSpirv {
let spirv_module = module.assemble();
File::create(path)
.unwrap()
.write_all(crate::slice_u32_to_u8(&spirv_module))
.write_all(spirv_tools::util::from_binary(&spirv_module))
.unwrap();
}

Expand Down
29 changes: 6 additions & 23 deletions crates/rustc_codegen_spirv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ struct SpirvModuleBuffer(Vec<u32>);

impl ModuleBufferMethods for SpirvModuleBuffer {
fn data(&self) -> &[u8] {
crate::slice_u32_to_u8(&self.0)
spirv_tools::util::from_binary(&self.0)
}
}

Expand All @@ -220,7 +220,7 @@ struct SpirvThinBuffer(Vec<u32>);

impl ThinBufferMethods for SpirvThinBuffer {
fn data(&self) -> &[u8] {
crate::slice_u32_to_u8(&self.0)
spirv_tools::util::from_binary(&self.0)
}
}

Expand Down Expand Up @@ -364,25 +364,6 @@ impl CodegenBackend for SpirvCodegenBackend {
}
}

// Note: endianness doesn't matter, readers deduce endianness from magic header.
fn slice_u32_to_u8(slice: &[u32]) -> &[u8] {
unsafe {
std::slice::from_raw_parts(
slice.as_ptr() as *const u8,
slice.len() * std::mem::size_of::<u32>(),
)
}
}

fn slice_u8_to_u32(slice: &[u8]) -> &[u32] {
unsafe {
std::slice::from_raw_parts(
slice.as_ptr() as *const u32,
slice.len() / std::mem::size_of::<u32>(),
)
}
}

impl WriteBackendMethods for SpirvCodegenBackend {
type Module = Vec<u32>;
type TargetMachine = ();
Expand Down Expand Up @@ -434,7 +415,9 @@ impl WriteBackendMethods for SpirvCodegenBackend {
thin_module: &mut ThinModule<Self>,
) -> Result<ModuleCodegen<Self::Module>, FatalError> {
let module = ModuleCodegen {
module_llvm: slice_u8_to_u32(thin_module.data()).to_vec(),
module_llvm: spirv_tools::util::to_binary(thin_module.data())
.unwrap()
.to_vec(),
name: thin_module.name().to_string(),
kind: ModuleKind::Regular,
};
Expand All @@ -451,7 +434,7 @@ impl WriteBackendMethods for SpirvCodegenBackend {
.output_filenames
.temp_path(OutputType::Object, Some(&module.name));
// Note: endianness doesn't matter, readers deduce endianness from magic header.
let spirv_module = slice_u32_to_u8(&module.module_llvm);
let spirv_module = spirv_tools::util::from_binary(&module.module_llvm);
File::create(&path)
.unwrap()
.write_all(spirv_module)
Expand Down
5 changes: 3 additions & 2 deletions crates/rustc_codegen_spirv/src/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fn link_exe(

{
let save_modules_timer = sess.timer("link_save_modules");
if let Err(e) = std::fs::write(out_filename, crate::slice_u32_to_u8(&spv_binary)) {
if let Err(e) = std::fs::write(out_filename, spirv_tools::util::from_binary(&spv_binary)) {
let mut err = sess.struct_err("failed to serialize spirv-binary to disk");
err.note(&format!("module {:?}", out_filename));
err.note(&format!("I/O error: {:#}", e));
Expand Down Expand Up @@ -395,7 +395,7 @@ fn do_link(sess: &Session, objects: &[PathBuf], rlibs: &[PathBuf], legalize: boo
for (num, module) in modules.iter().enumerate() {
File::create(path.join(format!("mod_{}.spv", num)))
.unwrap()
.write_all(crate::slice_u32_to_u8(&module.assemble()))
.write_all(spirv_tools::util::from_binary(&module.assemble()))
.unwrap();
}
}
Expand Down Expand Up @@ -428,6 +428,7 @@ fn do_link(sess: &Session, objects: &[PathBuf], rlibs: &[PathBuf], legalize: boo

/// As of right now, this is essentially a no-op, just plumbing through all the files.
// TODO: WorkProduct impl
#[allow(clippy::unnecessary_wraps)]
pub(crate) fn run_thin(
cgcx: &CodegenContext<SpirvCodegenBackend>,
modules: Vec<(String, SpirvThinBuffer)>,
Expand Down
1 change: 0 additions & 1 deletion crates/rustc_codegen_spirv/src/linker/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ fn assemble_and_link(binaries: &[&[u8]]) -> Result<Module, String> {
file_loader: None,
diagnostic_output: DiagnosticOutput::Raw(Box::new(write_diags)),
stderr: None,
crate_name: None,
lint_caps: Default::default(),
register_lints: None,
override_queries: None,
Expand Down
10 changes: 10 additions & 0 deletions crates/spirv-builder/src/test/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,13 @@ OpUnreachable
OpFunctionEnd"#,
);
}

#[test]
fn signum() {
val(r#"
#[allow(unused_attributes)]
#[spirv(fragment)]
pub fn main(i: Input<f32>, mut o: Output<f32>) {
o.store(i.load().signum());
}"#);
}
1 change: 1 addition & 0 deletions crates/spirv-builder/src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ static SRC_PREFIX: &str = r#"#![no_std]
#![allow(unused_imports)]
use spirv_std::*;
use spirv_std::storage_class::*;
use spirv_std::num_traits::Float;
"#;

fn setup(src: &str) -> Result<PathBuf, Box<dyn Error>> {
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
# to the user in the error, instead of "error: invalid channel name '[toolchain]'".

[toolchain]
channel = "nightly-2020-11-24"
channel = "nightly-2020-12-11"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]