nak: Implement From for SrcRef for more types

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
This commit is contained in:
Faith Ekstrand 2023-09-30 01:53:38 -05:00 committed by Marge Bot
parent 0d725cccbd
commit a4c1ec3892

View file

@ -837,6 +837,32 @@ impl SrcRef {
}
}
impl From<bool> for SrcRef {
fn from(b: bool) -> SrcRef {
if b {
SrcRef::True
} else {
SrcRef::False
}
}
}
impl From<u32> for SrcRef {
fn from(u: u32) -> SrcRef {
if u == 0 {
SrcRef::Zero
} else {
SrcRef::Imm32(u)
}
}
}
impl From<f32> for SrcRef {
fn from(f: f32) -> SrcRef {
f.to_bits().into()
}
}
impl From<CBufRef> for SrcRef {
fn from(cb: CBufRef) -> SrcRef {
SrcRef::CBuf(cb)
@ -966,11 +992,11 @@ impl Src {
}
pub fn new_imm_u32(u: u32) -> Src {
SrcRef::Imm32(u).into()
u.into()
}
pub fn new_imm_bool(b: bool) -> Src {
Src::from(if b { SrcRef::True } else { SrcRef::False })
b.into()
}
pub fn fabs(&self) -> Src {