Skip to content

Commit 34b768e

Browse files
39aliFirestar99
authored andcommitted
add memset const and dynamic support for f16
1 parent 25efe12 commit 34b768e

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

crates/rustc_codegen_spirv/src/builder/builder_methods.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
418418
)),
419419
},
420420
SpirvType::Float(width) => match width {
421+
16 => {
422+
let ty = SpirvType::Float(16).def(self.span(), self);
423+
self.def_constant(ty, SpirvConst::Scalar(memset_fill_u16(fill_byte) as u128))
424+
.def(self)
425+
}
421426
32 => self
422427
.constant_f32(self.span(), f32::from_bits(memset_fill_u32(fill_byte)))
423428
.def(self),
@@ -472,6 +477,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
472477
)),
473478
},
474479
SpirvType::Float(width) => match width {
480+
16 => memset_dynamic_scalar(self, fill_var, 2, true),
475481
32 => memset_dynamic_scalar(self, fill_var, 4, true),
476482
64 => memset_dynamic_scalar(self, fill_var, 8, true),
477483
_ => self.fatal(format!("memset on float width {width} not implemented yet")),
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// build-pass
2+
// compile-flags: -C target-feature=+Float16
3+
#![feature(f16)]
4+
5+
use spirv_std::num_traits::Float;
6+
use spirv_std::spirv;
7+
8+
#[spirv(fragment)]
9+
pub fn main(#[spirv(flat)] i: u32, o: &mut f32) {
10+
let a = [0.123f16; 16];
11+
*o = a[i as usize] as f32;
12+
}

0 commit comments

Comments
 (0)