From 127cc1bb994d12808dadea0324773ae1df10e437 Mon Sep 17 00:00:00 2001 From: khyperia Date: Wed, 30 Sep 2020 15:49:01 +0200 Subject: [PATCH] really_unsafe_ignore_bitcasts --- .../src/builder/builder_methods.rs | 7 +++++- rustc_codegen_spirv/src/codegen_cx/declare.rs | 22 +++++++++++++------ rustc_codegen_spirv/src/codegen_cx/mod.rs | 4 +++- rustc_codegen_spirv/src/symbols.rs | 5 +++++ spirv-std/src/lib.rs | 4 ++++ 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/rustc_codegen_spirv/src/builder/builder_methods.rs b/rustc_codegen_spirv/src/builder/builder_methods.rs index c98beedd0b..d1c29578f6 100644 --- a/rustc_codegen_spirv/src/builder/builder_methods.rs +++ b/rustc_codegen_spirv/src/builder/builder_methods.rs @@ -1014,7 +1014,12 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { SpirvType::Pointer { .. } => (), other => panic!("pointercast called on non-pointer dest type: {:?}", other), } - if val.ty == dest_ty { + if val.ty == dest_ty + || self + .really_unsafe_ignore_bitcasts + .borrow() + .contains(&self.current_fn) + { val } else { let result = self diff --git a/rustc_codegen_spirv/src/codegen_cx/declare.rs b/rustc_codegen_spirv/src/codegen_cx/declare.rs index 898c7736be..cbc6bf1c5c 100644 --- a/rustc_codegen_spirv/src/codegen_cx/declare.rs +++ b/rustc_codegen_spirv/src/codegen_cx/declare.rs @@ -289,7 +289,7 @@ impl<'tcx> PreDefineMethods<'tcx> for CodegenCx<'tcx> { ) { let fn_abi = FnAbi::of_instance(self, instance, &[]); let human_name = format!("{}", instance); - let linkage = match linkage { + let linkage2 = match linkage { Linkage::External => Some(LinkageType::Export), Linkage::Internal => None, other => panic!("TODO: Linkage type not supported yet: {:?}", other), @@ -298,15 +298,23 @@ impl<'tcx> PreDefineMethods<'tcx> for CodegenCx<'tcx> { let spv_attrs = attrs_to_spirv(rust_attrs); let declared = - self.declare_fn_ext(symbol_name, Some(&human_name), linkage, spv_attrs, &fn_abi); + self.declare_fn_ext(symbol_name, Some(&human_name), linkage2, spv_attrs, &fn_abi); for attr in self.tcx.get_attrs(instance.def_id()) { - if let Some(SpirvAttribute::Entry(execution_model)) = parse_attr(self, attr) { - if execution_model == ExecutionModel::Kernel { - self.kernel_entry_stub(declared, human_name.clone(), execution_model); - } else { - self.entry_stub(declared, human_name.clone(), execution_model); + match parse_attr(self, attr) { + Some(SpirvAttribute::Entry(execution_model)) => { + if execution_model == ExecutionModel::Kernel { + self.kernel_entry_stub(declared, human_name.clone(), execution_model); + } else { + self.entry_stub(declared, human_name.clone(), execution_model); + } } + Some(SpirvAttribute::ReallyUnsafeIgnoreBitcasts) => { + self.really_unsafe_ignore_bitcasts + .borrow_mut() + .insert(declared); + } + _ => {} } } diff --git a/rustc_codegen_spirv/src/codegen_cx/mod.rs b/rustc_codegen_spirv/src/codegen_cx/mod.rs index 257bf90b32..c38c0977ce 100644 --- a/rustc_codegen_spirv/src/codegen_cx/mod.rs +++ b/rustc_codegen_spirv/src/codegen_cx/mod.rs @@ -29,7 +29,7 @@ use rustc_target::abi::call::FnAbi; use rustc_target::abi::{HasDataLayout, TargetDataLayout}; use rustc_target::spec::{HasTargetSpec, Target}; use std::cell::RefCell; -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use std::iter::once; pub struct CodegenCx<'tcx> { @@ -50,6 +50,7 @@ pub struct CodegenCx<'tcx> { pub kernel_mode: bool, /// Cache of all the builtin symbols we need pub sym: Box, + pub really_unsafe_ignore_bitcasts: RefCell>, /// Functions created in get_fn_addr /// left: the OpUndef value. right: the function value. function_pointers: RefCell>, @@ -74,6 +75,7 @@ impl<'tcx> CodegenCx<'tcx> { zombie_values: Default::default(), kernel_mode, sym, + really_unsafe_ignore_bitcasts: Default::default(), function_pointers: Default::default(), i8_i16_atomics_allowed: false, } diff --git a/rustc_codegen_spirv/src/symbols.rs b/rustc_codegen_spirv/src/symbols.rs index 57a6972210..0324418565 100644 --- a/rustc_codegen_spirv/src/symbols.rs +++ b/rustc_codegen_spirv/src/symbols.rs @@ -14,6 +14,7 @@ pub struct Symbols { pub shader: Symbol, pub storage_class: Symbol, pub entry: Symbol, + pub really_unsafe_ignore_bitcasts: Symbol, storage_classes: HashMap, execution_models: HashMap, @@ -80,6 +81,7 @@ impl Symbols { shader: Symbol::intern("shader"), storage_class: Symbol::intern("storage_class"), entry: Symbol::intern("entry"), + really_unsafe_ignore_bitcasts: Symbol::intern("really_unsafe_ignore_bitcasts"), storage_classes: make_storage_classes(), execution_models: make_execution_models(), } @@ -97,6 +99,7 @@ impl Symbols { pub enum SpirvAttribute { StorageClass(StorageClass), Entry(ExecutionModel), + ReallyUnsafeIgnoreBitcasts, } // Note that we could mark the attr as used via cx.tcx.sess.mark_attr_used(attr), but unused reporting already happens @@ -167,6 +170,8 @@ pub fn parse_attr<'tcx>(cx: &CodegenCx<'tcx>, attr: &Attribute) -> Option {}; (true) => { #[inline] + #[allow(unused_attributes)] + #[spirv(really_unsafe_ignore_bitcasts)] pub fn store(&mut self, v: T) { *self.x = v } @@ -22,6 +24,8 @@ macro_rules! pointer_addrspace { impl<'a, T: Copy> $type_name<'a, T> { #[inline] + #[allow(unused_attributes)] + #[spirv(really_unsafe_ignore_bitcasts)] pub fn load(&self) -> T { *self.x }