nil: Add Extent/Offset4D::new() helpers

We're about to add a PhantomData to Extent/Offset4D and that'll make it
harder to construct.  Adding a helper lets us more easily construct them
elsewhere in the code.

Reviewed-by: Lina Versace <linyaa@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28639>
This commit is contained in:
Faith Ekstrand
2024-04-08 14:55:20 -05:00
committed by Marge Bot
parent 8f65ecac21
commit bc0de7a2cf
5 changed files with 41 additions and 49 deletions
+14
View File
@@ -31,6 +31,20 @@ pub extern "C" fn nil_extent4d(
}
impl Extent4D {
pub fn new(
width: u32,
height: u32,
depth: u32,
array_len: u32,
) -> Extent4D {
Extent4D {
width,
height,
depth,
array_len,
}
}
pub fn size(&self) -> u32 {
self.width * self.height * self.depth
}
+1 -6
View File
@@ -47,12 +47,7 @@ impl Format {
pub(crate) fn el_extent_sa(&self) -> Extent4D {
let desc = self.description();
Extent4D {
width: desc.block.width,
height: desc.block.height,
depth: desc.block.depth,
array_len: 1,
}
Extent4D::new(desc.block.width, desc.block.height, desc.block.depth, 1)
}
pub(crate) fn info(&self) -> &nil_format_info {
+6 -13
View File
@@ -55,20 +55,13 @@ impl SampleLayout {
}
pub fn px_extent_sa(&self) -> Extent4D {
let (width, height) = match self {
SampleLayout::_1x1 => (1, 1),
SampleLayout::_2x1 => (2, 1),
SampleLayout::_2x2 => (2, 2),
SampleLayout::_4x2 => (4, 2),
SampleLayout::_4x4 => (4, 4),
match self {
SampleLayout::_1x1 => Extent4D::new(1, 1, 1, 1),
SampleLayout::_2x1 => Extent4D::new(2, 1, 1, 1),
SampleLayout::_2x2 => Extent4D::new(2, 2, 1, 1),
SampleLayout::_4x2 => Extent4D::new(4, 2, 1, 1),
SampleLayout::_4x4 => Extent4D::new(4, 4, 1, 1),
SampleLayout::Invalid => panic!("Invalid sample layout"),
};
Extent4D {
width,
height,
depth: 1,
array_len: 1,
}
}
+2 -7
View File
@@ -212,13 +212,7 @@ fn nil_rs_max_mip_level(image: &Image, view: &View) -> u32 {
}
fn normalize_extent(image: &Image, view: &View) -> Extent4D {
let mut extent = Extent4D {
width: image.extent_px.width,
height: image.extent_px.height,
depth: 0,
array_len: 0,
};
let mut extent = image.extent_px;
match view.view_type {
ViewType::_1D
| ViewType::_2D
@@ -241,6 +235,7 @@ fn normalize_extent(image: &Image, view: &View) -> Extent4D {
extent.depth = view.array_len;
}
}
extent.array_len = 0;
extent
}
+18 -23
View File
@@ -1,7 +1,7 @@
// Copyright © 2024 Collabora, Ltd.
// SPDX-License-Identifier: MIT
use crate::extent::{nil_extent4d, Extent4D};
use crate::extent::Extent4D;
use crate::format::Format;
use crate::image::{
ImageDim, ImageUsageFlags, SampleLayout, IMAGE_USAGE_2D_VIEW_BIT,
@@ -76,20 +76,15 @@ impl Tiling {
pub fn extent_B(&self) -> Extent4D {
if self.is_tiled {
Extent4D {
width: GOB_WIDTH_B << self.x_log2,
height: gob_height(self.gob_height_is_8) << self.y_log2,
depth: GOB_DEPTH << self.z_log2,
array_len: 1,
}
Extent4D::new(
GOB_WIDTH_B << self.x_log2,
gob_height(self.gob_height_is_8) << self.y_log2,
GOB_DEPTH << self.z_log2,
1,
)
} else {
// We handle linear images in Image::new()
Extent4D {
width: 1,
height: 1,
depth: 1,
array_len: 1,
}
Extent4D::new(1, 1, 1, 1)
}
}
}
@@ -101,19 +96,19 @@ pub fn sparse_block_extent_el(format: Format, dim: ImageDim) -> Extent4D {
// Image Block Shapes".
match dim {
ImageDim::_2D => match bits {
8 => nil_extent4d(256, 256, 1, 1),
16 => nil_extent4d(256, 128, 1, 1),
32 => nil_extent4d(128, 128, 1, 1),
64 => nil_extent4d(128, 64, 1, 1),
128 => nil_extent4d(64, 64, 1, 1),
8 => Extent4D::new(256, 256, 1, 1),
16 => Extent4D::new(256, 128, 1, 1),
32 => Extent4D::new(128, 128, 1, 1),
64 => Extent4D::new(128, 64, 1, 1),
128 => Extent4D::new(64, 64, 1, 1),
other => panic!("Invalid texel size {other}"),
},
ImageDim::_3D => match bits {
8 => nil_extent4d(64, 32, 32, 1),
16 => nil_extent4d(32, 32, 32, 1),
32 => nil_extent4d(32, 32, 16, 1),
64 => nil_extent4d(32, 16, 16, 1),
128 => nil_extent4d(16, 16, 16, 1),
8 => Extent4D::new(64, 32, 32, 1),
16 => Extent4D::new(32, 32, 32, 1),
32 => Extent4D::new(32, 32, 16, 1),
64 => Extent4D::new(32, 16, 16, 1),
128 => Extent4D::new(16, 16, 16, 1),
_ => panic!("Invalid texel size"),
},
_ => panic!("Invalid sparse image dimension"),