nak: Handle non-DW-aligned UBO loads

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26348>
This commit is contained in:
Faith Ekstrand 2023-11-23 21:38:42 -06:00 committed by Faith Ekstrand
parent ed535c9d98
commit bda208665f
2 changed files with 21 additions and 5 deletions

View file

@ -2010,9 +2010,24 @@ impl<'a> ShaderFromNir<'a> {
offset: off_imm.try_into().unwrap(),
};
if off.is_zero() {
if off_imm % 4 == 0 {
for (i, comp) in dst.iter().enumerate() {
let i = u16::try_from(i).unwrap();
b.copy_to((*comp).into(), cb.offset(i * 4).into());
let i = i16::try_from(i).unwrap();
b.copy_to(
(*comp).into(),
cb.offset(i * 4).into(),
);
}
} else {
let delta: u8 = (off_imm % 4).try_into().unwrap();
let aligned_cb = cb.offset(-i16::from(delta));
let tmp = b.copy(aligned_cb.into());
let prmt = match size_B {
1 => [delta, 4, 4, 4],
2 => [delta, delta + 1, 4, 4],
_ => panic!("Invalid load_ubo"),
};
b.prmt_to(dst.into(), tmp.into(), 0.into(), prmt);
}
} else {
b.push_op(OpLdc {

View file

@ -742,10 +742,11 @@ pub struct CBufRef {
}
impl CBufRef {
pub fn offset(self, offset: u16) -> CBufRef {
pub fn offset(self, offset: i16) -> CBufRef {
CBufRef {
buf: self.buf,
offset: self.offset + offset,
offset: (i32::from(self.offset) +
i32::from(offset)).try_into().unwrap(),
}
}
}