Skip to content

Commit 12c09cb

Browse files
authored
Remove implicit bindless and kernel modes (#710)
* Remove +bindless mode * Remove +kernel mode
1 parent a43a174 commit 12c09cb

File tree

24 files changed

+195
-1768
lines changed

24 files changed

+195
-1768
lines changed

crates/rustc_codegen_spirv/src/abi.rs

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use crate::attr::{AggregatedSpirvAttributes, IntrinsicType};
55
use crate::codegen_cx::CodegenCx;
66
use crate::spirv_type::SpirvType;
7-
use rspirv::spirv::{Capability, StorageClass, Word};
7+
use rspirv::spirv::{StorageClass, Word};
88
use rustc_data_structures::fx::FxHashMap;
99
use rustc_errors::ErrorReported;
1010
use rustc_middle::bug;
@@ -58,18 +58,11 @@ impl<'tcx> RecursivePointeeCache<'tcx> {
5858
cx.emit_global()
5959
.type_forward_pointer(new_id, StorageClass::Generic);
6060
entry.insert(PointeeDefState::DefiningWithForward(new_id));
61-
if !cx.builder.has_capability(Capability::Addresses)
62-
&& !cx
63-
.builder
64-
.has_capability(Capability::PhysicalStorageBufferAddresses)
65-
{
66-
cx.zombie_with_span(
67-
new_id,
68-
span,
69-
"OpTypeForwardPointer without OpCapability \
70-
Addresses or PhysicalStorageBufferAddresses",
71-
);
72-
}
61+
cx.zombie_with_span(
62+
new_id,
63+
span,
64+
"Cannot create self-referential types, even through pointers",
65+
);
7366
Some(new_id)
7467
}
7568
// 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>(
424417
}
425418

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

653643
// see struct_llfields in librustc_codegen_llvm for implementation hints
654644
fn trans_struct<'tcx>(cx: &CodegenCx<'tcx>, span: Span, ty: TyAndLayout<'tcx>) -> Word {
655-
if let TyKind::Foreign(_) = ty.ty.kind() {
656-
// "An unsized FFI type that is opaque to Rust", `extern type A;` (currently unstable)
657-
if cx.target.is_kernel() {
658-
// TODO: This should use the name of the struct as the name. However, names are not stable across crates,
659-
// e.g. core::fmt::Opaque in one crate and fmt::Opaque in core.
660-
return SpirvType::Opaque {
661-
name: "".to_string(),
662-
}
663-
.def(span, cx);
664-
}
665-
// otherwise fall back
666-
};
667645
let size = if ty.is_unsized() { None } else { Some(ty.size) };
668646
let align = ty.align.abi;
669647
let mut field_types = Vec::new();

crates/rustc_codegen_spirv/src/attr.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ pub enum SpirvAttribute {
8989

9090
// `fn`/closure attributes:
9191
UnrollLoops,
92-
InternalBufferLoad,
93-
InternalBufferStore,
9492
}
9593

9694
// HACK(eddyb) this is similar to `rustc_span::Spanned` but with `value` as the
@@ -124,8 +122,6 @@ pub struct AggregatedSpirvAttributes {
124122

125123
// `fn`/closure attributes:
126124
pub unroll_loops: Option<Spanned<()>>,
127-
pub internal_buffer_load: Option<Spanned<()>>,
128-
pub internal_buffer_store: Option<Spanned<()>>,
129125
}
130126

131127
struct MultipleAttrs {
@@ -213,18 +209,6 @@ impl AggregatedSpirvAttributes {
213209
"#[spirv(attachment_index)]",
214210
),
215211
UnrollLoops => try_insert(&mut self.unroll_loops, (), span, "#[spirv(unroll_loops)]"),
216-
InternalBufferLoad => try_insert(
217-
&mut self.internal_buffer_load,
218-
(),
219-
span,
220-
"#[spirv(internal_buffer_load)]",
221-
),
222-
InternalBufferStore => try_insert(
223-
&mut self.internal_buffer_store,
224-
(),
225-
span,
226-
"#[spirv(internal_buffer_store)]",
227-
),
228212
}
229213
}
230214
}
@@ -349,9 +333,7 @@ impl CheckSpirvAttrVisitor<'_> {
349333

350334
_ => Err(Expected("function parameter")),
351335
},
352-
SpirvAttribute::InternalBufferLoad
353-
| SpirvAttribute::InternalBufferStore
354-
| SpirvAttribute::UnrollLoops => match target {
336+
SpirvAttribute::UnrollLoops => match target {
355337
Target::Fn
356338
| Target::Closure
357339
| Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => {

crates/rustc_codegen_spirv/src/builder/builder_methods.rs

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
209209
)),
210210
},
211211
SpirvType::Adt { .. } => self.fatal("memset on structs not implemented yet"),
212-
SpirvType::Opaque { .. } => self.fatal("memset on opaque type is invalid"),
213212
SpirvType::Vector { element, count } => {
214213
let elem_pat = self.memset_const_pattern(&self.lookup_type(element), fill_byte);
215214
self.constant_composite(
@@ -266,7 +265,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
266265
)),
267266
},
268267
SpirvType::Adt { .. } => self.fatal("memset on structs not implemented yet"),
269-
SpirvType::Opaque { .. } => self.fatal("memset on opaque type is invalid"),
270268
SpirvType::Array { element, count } => {
271269
let elem_pat = self.memset_dynamic_pattern(&self.lookup_type(element), fill_var);
272270
let count = self.builder.lookup_const_u64(count).unwrap() as usize;
@@ -355,29 +353,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
355353
}
356354

357355
fn zombie_convert_ptr_to_u(&self, def: Word) {
358-
if !self.builder.has_capability(Capability::Addresses)
359-
&& !self
360-
.builder
361-
.has_capability(Capability::PhysicalStorageBufferAddresses)
362-
{
363-
self.zombie(
364-
def,
365-
"OpConvertPtrToU without OpCapability Addresses or PhysicalStorageBufferAddresses",
366-
);
367-
}
356+
self.zombie(def, "Cannot convert pointers to integers");
368357
}
369358

370359
fn zombie_convert_u_to_ptr(&self, def: Word) {
371-
if !self.builder.has_capability(Capability::Addresses)
372-
&& !self
373-
.builder
374-
.has_capability(Capability::PhysicalStorageBufferAddresses)
375-
{
376-
self.zombie(
377-
def,
378-
"OpConvertUToPtr OpCapability Addresses or PhysicalStorageBufferAddresses",
379-
);
380-
}
360+
self.zombie(def, "Cannot convert integers to pointers");
381361
}
382362

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

1279-
if (val_is_ptr || dest_is_ptr) && self.logical_addressing_model() {
1259+
if val_is_ptr || dest_is_ptr {
12801260
if self.is_system_crate() {
12811261
self.zombie(
12821262
result.def(self),
1283-
"OpBitcast between ptr and non-ptr without AddressingModel != Logical",
1263+
&format!(
1264+
"Cannot cast between pointer and non-pointer types. From: {}. To: {}.",
1265+
self.debug_type(val.ty),
1266+
self.debug_type(dest_ty)
1267+
),
12841268
);
12851269
} else {
12861270
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> {
13971381
.access_chain(dest_ty, None, val.def(self), indices)
13981382
.unwrap()
13991383
.with_type(dest_ty)
1400-
} else if self.logical_addressing_model() {
1384+
} else {
14011385
// Defer the cast so that it has a chance to be avoided.
14021386
SpirvValue {
14031387
kind: SpirvValueKind::LogicalPtrCast {
@@ -1407,11 +1391,6 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
14071391
},
14081392
ty: dest_ty,
14091393
}
1410-
} else {
1411-
self.emit()
1412-
.bitcast(dest_ty, None, val.def(self))
1413-
.unwrap()
1414-
.with_type(dest_ty)
14151394
}
14161395
}
14171396

@@ -1713,12 +1692,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
17131692
empty(),
17141693
)
17151694
.unwrap();
1716-
if !self.builder.has_capability(Capability::Addresses) {
1717-
self.zombie(
1718-
dst.def(self),
1719-
"OpCopyMemorySized without OpCapability Addresses",
1720-
);
1721-
}
1695+
self.zombie(dst.def(self), "Cannot memcpy dynamically sized data");
17221696
}
17231697
}
17241698

@@ -2184,16 +2158,6 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
21842158
// needing to materialize `&core::panic::Location` or `format_args!`.
21852159
self.abort();
21862160
self.undef(result_type)
2187-
} else if self.internal_buffer_load_id.borrow().contains(&callee_val) {
2188-
self.codegen_internal_buffer_load(result_type, args)
2189-
} else if self.internal_buffer_store_id.borrow().contains(&callee_val) {
2190-
self.codegen_internal_buffer_store(args);
2191-
2192-
let void_ty = SpirvType::Void.def(rustc_span::DUMMY_SP, self);
2193-
SpirvValue {
2194-
kind: SpirvValueKind::IllegalTypeUsed(void_ty),
2195-
ty: void_ty,
2196-
}
21972161
} else {
21982162
let args = args.iter().map(|arg| arg.def(self)).collect::<Vec<_>>();
21992163
self.emit()
Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
use super::Builder;
22
use crate::builder_spirv::{SpirvValue, SpirvValueExt};
3-
use rspirv::spirv::{CLOp, GLOp, Word};
3+
use rspirv::spirv::{GLOp, Word};
44
use rspirv::{dr::Operand, spirv::Capability};
55

66
const GLSL_STD_450: &str = "GLSL.std.450";
7-
const OPENCL_STD: &str = "OpenCL.std";
87

98
/// Manager for OpExtInst/OpExtImport instructions
109
#[derive(Default)]
1110
pub struct ExtInst {
1211
glsl: Option<Word>,
13-
opencl: Option<Word>,
1412
integer_functions_2_intel: bool,
1513
}
1614

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

30-
pub fn import_opencl<'a, 'tcx>(&mut self, bx: &Builder<'a, 'tcx>) -> Word {
31-
assert!(bx.target.is_kernel());
32-
match self.opencl {
33-
Some(id) => id,
34-
None => {
35-
let id = bx.emit_global().ext_inst_import(OPENCL_STD);
36-
self.opencl = Some(id);
37-
id
38-
}
39-
}
40-
}
41-
4227
pub fn require_integer_functions_2_intel<'a, 'tcx>(
4328
&mut self,
4429
bx: &Builder<'a, 'tcx>,
4530
to_zombie: Word,
4631
) {
4732
if !self.integer_functions_2_intel {
48-
assert!(!bx.target.is_kernel());
4933
self.integer_functions_2_intel = true;
5034
if !bx
5135
.builder
@@ -86,24 +70,4 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
8670
.unwrap()
8771
.with_type(result_type)
8872
}
89-
90-
pub fn cl_op(
91-
&mut self,
92-
op: CLOp,
93-
result_type: Word,
94-
args: impl AsRef<[SpirvValue]>,
95-
) -> SpirvValue {
96-
let args = args.as_ref();
97-
let opencl = self.ext_inst.borrow_mut().import_opencl(self);
98-
self.emit()
99-
.ext_inst(
100-
result_type,
101-
None,
102-
opencl,
103-
op as u32,
104-
args.iter().map(|a| Operand::IdRef(a.def(self))),
105-
)
106-
.unwrap()
107-
.with_type(result_type)
108-
}
10973
}

0 commit comments

Comments
 (0)