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

update rspirv 0.11 to 0.12 #1118

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Changed 🛠
- [PR#1118](https://github.com/EmbarkStudios/rust-gpu/pull/1118) update rspirv to 0.12
- added support for `VK_KHR_fragment_shader_barycentric` with `bary_coord`/`bary_coord_no_persp` buildins
- [PR#1127](https://github.com/EmbarkStudios/rust-gpu/pull/1127) updated `spirv-tools` to `0.10.0`, which follows `vulkan-sdk-1.3.275`
- [PR#1101](https://github.com/EmbarkStudios/rust-gpu/pull/1101) added `ignore` and `no_run` to documentation to make `cargo test` pass
- [PR#1112](https://github.com/EmbarkStudios/rust-gpu/pull/1112) updated wgpu and winit in example runners
Expand Down
36 changes: 5 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/rustc_codegen_spirv-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ license.workspace = true
repository.workspace = true

[dependencies]
rspirv = "0.11"
rspirv = "0.12"
serde = { version = "1.0", features = ["derive"] }
2 changes: 1 addition & 1 deletion crates/rustc_codegen_spirv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ regex = { version = "1", features = ["perf"] }
ar = "0.9.0"
either = "1.8.0"
indexmap = "1.6.0"
rspirv = "0.11"
rspirv = "0.12"
rustc_codegen_spirv-types.workspace = true
rustc-demangle = "0.1.21"
sanitize-filename = "0.4"
Expand Down
30 changes: 26 additions & 4 deletions crates/rustc_codegen_spirv/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use crate::attr::{AggregatedSpirvAttributes, IntrinsicType};
use crate::codegen_cx::CodegenCx;
use crate::spirv_type::SpirvType;
use rspirv::spirv::{StorageClass, Word};
use rspirv::spirv::{Dim, ImageFormat, StorageClass, Word};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::ErrorGuaranteed;
use rustc_index::Idx;
Expand Down Expand Up @@ -647,7 +647,7 @@ fn trans_aggregate<'tcx>(cx: &CodegenCx<'tcx>, span: Span, ty: TyAndLayout<'tcx>
// spir-v doesn't support zero-sized arrays
create_zst(cx, span, ty)
} else {
let count_const = cx.constant_u32(span, count as u32);
let count_const = cx.constant_bit32(span, count as u32);
let element_spv = cx.lookup_type(element_type);
let stride_spv = element_spv
.sizeof(cx)
Expand Down Expand Up @@ -856,13 +856,35 @@ fn trans_intrinsic_type<'tcx>(
// let image_format: spirv::ImageFormat =
// type_from_variant_discriminant(cx, args.const_at(6));

fn const_int_value<'tcx, P: FromPrimitive>(
trait FromU128Const: Sized {
fn from_u128_const(n: u128) -> Option<Self>;
}

impl FromU128Const for u32 {
fn from_u128_const(n: u128) -> Option<Self> {
u32::from_u128(n)
}
}

impl FromU128Const for Dim {
fn from_u128_const(n: u128) -> Option<Self> {
Dim::from_u32(u32::from_u128(n)?)
}
}

impl FromU128Const for ImageFormat {
fn from_u128_const(n: u128) -> Option<Self> {
ImageFormat::from_u32(u32::from_u128(n)?)
}
}

fn const_int_value<'tcx, P: FromU128Const>(
cx: &CodegenCx<'tcx>,
const_: Const<'tcx>,
) -> Result<P, ErrorGuaranteed> {
assert!(const_.ty().is_integral());
let value = const_.eval_bits(cx.tcx, ParamEnv::reveal_all());
match P::from_u128(value) {
match P::from_u128_const(value) {
Some(v) => Ok(v),
None => Err(cx
.tcx
Expand Down
40 changes: 20 additions & 20 deletions crates/rustc_codegen_spirv/src/builder/builder_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
| MemorySemantics::SEQUENTIALLY_CONSISTENT
}
};
let semantics = self.constant_u32(self.span(), semantics.bits());
let semantics = self.constant_bit32(self.span(), semantics.bits());
if invalid_seq_cst {
self.zombie(
semantics.def(self),
Expand All @@ -196,10 +196,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
.constant_u16(self.span(), memset_fill_u16(fill_byte))
.def(self),
32 => self
.constant_u32(self.span(), memset_fill_u32(fill_byte))
.constant_bit32(self.span(), memset_fill_u32(fill_byte))
.def(self),
64 => self
.constant_u64(self.span(), memset_fill_u64(fill_byte))
.constant_bit64(self.span(), memset_fill_u64(fill_byte))
.def(self),
_ => self.fatal(format!(
"memset on integer width {width} not implemented yet"
Expand Down Expand Up @@ -314,7 +314,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
self.store(pat, ptr, Align::from_bytes(0).unwrap());
} else {
for index in 0..count {
let const_index = self.constant_u32(self.span(), index as u32);
let const_index = self.constant_bit32(self.span(), index as u32);
let gep_ptr = self.gep(pat.ty, ptr, &[const_index]);
self.store(pat, gep_ptr, Align::from_bytes(0).unwrap());
}
Expand Down Expand Up @@ -428,7 +428,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
} else {
let indices = indices
.into_iter()
.map(|idx| self.constant_u32(self.span(), idx).def(self))
.map(|idx| self.constant_bit32(self.span(), idx).def(self))
.collect::<Vec<_>>();
self.emit()
.access_chain(leaf_ptr_ty, None, ptr.def(self), indices)
Expand Down Expand Up @@ -904,9 +904,9 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
))
} else if signed {
// this cast chain can probably be collapsed, but, whatever, be safe
Operand::LiteralInt32(v as u8 as i8 as i32 as u32)
Operand::LiteralBit32(v as u8 as i8 as i32 as u32)
} else {
Operand::LiteralInt32(v as u8 as u32)
Operand::LiteralBit32(v as u8 as u32)
}
}
fn construct_16(self_: &Builder<'_, '_>, signed: bool, v: u128) -> Operand {
Expand All @@ -915,9 +915,9 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
"Switches to values above u16::MAX not supported: {v:?}"
))
} else if signed {
Operand::LiteralInt32(v as u16 as i16 as i32 as u32)
Operand::LiteralBit32(v as u16 as i16 as i32 as u32)
} else {
Operand::LiteralInt32(v as u16 as u32)
Operand::LiteralBit32(v as u16 as u32)
}
}
fn construct_32(self_: &Builder<'_, '_>, _signed: bool, v: u128) -> Operand {
Expand All @@ -926,7 +926,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
"Switches to values above u32::MAX not supported: {v:?}"
))
} else {
Operand::LiteralInt32(v as u32)
Operand::LiteralBit32(v as u32)
}
}
fn construct_64(self_: &Builder<'_, '_>, _signed: bool, v: u128) -> Operand {
Expand All @@ -935,7 +935,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
"Switches to values above u64::MAX not supported: {v:?}"
))
} else {
Operand::LiteralInt64(v as u64)
Operand::LiteralBit64(v as u64)
}
}
// pass in signed into the closure to be able to unify closure types
Expand Down Expand Up @@ -1217,7 +1217,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
let (ptr, access_ty) = self.adjust_pointer_for_typed_access(ptr, ty);

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

// TODO: Default to device scope
let memory = self.constant_u32(self.span(), Scope::Device as u32);
let memory = self.constant_bit32(self.span(), Scope::Device as u32);
let semantics = self.ordering_to_semantics_def(order);
self.validate_atomic(val.ty, ptr.def(self));
self.emit()
Expand Down Expand Up @@ -1413,7 +1413,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
let original_ptr = ptr.def(self);
let indices = indices
.into_iter()
.map(|idx| self.constant_u32(self.span(), idx).def(self))
.map(|idx| self.constant_bit32(self.span(), idx).def(self))
.collect::<Vec<_>>();
return self
.emit()
Expand All @@ -1433,7 +1433,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
if idx > u32::MAX as u64 {
self.fatal("struct_gep bigger than u32::MAX");
}
let index_const = self.constant_u32(self.span(), idx as u32).def(self);
let index_const = self.constant_bit32(self.span(), idx as u32).def(self);
self.emit()
.access_chain(
result_type,
Expand Down Expand Up @@ -1741,7 +1741,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
) {
let indices = indices
.into_iter()
.map(|idx| self.constant_u32(self.span(), idx).def(self))
.map(|idx| self.constant_bit32(self.span(), idx).def(self))
.collect::<Vec<_>>();
self.emit()
.access_chain(dest_ty, None, ptr.def(self), indices)
Expand Down Expand Up @@ -2292,7 +2292,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {

self.validate_atomic(access_ty, dst.def(self));
// TODO: Default to device scope
let memory = self.constant_u32(self.span(), Scope::Device as u32);
let memory = self.constant_bit32(self.span(), Scope::Device as u32);
let semantics_equal = self.ordering_to_semantics_def(order);
let semantics_unequal = self.ordering_to_semantics_def(failure_order);
// Note: OpAtomicCompareExchangeWeak is deprecated, and has the same semantics
Expand Down Expand Up @@ -2328,7 +2328,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
self.validate_atomic(access_ty, dst.def(self));
// TODO: Default to device scope
let memory = self
.constant_u32(self.span(), Scope::Device as u32)
.constant_bit32(self.span(), Scope::Device as u32)
.def(self);
let semantics = self.ordering_to_semantics_def(order).def(self);
use AtomicRmwBinOp::*;
Expand Down Expand Up @@ -2424,7 +2424,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
// Ignore sync scope (it only has "single thread" and "cross thread")
// TODO: Default to device scope
let memory = self
.constant_u32(self.span(), Scope::Device as u32)
.constant_bit32(self.span(), Scope::Device as u32)
.def(self);
let semantics = self.ordering_to_semantics_def(order).def(self);
self.emit().memory_barrier(memory, semantics).unwrap();
Expand Down Expand Up @@ -2697,7 +2697,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {

// HACK(eddyb) avoid the logic below that assumes only ID operands
if inst.class.opcode == Op::CompositeExtract {
if let (Some(r), &[Operand::IdRef(x), Operand::LiteralInt32(i)]) =
if let (Some(r), &[Operand::IdRef(x), Operand::LiteralBit32(i)]) =
(inst.result_id, &inst.operands[..])
{
return Some(Inst::CompositeExtract(r, x, i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
constant_offset: u32,
) -> SpirvValue {
let actual_index = if constant_offset != 0 {
let const_offset_val = self.constant_u32(DUMMY_SP, constant_offset);
let const_offset_val = self.constant_bit32(DUMMY_SP, constant_offset);
self.add(dynamic_index, const_offset_val)
} else {
dynamic_index
Expand Down Expand Up @@ -199,7 +199,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// Note that the &[u32] gets split into two arguments - pointer, length
let array = args[0];
let byte_index = args[2];
let two = self.constant_u32(DUMMY_SP, 2);
let two = self.constant_bit32(DUMMY_SP, 2);
let word_index = self.lshr(byte_index, two);
self.recurse_load_type(result_type, result_type, array, word_index, 0)
}
Expand All @@ -223,7 +223,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
value: SpirvValue,
) -> Result<(), ErrorGuaranteed> {
let actual_index = if constant_offset != 0 {
let const_offset_val = self.constant_u32(DUMMY_SP, constant_offset);
let const_offset_val = self.constant_bit32(DUMMY_SP, constant_offset);
self.add(dynamic_index, const_offset_val)
} else {
dynamic_index
Expand Down Expand Up @@ -367,7 +367,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// Note that the &[u32] gets split into two arguments - pointer, length
let array = args[0];
let byte_index = args[2];
let two = self.constant_u32(DUMMY_SP, 2);
let two = self.constant_bit32(DUMMY_SP, 2);
let word_index = self.lshr(byte_index, two);
if is_pair {
let value_one = args[3];
Expand Down
Loading