Skip to content
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

Remove implicit bindless and kernel modes #710

Merged
merged 2 commits into from
Aug 10, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
Remove +kernel mode
khyperia committed Aug 9, 2021
commit 8472d41102213385aaad2afc6ffcc3ae87f24f8b
36 changes: 7 additions & 29 deletions crates/rustc_codegen_spirv/src/abi.rs
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
use crate::attr::{AggregatedSpirvAttributes, IntrinsicType};
use crate::codegen_cx::CodegenCx;
use crate::spirv_type::SpirvType;
use rspirv::spirv::{Capability, StorageClass, Word};
use rspirv::spirv::{StorageClass, Word};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::ErrorReported;
use rustc_middle::bug;
@@ -58,18 +58,11 @@ impl<'tcx> RecursivePointeeCache<'tcx> {
cx.emit_global()
.type_forward_pointer(new_id, StorageClass::Generic);
entry.insert(PointeeDefState::DefiningWithForward(new_id));
if !cx.builder.has_capability(Capability::Addresses)
&& !cx
.builder
.has_capability(Capability::PhysicalStorageBufferAddresses)
{
cx.zombie_with_span(
new_id,
span,
"OpTypeForwardPointer without OpCapability \
Addresses or PhysicalStorageBufferAddresses",
);
}
cx.zombie_with_span(
new_id,
span,
"Cannot create self-referential types, even through pointers",
);
Some(new_id)
}
// State: This is the third or more time we've seen this type, and we've already emitted an
@@ -424,10 +417,7 @@ fn trans_scalar<'tcx>(
}

match scalar.value {
Primitive::Int(width, mut signedness) => {
if cx.target.is_kernel() {
signedness = false;
}
Primitive::Int(width, signedness) => {
SpirvType::Integer(width.size().bits() as u32, signedness).def(span, cx)
}
Primitive::F32 => SpirvType::Float(32).def(span, cx),
@@ -652,18 +642,6 @@ pub fn auto_struct_layout<'tcx>(

// see struct_llfields in librustc_codegen_llvm for implementation hints
fn trans_struct<'tcx>(cx: &CodegenCx<'tcx>, span: Span, ty: TyAndLayout<'tcx>) -> Word {
if let TyKind::Foreign(_) = ty.ty.kind() {
// "An unsized FFI type that is opaque to Rust", `extern type A;` (currently unstable)
if cx.target.is_kernel() {
// TODO: This should use the name of the struct as the name. However, names are not stable across crates,
// e.g. core::fmt::Opaque in one crate and fmt::Opaque in core.
return SpirvType::Opaque {
name: "".to_string(),
}
.def(span, cx);
}
// otherwise fall back
};
let size = if ty.is_unsized() { None } else { Some(ty.size) };
let align = ty.align.abi;
let mut field_types = Vec::new();
46 changes: 10 additions & 36 deletions crates/rustc_codegen_spirv/src/builder/builder_methods.rs
Original file line number Diff line number Diff line change
@@ -209,7 +209,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
)),
},
SpirvType::Adt { .. } => self.fatal("memset on structs not implemented yet"),
SpirvType::Opaque { .. } => self.fatal("memset on opaque type is invalid"),
SpirvType::Vector { element, count } => {
let elem_pat = self.memset_const_pattern(&self.lookup_type(element), fill_byte);
self.constant_composite(
@@ -266,7 +265,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
)),
},
SpirvType::Adt { .. } => self.fatal("memset on structs not implemented yet"),
SpirvType::Opaque { .. } => self.fatal("memset on opaque type is invalid"),
SpirvType::Array { element, count } => {
let elem_pat = self.memset_dynamic_pattern(&self.lookup_type(element), fill_var);
let count = self.builder.lookup_const_u64(count).unwrap() as usize;
@@ -355,29 +353,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}

fn zombie_convert_ptr_to_u(&self, def: Word) {
if !self.builder.has_capability(Capability::Addresses)
&& !self
.builder
.has_capability(Capability::PhysicalStorageBufferAddresses)
{
self.zombie(
def,
"OpConvertPtrToU without OpCapability Addresses or PhysicalStorageBufferAddresses",
);
}
self.zombie(def, "Cannot convert pointers to integers");
}

fn zombie_convert_u_to_ptr(&self, def: Word) {
if !self.builder.has_capability(Capability::Addresses)
&& !self
.builder
.has_capability(Capability::PhysicalStorageBufferAddresses)
{
self.zombie(
def,
"OpConvertUToPtr OpCapability Addresses or PhysicalStorageBufferAddresses",
);
}
self.zombie(def, "Cannot convert integers to pointers");
}

fn zombie_ptr_equal(&self, def: Word, inst: &str) {
@@ -1276,11 +1256,15 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
.unwrap()
.with_type(dest_ty);

if (val_is_ptr || dest_is_ptr) && self.logical_addressing_model() {
if val_is_ptr || dest_is_ptr {
if self.is_system_crate() {
self.zombie(
result.def(self),
"OpBitcast between ptr and non-ptr without AddressingModel != Logical",
&format!(
"Cannot cast between pointer and non-pointer types. From: {}. To: {}.",
self.debug_type(val.ty),
self.debug_type(dest_ty)
),
);
} else {
self.struct_err("Cannot cast between pointer and non-pointer types")
@@ -1397,7 +1381,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
.access_chain(dest_ty, None, val.def(self), indices)
.unwrap()
.with_type(dest_ty)
} else if self.logical_addressing_model() {
} else {
// Defer the cast so that it has a chance to be avoided.
SpirvValue {
kind: SpirvValueKind::LogicalPtrCast {
@@ -1407,11 +1391,6 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
},
ty: dest_ty,
}
} else {
self.emit()
.bitcast(dest_ty, None, val.def(self))
.unwrap()
.with_type(dest_ty)
}
}

@@ -1713,12 +1692,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
empty(),
)
.unwrap();
if !self.builder.has_capability(Capability::Addresses) {
self.zombie(
dst.def(self),
"OpCopyMemorySized without OpCapability Addresses",
);
}
self.zombie(dst.def(self), "Cannot memcpy dynamically sized data");
}
}

38 changes: 1 addition & 37 deletions crates/rustc_codegen_spirv/src/builder/ext_inst.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
use super::Builder;
use crate::builder_spirv::{SpirvValue, SpirvValueExt};
use rspirv::spirv::{CLOp, GLOp, Word};
use rspirv::spirv::{GLOp, Word};
use rspirv::{dr::Operand, spirv::Capability};

const GLSL_STD_450: &str = "GLSL.std.450";
const OPENCL_STD: &str = "OpenCL.std";

/// Manager for OpExtInst/OpExtImport instructions
#[derive(Default)]
pub struct ExtInst {
glsl: Option<Word>,
opencl: Option<Word>,
integer_functions_2_intel: bool,
}

impl ExtInst {
pub fn import_glsl<'a, 'tcx>(&mut self, bx: &Builder<'a, 'tcx>) -> Word {
assert!(!bx.target.is_kernel());
match self.glsl {
Some(id) => id,
None => {
@@ -27,25 +24,12 @@ impl ExtInst {
}
}

pub fn import_opencl<'a, 'tcx>(&mut self, bx: &Builder<'a, 'tcx>) -> Word {
assert!(bx.target.is_kernel());
match self.opencl {
Some(id) => id,
None => {
let id = bx.emit_global().ext_inst_import(OPENCL_STD);
self.opencl = Some(id);
id
}
}
}

pub fn require_integer_functions_2_intel<'a, 'tcx>(
&mut self,
bx: &Builder<'a, 'tcx>,
to_zombie: Word,
) {
if !self.integer_functions_2_intel {
assert!(!bx.target.is_kernel());
self.integer_functions_2_intel = true;
if !bx
.builder
@@ -86,24 +70,4 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
.unwrap()
.with_type(result_type)
}

pub fn cl_op(
&mut self,
op: CLOp,
result_type: Word,
args: impl AsRef<[SpirvValue]>,
) -> SpirvValue {
let args = args.as_ref();
let opencl = self.ext_inst.borrow_mut().import_opencl(self);
self.emit()
.ext_inst(
result_type,
None,
opencl,
op as u32,
args.iter().map(|a| Operand::IdRef(a.def(self))),
)
.unwrap()
.with_type(result_type)
}
}
Loading