Skip to content

Commit ff93116

Browse files
committed
update rspirv 0.11 to 0.12, bulk adjustments
1 parent d0e3749 commit ff93116

20 files changed

+154
-138
lines changed

Cargo.lock

Lines changed: 14 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/rustc_codegen_spirv-types/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ license.workspace = true
88
repository.workspace = true
99

1010
[dependencies]
11-
rspirv = "0.11"
11+
rspirv = "0.12"
1212
serde = { version = "1.0", features = ["derive"] }

crates/rustc_codegen_spirv/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ regex = { version = "1", features = ["perf"] }
5050
ar = "0.9.0"
5151
either = "1.8.0"
5252
indexmap = "1.6.0"
53-
rspirv = "0.11"
53+
rspirv = "0.12"
5454
rustc-demangle = "0.1.21"
5555
sanitize-filename = "0.4"
5656
serde = { version = "1.0", features = ["derive"] }

crates/rustc_codegen_spirv/src/abi.rs

Lines changed: 26 additions & 4 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::{StorageClass, Word};
7+
use rspirv::spirv::{Dim, ImageFormat, StorageClass, Word};
88
use rustc_data_structures::fx::FxHashMap;
99
use rustc_errors::ErrorGuaranteed;
1010
use rustc_index::Idx;
@@ -647,7 +647,7 @@ fn trans_aggregate<'tcx>(cx: &CodegenCx<'tcx>, span: Span, ty: TyAndLayout<'tcx>
647647
// spir-v doesn't support zero-sized arrays
648648
create_zst(cx, span, ty)
649649
} else {
650-
let count_const = cx.constant_u32(span, count as u32);
650+
let count_const = cx.constant_bit32(span, count as u32);
651651
let element_spv = cx.lookup_type(element_type);
652652
let stride_spv = element_spv
653653
.sizeof(cx)
@@ -856,13 +856,35 @@ fn trans_intrinsic_type<'tcx>(
856856
// let image_format: spirv::ImageFormat =
857857
// type_from_variant_discriminant(cx, args.const_at(6));
858858

859-
fn const_int_value<'tcx, P: FromPrimitive>(
859+
trait FromU128Const: Sized {
860+
fn from_u128_const(n: u128) -> Option<Self>;
861+
}
862+
863+
impl FromU128Const for u32 {
864+
fn from_u128_const(n: u128) -> Option<Self> {
865+
u32::from_u128(n)
866+
}
867+
}
868+
869+
impl FromU128Const for Dim {
870+
fn from_u128_const(n: u128) -> Option<Self> {
871+
Dim::from_u32(u32::from_u128(n)?)
872+
}
873+
}
874+
875+
impl FromU128Const for ImageFormat {
876+
fn from_u128_const(n: u128) -> Option<Self> {
877+
ImageFormat::from_u32(u32::from_u128(n)?)
878+
}
879+
}
880+
881+
fn const_int_value<'tcx, P: FromU128Const>(
860882
cx: &CodegenCx<'tcx>,
861883
const_: Const<'tcx>,
862884
) -> Result<P, ErrorGuaranteed> {
863885
assert!(const_.ty().is_integral());
864886
let value = const_.eval_bits(cx.tcx, ParamEnv::reveal_all());
865-
match P::from_u128(value) {
887+
match P::from_u128_const(value) {
866888
Some(v) => Ok(v),
867889
None => Err(cx
868890
.tcx

crates/rustc_codegen_spirv/src/builder/builder_methods.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
175175
| MemorySemantics::SEQUENTIALLY_CONSISTENT
176176
}
177177
};
178-
let semantics = self.constant_u32(self.span(), semantics.bits());
178+
let semantics = self.constant_bit32(self.span(), semantics.bits());
179179
if invalid_seq_cst {
180180
self.zombie(
181181
semantics.def(self),
@@ -196,10 +196,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
196196
.constant_u16(self.span(), memset_fill_u16(fill_byte))
197197
.def(self),
198198
32 => self
199-
.constant_u32(self.span(), memset_fill_u32(fill_byte))
199+
.constant_bit32(self.span(), memset_fill_u32(fill_byte))
200200
.def(self),
201201
64 => self
202-
.constant_u64(self.span(), memset_fill_u64(fill_byte))
202+
.constant_bit64(self.span(), memset_fill_u64(fill_byte))
203203
.def(self),
204204
_ => self.fatal(format!(
205205
"memset on integer width {width} not implemented yet"
@@ -314,7 +314,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
314314
self.store(pat, ptr, Align::from_bytes(0).unwrap());
315315
} else {
316316
for index in 0..count {
317-
let const_index = self.constant_u32(self.span(), index as u32);
317+
let const_index = self.constant_bit32(self.span(), index as u32);
318318
let gep_ptr = self.gep(pat.ty, ptr, &[const_index]);
319319
self.store(pat, gep_ptr, Align::from_bytes(0).unwrap());
320320
}
@@ -428,7 +428,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
428428
} else {
429429
let indices = indices
430430
.into_iter()
431-
.map(|idx| self.constant_u32(self.span(), idx).def(self))
431+
.map(|idx| self.constant_bit32(self.span(), idx).def(self))
432432
.collect::<Vec<_>>();
433433
self.emit()
434434
.access_chain(leaf_ptr_ty, None, ptr.def(self), indices)
@@ -904,9 +904,9 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
904904
))
905905
} else if signed {
906906
// this cast chain can probably be collapsed, but, whatever, be safe
907-
Operand::LiteralInt32(v as u8 as i8 as i32 as u32)
907+
Operand::LiteralBit32(v as u8 as i8 as i32 as u32)
908908
} else {
909-
Operand::LiteralInt32(v as u8 as u32)
909+
Operand::LiteralBit32(v as u8 as u32)
910910
}
911911
}
912912
fn construct_16(self_: &Builder<'_, '_>, signed: bool, v: u128) -> Operand {
@@ -915,9 +915,9 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
915915
"Switches to values above u16::MAX not supported: {v:?}"
916916
))
917917
} else if signed {
918-
Operand::LiteralInt32(v as u16 as i16 as i32 as u32)
918+
Operand::LiteralBit32(v as u16 as i16 as i32 as u32)
919919
} else {
920-
Operand::LiteralInt32(v as u16 as u32)
920+
Operand::LiteralBit32(v as u16 as u32)
921921
}
922922
}
923923
fn construct_32(self_: &Builder<'_, '_>, _signed: bool, v: u128) -> Operand {
@@ -926,7 +926,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
926926
"Switches to values above u32::MAX not supported: {v:?}"
927927
))
928928
} else {
929-
Operand::LiteralInt32(v as u32)
929+
Operand::LiteralBit32(v as u32)
930930
}
931931
}
932932
fn construct_64(self_: &Builder<'_, '_>, _signed: bool, v: u128) -> Operand {
@@ -935,7 +935,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
935935
"Switches to values above u64::MAX not supported: {v:?}"
936936
))
937937
} else {
938-
Operand::LiteralInt64(v as u64)
938+
Operand::LiteralBit64(v as u64)
939939
}
940940
}
941941
// pass in signed into the closure to be able to unify closure types
@@ -1217,7 +1217,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
12171217
let (ptr, access_ty) = self.adjust_pointer_for_typed_access(ptr, ty);
12181218

12191219
// TODO: Default to device scope
1220-
let memory = self.constant_u32(self.span(), Scope::Device as u32);
1220+
let memory = self.constant_bit32(self.span(), Scope::Device as u32);
12211221
let semantics = self.ordering_to_semantics_def(order);
12221222
let result = self
12231223
.emit()
@@ -1347,7 +1347,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
13471347
let val = self.bitcast(val, access_ty);
13481348

13491349
// TODO: Default to device scope
1350-
let memory = self.constant_u32(self.span(), Scope::Device as u32);
1350+
let memory = self.constant_bit32(self.span(), Scope::Device as u32);
13511351
let semantics = self.ordering_to_semantics_def(order);
13521352
self.validate_atomic(val.ty, ptr.def(self));
13531353
self.emit()
@@ -1413,7 +1413,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
14131413
let original_ptr = ptr.def(self);
14141414
let indices = indices
14151415
.into_iter()
1416-
.map(|idx| self.constant_u32(self.span(), idx).def(self))
1416+
.map(|idx| self.constant_bit32(self.span(), idx).def(self))
14171417
.collect::<Vec<_>>();
14181418
return self
14191419
.emit()
@@ -1433,7 +1433,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
14331433
if idx > u32::MAX as u64 {
14341434
self.fatal("struct_gep bigger than u32::MAX");
14351435
}
1436-
let index_const = self.constant_u32(self.span(), idx as u32).def(self);
1436+
let index_const = self.constant_bit32(self.span(), idx as u32).def(self);
14371437
self.emit()
14381438
.access_chain(
14391439
result_type,
@@ -1741,7 +1741,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
17411741
) {
17421742
let indices = indices
17431743
.into_iter()
1744-
.map(|idx| self.constant_u32(self.span(), idx).def(self))
1744+
.map(|idx| self.constant_bit32(self.span(), idx).def(self))
17451745
.collect::<Vec<_>>();
17461746
self.emit()
17471747
.access_chain(dest_ty, None, ptr.def(self), indices)
@@ -2292,7 +2292,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
22922292

22932293
self.validate_atomic(access_ty, dst.def(self));
22942294
// TODO: Default to device scope
2295-
let memory = self.constant_u32(self.span(), Scope::Device as u32);
2295+
let memory = self.constant_bit32(self.span(), Scope::Device as u32);
22962296
let semantics_equal = self.ordering_to_semantics_def(order);
22972297
let semantics_unequal = self.ordering_to_semantics_def(failure_order);
22982298
// Note: OpAtomicCompareExchangeWeak is deprecated, and has the same semantics
@@ -2328,7 +2328,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
23282328
self.validate_atomic(access_ty, dst.def(self));
23292329
// TODO: Default to device scope
23302330
let memory = self
2331-
.constant_u32(self.span(), Scope::Device as u32)
2331+
.constant_bit32(self.span(), Scope::Device as u32)
23322332
.def(self);
23332333
let semantics = self.ordering_to_semantics_def(order).def(self);
23342334
use AtomicRmwBinOp::*;
@@ -2424,7 +2424,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
24242424
// Ignore sync scope (it only has "single thread" and "cross thread")
24252425
// TODO: Default to device scope
24262426
let memory = self
2427-
.constant_u32(self.span(), Scope::Device as u32)
2427+
.constant_bit32(self.span(), Scope::Device as u32)
24282428
.def(self);
24292429
let semantics = self.ordering_to_semantics_def(order).def(self);
24302430
self.emit().memory_barrier(memory, semantics).unwrap();
@@ -2697,7 +2697,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
26972697

26982698
// HACK(eddyb) avoid the logic below that assumes only ID operands
26992699
if inst.class.opcode == Op::CompositeExtract {
2700-
if let (Some(r), &[Operand::IdRef(x), Operand::LiteralInt32(i)]) =
2700+
if let (Some(r), &[Operand::IdRef(x), Operand::LiteralBit32(i)]) =
27012701
(inst.result_id, &inst.operands[..])
27022702
{
27032703
return Some(Inst::CompositeExtract(r, x, i));

crates/rustc_codegen_spirv/src/builder/byte_addressable_buffer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
3131
constant_offset: u32,
3232
) -> SpirvValue {
3333
let actual_index = if constant_offset != 0 {
34-
let const_offset_val = self.constant_u32(DUMMY_SP, constant_offset);
34+
let const_offset_val = self.constant_bit32(DUMMY_SP, constant_offset);
3535
self.add(dynamic_index, const_offset_val)
3636
} else {
3737
dynamic_index
@@ -199,7 +199,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
199199
// Note that the &[u32] gets split into two arguments - pointer, length
200200
let array = args[0];
201201
let byte_index = args[2];
202-
let two = self.constant_u32(DUMMY_SP, 2);
202+
let two = self.constant_bit32(DUMMY_SP, 2);
203203
let word_index = self.lshr(byte_index, two);
204204
self.recurse_load_type(result_type, result_type, array, word_index, 0)
205205
}
@@ -223,7 +223,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
223223
value: SpirvValue,
224224
) -> Result<(), ErrorGuaranteed> {
225225
let actual_index = if constant_offset != 0 {
226-
let const_offset_val = self.constant_u32(DUMMY_SP, constant_offset);
226+
let const_offset_val = self.constant_bit32(DUMMY_SP, constant_offset);
227227
self.add(dynamic_index, const_offset_val)
228228
} else {
229229
dynamic_index
@@ -367,7 +367,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
367367
// Note that the &[u32] gets split into two arguments - pointer, length
368368
let array = args[0];
369369
let byte_index = args[2];
370-
let two = self.constant_u32(DUMMY_SP, 2);
370+
let two = self.constant_bit32(DUMMY_SP, 2);
371371
let word_index = self.lshr(byte_index, two);
372372
if is_pair {
373373
let value_one = args[3];

0 commit comments

Comments
 (0)