From bc0de7a2cf71d50cd2e777385082ac6cab1a1e71 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Mon, 8 Apr 2024 14:55:20 -0500 Subject: [PATCH] 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 Part-of: --- src/nouveau/nil/extent.rs | 14 +++++++++++++ src/nouveau/nil/format.rs | 7 +------ src/nouveau/nil/image.rs | 19 ++++++------------ src/nouveau/nil/tic.rs | 9 ++------- src/nouveau/nil/tiling.rs | 41 +++++++++++++++++---------------------- 5 files changed, 41 insertions(+), 49 deletions(-) diff --git a/src/nouveau/nil/extent.rs b/src/nouveau/nil/extent.rs index 221f8de41a6..3b53c31176a 100644 --- a/src/nouveau/nil/extent.rs +++ b/src/nouveau/nil/extent.rs @@ -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 } diff --git a/src/nouveau/nil/format.rs b/src/nouveau/nil/format.rs index 0cbe38480e5..323e4a6c23e 100644 --- a/src/nouveau/nil/format.rs +++ b/src/nouveau/nil/format.rs @@ -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 { diff --git a/src/nouveau/nil/image.rs b/src/nouveau/nil/image.rs index c30b220d627..32502663102 100644 --- a/src/nouveau/nil/image.rs +++ b/src/nouveau/nil/image.rs @@ -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, } } diff --git a/src/nouveau/nil/tic.rs b/src/nouveau/nil/tic.rs index f7400ddc16b..e5350a53f09 100644 --- a/src/nouveau/nil/tic.rs +++ b/src/nouveau/nil/tic.rs @@ -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 } diff --git a/src/nouveau/nil/tiling.rs b/src/nouveau/nil/tiling.rs index fbd6631e3c1..06fd0d9a471 100644 --- a/src/nouveau/nil/tiling.rs +++ b/src/nouveau/nil/tiling.rs @@ -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"),