SPIR-V doesnt like mismatched enums
This commit is contained in:
parent
7ebed27d4a
commit
31ce07e079
1 changed files with 57 additions and 12 deletions
|
|
@ -69,10 +69,55 @@ impl PixelFormat {
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub enum Pixels {
|
pub struct Pixels {
|
||||||
U8(Ptr<u8>),
|
ptr: Ptr<u8>,
|
||||||
F16(Ptr<u16>),
|
format: PixelFormat,
|
||||||
F32(Ptr<f32>),
|
}
|
||||||
|
|
||||||
|
impl Pixels {
|
||||||
|
pub fn new_u8(ptr: Ptr<u8>) -> Self {
|
||||||
|
Self {
|
||||||
|
ptr,
|
||||||
|
format: PixelFormat::U8,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_f16(ptr: Ptr<u16>) -> Self {
|
||||||
|
Self {
|
||||||
|
ptr: Ptr::from_raw(ptr.as_raw() as *const u8),
|
||||||
|
format: PixelFormat::F16,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_f32(ptr: Ptr<f32>) -> Self {
|
||||||
|
Self {
|
||||||
|
ptr: Ptr::from_raw(ptr.as_raw() as *const u8),
|
||||||
|
format: PixelFormat::F32,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn read_u8(&self, byte_offset: usize) -> u8 {
|
||||||
|
unsafe { *self.ptr.as_raw().add(byte_offset) }
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn read_f16(&self, elem_offset: usize) -> u16 {
|
||||||
|
let byte_offset = elem_offset * 2;
|
||||||
|
unsafe { *(self.ptr.as_raw().add(byte_offset) as *const u16) }
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn read_f32(&self, elem_offset: usize) -> f32 {
|
||||||
|
let byte_offset = elem_offset * 4;
|
||||||
|
unsafe { *(self.ptr.as_raw().add(byte_offset) as *const f32) }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unsure if ill need this
|
||||||
|
// pub unsafe fn read(&self, offset: usize) -> Float {
|
||||||
|
// match self.format {
|
||||||
|
// PixelFormat::U8 => unsafe { self.read_u8(offset) as Float / 255.0 },
|
||||||
|
// PixelFormat::F16 => unsafe { f16_to_f32_software(self.read_f16(offset)) },
|
||||||
|
// PixelFormat::F32 => unsafe { self.read_f32(offset) },
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
|
@ -170,18 +215,18 @@ impl ImageAccess for DeviceImage {
|
||||||
return 0.;
|
return 0.;
|
||||||
}
|
}
|
||||||
|
|
||||||
let offset = self.pixel_offset(p) + c as u32;
|
let offset = (self.pixel_offset(p) + c as u32) as usize;
|
||||||
unsafe {
|
unsafe {
|
||||||
match self.pixels {
|
match self.pixels.format {
|
||||||
Pixels::U8(ptr) => {
|
PixelFormat::U8 => {
|
||||||
let raw_val = *ptr.add(offset as usize);
|
let raw_val = self.pixels.read_u8(offset);
|
||||||
self.base().encoding.to_linear_scalar(raw_val)
|
self.base.encoding.to_linear_scalar(raw_val)
|
||||||
}
|
}
|
||||||
Pixels::F16(ptr) => {
|
PixelFormat::F16 => {
|
||||||
let raw_val = *ptr.add(offset as usize);
|
let raw_val = self.pixels.read_f16(offset);
|
||||||
f16_to_f32_software(raw_val)
|
f16_to_f32_software(raw_val)
|
||||||
}
|
}
|
||||||
Pixels::F32(ptr) => *ptr.add(offset as usize),
|
PixelFormat::F32 => self.pixels.read_f32(offset),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue