Skip to content
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
11 changes: 11 additions & 0 deletions crates/rustc_codegen_spirv/src/builder/builder_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
64 => self
.constant_u64(self.span(), memset_fill_u64(fill_byte))
.def(self),
128 => {
// NOTE: This is a quick solution to support the following case from issue #594:
// pub fn new_array_zero_fill_u128() -> [u128; 4] {
// return [0; 4];
// }
// This may be replaced by a more general memset fill solution in the future.
if fill_byte != 0 {
self.fatal("non-zero u128 array fill not implemented yet")
}
self.constant_u128(self.span(), 0_u128).def(self)
}
_ => self.fatal(format!(
"memset on integer width {width} not implemented yet"
)),
Expand Down
4 changes: 4 additions & 0 deletions crates/rustc_codegen_spirv/src/codegen_cx/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ impl<'tcx> CodegenCx<'tcx> {
self.constant_int_from_native_unsigned(span, val)
}

pub fn constant_u128(&self, span: Span, val: u128) -> SpirvValue {
self.constant_int_from_native_unsigned(span, val)
}

fn constant_int_from_native_unsigned(&self, span: Span, val: impl Into<u128>) -> SpirvValue {
let size = Size::from_bytes(std::mem::size_of_val(&val));
let ty = SpirvType::Integer(size.bits() as u32, false).def(span, self);
Expand Down
Comment thread
brody2consult marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Test creating a new u128 array with zero fill.

// build-pass

use spirv_std::spirv;

pub fn new_array_zero_fill_u128() -> [u128; 4] {
return [0; 4];
}

#[spirv(fragment)]
pub fn main() {
// TODO: enable the following once the "unsupported constant" of type u128 is resolved:
// let _ = new_array_zero_fill_u128();
}