mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 22:38:05 +02:00
nil: Add a nil_sample_offset() helper
Fixes: 8f1697b12d ("nil: Use D3D sample modes by default")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31727>
This commit is contained in:
parent
6e30ab8b16
commit
9724028c15
2 changed files with 49 additions and 0 deletions
|
|
@ -30,6 +30,7 @@ renaming_overrides_prefixing = true
|
|||
"ImageLevel" = "nil_image_level"
|
||||
"Offset4D" = "nil_offset4d"
|
||||
"SampleLayout" = "nil_sample_layout"
|
||||
"SampleOffset" = "nil_sample_offset"
|
||||
"Tiling" = "nil_tiling"
|
||||
"View" = "nil_view"
|
||||
"ViewType" = "nil_view_type"
|
||||
|
|
|
|||
|
|
@ -40,6 +40,12 @@ pub enum SampleLayout {
|
|||
Invalid,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct SampleOffset {
|
||||
pub x: u8,
|
||||
pub y: u8,
|
||||
}
|
||||
|
||||
impl SampleLayout {
|
||||
#[no_mangle]
|
||||
pub extern "C" fn nil_choose_sample_layout(samples: u32) -> SampleLayout {
|
||||
|
|
@ -92,6 +98,48 @@ impl SampleLayout {
|
|||
pub extern "C" fn nil_px_extent_sa(self) -> Extent4D<units::Samples> {
|
||||
self.px_extent_sa()
|
||||
}
|
||||
|
||||
pub fn sa_offset(&self, s: u8) -> SampleOffset {
|
||||
let (x, y) = match self {
|
||||
SampleLayout::_1x1 => (0, 0),
|
||||
SampleLayout::_2x1 => {
|
||||
debug_assert!(s < 2);
|
||||
(s, 0)
|
||||
}
|
||||
SampleLayout::_2x1D3d => {
|
||||
debug_assert!(s < 2);
|
||||
(1 - s, 0)
|
||||
}
|
||||
SampleLayout::_2x2 => {
|
||||
debug_assert!(s < 4);
|
||||
(s & 1, s >> 1)
|
||||
}
|
||||
SampleLayout::_4x2 => {
|
||||
debug_assert!(s < 8);
|
||||
(s & 3, s >> 2)
|
||||
}
|
||||
SampleLayout::_4x2D3d => match s {
|
||||
0 => (2, 0),
|
||||
1 => (1, 1),
|
||||
2 => (3, 1),
|
||||
3 => (1, 0),
|
||||
4 => (0, 1),
|
||||
5 => (0, 0),
|
||||
6 => (2, 1),
|
||||
7 => (3, 0),
|
||||
_ => panic!("Invalid sample"),
|
||||
},
|
||||
SampleLayout::_4x4 => todo!("Figure out the layout of 4x4"),
|
||||
SampleLayout::Invalid => panic!("Invalid sample layout"),
|
||||
};
|
||||
|
||||
SampleOffset { x, y }
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn nil_sample_offset(self, s: u8) -> SampleOffset {
|
||||
self.sa_offset(s)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Copy, PartialEq)]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue